From 16e44eb11a3d8bdfe3923d9aefed12750bff744d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 11 Apr 2023 12:13:47 +0200 Subject: [PATCH] Check for max 16 analog channels --- DCCTimerSTM32.cpp | 10 ++++++---- GITHUB_SHA.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index 5660be1..fcbf286 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -286,13 +286,15 @@ int ADCee::init(uint8_t pin) { while(!(ADC1->SR & (1 << 1))); // Wait until conversion is complete value = ADC1->DR; // Read value from register - if (analogvals == NULL) - { + uint8_t id = pin - PNUM_ANALOG_BASE; + if (id > 15) { // today we have not enough bits in the mask to support more + return -1021; + } + + if (analogvals == NULL) { // allocate analogvals and analogchans if this is the first invocation of init. analogvals = (int *)calloc(NUM_ADC_INPUTS+1, sizeof(int)); analogchans = (uint32_t *)calloc(NUM_ADC_INPUTS+1, sizeof(uint32_t)); } - - uint8_t id = pin - PNUM_ANALOG_BASE; analogvals[id] = value; // Store sampled value analogchans[id] = adcchan; // Keep track of which ADC channel is used for reading this pin usedpins |= (1 << id); // This pin is now ready diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index fbecd70..0ac9c5f 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202304092344Z" +#define GITHUB_SHA "devel-202304111013Z"