application: add channel initialisation

This commit is contained in:
King Kévin 2021-03-24 00:44:47 +01:00
parent 0ad8e037cf
commit bb15fdc634
1 changed files with 49 additions and 0 deletions

View File

@ -66,6 +66,12 @@ const uint8_t adc_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(TARGET_CHANNEL), ADC_
#define MUX_S2_PIN PB1 /**< pin to set S2 bit of analog multiplexer */
#define MUX_S3_PIN PB2 /**< pin to set S3 bit of analog multiplexer */
#define CHANNEL_NUMBERS 16 /**< number of target signals */
static const uint32_t channel_ports[] = {GPIO_PORT(PB12), GPIO_PORT(PB13), GPIO_PORT(PB14), GPIO_PORT(PB15), GPIO_PORT(PA8), GPIO_PORT(PA9), GPIO_PORT(PA10), GPIO_PORT(PA15), GPIO_PORT(PB3), GPIO_PORT(PB4), GPIO_PORT(PB5), GPIO_PORT(PB6), GPIO_PORT(PB7), GPIO_PORT(PB8), GPIO_PORT(PB9), GPIO_PORT(PB10)}; /**< GPIO ports for signal pin */
static const uint32_t channel_pins[] = {GPIO_PIN(PB12), GPIO_PIN(PB13), GPIO_PIN(PB14), GPIO_PIN(PB15), GPIO_PIN(PA8), GPIO_PIN(PA9), GPIO_PIN(PA10), GPIO_PIN(PA15), GPIO_PIN(PB3), GPIO_PIN(PB4), GPIO_PIN(PB5), GPIO_PIN(PB6), GPIO_PIN(PB7), GPIO_PIN(PB8), GPIO_PIN(PB9), GPIO_PIN(PB10)}; /**< GPIO pins for signal pin */
static uint8_t channel_start = 0; /**< first signal of range to probe */
static uint8_t channel_stop = CHANNEL_NUMBERS - 1; /**< last signal of range to probe */
size_t putc(char c)
{
size_t length = 0; // number of characters printed
@ -82,6 +88,42 @@ size_t putc(char c)
return length; // return number of characters printed
}
/** get RCC from corresponding port
* @param[in] port port address
* @return RCC address corresponding to port
*/
static uint32_t port2rcc(uint32_t port)
{
uint32_t rcc = 0;
switch (port) {
case GPIOA:
rcc = RCC_GPIOA;
break;
case GPIOB:
rcc = RCC_GPIOB;
break;
case GPIOC:
rcc = RCC_GPIOC;
break;
case GPIOD:
rcc = RCC_GPIOD;
break;
case GPIOE:
rcc = RCC_GPIOE;
break;
case GPIOF:
rcc = RCC_GPIOF;
break;
case GPIOG:
rcc = RCC_GPIOG;
break;
default: // unknown port
while (true); // halt firmware
break;
}
return rcc;
}
/** measure target and signal voltages
* @return voltages of channels
*/
@ -557,6 +599,13 @@ void main(void)
mux_select(-1); // ensure it is disabled
puts("OK\n");
puts("setup signal pins: ");
for (uint8_t i = 0; i < CHANNEL_NUMBERS; i++) {
rcc_periph_clock_enable(port2rcc(channel_ports[i])); // enable clock for port domain
gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_NONE, channel_pins[i]); // ensure pin is floating input
}
puts("OK\n");
puts("setup ADC to measure voltages: ");
rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain
adc_power_off(ADC1); // switch off ADC while configuring it