Добавлена библиотека IRremote

1. Инициализация hal библиотек, включение тактирования портов, установка вектора прерываний теперь производится в crt0.S
2. Добавлена библиотека IRremote. Для работы использует прерывание таймера timer16_0
Co-authored-by: KLASSENTS <klassen@elron.tech>
Co-committed-by: KLASSENTS <klassen@elron.tech>
This commit was merged in pull request #10.
This commit is contained in:
klassents authored and klassents committed 2025-01-25 06:52:10 +03:00
1 parent 2945cf9c8c
commit e53bac6ba8
122 files changed
+34285 -29

No files matched your search

+2 -2
View File
@@ -4,8 +4,8 @@
#include "Arduino.h"
// --------------------- init --------------------- //
// called before setup()
void pre_init(void)
// called from crt0.S before constructors initialization
extern "C" void SystemInit(void)
{
// set irq vector to ram region
write_csr(mtvec, 0x02000000);
+1 -2
View File
@@ -5,8 +5,7 @@ extern volatile bool use_error_messages;
#define DISABLE_ERROR_MESSAGES() (use_error_messages = false)
#define ENABLE_ERROR_MESSAGES() (use_error_messages = true)
// functions for init called before and after setup()
void pre_init(void) ;
// function for init called after setup()
void post_init(void);
#endif /* _BOARD_H_ */
-1
View File
@@ -4,7 +4,6 @@
int main()
{
pre_init();
setup();
post_init();
+8
View File
@@ -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)
{
@@ -46,6 +50,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();
+3 -3
View File
@@ -5,6 +5,7 @@
#include "mik32_hal_gpio.h"
#include "mik32_hal_scr1_timer.h"
#include "mik32_hal_timer16.h"
#include "pad_config.h"
// ----------------- COMMON ----------------- //
// convert pin mask from HAL_PinsTypeDef to pin number
@@ -32,6 +33,7 @@
#define TIM16_DISABLE_INT_BY_MASK(htim16,intMask) (htim16.Instance->IER &= ~(intMask))
// ----------------- EPIC ----------------- //
#define EPIC_LEVEL_SET_BY_MASK(mask) (EPIC->MASK_LEVEL_SET |= mask)
#define EPIC_LEVEL_CLEAR_BY_MASK(mask) (EPIC->MASK_LEVEL_CLEAR |= mask)
#define EPIC_CLEAR_ALL() (EPIC->CLEAR = 0xFFFFFFFF)
@@ -60,8 +62,6 @@
// return config of pin with pinNumber(0...16) in portReg (config, pupd, ds for ports 0...2)
#define PIN_GET_PAD_CONFIG(portReg, pinNumber) ((PAD_CONFIG->portReg >> (pinNumber<<1)) & 0b11)
#define PIN_SET_PAD_CONFIG(portReg, pinNumber, value) (PAD_CONFIG->portReg = (PAD_CONFIG->portReg & (~PAD_CONFIG_PIN_M(pinNumber))) \
| PAD_CONFIG_PIN(pinNumber, value))
| PAD_CONFIG_PIN(pinNumber, value))
#endif /* _WIRING_LL_H_ */
-1
View File
@@ -86,7 +86,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;
+21
View File
@@ -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,6 +67,26 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
additionalPinsInit(PinNumber);
}
void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
{
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)
{
+15 -6
View File
@@ -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);