0 | module Bindings.RtlSdr.Misc
 1 |
 2 | import Bindings.RtlSdr.Device
 3 | import Bindings.RtlSdr.Error
 4 | import Bindings.RtlSdr.Raw.Misc
 5 |
 6 | %default total
 7 |
 8 | data TunerType = RTLSDR_TUNER_UNKNOWN | RTLSDR_TUNER_E4000 | RTLSDR_TUNER_FC0012 | RTLSDR_TUNER_FC0013 | RTLSDR_TUNER_FC2580 | RTLSDR_TUNER_R820T | RTLSDR_TUNER_R828D
 9 |
10 | export
11 | Show TunerType where
12 |   show RTLSDR_TUNER_UNKNOWN = "Unknown"
13 |   show RTLSDR_TUNER_E4000   = "E4000"
14 |   show RTLSDR_TUNER_FC0012  = "FC0012"
15 |   show RTLSDR_TUNER_FC0013  = "FC0013"
16 |   show RTLSDR_TUNER_FC2580  = "FC2580"
17 |   show RTLSDR_TUNER_R820T   = "R820T"
18 |   show RTLSDR_TUNER_R828D   = "R828D"
19 |
20 | toTunerType : Int -> TunerType
21 | toTunerType 1 = RTLSDR_TUNER_E4000
22 | toTunerType 2 = RTLSDR_TUNER_FC0012
23 | toTunerType 3 = RTLSDR_TUNER_FC0013
24 | toTunerType 4 = RTLSDR_TUNER_FC2580
25 | toTunerType 5 = RTLSDR_TUNER_R820T
26 | toTunerType 6 = RTLSDR_TUNER_R828D
27 | toTunerType _ = RTLSDR_TUNER_UNKNOWN
28 |
29 | ||| Get the tuner type.
30 | |||
31 | ||| @h is the device handle
32 | export
33 | getTunerType : Ptr RtlSdrHandle -> TunerType
34 | getTunerType h = toTunerType $ get_tuner_type h
35 |
36 | ||| Enable or disable offset tuning for zero-IF tuners, which allows to avoid
37 | ||| problems caused by the DC offset of the ADCs and 1/f noise.
38 | |||
39 | ||| @h is the device handle
40 | ||| @t toggles where False means disabled and True means enabled
41 | export
42 | setOffsetTuning : Ptr RtlSdrHandle -> Bool -> IO (Either RTLSDR_ERROR ())
43 | setOffsetTuning h t = do
44 |   r <- fromPrim $ set_offset_tuning h (if t == False then 0 else 1)
45 |   io_pure $ if r == 0 then Right () else Left RtlSdrError
46 |
47 | ||| Get state of the offset tuning mode
48 | |||
49 | ||| @h is the device handle
50 | export
51 | getOffsetTuning : Ptr RtlSdrHandle -> IO (Either RTLSDR_ERROR Bool)
52 | getOffsetTuning h = do
53 |   r <- fromPrim $ get_offset_tuning h
54 |   io_pure $ if r < 0 then Left RtlSdrError else Right (if r == 0 then False else True)
55 |
56 |
57 | ||| Enable or disable the bias tee on GPIO PIN 0.
58 | |||
59 | ||| @h is the device handle
60 | ||| @t is the toggle of `True` for Bias T on. `False` for Bias T off.
61 | export
62 | setBiasTee : Ptr RtlSdrHandle -> Bool -> IO (Either RTLSDR_ERROR ())
63 | setBiasTee h t = do
64 |   r <- fromPrim $ set_bias_tee h (if t == True then 1 else 0)
65 |   io_pure $ if r == 0 then Right () else Left RtlSdrError
66 |
67 | ||| Enable or disable the bias tee on the given GPIO pin.
68 | |||
69 | ||| @h is the device handle
70 | ||| @g is the gpio pin to configure as a Bias T control.
71 | ||| @t is the toggle of `True` for Bias T on. `False` for Bias T off.
72 | export
73 | setBiasTeeGpio : Ptr RtlSdrHandle -> Nat -> Bool -> IO (Either RTLSDR_ERROR ())
74 | setBiasTeeGpio h g t = do
75 |   r <- fromPrim $ set_bias_tee_gpio h (cast {to = Int} g) (if t == True then 1 else 0)
76 |   io_pure $ if r == 0 then Right () else Left RtlSdrError
77 |