Обновление до версии 0.3.0

- обновлен elbear_fw_bootloader - добавлена проверка контрольной суммы каждой строки hex файла.
- в модуль работы с АЦП добавлена функция analogReadResolution(). Функция analogRead() теперь возвращает усредненное по 10 измерениям значение.
- общая функция обработки прерываний перенесена в память RAM. Обработчики прерываний модулей External Interrupts и Advanced I/O (функция tone()) так же перенесены в память RAM для увеличения скорости выполнения кода.
- в пакет добавлены библиотеки EEPROM, Servo, SoftSerial, NeoPixel, MFRC522 адаптированные для работы с платой Elbear Ace-Uno.
- добавлено описание особенностей работы с пакетом
This commit was merged in pull request #6.
This commit is contained in:
klassents committed 2024-10-17 08:27:39 +03:00
1 parent 7a7c552743
commit 766b7b32ea
114 files changed
+11064 -666

No files matched your search

+18 -16
View File
@@ -32,8 +32,6 @@ extern "C" {
#include "mik32_hal_gpio.h"
#include "mik32_hal_timer32.h"
extern bool spiNssPinIsBlocked;
// analog pins
#define PIN_A0 (14)
#define PIN_A1 (15)
@@ -73,11 +71,13 @@ volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x);
#define SERIAL_PORT_QTY 2
// ADC
#define MCU_ADC_RESOLUTION 12 // bits
// determines the ADC channel number by the board pin number
uint32_t analogInputToChannelNumber(uint32_t PinNumber);
// PWM
bool digitalPinHasPWM(uint8_t p);
bool digitalPinPwmIsOn(uint8_t digitalPin); // use only if digitalPinHasPWM() == true
// determines which timer the pin belongs to
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to
@@ -94,19 +94,13 @@ static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
// config SEL_NSS1 to replace D10 to different controller pin,
// because pin 1.3 which is D10 by default is needed to spi
inline void blockSpiPin(void)
{
spiNssPinIsBlocked = true;
}
inline void unblockSpiPin(void)
{
spiNssPinIsBlocked = false;
}
void spi_onBegin(void);
void spi_onEnd(void);
// I2C
#define PIN_WIRE_SDA (18)
#define PIN_WIRE_SCL (19)
#define I2C_NUM (1) // i2c number 0 or 1
#define I2C_NUM (1) // i2c number 1
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
// available frequencies
@@ -115,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
}
+93 -20
View File
@@ -13,14 +13,8 @@
#include "pins_arduino.h"
#include "mik32_hal_adc.h"
#ifdef __cplusplus
extern "C" {
#endif
void ErrorMsgHandler(const char * msg);
#ifdef __cplusplus
}
#endif
#include "wiring_analog.h"
#include "wiring_LL.h"
bool spiNssPinIsBlocked = false;
@@ -141,6 +135,38 @@ 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;
}
// 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);
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, pinShift);
else
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, pinShift);
if (config == 2)
return true;
else
return false;
}
bool digitalPinHasPWM(uint8_t p)
{
bool ret = false;
@@ -179,9 +205,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
@@ -192,19 +218,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)
@@ -225,4 +255,47 @@ int8_t digitalPinToInterrupt(uint32_t digPinNumber)
return i;
}
return NOT_AN_INTERRUPT;
}
// ---------------------- SPI ---------------------- //
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_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)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
}
else if(config == 2) // timer for pwm
{
// if D10 (spi NSS pin) was used as pwm, we need to stop timer, because 1.4 don't support it
analogWriteStop(10);
ErrorMsgHandler("analogWrite(): D10 cannot be used as PWM pin while SPI is running");
}
// switch seller to pin 1.4
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_6, HAL_GPIO_MODE_GPIO_OUTPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_HIGH);
spiNssPinIsBlocked = true; // block spi pin
}
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)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);
spiNssPinIsBlocked = false; // unblock spi pin
}