build old ir on non-beken (#1979)

* build old ir on non-beken

* fix potential issue

* final fixes
This commit is contained in:
NonPIayerCharacter
2026-02-10 01:50:51 +03:00
committed by GitHub
parent ee1a744edd
commit ec56008600
5 changed files with 150 additions and 49 deletions

View File

@@ -17,18 +17,16 @@ SRCS += $(OBK_SRCS)hal/xradio/xr872/hal_pins_xr872
include ../shared/platforms/obk_main.mk
SRCS += $(OBKM_SRC:.c=)
#needs sdk changes
#__CONFIG_CPLUSPLUS = y
#SRCS += $(OBKM_SRC_CXX:.cpp=)
CC_FLAGS += $(OBK_CFLAGS)
INCLUDE_PATHS += -I../shared/libraries/easyflash/inc
SRCS += ../shared/libraries/easyflash/ports/ef_port
SRCS += ../shared/libraries/easyflash/src/easyflash
#SRCS += ../shared/libraries/easyflash/src/ef_cmd
SRCS += ../shared/libraries/easyflash/src/ef_env
SRCS += ../shared/libraries/easyflash/src/ef_env_legacy
SRCS += ../shared/libraries/easyflash/src/ef_env_legacy_wl
SRCS += ../shared/libraries/easyflash/src/ef_iap
SRCS += ../shared/libraries/easyflash/src/ef_log
SRCS += ../shared/libraries/easyflash/src/ef_utils
BERRY_MODULEPATH = $(OBK_SRCS)berry/modules

View File

@@ -140,9 +140,22 @@ static commandResult_t CMD_PowerSave(const void* context, const char* cmd, const
#if defined(PLATFORM_BEKEN)
extern int bk_wlan_power_save_set_level(BK_PS_LEVEL level);
inline bool isBKSensitiveDriversRunning()
{
return PIN_FindPinIndexForRole(IOR_BL0937_CF, -1) != -1
|| PIN_FindPinIndexForRole(IOR_BL0937_CF1, -1) != -1
|| PIN_FindPinIndexForRole(IOR_BL0937_SEL, -1) != -1
|| PIN_FindPinIndexForRole(IOR_IRRecv, -1) != -1
|| PIN_FindPinIndexForRole(IOR_IRSend, -1) != -1
|| PIN_FindPinIndexForRole(IOR_IRRecv_nPup, -1) != -1
|| PIN_FindPinIndexForRole(IOR_RCRecv, -1) != -1
|| PIN_FindPinIndexForRole(IOR_RCRecv_nPup, -1) != -1;
}
if (bOn) {
BK_PS_LEVEL level = PS_RF_SLEEP_BIT;
if(PIN_FindPinIndexForRole(IOR_BL0937_CF, -1) == -1) level |= PS_MCU_SLEEP_BIT;
if(!isBKSensitiveDriversRunning()) level |= PS_MCU_SLEEP_BIT;
else bOn = 0;
bk_wlan_power_save_set_level(level);
}

View File

@@ -6,21 +6,20 @@
extern "C" {
// these cause error: conflicting declaration of 'int bk_wlan_mcu_suppress_and_sleep(unsigned int)' with 'C' linkage
#include "../new_common.h"
#include "../new_pins.h"
#include "../new_cfg.h"
#include "../logging/logging.h"
#include "../obk_config.h"
#include "../cmnds/cmd_public.h"
#include "../hal/hal_hwtimer.h"
#include "../hal/hal_pins.h"
#include "../mqtt/new_mqtt.h"
#if PLATFORM_BEKEN
#include "include.h"
#include "arm_arch.h"
#include "../new_pins.h"
#include "../new_cfg.h"
#include "../logging/logging.h"
#include "../obk_config.h"
#include "../cmnds/cmd_public.h"
#include "../hal/hal_hwtimer.h"
#include "bk_timer_pub.h"
#include "drv_model_pub.h"
// why can;t I call this?
#include "../mqtt/new_mqtt.h"
#include <gpio_pub.h>
//#include "pwm.h"
#include "pwm_pub.h"
@@ -28,7 +27,17 @@ extern "C" {
#include "../../beken378/func/include/net_param_pub.h"
#include "../../beken378/func/user_driver/BkDriverPwm.h"
#include "../../beken378/driver/gpio/gpio.h"
#elif PLATFORM_BL602
#include "bl602_glb.h"
#elif PLATFORM_LN882H || PLATFORM_LN8825
#define delay_ms OS_MsDelay
#elif PLATFORM_RTL8710B
int __wrap_atoi(const char* str);
char* _strncpy(char* dest, const char* src, size_t count);
int _sscanf_patch(const char* buf, const char* fmt, ...);
//#undef sscanf
#undef strlen
#endif
#include <ctype.h>
unsigned long ir_counter = 0;
@@ -88,33 +97,87 @@ class Print {
Print Serial;
#define INPUT 0
#define OUTPUT 1
#define HIGH 1
#define LOW 1
typedef enum
{
LOW = 0,
HIGH = 1,
CHANGE = 2,
FALLING = 3,
RISING = 4,
} PinStatus;
typedef enum
{
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
} PinModeOBK;
void digitalToggleFast(unsigned char P) {
void digitalToggleFast(unsigned char P)
{
#if PLATFORM_BEKEN
bk_gpio_output((GPIO_INDEX)P, !bk_gpio_input((GPIO_INDEX)P));
#else
HAL_PIN_SetOutputValue(P, !HAL_PIN_ReadDigitalInput(P));
#endif
}
unsigned char digitalReadFast(unsigned char P) {
return bk_gpio_input((GPIO_INDEX)P);
unsigned char digitalReadFast(unsigned char P)
{
#if PLATFORM_BEKEN
return bk_gpio_input((GPIO_INDEX)P);
#elif PLATFORM_BL602
return GLB_GPIO_Read((GLB_GPIO_Type)P);
#else
return HAL_PIN_ReadDigitalInput(P);
#endif
}
void digitalWriteFast(unsigned char P, unsigned char V) {
void digitalWriteFast(unsigned char P, unsigned char V)
{
//RAW_SetPinValue(P, V);
//HAL_PIN_SetOutputValue(index, iVal);
#if PLATFORM_BEKEN
bk_gpio_output((GPIO_INDEX)P, V);
#elif PLATFORM_BL602
GLB_GPIO_Write((GLB_GPIO_Type)P, V ? 1 : 0);
#else
HAL_PIN_SetOutputValue(P, V);
#endif
}
void pinModeFast(unsigned char P, unsigned char V) {
if (V == INPUT){
void pinModeFast(unsigned char P, unsigned char V)
{
#if PLATFORM_BEKEN
if(V == INPUT_PULLUP)
{
bk_gpio_config_input_pup((GPIO_INDEX)P);
}
else if(V == INPUT_PULLDOWN)
{
bk_gpio_config_input_pdwn((GPIO_INDEX)P);
}
else if(V == INPUT)
{
bk_gpio_config_input((GPIO_INDEX)P);
}
else if(V == OUTPUT)
{
bk_gpio_config_output((GPIO_INDEX)P);
}
#else
switch(V)
{
case INPUT_PULLUP: HAL_PIN_Setup_Input_Pulldown(P); break;
case INPUT_PULLDOWN: HAL_PIN_Setup_Input_Pullup(P); break;
case INPUT: HAL_PIN_Setup_Input(P); break;
case OUTPUT: HAL_PIN_Setup_Output(P); break;
}
#endif
}
#define EXTERNAL_IR_TIMER_ISR
//////////////////////////////////////////
@@ -194,6 +257,7 @@ class myIRsend : public IRsend {
public:
myIRsend(uint_fast8_t aSendPin){
//IRsend::IRsend(aSendPin); - has been called already?
sendPin = aSendPin;
our_us = 0;
our_ms = 0;
resetsendqueue();
@@ -202,9 +266,15 @@ class myIRsend : public IRsend {
void enableIROut(uint_fast8_t aFrequencyKHz){
// just setup variables for use in ISR
#if PLATFORM_BEKEN
pwmfrequency = ((uint32_t)aFrequencyKHz) * 1000;
pwmperiod = (26000000 / pwmfrequency);
pwmduty = pwmperiod/2;
#else
HAL_PIN_PWM_Start(sendPin, ((uint32_t)aFrequencyKHz) * 1000);
pwmduty = 50;
HAL_PIN_PWM_Update(sendPin, pwmduty);
#endif
}
uint32_t millis(){
@@ -275,9 +345,11 @@ class myIRsend : public IRsend {
int currentbitval;
uint8_t sendPin;
#if PLATFORM_BEKEN
uint8_t pwmIndex;
uint32_t pwmfrequency;
uint32_t pwmperiod;
#endif
uint32_t pwmduty;
uint32_t our_ms;
@@ -329,7 +401,11 @@ IRrecv *ourReceiver = NULL;
// it is called every 50us, so we need to work on making it as efficient as possible.
extern "C" void DRV_IR_ISR(void* arg){
int sending = 0;
if (pIRsend && (pIRsend->pwmIndex >= 0)){
if (pIRsend
#if PLATFORM_BEKEN
&& (pIRsend->pwmIndex >= 0)
#endif
){
pIRsend->our_us += 50;
if (pIRsend->our_us > 1000){
pIRsend->our_ms++;
@@ -374,15 +450,23 @@ extern "C" void DRV_IR_ISR(void* arg){
uint32_t duty = pIRsend->pwmduty;
if (!pinval){
if (gIRPinPolarity){
#if PLATFORM_BEKEN
duty = pIRsend->pwmperiod;
#else
duty = 50;
#endif
} else {
duty = 0;
}
}
#if PLATFORM_BEKEN
#if PLATFORM_BK7231N && !PLATFORM_BEKEN_NEW
bk_pwm_update_param((bk_pwm_t)pIRsend->pwmIndex, pIRsend->pwmperiod, duty,0,0);
#else
bk_pwm_update_param((bk_pwm_t)pIRsend->pwmIndex, pIRsend->pwmperiod, duty);
#endif
#else
HAL_PIN_PWM_Update(pIRsend->sendPin, duty);
#endif
}
@@ -570,10 +654,16 @@ extern "C" void DRV_IR_Init(){
int pin = -1; //9;// PWM3/25
int txpin = -1; //24;// PWM3/25
bool pup = true;
// allow user to change them
pin = PIN_FindPinIndexForRole(IOR_IRRecv,pin);
txpin = PIN_FindPinIndexForRole(IOR_IRSend,txpin);
pin = PIN_FindPinIndexForRole(IOR_IRRecv, pin);
if(pin == -1)
{
pin = PIN_FindPinIndexForRole(IOR_IRRecv_nPup, pin);
if(pin >= 0) pup = false;
}
txpin = PIN_FindPinIndexForRole(IOR_IRSend, txpin);
if (ourReceiver){
IRrecv *temp = ourReceiver;
@@ -589,7 +679,8 @@ extern "C" void DRV_IR_Init(){
if (pin > 0){
// setup IRrecv pin as input
bk_gpio_config_input_pup((GPIO_INDEX)pin);
//bk_gpio_config_input_pup((GPIO_INDEX)pin);
pinModeFast(pin, pup == true ? INPUT_PULLUP : INPUT);
ourReceiver = new IRrecv(pin);
ourReceiver->start();
@@ -602,28 +693,24 @@ extern "C" void DRV_IR_Init(){
}
if (txpin > 0){
int pwmIndex = PIN_GetPWMIndexForPinIndex(txpin);
// is this pin capable of PWM?
if(pwmIndex != -1) {
if(HAL_PIN_CanThisPinBePWM(txpin)) {
uint32_t pwmfrequency = 38000;
myIRsend* pIRsendTemp = new myIRsend((uint_fast8_t)txpin);
pIRsendTemp->resetsendqueue();
HAL_PIN_PWM_Start(txpin, pwmfrequency);
#if PLATFORM_BEKEN
int pwmIndex = PIN_GetPWMIndexForPinIndex(txpin);
uint32_t period = (26000000 / pwmfrequency);
uint32_t duty = period/2;
#if PLATFORM_BK7231N && !PLATFORM_BEKEN_NEW
// OSStatus bk_pwm_initialize(bk_pwm_t pwm, uint32_t frequency, uint32_t duty_cycle);
bk_pwm_initialize((bk_pwm_t)pwmIndex, period, duty, 0, 0);
#else
bk_pwm_initialize((bk_pwm_t)pwmIndex, period, duty);
#endif
bk_pwm_start((bk_pwm_t)pwmIndex);
myIRsend *pIRsendTemp = new myIRsend((uint_fast8_t) txpin);
pIRsendTemp->resetsendqueue();
pIRsendTemp->pwmIndex = pwmIndex;
pIRsendTemp->pwmfrequency = pwmfrequency;
pIRsendTemp->pwmperiod = period;
pIRsendTemp->pwmduty = duty;
#else
pIRsendTemp->pwmduty = 50;
#endif
pIRsend = pIRsendTemp;
//bk_pwm_stop((bk_pwm_t)pIRsend->pwmIndex);
//cmddetail:{"name":"IRSend","args":"[PROT-ADDR-CMD-REP-BITS]",
//cmddetail:"descr":"Sends IR commands in the form PROT-ADDR-CMD-REP-BITS, e.g. NEC-1-1A-0-0, note that -BITS is optional, it can be 0 for default one, so you can just do NEC-1-1A-0",

View File

@@ -213,7 +213,7 @@ void HAL_PIN_PWM_Start(int index, int freq) {
return;
pwm_demo_multiplex_config(channel, index);
ret = tls_pwm_init(channel, 1000, 0, 0);
ret = tls_pwm_init(channel, freq, 0, 0);
if (ret != WM_SUCCESS)
return;
tls_pwm_start(channel);

View File

@@ -114,11 +114,9 @@
#define ENABLE_DRIVER_NEO6M 1
#define ENABLE_TIME_SUNRISE_SUNSET 1
#define ENABLE_TIME_DST 1
#define ENABLE_DRIVER_LTR_ALS 1
#define ENABLE_DRIVER_SM16703P 1
#define ENABLE_DRIVER_PIXELANIM 1
#define ENABLE_DRIVER_IRREMOTEESP 1
#elif WINDOWS
@@ -516,7 +514,7 @@
#define ENABLE_OBK_BERRY 1
#endif
#if PLATFORM_RTL87X0C || PLATFORM_REALTEK_NEW || PLATFORM_RTL8720D || PLATFORM_RTL8710B
#if PLATFORM_RTL87X0C || PLATFORM_REALTEK_NEW || PLATFORM_RTL8720D
#undef ENABLE_DRIVER_DDP
#define ENABLE_DRIVER_IRREMOTEESP 1
#endif
@@ -652,5 +650,10 @@
// #define ENABLE_BL_MOVINGAVG 1
#endif
// ensure that there would be no conflicts
#if ENABLE_DRIVER_IRREMOTEESP
#undef ENABLE_DRIVER_IR
#endif
// closing OBK_CONFIG_H
#endif