diff --git a/variants/elsomik/variant.c b/variants/elsomik/variant.c index e2e2050..8362618 100644 --- a/variants/elsomik/variant.c +++ b/variants/elsomik/variant.c @@ -23,11 +23,11 @@ GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber) { - if (digitalPinNumber < 16) + if (digitalPinNumber <= P0_15) return GPIO_0; - else if ((digitalPinNumber >= 16) && (digitalPinNumber < 32)) + else if ((digitalPinNumber >= P1_0) && (digitalPinNumber <= P1_15)) return GPIO_1; - else if ((digitalPinNumber >= 32) && (digitalPinNumber < 40)) + else if ((digitalPinNumber >= P2_6) && (digitalPinNumber < PINS_COMMON_QTY)) return GPIO_2; else return NULL; @@ -107,15 +107,15 @@ bool digitalPinPwmIsOn(uint8_t digitalPin) bool digitalPinHasPWM(uint8_t digitalPin) { - return (digitalPin < 32) && ((digitalPin & 0xF) < 4); + return (digitalPin <= P1_15) && ((digitalPin & 0xF) < 4); } // function is used only if digitalPinHasPWM() is true TIMER32_TypeDef *pwmPinToTimer(uint32_t digPinNumber) { - if (digPinNumber < 16) + if (digPinNumber <= P0_15) return TIMER32_1; - else if ((digPinNumber >= 16) && (digPinNumber < 32)) + else if ((digPinNumber >= P1_0) && (digPinNumber <= P1_15)) return TIMER32_2; else return NULL; diff --git a/variants/start/pins_arduino.h b/variants/start/pins_arduino.h index d42da8d..4231d8a 100644 --- a/variants/start/pins_arduino.h +++ b/variants/start/pins_arduino.h @@ -32,49 +32,51 @@ extern "C" { #include "mik32_hal_gpio.h" #include "mik32_hal_timer32.h" -#define PORT_PIN_MASK 0xF - // digital pins -#define P0_0 0 -#define P0_1 1 -#define P0_2 2 -#define P0_3 3 -#define P0_4 4 -#define P0_5 5 -#define P0_6 6 -#define P0_7 7 -#define P0_8 8 -#define P0_9 9 -#define P0_10 10 -#define P0_11 11 -#define P0_12 12 -#define P0_13 13 -#define P0_14 14 -#define P0_15 15 -#define P1_0 16 -#define P1_1 17 -#define P1_2 18 -#define P1_3 19 -#define P1_4 20 -#define P1_5 21 -#define P1_6 22 -#define P1_7 23 -#define P1_8 24 -#define P1_9 25 -#define P1_10 26 -#define P1_11 27 -#define P1_12 28 -#define P1_13 29 -#define P1_14 30 -#define P1_15 31 -#define P2_0 32 -#define P2_1 33 -#define P2_2 34 -#define P2_3 35 -#define P2_4 36 -#define P2_5 37 -#define P2_6 38 -#define P2_7 39 +typedef enum +{ + P0_0 = 0, // 0 + P0_1, // 1 + P0_2, // 2 + P0_3, // 3 + P0_4, // 4 + P0_5, // 5 + P0_6, // 6 + P0_7, // 7 + P0_8, // 8 + P0_9, // 9 + P0_10, // 10 + P0_11, // 11 + P0_12, // 12 + P0_13, // 13 + P0_14, // 14 + P0_15, // 15 + P1_0, // 16 + P1_1, // 17 + P1_2, // 18 + P1_3, // 19 + P1_4, // 20 + P1_5, // 21 + P1_6, // 22 + P1_7, // 23 + P1_8, // 24 + P1_9, // 25 + P1_10, // 26 + P1_11, // 27 + P1_12, // 28 + P1_13, // 29 + P1_14, // 30 + P1_15, // 31 + P2_0, // 32 + P2_1, // 33 + P2_2, // 34 + P2_3, // 35 + P2_4, // 36 + P2_5, // 37 + P2_6, // 38 + P2_7, // 39 + PINS_COMMON_QTY, // 40 +} DigitalPinsTypeDef; // analog pins #define PIN_A0 (P1_5) @@ -112,7 +114,7 @@ static inline HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber) // total number of pins available for initialization static inline uint16_t pinCommonQty(void) { - return (uint16_t)40; + return (uint16_t)PINS_COMMON_QTY; } // the function returns a reference to the OUTPUT address of the GPIO register volatile uint32_t* portOutputRegister(GPIO_TypeDef* GPIO_x);