1 /* Copyright (C) 2013, 2015 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
13 * Analog Input RPP API implementation file.
17 * RPP API documentation.
23 #ifndef FREERTOS_POSIX
27 static uint16_t in_cache[PORT_ADC_CHANNELS];
30 static boolean_t initialized = FALSE;
39 #ifndef FREERTOS_POSIX
47 int16_t rpp_adc_get(uint8_t pin)
49 if ((pin < 1) || (pin > PORT_ADC_CHANNELS))
54 #ifndef FREERTOS_POSIX
55 // This conversion uint16_t -> int16_t is safe because we know values
56 // are 12bits. Here we are masking those 12bits just in case.
57 result = in_cache[pin - 1] & 0xFFF;
64 int8_t rpp_adc_update()
66 #ifndef FREERTOS_POSIX
67 const struct port_desc *port = &port_desc[PORT_ID_ADC];
69 /* Thread safety is ensured in port_adc_get() resp.
70 * drv_adc_generic_read() */
71 port->get(port, in_cache, sizeof(in_cache));