File tree Expand file tree Collapse file tree 5 files changed +288
-66
lines changed Expand file tree Collapse file tree 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)
3535 return i ;
3636}
3737
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+
3865#ifdef __cplusplus
3966}
4067#endif
Original file line number Diff line number Diff line change @@ -201,6 +201,18 @@ static const uint8_t SCK = PIN_SPI_SCK;
201201static const uint8_t SDA = PIN_WIRE_SDA ;
202202static const uint8_t SCL = PIN_WIRE_SCL ;
203203
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+
204216#ifdef __cplusplus
205217extern "C" {
206218#endif
@@ -218,7 +230,8 @@ uint32_t pinNametoDigitalPin(PinName p);
218230// Used by analogRead api to have A0 == 0
219231#define analogInputToDigitalPin (p ) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
220232// 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+
222235// All pins could manage EXTI
223236#define digitalPinToInterrupt (p ) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT)
224237
Original file line number Diff line number Diff line change @@ -207,6 +207,17 @@ typedef enum {
207207 PK_13 = (PortK << 4 ) + 0x0D ,
208208 PK_14 = (PortK << 4 ) + 0x0E ,
209209 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 ,
210221#endif
211222 // Specific pin name define in the variant
212223#if __has_include ("PinNamesVar .h ")
You can’t perform that action at this time.
0 commit comments