1 /* Copyright (C) 2012-2013 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.
25 // See mcp4922.pdf p. 24
27 // Bit 13: Output Gain Selection bit set = 1x (VOUT = VREF * D/4096)
28 // Bit 15: DACA (0) or DACB (1) Selection bit.
29 #define DAC1_INIT_VAL (_BV(13) )
30 #define DAC2_INIT_VAL (_BV(13) | _BV(15))
31 #define DAC3_INIT_VAL (_BV(13) )
32 #define DAC4_INIT_VAL (_BV(13) | _BV(15))
35 * Pin status for each DAC pin, the structure of each field is defined
36 * as spi command structure.
38 uint16_t dac_pin_stat[DAC_PIN_NUM] = {
46 * Port names for each DAC port, to be easily accessible by indexing
48 const char *dac_port_names[DAC_PIN_NUM] = {
58 static uint32_t dac_spi_cmd;
60 * Shadow variable of SPI command
62 static uint32_t dac_spi_cmd_sh;
64 int drv_dac_spi_transfer(uint8_t pin, boolean_t enabled, uint16_t value)
67 if (pin >= DAC_PIN_NUM)
76 bit_set(dac_pin_stat[pin], 12);
78 bit_clear(dac_pin_stat[pin], 12);
80 dac_pin_stat[pin] = dac_pin_stat[pin] & 0xF000;
81 dac_pin_stat[pin] |= (value & 0xFFF);
85 // Warning!!! Can be "optimized" by compiler
86 dac_spi_cmd = dac_pin_stat[pin];
87 dac_spi_cmd_sh = dac_spi_cmd;
90 desc = hal_port_get_dsc(dac_port_names[pin], -1);
91 commands[0] = (dac_spi_cmd_sh & 0xFF00) >> 8;
92 commands[1] = (dac_spi_cmd_sh & 0xFF);
94 return desc->port_setfnc_ptr(desc->config, desc->numValues, commands);