altos/telefire: Add siren/strobe support
[fw/altos] / src / cc1111 / ao_adc.c
index 956439566abacdaa3340cc98dae5c668dcf64645..f80004104130c324c19cd4e68884edc4b5a208a4 100644 (file)
 volatile __xdata struct ao_data        ao_data_ring[AO_DATA_RING];
 volatile __data uint8_t                ao_data_head;
 
+#ifndef AO_ADC_FIRST_PIN
+#define AO_ADC_FIRST_PIN       0
+#endif
+
 void
 ao_adc_poll(void)
 {
@@ -29,7 +33,7 @@ ao_adc_poll(void)
 # ifdef TELENANO_V_0_1
        ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 1;
 # else
-       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | 0;
+       ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | AO_ADC_FIRST_PIN;
 # endif
 #endif
 }
@@ -56,7 +60,7 @@ ao_adc_isr(void) __interrupt 1
        /* TeleMetrum readings */
 #if HAS_ACCEL_REF
        if (sequence == 2) {
-               a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].accel_ref);
+               a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.accel_ref);
                sequence = 0;
        } else
 #endif
@@ -140,6 +144,15 @@ ao_adc_isr(void) __interrupt 1
        }
 #endif /* telemini || telenano */
 
+#ifdef TELEFIRE_V_0_1
+       a = (uint8_t __xdata *) (&ao_data_ring[ao_data_head].adc.sense[0] + sequence - AO_ADC_FIRST_PIN);
+       a[0] = ADCL;
+       a[1] = ADCH;
+       if (sequence < 5)
+               ADCCON3 = ADCCON3_EREF_VDD | ADCCON3_EDIV_512 | (sequence + 1);
+#define GOT_ADC
+#endif /* TELEFIRE_V_0_1 */
+
 #ifndef GOT_ADC
 #error No known ADC configuration set
 #endif
@@ -157,9 +170,13 @@ ao_adc_dump(void) __reentrant
 {
        static __xdata struct ao_data   packet;
        ao_data_get(&packet);
+#ifndef AO_ADC_DUMP
        printf("tick: %5u accel: %5d pres: %5d temp: %5d batt: %5d drogue: %5d main: %5d\n",
               packet.tick, packet.adc.accel, packet.adc.pres, packet.adc.temp,
               packet.adc.v_batt, packet.adc.sense_d, packet.adc.sense_m);
+#else
+       AO_ADC_DUMP(&packet);
+#endif
 }
 
 __code struct ao_cmds ao_adc_cmds[] = {
@@ -170,6 +187,11 @@ __code struct ao_cmds ao_adc_cmds[] = {
 void
 ao_adc_init(void)
 {
+#ifdef AO_ADC_PINS
+       ADCCFG = AO_ADC_PINS;
+
+#else
+
 #if IGNITE_ON_P2
        /* TeleMetrum configuration */
        ADCCFG = ((1 << 0) |    /* acceleration */
@@ -190,6 +212,8 @@ ao_adc_init(void)
                  (1 << 3));    /* battery voltage */
 #endif
 
+#endif /* else AO_ADC_PINS */
+
        /* enable interrupts */
        ADCIF = 0;
        IEN0 |= IEN0_ADCIE;