2 * Analog Output RPP API header file.
6 * @copyright Copyright (C) 2013 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
16 * DAC output operational amplifier multiplication constant.
18 #define RPP_DAC_OA 5.6
20 * DAC hardware reference voltage.
22 #define RPP_DAC_VREF 2.5
25 * DAC module initialization.
27 * Call this method before using this module.
29 * This function is not thread safe. Do not call it from multiple threads.
31 * @return SUCCESS if initialization successful.\n
32 * FAILURE if module already initialized.
34 int8_t rpp_dac_init();
38 * Configure enabled/disabled state for given pin.
40 * Call rpp_dac_update() to commit setup changes to real hardware.
42 * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
44 * @param[in] pin The pin number to setup [1-4].
45 * @param[in] enabled TRUE to enable pin or FALSE to disable it.
47 * @return SUCCESS if successful.\n
48 * -1 if pin number is out of range.
50 int8_t rpp_dac_setup(uint8_t pin, boolean_t enabled);
54 * Set the output cache of given pin to given value.
56 * Call rpp_dac_update() to flush cached values to real hardware.
58 * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
60 * @param[in] pin The pin number to set [1-4].
61 * @param[in] val The value to be set [0-4095] (DAC is 12bit resolution).
63 * @return SUCCESS when success.\n
64 * -1 if pin number is out of range.\n
65 * -2 if value is out of range.
67 * @note Due to hardware characteristics (operational amplifiers and voltage
68 * reference) the DAC outputs top 12V at arround 3510. To avoid confusion
69 * to the user and to support future changes the value given is mapped
70 * from [0-4095] to [0-3510] with the expected resolution loss.
72 int8_t rpp_dac_set(uint8_t pin, uint16_t val);
76 * Set output to given voltage.
78 * Helper function that calculates DAC value given a voltage in millivolts.
80 * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
82 * @param[in] pin The pin number to set [1-4].
83 * @param[in] mv Voltage level in mV to be set on specified pin [0-12000].
85 * @return SUCCESS when success.\n
86 * -1 if pin number is out of range.\n
87 * -2 if voltage is out of range.
89 int8_t rpp_dac_set_voltage(uint8_t pin, uint16_t mv);
93 * Flush cached output values and configuration changes.
95 * The function is thread safe, unless compiled with -DRPP_THREADSAFE=0
97 * @bug This function should be called only after the FreeRTOS Scheduler has
98 * started (which implies from a FreeRTOS Task). If called before starting the
99 * scheduler, like for library initialization, or application DAC
100 * initialization, the application will freeze. The cause of this is unknown at
103 * @return SUCCESS when transaction was successful.\n
104 * FAILURE if transaction could not be confirmed.
106 int8_t rpp_dac_update();
109 #endif /* __RPP_DAC_H */