-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2015 Czech Technical University in Prague
*
* Authors:
* - Michal Horn
* - Carlos Jenkins <carlos@jenkins.co.cr>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
*
* File : dac.c
* Abstract:
#define DAC_PIN_NUM 4
-// See mcp4922.pdf p. 24
-// Options:
-// Bit 13: Output Gain Selection bit set = 1x (VOUT = VREF * D/4096)
-// Bit 15: DACA (0) or DACB (1) Selection bit.
-#define DAC1_INIT_VAL (_BV(13) )
-#define DAC2_INIT_VAL (_BV(13) | _BV(15))
-#define DAC3_INIT_VAL (_BV(13) )
-#define DAC4_INIT_VAL (_BV(13) | _BV(15))
/**
* Pin status for each DAC pin, the structure of each field is defined
* as spi command structure.
+ *
+ * See mcp4922.pdf p. 24
+ * Options:
+ * Bit 13: Output Gain Selection bit set = 1x (VOUT = VREF * D/4096)
+ * Bit 15: DACA (0) or DACB (1) Selection bit.
+ *
*/
-uint16_t dac_pin_stat[DAC_PIN_NUM] = {
- DAC1_INIT_VAL,
- DAC2_INIT_VAL,
- DAC3_INIT_VAL,
- DAC4_INIT_VAL
+static uint16_t dac_pin_status[DAC_PIN_NUM] = {
+ (_BV(13) ),
+ (_BV(13) | _BV(15)),
+ (_BV(13) ),
+ (_BV(13) | _BV(15))
};
/**
* Port names for each DAC port, to be easily accessible by indexing
*/
-const char* dac_port_names[DAC_PIN_NUM] = {
- PORT_NAME_DAC1_2,
- PORT_NAME_DAC1_2,
- PORT_NAME_DAC3_4,
- PORT_NAME_DAC3_4
+const char *dac_port_names[DAC_PIN_NUM] = {
+ DIO_PORT_NAME_DAC1_2,
+ DIO_PORT_NAME_DAC1_2,
+ DIO_PORT_NAME_DAC3_4,
+ DIO_PORT_NAME_DAC3_4
};
/**
int drv_dac_spi_transfer(uint8_t pin, boolean_t enabled, uint16_t value)
{
- // Check pin range
- if(pin >= DAC_PIN_NUM) {
- return -1;
- }
+ // Check pin range
+ if (pin >= DAC_PIN_NUM)
+ return -1;
- // Check value range
- if(value > 4095) {
- return -2;
- }
+ // Check value range
+ if (value > 4095)
+ return -2;
- // Prepare command
- if(enabled) {
- bit_set(dac_pin_stat[pin], 12);
- } else {
- bit_clear(dac_pin_stat[pin], 12);
- }
+ // Prepare command
+ if (enabled)
+ bit_set(dac_pin_status[pin], 12);
+ else
+ bit_clear(dac_pin_status[pin], 12);
- dac_pin_stat[pin] = dac_pin_stat[pin] & 0xF000;
- dac_pin_stat[pin] |= (value & 0xFFF);
+ dac_pin_status[pin] = dac_pin_status[pin] & 0xF000;
+ dac_pin_status[pin] |= (value & 0xFFF);
- uint32_t commands[2];
+ uint32_t commands[2];
- // Warning!!! Can be "optimized" by compiler
- dac_spi_cmd = dac_pin_stat[pin];
- dac_spi_cmd_sh = dac_spi_cmd;
- //--
- port_desc_t* desc;
- desc = hal_port_get_dsc(dac_port_names[pin], -1);
- commands[0] = (dac_spi_cmd_sh & 0xFF00) >> 8;
- commands[1] = (dac_spi_cmd_sh & 0xFF);
+ // Warning!!! Can be "optimized" by compiler
+ dac_spi_cmd = dac_pin_status[pin];
+ dac_spi_cmd_sh = dac_spi_cmd;
+ //--
+ dio_port_desc_t *desc;
+ desc = dio_port_get_dsc(dac_port_names[pin], -1);
+ commands[0] = (dac_spi_cmd_sh & 0xFF00) >> 8;
+ commands[1] = (dac_spi_cmd_sh & 0xFF);
- return desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+ return desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
}
-