Skip to content

Add ADC internal channels #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cores/arduino/pins_arduino.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ WEAK uint32_t pinNametoDigitalPin(PinName p)
return i;
}

PinName analogInputToPinName(uint32_t pin)
{
PinName pn = digitalPinToPinName(analogInputToDigitalPin(pin));
if (pn == NC) {
switch (pin) {
#ifdef ATEMP
case ATEMP:
pn = PADC_TEMP;
break;
#endif
#ifdef AVREF
case AVREF:
pn = PADC_VREF;
break;
#endif
#ifdef AVBAT
case AVBAT:
pn = PADC_VBAT;
break;
#endif
default:
break;
}
}
return pn;
}

#ifdef __cplusplus
}
#endif
15 changes: 14 additions & 1 deletion cores/arduino/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ static const uint8_t SCK = PIN_SPI_SCK;
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;

// ADC internal channels (not a pins)
// Only used for analogRead()
#ifdef ADC_CHANNEL_TEMPSENSOR
#define ATEMP (NUM_DIGITAL_PINS + 1)
#endif
#ifdef ADC_CHANNEL_VREFINT
#define AVREF (NUM_DIGITAL_PINS + 2)
#endif
#ifdef ADC_CHANNEL_VBAT
#define AVBAT (NUM_DIGITAL_PINS + 3)
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -218,7 +230,8 @@ uint32_t pinNametoDigitalPin(PinName p);
// Used by analogRead api to have A0 == 0
#define analogInputToDigitalPin(p) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
// Convert an analog pin number Axx to a PinName PX_n
#define analogInputToPinName(p) (digitalPinToPinName(analogInputToDigitalPin(p)))
PinName analogInputToPinName(uint32_t pin);

// All pins could manage EXTI
#define digitalPinToInterrupt(p) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT)

Expand Down
11 changes: 11 additions & 0 deletions cores/arduino/stm32/PinNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ typedef enum {
PK_13 = (PortK << 4) + 0x0D,
PK_14 = (PortK << 4) + 0x0E,
PK_15 = (PortK << 4) + 0x0F,
#endif
// Specific pin name
PADC_BASE = 0x100,
#ifdef ADC_CHANNEL_TEMPSENSOR
PADC_TEMP,
#endif
#ifdef ADC_CHANNEL_VREFINT
PADC_VREF,
#endif
#ifdef ADC_CHANNEL_VBAT
PADC_VBAT,
#endif
// Specific pin name define in the variant
#if __has_include("PinNamesVar.h")
Expand Down
Loading