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 was merged in pull request #19.
This commit is contained in:
1 parent
de1f0d7fda
commit
1c8e06634c
211 files changed
+97525
-591
No files matched your search
@@ -79,6 +79,12 @@ static void calcFrequencyParams(FrequencyParams_t* params, unsigned int newFrequ
|
||||
// start tone with frequency (in hertz) and duration (in milliseconds)
|
||||
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
|
||||
{
|
||||
if ((pin>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("tone(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!timerIsOn) // if tone is not generated at the moment
|
||||
{
|
||||
// calculate the parameters necessary to ensure a given frequency if the frequency has changed
|
||||
@@ -123,6 +129,12 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
|
||||
// stop tone
|
||||
void noTone(uint8_t pin)
|
||||
{
|
||||
if ((pin>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("noTone(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
if (timerIsOn)
|
||||
{
|
||||
// pin to 0
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
// Weak empty variant initialization function.
|
||||
// May be redefined by variant files.
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() { }
|
||||
|
||||
int main()
|
||||
{
|
||||
initVariant(); // for freeRTOS
|
||||
setup();
|
||||
post_init();
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ extern "C" {
|
||||
*/
|
||||
typedef enum __HAL_PinsTypeDef
|
||||
{
|
||||
NOT_A_PIN = (0 << 0), /**< Не выбран пин. */
|
||||
GPIO_PIN_0 = (1 << 0), /**< Выбран пин 0. */
|
||||
GPIO_PIN_1 = (1 << 1), /**< Выбран пин 1. */
|
||||
GPIO_PIN_2 = (1 << 2), /**< Выбран пин 2. */
|
||||
|
||||
@@ -123,6 +123,7 @@ SECTIONS {
|
||||
PROVIDE(__STACK_START__ = .);
|
||||
. += STACK_SIZE;
|
||||
PROVIDE(__C_STACK_TOP__ = .);
|
||||
PROVIDE(__freertos_irq_stack_top = .);
|
||||
PROVIDE(__STACK_END__ = .);
|
||||
} >ram
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,7 +5,7 @@
|
||||
extern void serial_interrupt_handler(uint8_t uartNumInt);
|
||||
extern void gpio_interrupt_handler(void);
|
||||
extern void tone_interrupt_handler(void);
|
||||
void __attribute__((weak)) wire_interrupt_handler(void)
|
||||
void __attribute__((weak)) wire_interrupt_handler(uint8_t num)
|
||||
{
|
||||
// dummy function for case when wire library is not in use
|
||||
}
|
||||
@@ -13,6 +13,10 @@ void __attribute__((weak)) servo_interrupt_handler(void)
|
||||
{
|
||||
// dummy function for case when servo library is not in use
|
||||
}
|
||||
void __attribute__((weak)) IRremote_interrupt_handler(void)
|
||||
{
|
||||
// dummy function for case when IRremote library is not in use
|
||||
}
|
||||
|
||||
void __attribute__((weak)) ISR(void)
|
||||
{
|
||||
@@ -21,13 +25,16 @@ void __attribute__((weak)) ISR(void)
|
||||
In the project, you need to create a function of the form:
|
||||
extern "C" void ISR()
|
||||
{
|
||||
// timer16 is taken as an example
|
||||
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
|
||||
if (EPIC_CHECK_TIMER16_1())
|
||||
{
|
||||
// necessary actions
|
||||
// timer16 is taken as an example
|
||||
if (TIM16_GET_ARRM_INT_STATUS(htimer16_1_))
|
||||
{
|
||||
// necessary actions
|
||||
}
|
||||
// reset timer interrupt flags
|
||||
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
|
||||
}
|
||||
// reset timer interrupt flags
|
||||
TIM16_CLEAR_INT_MASK(htimer16_1_, 0xFFFFFFFF);
|
||||
}
|
||||
libraries required to use this example:
|
||||
#include "mik32_hal_timer16.h"
|
||||
@@ -46,6 +53,10 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
|
||||
if (EPIC_CHECK_GPIO_IRQ())
|
||||
gpio_interrupt_handler();
|
||||
|
||||
// IRremote timer interrupt
|
||||
if (EPIC_CHECK_TIMER16_0())
|
||||
IRremote_interrupt_handler();
|
||||
|
||||
// tone timer interrupt
|
||||
if (EPIC_CHECK_TIMER16_1())
|
||||
tone_interrupt_handler();
|
||||
@@ -62,9 +73,12 @@ void __attribute__((noinline, section(".ram_text"), optimize("O3"))) trap_handle
|
||||
if (EPIC_CHECK_UART_1())
|
||||
serial_interrupt_handler(1);
|
||||
|
||||
// i2c interrupt
|
||||
// i2c0 interrupt
|
||||
if (EPIC_CHECK_I2C_0())
|
||||
wire_interrupt_handler(0);
|
||||
|
||||
if (EPIC_CHECK_I2C_1())
|
||||
wire_interrupt_handler();
|
||||
wire_interrupt_handler(1);
|
||||
|
||||
// reset all interrupts
|
||||
EPIC_CLEAR_ALL();
|
||||
|
||||
@@ -73,6 +73,7 @@ uint32_t analogRead(uint32_t PinNumber)
|
||||
// extra least significant bits read from the ADC are discarded
|
||||
value = (value >> (MCU_ADC_RESOLUTION - currentResolution));
|
||||
}
|
||||
additionalPinsDeinit(PinNumber);
|
||||
}
|
||||
else
|
||||
ErrorMsgHandler("analogRead(): invalid analog pin number");
|
||||
@@ -86,7 +87,6 @@ uint32_t analogRead(uint32_t PinNumber)
|
||||
#define PWM_RESOLUTION_DEFAULT 8
|
||||
#define WRITE_VAL_MAX_DEFAULT ((1<<PWM_RESOLUTION_DEFAULT) - 1)
|
||||
#define PWM_TOP_VAL_DEFAULT 32000 // corresponds 1000 Hz
|
||||
#define PWM_FREQUENCY_MAX 1000000 // Hz
|
||||
|
||||
static TIMER32_HandleTypeDef htimer32;
|
||||
static TIMER32_CHANNEL_HandleTypeDef htimer32_channel;
|
||||
@@ -170,7 +170,7 @@ It is recommended to turn off the timer in the following order:
|
||||
*/
|
||||
void analogWriteStop(uint32_t PinNumber)
|
||||
{
|
||||
if ((pwmIsInited > 0) && (digitalPinPwmIsOn(PinNumber)))
|
||||
if (digitalPinHasPWM(PinNumber) && (pwmIsInited > 0) && digitalPinPwmIsOn(PinNumber))
|
||||
{
|
||||
// load the timer address and channel number corresponding to the specified pin
|
||||
htimer32.Instance = pwmPinToTimer(PinNumber);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "pins_arduino.h"
|
||||
#include "mik32_hal_gpio.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -66,51 +67,82 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
additionalPinsInit(PinNumber);
|
||||
}
|
||||
|
||||
void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("fastPinMode(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
|
||||
HAL_PinsTypeDef pinMask = digitalPinToBitMask(PinNumber);
|
||||
|
||||
// set direction
|
||||
if (PinMode == OUTPUT)
|
||||
GPIO_OUTPUT_MODE_PIN(port, pinMask);
|
||||
else
|
||||
GPIO_INPUT_MODE_PIN(port, pinMask);
|
||||
|
||||
// set pullup
|
||||
if (PinMode == INPUT_PULLUP)
|
||||
{
|
||||
uint8_t pos = PIN_MASK_TO_PIN_NUMBER(pinMask);
|
||||
if (port == GPIO_0) PIN_SET_PAD_CONFIG(PORT_0_PUPD, pos, HAL_GPIO_PULL_UP);
|
||||
else if (port == GPIO_1) PIN_SET_PAD_CONFIG(PORT_1_PUPD, pos, HAL_GPIO_PULL_UP);
|
||||
else PIN_SET_PAD_CONFIG(PORT_2_PUPD, pos, HAL_GPIO_PULL_UP);
|
||||
}
|
||||
}
|
||||
|
||||
// write pin
|
||||
void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
||||
__attribute__((noinline, section(".ram_text"))) void digitalWrite(uint32_t PinNumber, uint32_t Val)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalWrite(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_WritePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber), (Val == HIGH) ? GPIO_PIN_HIGH : GPIO_PIN_LOW);
|
||||
if (Val == HIGH)
|
||||
GPIO_SET_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
else
|
||||
GPIO_CLEAR_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
// read pin
|
||||
int digitalRead(uint32_t PinNumber)
|
||||
__attribute__((noinline, section(".ram_text"))) int digitalRead(uint32_t PinNumber)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalRead(): pin number exceeds the total number of pins");
|
||||
return -1;
|
||||
}
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
GPIO_PinState pinState = HAL_GPIO_ReadPin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
return (pinState == GPIO_PIN_LOW) ? LOW : HIGH;
|
||||
return GPIO_READ_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
// toggle pin
|
||||
void digitalToggle(uint32_t PinNumber)
|
||||
__attribute__((noinline, section(".ram_text"))) void digitalToggle(uint32_t PinNumber)
|
||||
{
|
||||
if ((PinNumber>=pinCommonQty()))
|
||||
{
|
||||
ErrorMsgHandler("digitalToggle(): pin number exceeds the total number of pins");
|
||||
return;
|
||||
}
|
||||
if (digitalPinHasPWM(PinNumber))
|
||||
|
||||
if (digitalPinPwmIsOn(PinNumber))
|
||||
// if the pin can use PWM, disable PWM
|
||||
analogWriteStop(PinNumber);
|
||||
|
||||
HAL_GPIO_TogglePin(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
|
||||
GPIO_TOGGLE_PIN(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -26,26 +26,35 @@ extern "C" {
|
||||
/**
|
||||
* \brief Configures the specified pin to behave either as an input or an output.
|
||||
*
|
||||
* \param dwPin The number of the pin whose mode you wish to set
|
||||
* \param dwMode Either INPUT, INPUT_PULLUP or OUTPUT
|
||||
* \param PinNumber The number of the pin whose mode you wish to set
|
||||
* \param PinMode Either INPUT, INPUT_PULLUP or OUTPUT
|
||||
*/
|
||||
void pinMode(uint32_t PinNumber, uint32_t PinMode);
|
||||
|
||||
/**
|
||||
* \brief Configures the specified pin to behave either as an input or an output
|
||||
* using quick macros and without calling checks
|
||||
*
|
||||
* \param PinNumber The number of the pin whose mode you wish to set
|
||||
* \param PinMode Either INPUT, INPUT_PULLUP or OUTPUT
|
||||
*/
|
||||
void fastPinMode(uint32_t PinNumber, uint32_t PinMode);
|
||||
|
||||
/**
|
||||
* \brief Write a HIGH or a LOW value to a digital pin.
|
||||
*
|
||||
* If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the
|
||||
* corresponding value: 3.3V for HIGH, 0V (ground) for LOW.
|
||||
*
|
||||
* \param dwPin the pin number
|
||||
* \param dwVal HIGH or LOW
|
||||
* \param PinNumber the pin number
|
||||
* \param PinMode HIGH or LOW
|
||||
*/
|
||||
void digitalWrite(uint32_t PinNumber, uint32_t Val);
|
||||
|
||||
/**
|
||||
* \brief Reads the value from a specified digital pin, either HIGH or LOW.
|
||||
*
|
||||
* \param ulPin The number of the digital pin you want to read (int)
|
||||
* \param PinNumber The number of the digital pin you want to read (int)
|
||||
*
|
||||
* \return HIGH or LOW
|
||||
*/
|
||||
@@ -54,7 +63,7 @@ int digitalRead(uint32_t PinNumber);
|
||||
/**
|
||||
* \brief Toggle the value from a specified digital pin.
|
||||
*
|
||||
* \param ulPin The number of the digital pin you want to toggle (int)
|
||||
* \param PinNumber The number of the digital pin you want to toggle (int)
|
||||
*/
|
||||
void digitalToggle(uint32_t PinNumber);
|
||||
|
||||
|
||||
Reference in new issue
Block a user