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:
parent
4bad334875
commit
16e44eb11a
|
@ -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
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-202304092344Z"
|
#define GITHUB_SHA "devel-202304111013Z"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user