forked from Elron_dev/elbear_arduino_bsp
Добавлена библиотека softSerial. Общий обработчик прерываний, а также некоторые обработчики прерываний конкретных модулей перенесены в память ram
- добавлена библиотека softwareSerial. Скорость работы до 57600 включительно и на отправку, и на прием. - в bootloader добавлена проверка контрольной суммы - добавлен файл wiringLL.h, в котором собраны некоторые макросы. Этими макросами заменены функции в местах, чувствительных к длительности выполнения кода. - общие функции обработки прерываний перенесены в ram память для увеличения скорости выполнения. Так же в память ram перенесены функции обработки прерываний модулей WInterrupt (прерывания от gpio), модуля tone, модуля softwareSerial - добавлен файл-заглушка util/delay.h, необходимый для некоторых библиотек
This commit is contained in:
1 parent
a7468870fc
commit
47c01383e6
26 files changed
+1120
-315
No files matched your search
@@ -109,16 +109,24 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#define WIRE_FREQ_1000K 1000000
|
||||
|
||||
// interrupts
|
||||
extern uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3];
|
||||
// determines the board pin number by interrupt number
|
||||
uint32_t interruptToDigitalPin(uint8_t interruptNum);
|
||||
#define interruptToDigitalPin(interruptNum) (interruptInfo[interruptNum][0])
|
||||
// determines gpio interrupt line by interrupt number
|
||||
#define interruptToGpioIntLine(interruptNum) ((uint8_t)interruptInfo[interruptNum][1])
|
||||
// determines gpio interrupt mux by interrupt number
|
||||
#define interruptToGpioIntMux(interruptNum) ((uint8_t)interruptInfo[interruptNum][2])
|
||||
// determines interrupt number by the board pin number
|
||||
int8_t digitalPinToInterrupt(uint32_t digPinNumber);
|
||||
// determines gpio interrupt line by interrupt number
|
||||
uint32_t interruptToGpioIntLine(uint8_t interruptNum);
|
||||
// determines interrupt number by the gpio interrupt line
|
||||
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine);
|
||||
// determines gpio interrupt mux by interrupt number
|
||||
uint32_t interruptToGpioIntMux(uint8_t interruptNum);
|
||||
// determines gpio interrupt mux by the board pin number
|
||||
int8_t digitalPinToGpioIntMux(uint8_t digPinNumber);
|
||||
// determines gpio interrupt line by the board pin number
|
||||
int8_t digitalPinToGpioIntLine(uint8_t digPinNumber);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+25
-29
@@ -14,6 +14,7 @@
|
||||
#include "pins_arduino.h"
|
||||
#include "mik32_hal_adc.h"
|
||||
#include "wiring_analog.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -107,10 +108,6 @@ volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x)
|
||||
return &GPIO_x->STATE;
|
||||
}
|
||||
|
||||
// return config of pin with pinShift(0...16) in portReg (config, pupd, ds for ports 0...2)
|
||||
#define PIN_PAD_CONFIG(portReg, pinShift) ((PAD_CONFIG->portReg >> (pinShift<<1)) & 0b11)
|
||||
|
||||
|
||||
// ---------------------- ADC ---------------------- //
|
||||
// determines the ADC channel number by the board pin number
|
||||
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||
@@ -168,9 +165,9 @@ bool digitalPinPwmIsOn(uint8_t digitalPin)
|
||||
uint8_t pinShift = pwmPinToGpioPinShift(digitalPin);
|
||||
|
||||
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||
config = PIN_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||
else
|
||||
config = PIN_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||
|
||||
if (config == 2)
|
||||
return true;
|
||||
@@ -216,9 +213,9 @@ HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber)
|
||||
}
|
||||
|
||||
// ---------------------- interrupts ---------------------- //
|
||||
// interrupt table
|
||||
// interrupt table is stored in ram to improve performance
|
||||
// index = interrupt number. In each row {digitalPinNumber, IntLineValue, IntMuxValue}
|
||||
const uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
||||
uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
||||
{
|
||||
{ 2, GPIO_LINE_2, GPIO_MUX_LINE_2_PORT0_10}, // INT0
|
||||
{ 3, GPIO_LINE_0, GPIO_MUX_LINE_0_PORT0_0}, // INT1
|
||||
@@ -229,19 +226,23 @@ const uint8_t interruptInfo[EXTERNAL_NUM_INTERRUPTS][3] =
|
||||
{BTN_BUILTIN, GPIO_LINE_6, GPIO_MUX_LINE_6_PORT2_6}, // INT6 (button)
|
||||
};
|
||||
|
||||
uint32_t interruptToDigitalPin(uint8_t interruptNum)
|
||||
int8_t digitalPinToGpioIntMux(uint8_t digPinNumber)
|
||||
{
|
||||
return interruptInfo[interruptNum][0];
|
||||
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||
{
|
||||
if (interruptInfo[i][0] == digPinNumber)
|
||||
return interruptInfo[i][2];
|
||||
}
|
||||
return NOT_AN_INTERRUPT;
|
||||
}
|
||||
|
||||
uint32_t interruptToGpioIntLine(uint8_t interruptNum)
|
||||
int8_t digitalPinToGpioIntLine(uint8_t digPinNumber)
|
||||
{
|
||||
return (uint32_t)interruptInfo[interruptNum][1];
|
||||
}
|
||||
|
||||
uint32_t interruptToGpioIntMux(uint8_t interruptNum)
|
||||
{
|
||||
return (uint32_t)interruptInfo[interruptNum][2];
|
||||
for (uint8_t i = 0; i < EXTERNAL_NUM_INTERRUPTS; i++)
|
||||
{
|
||||
if (interruptInfo[i][0] == digPinNumber)
|
||||
return interruptInfo[i][1];
|
||||
}
|
||||
return NOT_AN_INTERRUPT;
|
||||
}
|
||||
|
||||
int8_t gpioIntLineToInterrupt(uint32_t gpioIntLine)
|
||||
@@ -265,25 +266,20 @@ int8_t digitalPinToInterrupt(uint32_t digPinNumber)
|
||||
}
|
||||
|
||||
// ---------------------- SPI ---------------------- //
|
||||
// pins shift in registers
|
||||
#define PIN_3_SHIFT 3
|
||||
#define PIN_4_SHIFT 4
|
||||
#define PORT1_GET_PAD_PUPD(pinShift) ((PAD_CONFIG->PORT_1_PUPD >> (pinShift<<1)) & 0b11)
|
||||
#define PORT1_GET_GPIO_STATE(pinShift) ((GPIO_1->OUTPUT_ >> pinShift) & 0b1)
|
||||
|
||||
void spi_onBegin(void)
|
||||
{
|
||||
// On Elbear Ace-Uno rev1.1.0 there is a seller on pin 1.6 which replace D10 from spi NSS pin 1.3 to pin 1.4,
|
||||
// because spi needs pin 1.3 for correct work
|
||||
|
||||
// replace config from 1.3 to 1.4
|
||||
uint8_t config = PIN_PAD_CONFIG(PORT_1_CFG, PIN_3_SHIFT);
|
||||
uint8_t config = PIN_GET_PAD_CONFIG(PORT_1_CFG, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3));
|
||||
if (config == 0) // common gpio
|
||||
{
|
||||
// get info from pin gpio1.3 and set config to gpio1.4
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_4, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_3),
|
||||
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_3_SHIFT), HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_3_SHIFT));
|
||||
(HAL_GPIO_PullTypeDef)PIN_GET_PAD_CONFIG(PORT_1_PUPD, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3)),
|
||||
HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, (GPIO_PinState)GPIO_GET_PIN_STATE(GPIO_1, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3)));
|
||||
|
||||
// pin D10 was switched to different gpio and can be used further
|
||||
}
|
||||
@@ -304,8 +300,8 @@ void spi_onEnd(void)
|
||||
{
|
||||
// get info from pin gpio1.4 and set config to gpio1.3
|
||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_3, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_4),
|
||||
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_4_SHIFT), HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_3, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_4_SHIFT));
|
||||
(HAL_GPIO_PullTypeDef)PIN_GET_PAD_CONFIG(PORT_1_PUPD, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_4)), HAL_GPIO_DS_2MA);
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_3, (GPIO_PinState)GPIO_GET_PIN_STATE(GPIO_1, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_4)));
|
||||
|
||||
// switch seller back to pin 1.3
|
||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_LOW);
|
||||
|
||||
Reference in new issue
Block a user