- добавлена поддержка платы ELBEAR ACE-NANO;
- добавлена поддержка плат ELSOMIK OEM и SE;
- добавлена возможность работы в режиме отладки для всех плат, входящих в состав пакета. Доступно для версии ArduinoIDE 2 и выше;
- добавлена поддержка библиотеки FreeRTOS;
- добавлена поддержка библиотеки IRremote;
- добавлена поддержка библиотеки OneWire;
- добавлена поддержка аппаратного I2C0 для плат START-MIK32 и ELSOMIK. Для работы с ним доступен экземпляр класса Wire1;
- добавлена поддержка аппаратного SPI0 для всех плат, входящих в пакет. Для работы с ним доступен экземпляр класса SPI1;
- увеличено быстродействие функций digitalWrite, digitalRead;
- исправлены известные ошибки.
Co-authored-by: KlassenTS <klassen@elron.tech>
Co-committed-by: KlassenTS <klassen@elron.tech>
This commit was merged in pull request #19.
This commit is contained in:
klassents authored and klassents committed 2025-04-28 07:06:08 +03:00
1 parent de1f0d7fda
commit 1c8e06634c
211 files changed
+97525 -591

No files matched your search

+43 -24
View File
@@ -78,6 +78,9 @@ typedef enum
PINS_COMMON_QTY, // 40
} DigitalPinsTypeDef;
// total number of pins available for initialization
#define pinCommonQty() (PINS_COMMON_QTY)
// analog pins
#define PIN_A0 (P1_5)
#define PIN_A1 (P1_7)
@@ -107,21 +110,14 @@ 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
static inline HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
{
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
}
// total number of pins available for initialization
static inline uint16_t pinCommonQty(void)
{
return (uint16_t)PINS_COMMON_QTY;
}
HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber);
// 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
volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x);
// the function is needed for compatibility with other boards
// functions are needed for compatibility with other boards
static inline void additionalPinsInit(uint32_t PinNumber) {}
static inline void additionalPinsDeinit(uint32_t PinNumber){}
// UART
// available uarts quantity
@@ -133,32 +129,55 @@ static inline void additionalPinsInit(uint32_t PinNumber) {}
uint32_t analogInputToChannelNumber(uint32_t PinNumber);
// PWM
bool digitalPinHasPWM(uint8_t p);
bool digitalPinPwmIsOn(uint8_t digitalPin); // use only if digitalPinHasPWM() == true
#define PWM_FREQUENCY_MAX 1000000 // Hz
static inline __attribute__((always_inline)) bool digitalPinHasPWM(uint8_t p)
{
return (p < 32) && ((p & 0xF) < 4);
}
// return true if digitalPin configured as pwm
bool digitalPinPwmIsOn(uint8_t digitalPin);
// determines which timer the pin belongs to
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
// determines which timer channel the pin belongs to
HAL_TIMER32_CHANNEL_IndexTypeDef pwmPinToTimerChannel(uint32_t digPinNumber);
// SPI
#define PIN_SPI_SS (P1_3)
#define PIN_SPI_MOSI (P1_1)
#define PIN_SPI_MISO (P1_0)
#define PIN_SPI_SCK (P1_2)
#define SPI_COMMON_QTY 2
#define PIN_SPI_SS P1_3
#define PIN_SPI_MOSI P1_1
#define PIN_SPI_MISO P1_0
#define PIN_SPI_SCK P1_2
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
// functions is needed for compatibility with other boards
static inline void spi_onBegin(void) {}
static inline void spi_onEnd(void) {}
#define PIN_SPI1_SS P0_3
#define PIN_SPI1_MOSI P0_1
#define PIN_SPI1_MISO P0_0
#define PIN_SPI1_SCK P0_2
static const uint8_t SS1 = PIN_SPI1_SS;
static const uint8_t MOSI1 = PIN_SPI1_MOSI;
static const uint8_t MISO1 = PIN_SPI1_MISO;
static const uint8_t SCK1 = PIN_SPI1_SCK;
// check if pwm is used on spi pins
void spi_onBegin(uint8_t spiNum);
static inline void spi_onEnd(uint8_t spiNum){}
// I2C
#define PIN_WIRE_SDA (P1_12)
#define PIN_WIRE_SCL (P1_13)
#define I2C_NUM (1) // i2c number 1
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
#define I2C_COMMON_QTY 2
// Wire (I2C1)
#define PIN_WIRE_SDA P1_12
#define PIN_WIRE_SCL P1_13
static const uint8_t SDA = PIN_WIRE_SDA;
static const uint8_t SCL = PIN_WIRE_SCL;
// Wire1 (I2C0)
#define PIN_WIRE_SDA1 P0_9
#define PIN_WIRE_SCL1 P0_10
static const uint8_t SDA1 = PIN_WIRE_SDA1;
static const uint8_t SCL1 = PIN_WIRE_SCL1;
// available frequencies
#define WIRE_FREQ_100K 100000
#define WIRE_FREQ_400K 400000
+61 -27
View File
@@ -21,24 +21,33 @@
* @return The address of the port corresponding to the board pin number. Can return 0 if the pin not exists
*/
GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
__attribute__((noinline, section(".ram_text"))) GPIO_TypeDef *digitalPinToPort(uint32_t digitalPinNumber)
{
if (digitalPinNumber < 16u)
GPIO_TypeDef* port = NULL;
if (digitalPinNumber < pinCommonQty())
{
return GPIO_0;
}
else if ((digitalPinNumber >= 16u) && (digitalPinNumber < 32u))
{
return GPIO_1;
}
else if ((digitalPinNumber >= 32u) && (digitalPinNumber < 40u))
{
return GPIO_2;
if (digitalPinNumber < 16u)
port = GPIO_0;
else if ((digitalPinNumber >= 16u) && (digitalPinNumber < 32u))
port = GPIO_1;
else if ((digitalPinNumber >= 32u) && (digitalPinNumber < 40u))
port = GPIO_2;
}
else
ErrorMsgHandler("digitalPinToPort(): pin number exceeds the total number of pins");
return port;
}
// determines the pin address inside the port by the board pin number
__attribute__((noinline, section(".ram_text"))) HAL_PinsTypeDef digitalPinToBitMask(uint32_t digitalPinNumber)
{
if (digitalPinNumber >= pinCommonQty())
{
return NULL;
ErrorMsgHandler("digitalPinToBitMask(): pin number exceeds the total number of pins");
return NOT_A_PIN;
}
return (HAL_PinsTypeDef)(1 << (digitalPinNumber & 0xF));
}
// the function returns a reference to the OUTPUT address of the GPIO register
@@ -97,27 +106,24 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
// use only if digitalPinHasPWM() == true
// return true if digitalPin configured as pwm
bool digitalPinPwmIsOn(uint8_t digitalPin)
__attribute__((noinline, section(".ram_text"))) bool digitalPinPwmIsOn(uint8_t digitalPin)
{
uint8_t config = 0;
uint8_t pinShift = digitalPin & 3;
if (digitalPinHasPWM(digitalPin))
{
uint8_t config = 0;
uint8_t pinShift = digitalPin & 3;
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 (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
if (config == 2)
return true;
}
return false;
}
bool digitalPinHasPWM(uint8_t p)
{
return (p < 32) && ((p & 0xF) < 4);
}
// function is used only if digitalPinHasPWM() is true
TIMER32_TypeDef *pwmPinToTimer(uint32_t digPinNumber)
{
@@ -205,4 +211,32 @@ int8_t digitalPinToInterrupt(uint32_t digPinNumber)
return i;
}
return NOT_AN_INTERRUPT;
}
// ---------------------- SPI ---------------------- //
void spi_onBegin(uint8_t spiNum)
{
// On mik32 spi0 needs pin 0.3, spi1 needs pin 1.3 for correct work.
// This pins also can be used as pwm. If pwm is working when spi begins, we should stop the pwm channel
// get pin NSS_IN config
uint8_t config;
if (spiNum == 1)
config = PIN_GET_PAD_CONFIG(PORT_1_CFG, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3));
else
config = PIN_GET_PAD_CONFIG(PORT_0_CFG, PIN_MASK_TO_PIN_NUMBER(GPIO_PIN_3));
if(config == 2) // timer for pwm
{
if (spiNum == 1)
{
analogWriteStop(P1_3);
ErrorMsgHandler("analogWrite(): P1_3 cannot be used as PWM pin while SPI is running");
}
else
{
analogWriteStop(P0_3);
ErrorMsgHandler("analogWrite(): P0_3 cannot be used as PWM pin while SPI1 is running");
}
}
}