1 /* Copyright (C) 2012-2015 Czech Technical University in Prague
5 * - Carlos Jenkins <carlos@jenkins.co.cr>
7 * This document contains proprietary information belonging to Czech
8 * Technical University in Prague. Passing on and copying of this
9 * document, and communication of its contents is not permitted
10 * without prior written authorization.
14 * RPP driver implementation for DAC.
27 * Pin status for each DAC pin, the structure of each field is defined
28 * as spi command structure.
30 * See mcp4922.pdf p. 24
32 * Bit 13: Output Gain Selection bit set = 1x (VOUT = VREF * D/4096)
33 * Bit 15: DACA (0) or DACB (1) Selection bit.
36 static uint16_t dac_pin_status[DAC_PIN_NUM] = {
44 * Port names for each DAC port, to be easily accessible by indexing
46 const char *dac_port_names[DAC_PIN_NUM] = {
56 static uint32_t dac_spi_cmd;
58 * Shadow variable of SPI command
60 static uint32_t dac_spi_cmd_sh;
62 int drv_dac_spi_transfer(uint8_t pin, boolean_t enabled, uint16_t value)
65 if (pin >= DAC_PIN_NUM)
74 bit_set(dac_pin_status[pin], 12);
76 bit_clear(dac_pin_status[pin], 12);
78 dac_pin_status[pin] = dac_pin_status[pin] & 0xF000;
79 dac_pin_status[pin] |= (value & 0xFFF);
83 // Warning!!! Can be "optimized" by compiler
84 dac_spi_cmd = dac_pin_status[pin];
85 dac_spi_cmd_sh = dac_spi_cmd;
87 dio_port_desc_t *desc;
88 desc = dio_port_get_dsc(dac_port_names[pin], -1);
89 commands[0] = (dac_spi_cmd_sh & 0xFF00) >> 8;
90 commands[1] = (dac_spi_cmd_sh & 0xFF);
92 return desc->port_setfnc_ptr(desc->config, desc->numValues, commands);