From 948237869fedb6319aa0090a31c17b8fa418b0cb Mon Sep 17 00:00:00 2001 From: NonPIayerCharacter <18557343+NonPIayerCharacter@users.noreply.github.com> Date: Wed, 3 Sep 2025 12:45:24 +0300 Subject: [PATCH] LN882H IR (#1783) --- platforms/LN882H/CMakeLists.txt | 3 ++ src/driver/drv_ir_new.cpp | 50 +++++++++++++++++-- src/hal/ln882h/hal_pins_ln882h.c | 9 +++- src/libraries/IRremoteESP8266/src/IRtimer.cpp | 4 +- src/obk_config.h | 1 + 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/platforms/LN882H/CMakeLists.txt b/platforms/LN882H/CMakeLists.txt index 13626d31b..626962a1b 100644 --- a/platforms/LN882H/CMakeLists.txt +++ b/platforms/LN882H/CMakeLists.txt @@ -14,6 +14,7 @@ include_directories(${BERRY_SRCPATH}) include(app/libraries/berry.cmake) set(PROJ_ALL_SRC + ${OBKM_SRC_CXX} ${OBKM_SRC} ${BERRY_SRC_C} ${OBK_SRCS}hal/ln882h/hal_adc_ln882h.c @@ -68,3 +69,5 @@ target_include_directories(${pro_executable_target} ) include(gcc/gcc-custom-build-stage.cmake) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undef -Wno-unused-parameter -Wno-pedantic -Wno-float-conversion") diff --git a/src/driver/drv_ir_new.cpp b/src/driver/drv_ir_new.cpp index d8edde3aa..9463bdec2 100644 --- a/src/driver/drv_ir_new.cpp +++ b/src/driver/drv_ir_new.cpp @@ -40,6 +40,17 @@ void pwmout_stop(pwmout_t* obj); #include "bl602_timer.h" #include "hosal_timer.h" #define UINT32 uint32_t +#elif PLATFORM_LN882H +#define __HAL_COMMON_H__ +typedef enum +{ + HAL_DISABLE = 0u, + HAL_ENABLE = 1u +} hal_en_t; +#include "hal/hal_timer.h" +#include "hal/hal_clock.h" +#define delay_ms OS_MsDelay +#define UINT32 uint32_t #endif // why can;t I call this? @@ -148,16 +159,24 @@ extern void IR_ISR(); #if PLATFORM_BEKEN static UINT32 ir_chan = BKTIMER0; static UINT32 ir_div = 1; -static UINT32 ir_periodus = 50; #elif PLATFORM_REALTEK static gtimer_t ir_timer; static UINT32 ir_chan = TIMER2; -static UINT32 ir_periodus = 50; #elif PLATFORM_BL602 static hosal_timer_dev_t ir_timer; static UINT32 ir_chan = TIMER_CH0; -static UINT32 ir_periodus = 50; +#elif PLATFORM_LN882H +static UINT32 ir_chan = TIMER0_BASE; +extern "C" void TIMER0_IRQHandler() +{ + if(hal_tim_get_it_flag(TIMER0_BASE, TIM_IT_FLAG_ACTIVE)) + { + hal_tim_clr_it_flag(TIMER0_BASE, TIM_IT_FLAG_ACTIVE); + DRV_IR_ISR(NULL); + } +} #endif +static UINT32 ir_periodus = 50; void timerConfigForReceive() { // nothing here` @@ -211,6 +230,23 @@ void _timerConfigForReceive() { ir_timer.config.cb = DRV_IR_ISR; ir_timer.config.arg = NULL; hosal_timer_init(&ir_timer); +#elif PLATFORM_LN882H + tim_init_t_def tim_init; + memset(&tim_init, 0, sizeof(tim_init)); + tim_init.tim_mode = TIM_USER_DEF_CNT_MODE; + if(ir_periodus < 1000) + { + tim_init.tim_div = 0; + tim_init.tim_load_value = ir_periodus * (uint32_t)(hal_clock_get_apb0_clk() / 1000000) - 1; + } + else + { + tim_init.tim_div = (uint32_t)(hal_clock_get_apb0_clk() / 1000000) - 1; + tim_init.tim_load_value = ir_periodus - 1; + } + hal_tim_init(ir_chan, &tim_init); + NVIC_SetPriority(TIMER0_IRQn, 4); + NVIC_EnableIRQ(TIMER0_IRQn); #endif } @@ -226,6 +262,9 @@ static void _timer_enable() { gtimer_start_periodical(&ir_timer, ir_periodus, (void*)&DRV_IR_ISR, (uint32_t)&ir_timer); #elif PLATFORM_BL602 hosal_timer_start(&ir_timer); +#elif PLATFORM_LN882H + hal_tim_en(ir_chan, HAL_ENABLE); + hal_tim_it_cfg(ir_chan, TIM_IT_FLAG_ACTIVE, HAL_ENABLE); #endif ADDLOG_INFO(LOG_FEATURE_IR, (char *)"ir timer enabled %u", res); } @@ -238,6 +277,9 @@ static void _timer_disable() { #elif PLATFORM_BL602 hosal_timer_stop(&ir_timer); hosal_timer_finalize(&ir_timer); +#elif PLATFORM_LN882H + hal_tim_en(ir_chan, HAL_DISABLE); + hal_tim_it_cfg(ir_chan, TIM_IT_FLAG_ACTIVE, HAL_DISABLE); #endif ADDLOG_INFO(LOG_FEATURE_IR, (char *)"ir timer disabled %u", res); } @@ -838,7 +880,7 @@ extern "C" void DRV_IR_Init() { CMD_RegisterCommand("IRParam",IR_Param, NULL); } } - if ((pin > 0) || (txpin > 0)) { + if ((pin >= 0) || (txpin >= 0)) { // both tx and rx need the interrupt _timerConfigForReceive(); delay_ms(10); diff --git a/src/hal/ln882h/hal_pins_ln882h.c b/src/hal/ln882h/hal_pins_ln882h.c index 0ae9a3fcc..7fa07070c 100644 --- a/src/hal/ln882h/hal_pins_ln882h.c +++ b/src/hal/ln882h/hal_pins_ln882h.c @@ -215,13 +215,18 @@ void HAL_PIN_PWM_Start(int index, int freq) { if(index >= g_numPins) return; + lnPinMapping_t* pin = g_pins + index; + if(pin->pwm_cha > 0) + { + pwm_init(freq, pin->pwm_cha, pin->base, pin->pin); + return; + } uint8_t freecha; for(freecha = 0; freecha < 5; freecha++) if((g_active_pwm >> freecha & 1) == 0) break; - lnPinMapping_t* pin = g_pins + index; g_active_pwm |= 1 << freecha; pin->pwm_cha = freecha; ADDLOG_DEBUG(LOG_FEATURE_CMD, "PWM_Start: ch_pwm: %u", freecha); - pwm_init(10000, freecha, pin->base, pin->pin); + pwm_init(freq, freecha, pin->base, pin->pin); pwm_start(freecha); } diff --git a/src/libraries/IRremoteESP8266/src/IRtimer.cpp b/src/libraries/IRremoteESP8266/src/IRtimer.cpp index 9794f9eeb..7d1c1b8cd 100644 --- a/src/libraries/IRremoteESP8266/src/IRtimer.cpp +++ b/src/libraries/IRremoteESP8266/src/IRtimer.cpp @@ -6,12 +6,12 @@ #endif -#if PLATFORM_BEKEN || PLATFORM_REALTEK || PLATFORM_BL602 +//#if PLATFORM_BEKEN || PLATFORM_REALTEK || PLATFORM_BL602 || PLATFORM_LN882H //TODO extern unsigned long micros(void); extern unsigned long millis(void); -#endif +//#endif #ifdef UNIT_TEST diff --git a/src/obk_config.h b/src/obk_config.h index 5e0bfbc2f..071d27fc9 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -366,6 +366,7 @@ #define ENABLE_OBK_BERRY 1 #define ENABLE_DRIVER_SM16703P 1 #define ENABLE_DRIVER_PIXELANIM 1 +#define ENABLE_DRIVER_IRREMOTEESP 1 #elif PLATFORM_ESPIDF