From 1c7fc6a20856f6d43d3e54687300f9278db54fed Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Tue, 28 Jan 2025 10:22:48 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D0=BF=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B4=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=83=20elsomik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- variants/elsomik/pins_arduino.h | 88 +++++++++++++++------------------ variants/elsomik/variant.c | 48 ++++++------------ 2 files changed, 54 insertions(+), 82 deletions(-) diff --git a/variants/elsomik/pins_arduino.h b/variants/elsomik/pins_arduino.h index d42da8d..a311bcb 100644 --- a/variants/elsomik/pins_arduino.h +++ b/variants/elsomik/pins_arduino.h @@ -32,49 +32,45 @@ 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 // TDI + P0_12, // 12 // TCK + P0_13, // 13 // TMS + P0_14, // 14 // TRST + P0_15, // 15 // TDO + 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_6, // 32 + P2_7, // 33 + PINS_COMMON_QTY, // 34 +} DigitalPinsTypeDef; // analog pins #define PIN_A0 (P1_5) @@ -96,12 +92,6 @@ static const uint8_t A6 = PIN_A6; static const uint8_t A7 = PIN_A7; -// User led and button -#define LED_BUILTIN0 (P0_3) -#define LED_BUILTIN1 (P1_3) -#define LED_BUILTIN LED_BUILTIN0 -#define BTN_BUILTIN (P0_8) - // determines the address of the port by the board pin number to which this pin belongs on the MCU GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber); // determines the pin address inside the port by the board pin number @@ -112,7 +102,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); diff --git a/variants/elsomik/variant.c b/variants/elsomik/variant.c index d220902..e2e2050 100644 --- a/variants/elsomik/variant.c +++ b/variants/elsomik/variant.c @@ -23,22 +23,14 @@ GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber) { - if (digitalPinNumber < 16u) - { + if (digitalPinNumber < 16) return GPIO_0; - } - else if ((digitalPinNumber >= 16u) && (digitalPinNumber < 32u)) - { + else if ((digitalPinNumber >= 16) && (digitalPinNumber < 32)) return GPIO_1; - } - else if ((digitalPinNumber >= 32u) && (digitalPinNumber < 40u)) - { + else if ((digitalPinNumber >= 32) && (digitalPinNumber < 40)) return GPIO_2; - } else - { return NULL; - } } // the function returns a reference to the OUTPUT address of the GPIO register @@ -94,17 +86,13 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber) // ---------------------- PWM ---------------------- // // use only if digitalPinHasPWM() == true #define PWM_PIN_TO_PORT_NUMBER(pin) (((pin) & 16) ? 1 : 0) -// use only if digitalPinHasPWM() == true -static inline uint8_t pwmPinToGpioPinShift(uint8_t digitalPin) -{ - return digitalPin & 3; -} + // use only if digitalPinHasPWM() == true // return true if digitalPin configured as pwm bool digitalPinPwmIsOn(uint8_t digitalPin) { uint8_t config = 0; - uint8_t pinShift = pwmPinToGpioPinShift(digitalPin); + uint8_t pinShift = digitalPin & 0x3; if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0) config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift); @@ -117,26 +105,20 @@ bool digitalPinPwmIsOn(uint8_t digitalPin) return false; } -bool digitalPinHasPWM(uint8_t p) +bool digitalPinHasPWM(uint8_t digitalPin) { - return (p < 32) && ((p & 0xF) < 4); + return (digitalPin < 32) && ((digitalPin & 0xF) < 4); } // function is used only if digitalPinHasPWM() is true TIMER32_TypeDef *pwmPinToTimer(uint32_t digPinNumber) { if (digPinNumber < 16) - { return TIMER32_1; - } else if ((digPinNumber >= 16) && (digPinNumber < 32)) - { return TIMER32_2; - } else - { return NULL; - } } // function is used only if digitalPinHasPWM() is true @@ -162,14 +144,14 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber) // index = interrupt number. In each row {digitalPinNumber, IntLineValue, IntMuxValue} uint8_t interruptInfo[EXTERNAL_INTERRUPTS_QTY][3] = { - {BTN_BUILTIN, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT0_8}, // INT0 - {P1_9, GPIO_LINE_1, GPIO_MUX_LINE_1_PORT1_9}, // INT1 - {P0_10, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT2 - {P1_15, GPIO_LINE_3, GPIO_MUX_LINE_3_PORT1_15}, // INT3 - {P0_12, GPIO_LINE_4, GPIO_MUX_LINE_4_PORT0_12}, // INT4 - {P0_13, GPIO_LINE_5, GPIO_MUX_LINE_5_PORT0_13}, // INT5 - {P0_14, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT0_14}, // INT6 - {P0_15, GPIO_LINE_7, GPIO_MUX_LINE_7_PORT0_15}, // INT7 + {P0_4, GPIO_LINE_4, GPIO_MUX_LINE_4_PORT0_4}, // INT0 + {P0_9, GPIO_LINE_5, GPIO_MUX_LINE_5_PORT0_9}, // INT1 + {P0_10, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT2 + {P0_15, GPIO_LINE_7, GPIO_MUX_LINE_7_PORT0_15}, // INT3 + {P1_6, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT1_6}, // INT4 + {P1_9, GPIO_LINE_1, GPIO_MUX_LINE_1_PORT1_9}, // INT5 + {P1_12, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT1_12}, // INT6 + {P1_15, GPIO_LINE_3, GPIO_MUX_LINE_3_PORT1_15}, // INT7 }; int8_t digitalPinToGpioIntMux(uint8_t digPinNumber)