Skip to content

Commit eb90a45

Browse files
committed
Allow not to have analog pin
If no analog pin required then `NUM_ANALOG_INPUTS` and `NUM_ANALOG_FIRST` could be not defined or set to respectively `0` and `NUM_DIGITAL_PINS` Nevertheless, this kept ADC internal channels functional if `HAL_ADC_MODULE_ENABLED` still defined. Signed-off-by: Frederic Pillon <[email protected]>
1 parent c2090e2 commit eb90a45

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: cores/arduino/pins_arduino.h

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ enum {
5151
};
5252

5353
// Arduino analog pins
54+
#ifndef NUM_ANALOG_INPUTS
55+
#define NUM_ANALOG_INPUTS 0
56+
#endif
57+
#ifndef NUM_ANALOG_FIRST
58+
#define NUM_ANALOG_FIRST NUM_DIGITAL_PINS
59+
#endif
60+
5461
// Analog pins must be contiguous to be able to loop on each value
5562
#define MAX_ANALOG_INPUTS 24
5663
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS,
@@ -230,8 +237,12 @@ extern const PinName digitalPin[];
230237
uint32_t pinNametoDigitalPin(PinName p);
231238

232239
// Convert an analog pin number to a digital pin number
240+
#if defined(NUM_ANALOG_INPUTS) && (NUM_ANALOG_INPUTS>0)
233241
// Used by analogRead api to have A0 == 0
234242
#define analogInputToDigitalPin(p) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
243+
#else
244+
#define analogInputToDigitalPin(p) (NUM_DIGITAL_PINS)
245+
#endif
235246
// Convert an analog pin number Axx to a PinName PX_n
236247
PinName analogInputToPinName(uint32_t pin);
237248

Diff for: variants/board_template/variant.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ extern "C" {
5151
#define NUM_DIGITAL_PINS 0
5252

5353
// Allow to define Arduino style alias for analog input pin number --> Ax
54+
// If no analog pin required then NUM_ANALOG_INPUTS and NUM_ANALOG_FIRST
55+
// could not be defined or set to respectively `0` and `NUM_DIGITAL_PINS`
5456
// All pins are digital, analog inputs are a subset of digital pins
5557
// and must be contiguous to be able to loop on each value
5658
// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS

0 commit comments

Comments
 (0)