1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Check for max 16 analog channels

This commit is contained in:
Harald Barth 2023-04-11 12:13:47 +02:00
parent 4bad334875
commit 16e44eb11a
2 changed files with 7 additions and 5 deletions

View File

@ -286,13 +286,15 @@ int ADCee::init(uint8_t pin) {
while(!(ADC1->SR & (1 << 1))); // Wait until conversion is complete while(!(ADC1->SR & (1 << 1))); // Wait until conversion is complete
value = ADC1->DR; // Read value from register 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)); analogvals = (int *)calloc(NUM_ADC_INPUTS+1, sizeof(int));
analogchans = (uint32_t *)calloc(NUM_ADC_INPUTS+1, sizeof(uint32_t)); analogchans = (uint32_t *)calloc(NUM_ADC_INPUTS+1, sizeof(uint32_t));
} }
uint8_t id = pin - PNUM_ANALOG_BASE;
analogvals[id] = value; // Store sampled value analogvals[id] = value; // Store sampled value
analogchans[id] = adcchan; // Keep track of which ADC channel is used for reading this pin analogchans[id] = adcchan; // Keep track of which ADC channel is used for reading this pin
usedpins |= (1 << id); // This pin is now ready usedpins |= (1 << id); // This pin is now ready

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202304092344Z" #define GITHUB_SHA "devel-202304111013Z"