X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fstm%2Fao_adc_stm.c;h=2399e6a281bf7196f1e75474d89fb84d77b056c6;hp=53f19b406d20a884f6c33b6219b2dc55f10e9b76;hb=684741765117611b7d666efbdfafd87c6199752c;hpb=6d553230903ddd0ec522c07be0df975b38ef23d3 diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index 53f19b40..2399e6a2 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -3,7 +3,8 @@ * * 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; version 2 of the License. + * 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 @@ -41,6 +42,7 @@ static uint8_t ao_adc_ready; */ static void ao_adc_done(int index) { + (void) index; AO_DATA_PRESENT(AO_DATA_ADC); ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); if (ao_data_present == AO_DATA_ALL) { @@ -55,6 +57,9 @@ static void ao_adc_done(int index) #endif #if HAS_MPU6000 ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current; +#endif +#if HAS_MPU9250 + ao_data_ring[ao_data_head].mpu9250 = ao_mpu9250_current; #endif ao_data_ring[ao_data_head].tick = ao_tick_count; ao_data_head = ao_data_ring_next(ao_data_head); @@ -95,7 +100,7 @@ ao_adc_poll(void) * Fetch a copy of the most recent ADC data */ void -ao_adc_get(__xdata struct ao_adc *packet) +ao_adc_get(struct ao_adc *packet) { #if HAS_FLIGHT uint8_t i = ao_data_ring_prev(ao_sample_data); @@ -105,12 +110,80 @@ ao_adc_get(__xdata struct ao_adc *packet) memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc)); } +#ifdef AO_ADC_SQ1_NAME +static const char *ao_adc_name[AO_NUM_ADC] = { + AO_ADC_SQ1_NAME, +#ifdef AO_ADC_SQ2_NAME + AO_ADC_SQ2_NAME, +#endif +#ifdef AO_ADC_SQ3_NAME + AO_ADC_SQ3_NAME, +#endif +#ifdef AO_ADC_SQ4_NAME + AO_ADC_SQ4_NAME, +#endif +#ifdef AO_ADC_SQ5_NAME + AO_ADC_SQ5_NAME, +#endif +#ifdef AO_ADC_SQ6_NAME + AO_ADC_SQ6_NAME, +#endif +#ifdef AO_ADC_SQ7_NAME + AO_ADC_SQ7_NAME, +#endif +#ifdef AO_ADC_SQ8_NAME + AO_ADC_SQ8_NAME, +#endif +#ifdef AO_ADC_SQ9_NAME + AO_ADC_SQ9_NAME, +#endif +#ifdef AO_ADC_SQ10_NAME + AO_ADC_SQ10_NAME, +#endif +#ifdef AO_ADC_SQ11_NAME + AO_ADC_SQ11_NAME, +#endif +#ifdef AO_ADC_SQ12_NAME + AO_ADC_SQ12_NAME, +#endif +#ifdef AO_ADC_SQ13_NAME + AO_ADC_SQ13_NAME, +#endif +#ifdef AO_ADC_SQ14_NAME + AO_ADC_SQ14_NAME, +#endif +#ifdef AO_ADC_SQ15_NAME + AO_ADC_SQ15_NAME, +#endif +#ifdef AO_ADC_SQ16_NAME + AO_ADC_SQ16_NAME, +#endif +#ifdef AO_ADC_SQ17_NAME + AO_ADC_SQ17_NAME, +#endif +#ifdef AO_ADC_SQ18_NAME + AO_ADC_SQ18_NAME, +#endif +#ifdef AO_ADC_SQ19_NAME + AO_ADC_SQ19_NAME, +#endif +#ifdef AO_ADC_SQ20_NAME + AO_ADC_SQ20_NAME, +#endif +#ifdef AO_ADC_SQ21_NAME + #error "too many ADC names" +#endif +}; +#endif + static void -ao_adc_dump(void) __reentrant +ao_adc_dump(void) { struct ao_data packet; - int16_t *d; +#ifndef AO_ADC_DUMP uint8_t i; + int16_t *d; +#endif ao_data_get(&packet); #ifdef AO_ADC_DUMP @@ -118,13 +191,19 @@ ao_adc_dump(void) __reentrant #else printf("tick: %5u", packet.tick); d = (int16_t *) (&packet.adc); - for (i = 0; i < AO_NUM_ADC; i++) - printf (" %2d: %5d", i, d[i]); + for (i = 0; i < AO_NUM_ADC; i++) { +#ifdef AO_ADC_SQ1_NAME + if (ao_adc_name[i]) + printf (" %s: %5d", ao_adc_name[i], d[i]); + else +#endif + printf (" %2d: %5d", i, d[i]); + } printf("\n"); #endif } -__code struct ao_cmds ao_adc_cmds[] = { +const struct ao_cmds ao_adc_cmds[] = { { ao_adc_dump, "a\0Display current ADC values" }, { 0, NULL }, }; @@ -175,6 +254,42 @@ ao_adc_init(void) #ifdef AO_ADC_PIN12_PORT stm_moder_set(AO_ADC_PIN12_PORT, AO_ADC_PIN12_PIN, STM_MODER_ANALOG); #endif +#ifdef AO_ADC_PIN13_PORT + stm_moder_set(AO_ADC_PIN13_PORT, AO_ADC_PIN13_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN14_PORT + stm_moder_set(AO_ADC_PIN14_PORT, AO_ADC_PIN14_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN15_PORT + stm_moder_set(AO_ADC_PIN15_PORT, AO_ADC_PIN15_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN16_PORT + stm_moder_set(AO_ADC_PIN16_PORT, AO_ADC_PIN16_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN17_PORT + stm_moder_set(AO_ADC_PIN17_PORT, AO_ADC_PIN17_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN18_PORT + stm_moder_set(AO_ADC_PIN18_PORT, AO_ADC_PIN18_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN19_PORT + stm_moder_set(AO_ADC_PIN19_PORT, AO_ADC_PIN19_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN20_PORT + stm_moder_set(AO_ADC_PIN20_PORT, AO_ADC_PIN20_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN21_PORT + stm_moder_set(AO_ADC_PIN21_PORT, AO_ADC_PIN21_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN22_PORT + stm_moder_set(AO_ADC_PIN22_PORT, AO_ADC_PIN22_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN23_PORT + stm_moder_set(AO_ADC_PIN23_PORT, AO_ADC_PIN23_PIN, STM_MODER_ANALOG); +#endif +#ifdef AO_ADC_PIN24_PORT + #error "Too many ADC ports" +#endif stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_ADC1EN); @@ -245,9 +360,27 @@ ao_adc_init(void) stm_adc.sqr4 |= (AO_ADC_SQ12 << 25); #endif #if AO_NUM_ADC > 12 + stm_adc.sqr3 |= (AO_ADC_SQ13 << 0); +#endif +#if AO_NUM_ADC > 13 + stm_adc.sqr3 |= (AO_ADC_SQ14 << 5); +#endif +#if AO_NUM_ADC > 14 + stm_adc.sqr3 |= (AO_ADC_SQ15 << 10); +#endif +#if AO_NUM_ADC > 15 + stm_adc.sqr3 |= (AO_ADC_SQ16 << 15); +#endif +#if AO_NUM_ADC > 16 + stm_adc.sqr3 |= (AO_ADC_SQ17 << 20); +#endif +#if AO_NUM_ADC > 17 + stm_adc.sqr3 |= (AO_ADC_SQ18 << 25); +#endif +#if AO_NUM_ADC > 18 #error "need to finish stm_adc.sqr settings" #endif - + /* Turn ADC on */ stm_adc.cr2 = AO_ADC_CR2_VAL; @@ -255,6 +388,9 @@ ao_adc_init(void) while (!(stm_adc.sr & (1 << STM_ADC_SR_ADONS))) ; +#ifndef HAS_ADC_TEMP +#error Please define HAS_ADC_TEMP +#endif #if HAS_ADC_TEMP stm_adc.ccr = ((1 << STM_ADC_CCR_TSVREFE)); #else