From c4c9f480f9999bc0038d5e209881119de3014772 Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Mon, 29 Jan 2018 10:38:42 +0100 Subject: [PATCH] [Arduino compatibility] Ax pin definition Ax definition is now inline with Arduino style Variant has only to define the digital pin number of the first analog input (i.e. which digital pin is A0) Clean variant header include Fix #140 Signed-off-by: Frederic Pillon --- cores/arduino/Arduino.h | 2 +- cores/arduino/pins_arduino.c | 1 - cores/arduino/pins_arduino.h | 232 ++++++++++++++++++++++++- cores/arduino/pins_arduino_var.h | 158 ----------------- variants/DISCO_F100RB/variant.h | 32 ++-- variants/DISCO_F407VG/variant.h | 25 +-- variants/DISCO_F746NG/variant.h | 13 +- variants/DISCO_L072CZ_LRWAN1/variant.h | 13 +- variants/DISCO_L475VG_IOT/variant.h | 14 +- variants/NUCLEO_F030R8/variant.h | 14 +- variants/NUCLEO_F091RC/variant.h | 14 +- variants/NUCLEO_F103RB/variant.h | 14 +- variants/NUCLEO_F207ZG/variant.h | 15 +- variants/NUCLEO_F302R8/variant.h | 14 +- variants/NUCLEO_F303K8/variant.h | 17 +- variants/NUCLEO_F303RE/variant.h | 14 +- variants/NUCLEO_F401RE/variant.h | 14 +- variants/NUCLEO_F411RE/variant.h | 14 +- variants/NUCLEO_F429ZI/variant.h | 14 +- variants/NUCLEO_F446RE/variant.h | 14 +- variants/NUCLEO_L031K6/variant.h | 17 +- variants/NUCLEO_L053R8/variant.h | 14 +- variants/NUCLEO_L152RE/variant.h | 15 +- variants/NUCLEO_L432KC/variant.h | 17 +- variants/NUCLEO_L476RG/variant.h | 14 +- variants/board_template/variant.h | 47 +++-- 26 files changed, 337 insertions(+), 435 deletions(-) delete mode 100644 cores/arduino/pins_arduino_var.h diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index d2fc443aa4..c00b8bac50 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -45,6 +45,6 @@ void yield(void); #endif // __cplusplus // Include pins variant -#include "pins_arduino_var.h" +#include "pins_arduino.h" #endif // Arduino_h diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c index adcea54647..cebc377375 100644 --- a/cores/arduino/pins_arduino.c +++ b/cores/arduino/pins_arduino.c @@ -17,7 +17,6 @@ */ #include "pins_arduino.h" -#include "pins_arduino_var.h" #ifdef __cplusplus extern "C" { diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index e78b6dd510..d40ab89bf4 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -17,10 +17,13 @@ */ #ifndef _PINS_ARDUINO_H_ #define _PINS_ARDUINO_H_ +// Include board variant +#include "variant.h" -#include "PeripheralPins.h" +// Avoid pins number misalignment +_Static_assert(NUM_DIGITAL_PINS==PEND, "NUM_DIGITAL_PINS and PEND differ!"); -// Arduino digital pin alias +// Arduino digital pins alias // GPIO port (A to K) * 16 pins: 176 enum { D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, @@ -44,4 +47,229 @@ enum { DMAX }; +// Arduino analog pins +// Analog pins must be contiguous to be able to loop on each value +#define MAX_ANALOG_INPUTS 20 +_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS, "Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS" ); + +// Defined for backward compatibility with Firmata which unfortunately use it +#define AEND (NUM_ANALOG_FIRST+NUM_ANALOG_INPUTS) + +#if NUM_ANALOG_INPUTS > 0 +#define PIN_A0 NUM_ANALOG_FIRST +static const uint8_t A0 = PIN_A0; +#endif +#if NUM_ANALOG_INPUTS > 1 +#define PIN_A1 (PIN_A0 + 1) +static const uint8_t A1 = PIN_A1; +#endif +#if NUM_ANALOG_INPUTS > 2 +#define PIN_A2 (PIN_A1 + 1) +static const uint8_t A2 = PIN_A2; +#endif +#if NUM_ANALOG_INPUTS > 3 +#define PIN_A3 (PIN_A2 + 1) +static const uint8_t A3 = PIN_A3; +#endif +#if NUM_ANALOG_INPUTS > 4 +#define PIN_A4 (PIN_A3 + 1) +static const uint8_t A4 = PIN_A4; +#endif +#if NUM_ANALOG_INPUTS > 5 +#define PIN_A5 (PIN_A4 + 1) +static const uint8_t A5 = PIN_A5; +#endif +#if NUM_ANALOG_INPUTS > 6 +#define PIN_A6 (PIN_A5 + 1) +static const uint8_t A6 = PIN_A6; +#endif +#if NUM_ANALOG_INPUTS > 7 +#define PIN_A7 (PIN_A6 + 1) +static const uint8_t A7 = PIN_A7; +#endif +#if NUM_ANALOG_INPUTS > 8 +#define PIN_A8 (PIN_A7 + 1) +static const uint8_t A8 = PIN_A8; +#endif +#if NUM_ANALOG_INPUTS > 9 +#define PIN_A9 (PIN_A8 + 1) +static const uint8_t A9 = PIN_A9; +#endif +#if NUM_ANALOG_INPUTS > 10 +#define PIN_A10 (PIN_A9 + 1) +static const uint8_t A10 = PIN_A10; +#endif +#if NUM_ANALOG_INPUTS > 11 +#define PIN_A11 (PIN_A10 + 1) +static const uint8_t A11 = PIN_A11; +#endif +#if NUM_ANALOG_INPUTS > 12 +#define PIN_A12 (PIN_A11 + 1) +static const uint8_t A12 = PIN_A12; +#endif +#if NUM_ANALOG_INPUTS > 13 +#define PIN_A13 (PIN_A12 + 1) +static const uint8_t A13 = PIN_A13; +#endif +#if NUM_ANALOG_INPUTS > 14 +#define PIN_A14 (PIN_A13 + 1) +static const uint8_t A14 = PIN_A14; +#endif +#if NUM_ANALOG_INPUTS > 15 +#define PIN_A15 (PIN_A14 + 1) +static const uint8_t A15 = PIN_A15; +#endif +#if NUM_ANALOG_INPUTS > 16 +#define PIN_A16 (PIN_A15 + 1) +static const uint8_t A16 = PIN_A16; +#endif +#if NUM_ANALOG_INPUTS > 17 +#define PIN_A17 (PIN_A16 + 1) +static const uint8_t A17 = PIN_A17; +#endif +#if NUM_ANALOG_INPUTS > 18 +#define PIN_A18 (PIN_A17 + 1) +static const uint8_t A18 = PIN_A18; +#endif +#if NUM_ANALOG_INPUTS > 19 +#define PIN_A19 (PIN_A18 + 1) +static const uint8_t A19 = PIN_A19; +#endif + +// Default for Arduino connector compatibility +// SPI Definitions +#ifndef PIN_SPI_SS +#define PIN_SPI_SS 10 +#endif +#ifndef PIN_SPI_SS1 +#define PIN_SPI_SS1 4 +#endif +#ifndef PIN_SPI_SS2 +#define PIN_SPI_SS2 7 +#endif +#ifndef PIN_SPI_SS3 +#define PIN_SPI_SS3 8 +#endif +#ifndef PIN_SPI_MOSI +#define PIN_SPI_MOSI 11 +#endif +#ifndef PIN_SPI_MISO +#define PIN_SPI_MISO 12 +#endif +#ifndef PIN_SPI_SCK +#define PIN_SPI_SCK 13 +#endif + +static const uint8_t SS = PIN_SPI_SS; +static const uint8_t SS1 = PIN_SPI_SS1; +static const uint8_t SS2 = PIN_SPI_SS2; +static const uint8_t SS3 = PIN_SPI_SS3; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +// I2C Definitions +#ifndef PIN_WIRE_SDA +#define PIN_WIRE_SDA 14 +#endif +#ifndef PIN_WIRE_SCL +#define PIN_WIRE_SCL 15 +#endif + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +#ifdef __cplusplus +extern "C" { +#endif + +#define NOT_AN_INTERRUPT NC // -1 + +// Convert a digital pin number Dxx to a PinName PX_n +// Note: Analog pin is also a digital pin. +#define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC) +// Convert a PinName PX_n to a digital pin number +uint32_t pinNametoDigitalPin(PinName p); + +// Convert an analog pin number to a digital pin number +// 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))) +// All pins could manage EXTI +#define digitalPinToInterrupt(p) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT) + +#define digitalPinHasI2C(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SDA) ||\ + pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SCL)) +#define digitalPinHasPWM(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_PWM)) +#define digitalPinHasSerial(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_RX) ||\ + pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_TX)) +#define digitalPinHasSPI(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MOSI) ||\ + pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MISO) ||\ + pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SCLK) ||\ + pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SSEL)) + + +#define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p)))) +#define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p))) + +#define analogInPinToBit(p) (STM_PIN(digitalPinToPinName(p))) +#define portOutputRegister(P) (&(P->ODR)) +#define portInputRegister(P) (&(P->IDR)) + +#define portSetRegister(P) (&(P->BSRR)) +#if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) +// For those series reset are in the high part so << 16U needed +#define portClearRegister(P) (&(P->BSRR)) +#else +#define portClearRegister(P) (&(P->BRR)) +#endif + + +#if defined(STM32F1xx) +// Config registers split in 2 registers: +// CRL: pin 0..7 +// CRH: pin 8..15 +// Return only CRL +#define portModeRegister(P) (&(P->CRL)) +#else +#define portModeRegister(P) (&(P->MODER)) +#endif +#define portConfigRegister(P) (portModeRegister(P)) + + +#define digitalPinIsValid(p) (digitalPinToPinName(p) != NC) + +// As some pin could be duplicated in digitalPin[] +// return first occurence of linked PinName (PYx) +#define digitalPinFirstOccurence(p) (pinNametoDigitalPin(digitalPinToPinName(p))) + +// Specific for Firmata. As some pins could be duplicated, +// ensure 'p' is not one of the serial pins +#if defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX) +#define pinIsSerial(p) ((digitalPinFirstOccurence(p) == PIN_SERIAL_RX) ||\ + (digitalPinFirstOccurence(p) == PIN_SERIAL_TX)) +#endif + +#ifdef __cplusplus +} +#endif + +// Default Definitions, could be redefined in variant.h +#ifndef ADC_RESOLUTION +#define ADC_RESOLUTION 12 +#endif +#ifndef DACC_RESOLUTION +#define DACC_RESOLUTION 12 +#endif +#ifndef PWM_RESOLUTION +#define PWM_RESOLUTION 8 +#endif +#ifndef PWM_FREQUENCY +#define PWM_FREQUENCY 1000 +#endif +#ifndef PWM_MAX_DUTY_CYCLE +#define PWM_MAX_DUTY_CYCLE 255 +#endif + #endif /*_PINS_ARDUINO_H_*/ diff --git a/cores/arduino/pins_arduino_var.h b/cores/arduino/pins_arduino_var.h deleted file mode 100644 index 38d899f8d0..0000000000 --- a/cores/arduino/pins_arduino_var.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Variant pins Arduino definition - * - * Copyright (C) 2017, STMicroelectronics - All Rights Reserved - * Author: Frederic Pillon for STMicroelectronics. - * - * License type: GPLv2 - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published by - * the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see - * . - */ -#ifndef _PINS_ARDUINO_VAR_H_ -#define _PINS_ARDUINO_VAR_H_ - -// Include board variant -#include "variant.h" - -// Avoid pins number misalignment -_Static_assert(NUM_DIGITAL_PINS==PEND, "NUM_DIGITAL_PINS and PEND differ!"); -_Static_assert(NUM_ANALOG_INPUTS==(AEND-A0), "NUM_ANALOG_INPUTS and (AEND-A0) differ!"); - -#ifdef __cplusplus -extern "C" { -#endif - -#define NOT_AN_INTERRUPT NC // -1 -#define DEND NUM_DIGITAL_PINS - -// Convert a digital pin number Dxx to a PinName PX_n -// Note: Analog pin is also a digital pin. -#define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC) -// Convert a PinName PX_n to a digital pin number -uint32_t pinNametoDigitalPin(PinName p); - -// Convert an analog pin number to a digital pin number -// 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))) -// All pins could manage EXTI -#define digitalPinToInterrupt(p) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT) - -#define digitalPinHasI2C(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SDA) ||\ - pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SCL)) -#define digitalPinHasPWM(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_PWM)) -#define digitalPinHasSerial(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_RX) ||\ - pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_TX)) -#define digitalPinHasSPI(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MOSI) ||\ - pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MISO) ||\ - pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SCLK) ||\ - pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SSEL)) - - -#define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p)))) -#define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p))) - -#define analogInPinToBit(p) (STM_PIN(digitalPinToPinName(p))) -#define portOutputRegister(P) (&(P->ODR)) -#define portInputRegister(P) (&(P->IDR)) - -#define portSetRegister(P) (&(P->BSRR)) -#if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx) -// For those series reset are in the high part so << 16U needed -#define portClearRegister(P) (&(P->BSRR)) -#else -#define portClearRegister(P) (&(P->BRR)) -#endif - - -#if defined(STM32F1xx) -// Config registers split in 2 registers: -// CRL: pin 0..7 -// CRH: pin 8..15 -// Return only CRL -#define portModeRegister(P) (&(P->CRL)) -#else -#define portModeRegister(P) (&(P->MODER)) -#endif -#define portConfigRegister(P) (portModeRegister(P)) - - -#define digitalPinIsValid(p) (digitalPinToPinName(p) != NC) - -// As some pin could be duplicated in digitalPin[] -// return first occurence of linked PinName (PYx) -#define digitalPinFirstOccurence(p) (pinNametoDigitalPin(digitalPinToPinName(p))) - -// Specific for Firmata. As some pins could be duplicated, -// ensure 'p' is not one of the serial pins -#if defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX) -#define pinIsSerial(p) ((digitalPinFirstOccurence(p) == PIN_SERIAL_RX) ||\ - (digitalPinFirstOccurence(p) == PIN_SERIAL_TX)) -#endif - -// Default Definitions, could be redefined in variant.h -#ifndef ADC_RESOLUTION -#define ADC_RESOLUTION 12 -#endif -#ifndef DACC_RESOLUTION -#define DACC_RESOLUTION 12 -#endif -#ifndef PWM_RESOLUTION -#define PWM_RESOLUTION 8 -#endif -#ifndef PWM_FREQUENCY -#define PWM_FREQUENCY 1000 -#endif -#ifndef PWM_MAX_DUTY_CYCLE -#define PWM_MAX_DUTY_CYCLE 255 -#endif - -// Default for Arduino connector compatibility -// SPI Definitions -#ifndef SS -#define SS 10 -#endif -#ifndef SS1 -#define SS1 4 -#endif -#ifndef SS2 -#define SS2 7 -#endif -#ifndef SS3 -#define SS3 8 -#endif -#ifndef MOSI -#define MOSI 11 -#endif -#ifndef MISO -#define MISO 12 -#endif -#ifndef SCK -#define SCK 13 -#endif -// I2C Definitions -#ifndef SDA -#define SDA 14 -#endif -#ifndef SCL -#define SCL 15 -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_PINS_ARDUINO_VAR_H_*/ - diff --git a/variants/DISCO_F100RB/variant.h b/variants/DISCO_F100RB/variant.h index 82413c8d92..f241b3b9c1 100644 --- a/variants/DISCO_F100RB/variant.h +++ b/variants/DISCO_F100RB/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -107,16 +106,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 63 - -enum { - A_START_AFTER = D46, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 16 +#define NUM_ANALOG_FIRST 47 // On-board LED pin number #define LED_BUILTIN PC9 @@ -127,17 +119,17 @@ enum { #define USER_BTN 5 // SPI Definitions -#define SS PB12 -#define SS1 PB9 -#define SS2 PB10 -#define SS3 PB11 -#define MOSI PB15 -#define MISO PB14 -#define SCK PB13 +#define PIN_SPI_SS PB12 +#define PIN_SPI_SS1 PB9 +#define PIN_SPI_SS2 PB10 +#define PIN_SPI_SS3 PB11 +#define PIN_SPI_MOSI PB15 +#define PIN_SPI_MISO PB14 +#define PIN_SPI_SCK PB13 // I2C Definitions -#define SDA PB7 -#define SCL PB6 +#define PIN_WIRE_SDA PB7 +#define PIN_WIRE_SCL PB6 // Timer Definitions // Do not use timer used by PWM pins when possible. See PinMap_PWM. diff --git a/variants/DISCO_F407VG/variant.h b/variants/DISCO_F407VG/variant.h index 55b6b151cb..cf5b13dfd9 100644 --- a/variants/DISCO_F407VG/variant.h +++ b/variants/DISCO_F407VG/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -133,15 +132,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 87 - -enum { - A_START_AFTER = D78, - A0, A1, A2, A3, A4, A5, A6, A7, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 8 +#define NUM_ANALOG_FIRST 79 // On-board LED pin number #define LED_BUILTIN PD12 @@ -154,14 +147,14 @@ enum { #define USER_BTN 2 // SPI Definitions -#define SS2 14 -#define MOSI PA7 -#define MISO 5 -#define SCK PA5 +#define PIN_SPI_SS2 14 +#define PIN_SPI_MOSI PA7 +#define PIN_SPI_MISO 5 +#define PIN_SPI_SCK PA5 // I2C Definitions -#define SDA PB7 -#define SCL PB8 +#define PIN_WIRE_SDA PB7 +#define PIN_WIRE_SCL PB8 // Timer Definitions // Do not use timer used by PWM pin. See PinMap_PWM. diff --git a/variants/DISCO_F746NG/variant.h b/variants/DISCO_F746NG/variant.h index fe9d07140f..b4a27b20c2 100644 --- a/variants/DISCO_F746NG/variant.h +++ b/variants/DISCO_F746NG/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -65,15 +64,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 25 - -enum { - A_START_AFTER = D15, - A0, A1, A2, A3, A4, A5, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 6 +#define NUM_ANALOG_FIRST 16 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/DISCO_L072CZ_LRWAN1/variant.h b/variants/DISCO_L072CZ_LRWAN1/variant.h index 4d3f644696..8847895b8a 100644 --- a/variants/DISCO_L072CZ_LRWAN1/variant.h +++ b/variants/DISCO_L072CZ_LRWAN1/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -75,15 +74,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 33 - -enum { - A_START_AFTER = D25, - A0, A1, A2, A3, A4, A5, A6, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 7 +#define NUM_ANALOG_FIRST 26 // On-board LED pin number #define LED_BUILTIN PA5 diff --git a/variants/DISCO_L475VG_IOT/variant.h b/variants/DISCO_L475VG_IOT/variant.h index b8ef035e79..0367dfaa6e 100644 --- a/variants/DISCO_L475VG_IOT/variant.h +++ b/variants/DISCO_L475VG_IOT/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -134,16 +133,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 85 - -enum { - A_START_AFTER = D68, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 16 +#define NUM_ANALOG_FIRST 69 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F030R8/variant.h b/variants/NUCLEO_F030R8/variant.h index 44065b8037..d13db669df 100644 --- a/variants/NUCLEO_F030R8/variant.h +++ b/variants/NUCLEO_F030R8/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -107,16 +106,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 61 - -enum { - A_START_AFTER = D48, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 12 +#define NUM_ANALOG_FIRST 49 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F091RC/variant.h b/variants/NUCLEO_F091RC/variant.h index 9f4e537c7a..daf438de0d 100644 --- a/variants/NUCLEO_F091RC/variant.h +++ b/variants/NUCLEO_F091RC/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -104,16 +103,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 58 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 12 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index 7d3b8817ea..2d8d8ec7d8 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -106,16 +105,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 60 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 14 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F207ZG/variant.h b/variants/NUCLEO_F207ZG/variant.h index 04c391182d..2ce4ea92d4 100644 --- a/variants/NUCLEO_F207ZG/variant.h +++ b/variants/NUCLEO_F207ZG/variant.h @@ -34,8 +34,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -150,17 +149,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 96 - -// Enum defining Arduino style alias for analog pin number --> Ax -enum { - A_START_AFTER = D77, // pin number preceding A0 - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, A16, A17, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 18 +#define NUM_ANALOG_FIRST 78 // On-board LED pin number #define LED_BUILTIN PB0 diff --git a/variants/NUCLEO_F302R8/variant.h b/variants/NUCLEO_F302R8/variant.h index 64dcfa3bc5..5398ee58b3 100644 --- a/variants/NUCLEO_F302R8/variant.h +++ b/variants/NUCLEO_F302R8/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -104,16 +103,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 58 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 12 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F303K8/variant.h b/variants/NUCLEO_F303K8/variant.h index 70c7829523..2883f93896 100644 --- a/variants/NUCLEO_F303K8/variant.h +++ b/variants/NUCLEO_F303K8/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -63,15 +62,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 23 - -enum { - A_START_AFTER = D13, - A0, A1, A2, A3, A4, A5, A6, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 7 +#define NUM_ANALOG_FIRST 14 // On-board LED pin number #define LED_BUILTIN 13 @@ -81,8 +74,8 @@ enum { //#define USER_BTN NC // I2C Definitions -#define SDA 4 -#define SCL 5 +#define PIN_WIRE_SDA 4 +#define PIN_WIRE_SCL 5 // Timer Definitions // Do not use timer used by PWM pins when possible. See PinMap_PWM. diff --git a/variants/NUCLEO_F303RE/variant.h b/variants/NUCLEO_F303RE/variant.h index 1349f4a118..0893ba18ea 100644 --- a/variants/NUCLEO_F303RE/variant.h +++ b/variants/NUCLEO_F303RE/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -106,16 +105,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 60 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 14 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F401RE/variant.h b/variants/NUCLEO_F401RE/variant.h index 2d1e201c43..deabf2e9ec 100644 --- a/variants/NUCLEO_F401RE/variant.h +++ b/variants/NUCLEO_F401RE/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -105,16 +104,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 59 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 13 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F411RE/variant.h b/variants/NUCLEO_F411RE/variant.h index 2be2eb01f2..4ec64f2f47 100644 --- a/variants/NUCLEO_F411RE/variant.h +++ b/variants/NUCLEO_F411RE/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -105,16 +104,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 59 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 13 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_F429ZI/variant.h b/variants/NUCLEO_F429ZI/variant.h index 0b04ad4059..14686e6031 100644 --- a/variants/NUCLEO_F429ZI/variant.h +++ b/variants/NUCLEO_F429ZI/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -137,16 +136,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 96 - -enum { - A_START_AFTER = D77, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, A16, A17, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 18 +#define NUM_ANALOG_FIRST 78 // On-board LED pin number #define LED_BUILTIN PB0 diff --git a/variants/NUCLEO_F446RE/variant.h b/variants/NUCLEO_F446RE/variant.h index db06591554..3977feab20 100644 --- a/variants/NUCLEO_F446RE/variant.h +++ b/variants/NUCLEO_F446RE/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -106,16 +105,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 60 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 14 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_L031K6/variant.h b/variants/NUCLEO_L031K6/variant.h index 4e5f2355ef..57f6f3ec7b 100644 --- a/variants/NUCLEO_L031K6/variant.h +++ b/variants/NUCLEO_L031K6/variant.h @@ -34,8 +34,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -75,23 +74,17 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 23 - -enum { - A_START_AFTER = D13, - A0, A1, A2, A3, A4, A5, A6, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 7 +#define NUM_ANALOG_FIRST 14 // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN // I2C Definitions -#define SDA 4 -#define SCL 5 +#define PIN_WIRE_SDA 4 +#define PIN_WIRE_SCL 5 //Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM in PeripheralPins.c diff --git a/variants/NUCLEO_L053R8/variant.h b/variants/NUCLEO_L053R8/variant.h index 35e281eb65..ca8fb40caa 100644 --- a/variants/NUCLEO_L053R8/variant.h +++ b/variants/NUCLEO_L053R8/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -104,16 +103,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 58 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 12 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_L152RE/variant.h b/variants/NUCLEO_L152RE/variant.h index 25621d7b82..99590cbd09 100644 --- a/variants/NUCLEO_L152RE/variant.h +++ b/variants/NUCLEO_L152RE/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -109,17 +108,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 63 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, A16, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 17 - +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/NUCLEO_L432KC/variant.h b/variants/NUCLEO_L432KC/variant.h index e7bbfafe0c..58e8df1013 100644 --- a/variants/NUCLEO_L432KC/variant.h +++ b/variants/NUCLEO_L432KC/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -63,15 +62,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 23 - -enum { - A_START_AFTER = D13, - A0, A1, A2, A3, A4, A5, A6, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 7 +#define NUM_ANALOG_FIRST 14 // On-board LED pin number #define LED_BUILTIN 13 @@ -81,8 +74,8 @@ enum { //#define USER_BTN NC // I2C Definitions -#define SDA 4 -#define SCL 5 +#define PIN_WIRE_SDA 4 +#define PIN_WIRE_SCL 5 // Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM. diff --git a/variants/NUCLEO_L476RG/variant.h b/variants/NUCLEO_L476RG/variant.h index ad75cf3dc6..06100e2d24 100644 --- a/variants/NUCLEO_L476RG/variant.h +++ b/variants/NUCLEO_L476RG/variant.h @@ -22,8 +22,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -104,16 +103,9 @@ enum { // This must be a literal with the same value as PEND #define NUM_DIGITAL_PINS 58 - -enum { - A_START_AFTER = D45, - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, - AEND -}; - -// This must be a literal with the same value as AEND-A0 +// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS #define NUM_ANALOG_INPUTS 12 +#define NUM_ANALOG_FIRST 46 // On-board LED pin number #define LED_BUILTIN 13 diff --git a/variants/board_template/variant.h b/variants/board_template/variant.h index 3e19bf2e9f..06182b2d97 100644 --- a/variants/board_template/variant.h +++ b/variants/board_template/variant.h @@ -34,8 +34,7 @@ /*---------------------------------------------------------------------------- * Headers *----------------------------------------------------------------------------*/ - -#include "pins_arduino.h" +#include "PeripheralPins.h" #ifdef __cplusplus extern "C"{ @@ -63,22 +62,20 @@ enum { // so an enum will not work. #define NUM_DIGITAL_PINS 0 -// Enum defining Arduino style alias for analog pin number --> Ax +// Allow to define Arduino style alias for analog input pin number --> Ax +// All pins are digital, analog inputs are a subset of digital pins +// and must be contiguous to be able to loop on each value +// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS +// defined in pin_arduino.h +// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3) +// so an enum will not work. // !!! // !!! It must be aligned with the number of analog PinName // !!! defined in digitalPin[] array in variant.cpp // !!! -enum { - A_START_AFTER = Dx, // pin number preceding A0 - A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, - A10, A11, A12, A13, A14, A15, A16, A17, - AEND -}; - -// This must be a literal with the same value as AEND-A0 -// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3) -// so an enum will not work. -#define NUM_ANALOG_INPUTS 18 +#define NUM_ANALOG_INPUTS 0 +// Define digital pin number of the first analog input (i.e. which digital pin is A0) +#define NUM_ANALOG_FIRST 0 // Below ADC, DAC and PWM definitions already done in the core // Could be redefined here if needed @@ -92,23 +89,23 @@ enum { //#define PWM_MAX_DUTY_CYCLE 255 // On-board LED pin number -#define LED_BUILTIN Dx +#define LED_BUILTIN x #define LED_GREEN LED_BUILTIN // On-board user button -#define USER_BTN Dx +#define USER_BTN x // Below SPI and I2C definitions already done in the core -// Could be redefined here if needed +// Could be redefined here if differs from the default one // SPI Definitions -//#define SS 10 // Default for Arduino connector compatibility -//#define MOSI 11 // Default for Arduino connector compatibility -//#define MISO 12 // Default for Arduino connector compatibility -//#define SCK 13 // Default for Arduino connector compatibility +//#define PIN_SPI_SS 10 // Default for Arduino connector compatibility +//#define PIN_SPI_MOSI 11 // Default for Arduino connector compatibility +//#define PIN_SPI_MISO 12 // Default for Arduino connector compatibility +//#define PIN_SPI_SCK 13 // Default for Arduino connector compatibility // I2C Definitions -//#define SDA 14 // Default for Arduino connector compatibility -//#define SCL 15 // Default for Arduino connector compatibility +//#define PIN_WIRE_SDA 14 // Default for Arduino connector compatibility +//#define PIN_WIRE_SCL 15 // Default for Arduino connector compatibility // Timer Definitions //Do not use timer used by PWM pins when possible. See PinMap_PWM in PeripheralPins.c @@ -134,8 +131,8 @@ enum { // Default pin used for 'Serial' instance (ex: ST-Link) // Mandatory for Firmata -#define PIN_SERIAL_RX Dx -#define PIN_SERIAL_TX Dx +#define PIN_SERIAL_RX x +#define PIN_SERIAL_TX x #ifdef __cplusplus } // extern "C"