altos: Intgrate hmc5883 sensor into adc ring
[fw/altos] / src / stm / ao_adc_stm.c
index 02187205eb18a82b4256c9669c33ee5cde2bb4ee..71299de93c7a4a77814ea843477117d173f1dad6 100644 (file)
@@ -62,6 +62,11 @@ static void ao_adc_done(int index)
                step = 0;
        ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current;
 #endif 
+#if HAS_HMC5883
+       if (!ao_hmc5883_valid)
+               step = 0;
+       ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current;
+#endif
        if (step) {
                ao_data_head = ao_data_ring_next(ao_data_head);
                ao_wakeup((void *) &ao_data_head);
@@ -82,7 +87,7 @@ ao_adc_poll(void)
        stm_adc.sr = 0;
        ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1),
                            &stm_adc.dr,
-                           (void *) (&ao_data_ring[ao_data_head].tick + 1),
+                           (void *) (&ao_data_ring[ao_data_head].adc),
                            AO_NUM_ADC,
                            (0 << STM_DMA_CCR_MEM2MEM) |
                            (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) |
@@ -104,14 +109,22 @@ ao_adc_poll(void)
 void
 ao_adc_get(__xdata struct ao_adc *packet)
 {
+#if HAS_FLIGHT
+       uint8_t i = ao_data_ring_prev(ao_sample_data);
+#else
        uint8_t i = ao_data_ring_prev(ao_data_head);
+#endif
        memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc));
 }
 
 void
 ao_data_get(__xdata struct ao_data *packet)
 {
+#if HAS_FLIGHT
+       uint8_t i = ao_data_ring_prev(ao_sample_data);
+#else
        uint8_t i = ao_data_ring_prev(ao_data_head);
+#endif
        memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data));
 }
 
@@ -172,6 +185,15 @@ ao_adc_init(void)
 #ifdef AO_ADC_PIN9_PORT
        stm_moder_set(&AO_ADC_PIN9_PORT, AO_ADC_PIN9_PIN, STM_MODER_ANALOG);
 #endif
+#ifdef AO_ADC_PIN10_PORT
+       stm_moder_set(&AO_ADC_PIN10_PORT, AO_ADC_PIN10_PIN, STM_MODER_ANALOG);
+#endif
+#ifdef AO_ADC_PIN11_PORT
+       stm_moder_set(&AO_ADC_PIN11_PORT, AO_ADC_PIN11_PIN, STM_MODER_ANALOG);
+#endif
+#ifdef AO_ADC_PIN12_PORT
+       stm_moder_set(&AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG);
+#endif
 
        stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_ADC1EN);
 
@@ -232,7 +254,19 @@ ao_adc_init(void)
 #if AO_NUM_ADC > 8
        stm_adc.sqr4 |= (AO_ADC_SQ9 << 10);
 #endif
-
+#if AO_NUM_ADC > 9
+       stm_adc.sqr4 |= (AO_ADC_SQ10 << 15);
+#endif
+#if AO_NUM_ADC > 10
+       stm_adc.sqr4 |= (AO_ADC_SQ11 << 20);
+#endif
+#if AO_NUM_ADC > 11
+       stm_adc.sqr4 |= (AO_ADC_SQ12 << 25);
+#endif
+#if AO_NUM_ADC > 12
+#error "need to finish stm_adc.sqr settings"
+#endif
+       
        /* Turn ADC on */
        stm_adc.cr2 = AO_ADC_CR2_VAL;