forked from Elron_dev/elbear_arduino_bsp
v0.5.0
- добавлена поддержка платы 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 is contained in:
1 parent
de1f0d7fda
commit
1c8e06634c
211 files changed
+97525
-591
No files matched your search
+61
-27
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user