diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 2ae48baf83..a553f45bdc 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -34,7 +34,7 @@ void yield(void); } // extern "C" #endif // __cplusplus -// Include board variant -#include "pins_arduino.h" +// Include pins variant +#include "pins_arduino_var.h" #endif // Arduino_h diff --git a/cores/arduino/pins_arduino.c b/cores/arduino/pins_arduino.c index cebc377375..adcea54647 100644 --- a/cores/arduino/pins_arduino.c +++ b/cores/arduino/pins_arduino.c @@ -17,6 +17,7 @@ */ #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 723fe2d0a4..4e2708b052 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -19,12 +19,6 @@ #define _PINS_ARDUINO_H_ #include "PeripheralPins.h" -#include "pins_arduino_common.h" -#include "variant.h" - -#ifdef __cplusplus -extern "C" { -#endif /** * Libc porting layers @@ -34,79 +28,28 @@ extern "C" { #define WEAK __attribute__ ((weak)) #endif -#define NOT_AN_INTERRUPT NC // -1 -#define DEND PEND -#define NUM_DIGITAL_PINS ((uint32_t)DEND) -#define NUM_ANALOG_INPUTS ((uint32_t)(AEND-A0)) - -// 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 +// Arduino digital pin alias +// GPIO port (A to K) * 16 pins: 176 +enum { + D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, + D10, D11, D12, D13, D14, D15, D16, D17, D18, D19, + D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, + D30, D31, D32, D33, D34, D35, D36, D37, D38, D39, + D40, D41, D42, D43, D44, D45, D46, D47, D48, D49, + D50, D51, D52, D53, D54, D55, D56, D57, D58, D59, + D60, D61, D62, D63, D64, D65, D66, D67, D68, D69, + D70, D71, D72, D73, D74, D75, D76, D77, D78, D79, + D80, D81, D82, D83, D84, D85, D86, D87, D88, D89, + D90, D91, D92, D93, D94, D95, D96, D97, D98, D99, + D100, D101, D102, D103, D104, D105, D106, D107, D108, D109, + D110, D111, D112, D113, D114, D115, D116, D117, D118, D119, + D120, D121, D122, D123, D124, D125, D126, D127, D128, D129, + D130, D131, D132, D133, D134, D135, D136, D137, D138, D139, + D140, D141, D142, D143, D144, D145, D146, D147, D148, D149, + D150, D151, D152, D153, D154, D155, D156, D157, D158, D159, + D160, D161, D162, D163, D164, D165, D166, D167, D168, D169, + D170, D171, D172, D173, D174, D175, + DMAX +}; #endif /*_PINS_ARDUINO_H_*/ diff --git a/cores/arduino/pins_arduino_common.h b/cores/arduino/pins_arduino_common.h deleted file mode 100644 index 2467499583..0000000000 --- a/cores/arduino/pins_arduino_common.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Common 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_COMMON_H_ -#define _PINS_ARDUINO_COMMON_H_ - -// Arduino digital pin alias -// GPIO port (A to K) * 16 pins: 176 -enum { - D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, - D10, D11, D12, D13, D14, D15, D16, D17, D18, D19, - D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, - D30, D31, D32, D33, D34, D35, D36, D37, D38, D39, - D40, D41, D42, D43, D44, D45, D46, D47, D48, D49, - D50, D51, D52, D53, D54, D55, D56, D57, D58, D59, - D60, D61, D62, D63, D64, D65, D66, D67, D68, D69, - D70, D71, D72, D73, D74, D75, D76, D77, D78, D79, - D80, D81, D82, D83, D84, D85, D86, D87, D88, D89, - D90, D91, D92, D93, D94, D95, D96, D97, D98, D99, - D100, D101, D102, D103, D104, D105, D106, D107, D108, D109, - D110, D111, D112, D113, D114, D115, D116, D117, D118, D119, - D120, D121, D122, D123, D124, D125, D126, D127, D128, D129, - D130, D131, D132, D133, D134, D135, D136, D137, D138, D139, - D140, D141, D142, D143, D144, D145, D146, D147, D148, D149, - D150, D151, D152, D153, D154, D155, D156, D157, D158, D159, - D160, D161, D162, D163, D164, D165, D166, D167, D168, D169, - D170, D171, D172, D173, D174, D175, - DMAX -}; - -#endif /*_PINS_ARDUINO_COMMON_H_*/ - diff --git a/cores/arduino/pins_arduino_var.h b/cores/arduino/pins_arduino_var.h new file mode 100644 index 0000000000..afec16ff11 --- /dev/null +++ b/cores/arduino/pins_arduino_var.h @@ -0,0 +1,108 @@ +/* + * 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" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NOT_AN_INTERRUPT NC // -1 +#define DEND PEND +#define NUM_DIGITAL_PINS ((uint32_t)DEND) +#define NUM_ANALOG_INPUTS ((uint32_t)(AEND-A0)) + +// 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 + +#endif /*_PINS_ARDUINO_VAR_H_*/ +