forked from Elron_dev/elbear_arduino_bsp
добавлена поддержка еще одного прерывания и еще двух выводов для ШИМ для
платы Elbear. добавлены флаги компиляции, необходимые для работы в ArduinoIDE v1.8.19
This commit is contained in:
1 parent
f06650400b
commit
a32d749c60
19 files changed
+172
-116
No files matched your search
@@ -111,7 +111,7 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#define WIRE_FREQ_1000K 1000000
|
||||
|
||||
// interrupts
|
||||
#define EXTERNAL_INTERRUPTS_QTY 7
|
||||
#define EXTERNAL_INTERRUPTS_QTY 8
|
||||
extern uint8_t interruptInfo[EXTERNAL_INTERRUPTS_QTY][3];
|
||||
// determines the board pin number by interrupt number
|
||||
#define interruptToDigitalPin(interruptNum) (interruptInfo[interruptNum][0])
|
||||
|
||||
@@ -153,25 +153,14 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||
|
||||
// ---------------------- PWM ---------------------- //
|
||||
// use only if digitalPinHasPWM() == true
|
||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)) ? 1:0)
|
||||
// use only if digitalPinHasPWM() == true
|
||||
static inline uint8_t pwmPinToGpioPinShift(uint8_t digitalPin)
|
||||
{
|
||||
if (digitalPin == 3)
|
||||
return 0;
|
||||
else if ((digitalPin == 5) || (digitalPin == 11))
|
||||
return 1;
|
||||
else if (digitalPin == 6)
|
||||
return 2;
|
||||
else // pins 9 10
|
||||
return 3;
|
||||
}
|
||||
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)||(pin==12)||(pin==13)) ? 1:0)
|
||||
|
||||
// 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 = PIN_MASK_TO_PIN_NUMBER(digitalPinToBitMask(digitalPin));
|
||||
|
||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
@@ -190,7 +179,7 @@ bool digitalPinHasPWM(uint8_t p)
|
||||
// if spi is in use D10 cannot work as pwm
|
||||
if (spiNssPinIsBlocked && (p == 10))
|
||||
ret = false;
|
||||
else if ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
|
||||
else if (p == 3 || p == 5 || p == 6 || (p >= 9 && p <= 13))
|
||||
ret = true;
|
||||
return ret;
|
||||
}
|
||||
@@ -204,7 +193,7 @@ TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber)
|
||||
if (digPinNumber == 3 || digPinNumber == 5 || digPinNumber == 6 || digPinNumber == 9)
|
||||
timerNum = TIMER32_1;
|
||||
// timer 2
|
||||
else if (digPinNumber == 10 || digPinNumber == 11)
|
||||
else if (digPinNumber == 10 || digPinNumber == 11 || digPinNumber == 12 || digPinNumber == 13)
|
||||
timerNum = TIMER32_2;
|
||||
|
||||
return timerNum;
|
||||
@@ -214,9 +203,9 @@ TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber)
|
||||
HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber)
|
||||
{
|
||||
HAL_TIMER32_CHANNEL_IndexTypeDef channel = 0;
|
||||
if (digPinNumber == 3) channel = TIMER32_CHANNEL_0;
|
||||
if (digPinNumber == 3 || digPinNumber == 12) channel = TIMER32_CHANNEL_0;
|
||||
else if (digPinNumber == 5 || digPinNumber == 11) channel = TIMER32_CHANNEL_1;
|
||||
else if (digPinNumber == 6) channel = TIMER32_CHANNEL_2;
|
||||
else if (digPinNumber == 6 || digPinNumber == 13) channel = TIMER32_CHANNEL_2;
|
||||
else if (digPinNumber == 9 || digPinNumber == 10) channel = TIMER32_CHANNEL_3;
|
||||
return channel;
|
||||
}
|
||||
@@ -232,7 +221,9 @@ uint8_t interruptInfo[EXTERNAL_INTERRUPTS_QTY][3] =
|
||||
{ 5, GPIO_LINE_1, GPIO_MUX_LINE_1_PORT0_1}, // INT3
|
||||
{ 8, GPIO_LINE_5, GPIO_MUX_LINE_5_PORT1_9}, // INT4
|
||||
{ 9, GPIO_LINE_3, GPIO_MUX_LINE_3_PORT0_3}, // INT5
|
||||
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT6 (button)
|
||||
{ A1, GPIO_LINE_7, GPIO_MUX_LINE_7_PORT1_7}, // INT6
|
||||
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT7 (button)
|
||||
|
||||
};
|
||||
|
||||
int8_t digitalPinToGpioIntMux(uint8_t digPinNumber)
|
||||
|
||||
@@ -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)
|
||||
@@ -105,9 +107,15 @@ static const uint8_t A7 = PIN_A7;
|
||||
// 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
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digPinNumber);
|
||||
static inline HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
|
||||
}
|
||||
// total number of pins available for initialization
|
||||
uint16_t pinCommonQty(void);
|
||||
static inline uint16_t pinCommonQty(void)
|
||||
{
|
||||
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);
|
||||
// the function returns a reference to the STATE address of the GPIO register
|
||||
|
||||
@@ -41,17 +41,6 @@ GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
|
||||
}
|
||||
}
|
||||
|
||||
// determines the pin address inside the port by the board pin number
|
||||
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
|
||||
{
|
||||
return 1 << (digitalPinNumber & 0xF);
|
||||
}
|
||||
|
||||
uint16_t pinCommonQty(void)
|
||||
{
|
||||
return (uint16_t)40;
|
||||
}
|
||||
|
||||
// the function returns a reference to the OUTPUT address of the GPIO register
|
||||
volatile uint32_t *portOutputRegister(GPIO_TypeDef *GPIO_x)
|
||||
{
|
||||
@@ -105,17 +94,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 & 3;
|
||||
|
||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
|
||||
Reference in new issue
Block a user