Skip to content

Commit acd6b31

Browse files
committed
Merge branch 'adc_channel' into hyperfirmata
2 parents 97b5c09 + 22bf611 commit acd6b31

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

cores/nRF5/wiring_analog_nRF51.c

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ uint32_t analogRead( uint32_t ulPin )
132132
uint32_t resolution;
133133
int16_t value;
134134

135+
#ifdef ARDUINO_ADC_NON_STANDARD_PINS
136+
ulPin = _analogChannelPin(ulPin);
137+
#elif NUM_ANALOG_INPUTS > 0
138+
if (ulPin < A0) {
139+
ulPin += A0;
140+
}
141+
#else
142+
return 0;
143+
#endif
144+
135145
if (ulPin >= PINS_COUNT) {
136146
return 0;
137147
}

variants/BBCmicrobit/variant.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ extern "C"
4040
// LEDs
4141
#define PIN_LED (13)
4242
#define LED_BUILTIN PIN_LED
43-
// #define
4443

4544
// Buttons
4645
#define PIN_BUTTON_A (5)
@@ -65,6 +64,23 @@ static const uint8_t A4 = PIN_A4 ;
6564
static const uint8_t A5 = PIN_A5 ;
6665
#define ADC_RESOLUTION 10
6766

67+
// Non standard distribution of Analog Pins requires a lookup table
68+
#define ARDUINO_ADC_NON_STANDARD_PINS
69+
__inline__ uint32_t _analogChannelPin(uint32_t pin) __attribute__((always_inline));
70+
__inline__ uint32_t _analogChannelPin(uint32_t pin) {
71+
switch (pin) {
72+
case 0: return PIN_A0;
73+
case 1: return PIN_A1;
74+
case 2: return PIN_A2;
75+
case 3: return PIN_A3;
76+
case 4: return PIN_A4;
77+
case 5: return PIN_A5;
78+
case 10: return PIN_A5;
79+
// Otherwise non-analog pin so return out of range pin to exit early
80+
default: return PINS_COUNT;
81+
}
82+
}
83+
6884
/*
6985
* Serial interfaces
7086
*/

0 commit comments

Comments
 (0)