#define __DRV_ADC_H
#include "sys/ti_drv_adc.h"
+#include "drv/port.h"
#define ADC_MAX_CHANNELS 24
uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
uint32_t *values);
+int8_t port_adc_get(const struct port_desc *port, void *values, size_t size);
#endif /* __DRV_ADC_H */
*
* @file spi.h
*
- * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
*
*/
int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void *rx_buf);
//spi_drv_t *spi_find_drv(char *name, int number);
int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg);
+int8_t port_spi_set(const struct port_desc *port, void *values, size_t size);
#endif /* _SPI_DRV_H_ */
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
*
* Authors:
* - Michal Horn
#include "drv/drv.h"
+#include "drv/port.h"
// Binary semaphore for ADC1 GRP1 conversion (AIN)
xSemaphoreHandle adcSemaphore_ADC1GRP1;
return result;
}
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
- uint32_t *values)
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+int8_t port_adc_get(const struct port_desc *port, void *values, size_t size)
{
uint32_t i;
- adcBASE_t *adcReg = (adcBASE_t *)config[0];
- uint32_t adcGroup = config[1];
- uint32_t adcSemaphore = config[2];
adcData_t data[ADC_MAX_CHANNELS];
+ int count = MIN(port->numchn, size/sizeof(uint16_t));
+ uint16_t *adcval = values;
+
+ assert(port->bpch == 16);
+ assert(size % sizeof(uint16_t) == 0);
drv_adc_generic_read(
- adcReg,
- adcGroup,
- (adcSemaphore == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
+ port->cfg.adc.reg,
+ port->cfg.adc.group,
+ (port->cfg.adc.sem == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
data
);
- for (i = 0; i < num_channels; i++) {
- values[i] = data[i].value;
- values[i+num_channels] = data[i].id;
- }
+ for (i = 0; i < count; i++)
+ adcval[i] = data[i].value;
return 0;
}
return msg.rq_len;
}
+
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+int8_t port_spi_set(const struct port_desc *port, void *values, size_t size)
+{
+ spi_drv_t *ifc;
+ uint8_t rx[4];
+
+ assert(port->numchn == 1);
+ assert(size == port->bpch/8);
+ assert(size <= sizeof(rx));
+
+ ifc = spi_find_drv(NULL, port->cfg.spi.ifc);
+ if (ifc == NULL)
+ return FAILURE;
+
+ if (!(ifc->flags & SPI_IFC_ON))
+ return FAILURE;
+
+ spi_transfer(ifc, port->cfg.spi.cs, size, values, rx);
+
+ memcpy(values, rx, MIN(size, port->numchn * port->bpch/8));
+ return SUCCESS;
+}