]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Simplify dac.c
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 1 Aug 2015 14:19:09 +0000 (16:19 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 1 Aug 2015 15:04:11 +0000 (17:04 +0200)
... and rename ambiguous "stat" to status.

rpp/src/drv/dac.c

index 04daca1e40042b7f11519baf3edf1b6f7b2195b1..4a01fdd9fe0847477c11a34991748aabfa211bc5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn
 
 #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))
 };
 
 /**
@@ -73,17 +71,17 @@ int drv_dac_spi_transfer(uint8_t pin, boolean_t enabled, uint16_t value)
 
        // Prepare command
        if (enabled)
-               bit_set(dac_pin_stat[pin], 12);
+               bit_set(dac_pin_status[pin], 12);
        else
-               bit_clear(dac_pin_stat[pin], 12);
+               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];
 
        // Warning!!! Can be "optimized" by compiler
-       dac_spi_cmd = dac_pin_stat[pin];
+       dac_spi_cmd = dac_pin_status[pin];
        dac_spi_cmd_sh = dac_spi_cmd;
        //--
        port_desc_t *desc;