File tree 5 files changed +288
-66
lines changed
5 files changed +288
-66
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,33 @@ WEAK uint32_t pinNametoDigitalPin(PinName p)
35
35
return i ;
36
36
}
37
37
38
+ PinName analogInputToPinName (uint32_t pin )
39
+ {
40
+ PinName pn = digitalPinToPinName (analogInputToDigitalPin (pin ));
41
+ if (pn == NC ) {
42
+ switch (pin ) {
43
+ #ifdef ATEMP
44
+ case ATEMP :
45
+ pn = PADC_TEMP ;
46
+ break ;
47
+ #endif
48
+ #ifdef AVREF
49
+ case AVREF :
50
+ pn = PADC_VREF ;
51
+ break ;
52
+ #endif
53
+ #ifdef AVBAT
54
+ case AVBAT :
55
+ pn = PADC_VBAT ;
56
+ break ;
57
+ #endif
58
+ default :
59
+ break ;
60
+ }
61
+ }
62
+ return pn ;
63
+ }
64
+
38
65
#ifdef __cplusplus
39
66
}
40
67
#endif
Original file line number Diff line number Diff line change @@ -201,6 +201,18 @@ static const uint8_t SCK = PIN_SPI_SCK;
201
201
static const uint8_t SDA = PIN_WIRE_SDA ;
202
202
static const uint8_t SCL = PIN_WIRE_SCL ;
203
203
204
+ // ADC internal channels (not a pins)
205
+ // Only used for analogRead()
206
+ #ifdef ADC_CHANNEL_TEMPSENSOR
207
+ #define ATEMP (NUM_DIGITAL_PINS + 1)
208
+ #endif
209
+ #ifdef ADC_CHANNEL_VREFINT
210
+ #define AVREF (NUM_DIGITAL_PINS + 2)
211
+ #endif
212
+ #ifdef ADC_CHANNEL_VBAT
213
+ #define AVBAT (NUM_DIGITAL_PINS + 3)
214
+ #endif
215
+
204
216
#ifdef __cplusplus
205
217
extern "C" {
206
218
#endif
@@ -218,7 +230,8 @@ uint32_t pinNametoDigitalPin(PinName p);
218
230
// Used by analogRead api to have A0 == 0
219
231
#define analogInputToDigitalPin (p ) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
220
232
// Convert an analog pin number Axx to a PinName PX_n
221
- #define analogInputToPinName (p ) (digitalPinToPinName(analogInputToDigitalPin(p)))
233
+ PinName analogInputToPinName (uint32_t pin );
234
+
222
235
// All pins could manage EXTI
223
236
#define digitalPinToInterrupt (p ) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT)
224
237
Original file line number Diff line number Diff line change @@ -207,6 +207,17 @@ typedef enum {
207
207
PK_13 = (PortK << 4 ) + 0x0D ,
208
208
PK_14 = (PortK << 4 ) + 0x0E ,
209
209
PK_15 = (PortK << 4 ) + 0x0F ,
210
+ #endif
211
+ // Specific pin name
212
+ PADC_BASE = 0x100 ,
213
+ #ifdef ADC_CHANNEL_TEMPSENSOR
214
+ PADC_TEMP ,
215
+ #endif
216
+ #ifdef ADC_CHANNEL_VREFINT
217
+ PADC_VREF ,
218
+ #endif
219
+ #ifdef ADC_CHANNEL_VBAT
220
+ PADC_VBAT ,
210
221
#endif
211
222
// Specific pin name define in the variant
212
223
#if __has_include ("PinNamesVar .h ")
You can’t perform that action at this time.
0 commit comments