добавлено еще одно прерывание на ноге А1. Добавлено еще два вывода с ШИМ
This commit is contained in:
parent
7e2d0b19cc
commit
3a02bddf3f
@ -112,7 +112,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])
|
||||
|
||||
@ -51,17 +51,16 @@ const HAL_PinsTypeDef digitalPinToGpioPinArray[] =
|
||||
GPIO_TypeDef* digitalPinToPort(uint32_t digPinNumber)
|
||||
{
|
||||
GPIO_TypeDef* gpioNum = 0;
|
||||
// port 0 - board pins 0...6, 9, 16(A2), 17(A3), 20(A4), 21(A5)
|
||||
if ((digPinNumber >= 0 && digPinNumber <= 6) || digPinNumber == 9 || digPinNumber == 16
|
||||
|| digPinNumber == 17 || digPinNumber == 20 || digPinNumber == 21) // 12 pieces
|
||||
gpioNum = GPIO_0;
|
||||
// port 2 - led and button
|
||||
if (digPinNumber == LED_BUILTIN || digPinNumber == BTN_BUILTIN)
|
||||
gpioNum = GPIO_2;
|
||||
// port 1 - board pins 7, 8, 10...13, 14(А0), 15(А1), 18,19
|
||||
else if (digPinNumber == 7 || digPinNumber == 8 || (digPinNumber >= 10 && digPinNumber <= 15)
|
||||
|| digPinNumber == 18 || digPinNumber == 19) // 10 pieces
|
||||
gpioNum = GPIO_1;
|
||||
// port 2 - led and button
|
||||
else if (digPinNumber == LED_BUILTIN || digPinNumber == BTN_BUILTIN)
|
||||
gpioNum = GPIO_2;
|
||||
// port 0 - board pins 0...6, 9, 16(A2), 17(A3), 20(A4), 21(A5)
|
||||
else
|
||||
gpioNum = GPIO_0;
|
||||
|
||||
return gpioNum;
|
||||
}
|
||||
@ -101,20 +100,22 @@ volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x)
|
||||
}
|
||||
|
||||
// the function initializes additional MCU pins depending on the specified pin number
|
||||
#define SELA45_PORT GPIO_1
|
||||
#define SELA45_PIN GPIO_PIN_15
|
||||
static bool selaSwitchIsInited = false;
|
||||
void additionalPinsInit(uint32_t PinNumber)
|
||||
{
|
||||
// if we use pin A5, we need to set SELA45 (1.15) to 1 to switch the output from A4 to A5
|
||||
if (!selaSwitchIsInited)
|
||||
{
|
||||
HAL_GPIO_PinConfig(SELA45_PORT, SELA45_PIN, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||
selaSwitchIsInited = true;
|
||||
}
|
||||
// if we use pin A5, we need to set SELA45 to 1 to switch the output from A4 to A5
|
||||
if (PinNumber == A5)
|
||||
{
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_HIGH);
|
||||
}
|
||||
HAL_GPIO_WritePin(SELA45_PORT, SELA45_PIN, GPIO_PIN_HIGH);
|
||||
else if(PinNumber == A4)
|
||||
{
|
||||
// return the switch to A4 in case A5 was previously read
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_15, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_15, GPIO_PIN_LOW);
|
||||
}
|
||||
HAL_GPIO_WritePin(SELA45_PORT, SELA45_PIN, GPIO_PIN_LOW);
|
||||
}
|
||||
|
||||
// ---------------------- ADC ---------------------- //
|
||||
@ -153,25 +154,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 +180,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 +194,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 +204,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 +222,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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user