From 77192e802ee1fcc291c324a674b6a8f11aec629e Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 23 Aug 2017 08:26:01 +0200 Subject: [PATCH 1/3] Fix digitalPinToPort(p) Signed-off-by: Frederic.Pillon --- cores/arduino/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index 7e024a8ace..bd9e92a185 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -62,7 +62,7 @@ uint32_t pinNametoDigitalPin(PinName p); pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SSEL)) -#define digitalPinToPort(p) (get_GPIO_Port(digitalPinToPinName(p))) +#define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p)))) #define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p))) #define digitalPinIsValid(p) (digitalPinToPinName(p) != NC) From f50539adccec8980e7477e387651a3ffd555008c Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 23 Aug 2017 10:37:34 +0200 Subject: [PATCH 2/3] Extend compatibility Add several macro for compatibily (register access) Added: analogInPinToBit portOutputRegister portInputRegister portSetRegister portClearRegister portConfigRegister portModeRegister _BV cbi sbi Signed-off-by: Frederic.Pillon --- cores/arduino/pins_arduino.h | 25 +++++++++++++++++++++++++ cores/arduino/wiring_constants.h | 13 +++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index bd9e92a185..e7f78fbc97 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -65,6 +65,31 @@ uint32_t pinNametoDigitalPin(PinName p); #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[] diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h index f249e66b76..cccfe4eb72 100644 --- a/cores/arduino/wiring_constants.h +++ b/cores/arduino/wiring_constants.h @@ -112,10 +112,19 @@ enum BitOrder { #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) -typedef unsigned int word; - #define bit(b) (1UL << (b)) +//macro added for compatibility +#ifndef _BV +#define _BV(bit) (1 << (bit)) +#endif +#ifndef cbi +#define cbi(reg, bitmask) *reg &= ~bitmask +#endif +#ifndef sbi +#define sbi(reg, bitmask) *reg |= bitmask +#endif +typedef unsigned int word; typedef bool boolean ; From e42a83c538aefe2540116ced2b97d102f278cd5d Mon Sep 17 00:00:00 2001 From: "Frederic.Pillon" Date: Wed, 23 Aug 2017 10:02:28 +0200 Subject: [PATCH 3/3] warning: Fix warning: comparison between 'enum' and 'enum' [-Wenum-compare] Signed-off-by: Frederic.Pillon --- cores/arduino/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/pins_arduino.h b/cores/arduino/pins_arduino.h index e7f78fbc97..048a6c87d4 100644 --- a/cores/arduino/pins_arduino.h +++ b/cores/arduino/pins_arduino.h @@ -34,7 +34,7 @@ extern "C" { #define NOT_AN_INTERRUPT NC // -1 #define DEND PEND -#define NUM_DIGITAL_PINS DEND +#define NUM_DIGITAL_PINS ((uint32_t)DEND) #define NUM_ANALOG_INPUTS (AEND-A0) // Convert a digital pin number Dxx to a PinName PX_n