//#include "drv_din.h"
#include "drv/drv.h"
+// 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 DACA_INIT_VAL _BV(13)
+#define DACB_INIT_VAL _BV(13) | _BV(15)
+
+int8_t drv_din_ref(uint16_t ref_a, uint16_t ref_b)
+{
+ uint16_t cmd;
+
+ // Get descriptor
+ uint32_t commands[2];
+ port_desc_t* desc = hal_port_get_dsc(PORT_NAME_DACDREF, -1);
+
+ // Send command for DAC A
+ cmd = DACA_INIT_VAL | (ref_a & 0x0FFF);
+
+ commands[0] = (cmd & 0xFF00) >> 8;
+ commands[1] = (cmd & 0xFF);
+ desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+
+ // Send command for DAC B
+ cmd = DACB_INIT_VAL | (ref_b & 0x0FFF);
+
+ commands[0] = (cmd & 0xFF00) >> 8;
+ commands[1] = (cmd & 0xFF);
+ desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+
+ // Fixme: check SPI return value.
+ return SUCCESS;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/** REVISION REQUIRED *********************/
+
+
/** Prepared command */
uint32_t din_spi_cmd = DIN_SPICMD_INIT_VAL;
/** Shadow variable used during sending */
uint8_t val;
din_spi_cmd = 1 << 16; // Set command
- for (i = 0; i < 8; i++,word >>= 1) {
+ for (i = 0; i < 8; i++, word >>= 1) {
val = word&0x1;
if (val == 1) {
din_spi_cmd |= 1 << din_set_pin_pr_i[i];