Skip to content

Commit ec56008

Browse files
build old ir on non-beken (#1979)
* build old ir on non-beken * fix potential issue * final fixes
1 parent ee1a744 commit ec56008

File tree

5 files changed

+150
-49
lines changed

5 files changed

+150
-49
lines changed

platforms/XR809/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ SRCS += $(OBK_SRCS)hal/xradio/xr872/hal_pins_xr872
1717

1818
include ../shared/platforms/obk_main.mk
1919
SRCS += $(OBKM_SRC:.c=)
20+
#needs sdk changes
21+
#__CONFIG_CPLUSPLUS = y
22+
#SRCS += $(OBKM_SRC_CXX:.cpp=)
2023
CC_FLAGS += $(OBK_CFLAGS)
2124

2225
INCLUDE_PATHS += -I../shared/libraries/easyflash/inc
2326

2427
SRCS += ../shared/libraries/easyflash/ports/ef_port
2528
SRCS += ../shared/libraries/easyflash/src/easyflash
26-
#SRCS += ../shared/libraries/easyflash/src/ef_cmd
2729
SRCS += ../shared/libraries/easyflash/src/ef_env
28-
SRCS += ../shared/libraries/easyflash/src/ef_env_legacy
29-
SRCS += ../shared/libraries/easyflash/src/ef_env_legacy_wl
30-
SRCS += ../shared/libraries/easyflash/src/ef_iap
31-
SRCS += ../shared/libraries/easyflash/src/ef_log
3230
SRCS += ../shared/libraries/easyflash/src/ef_utils
3331

3432
BERRY_MODULEPATH = $(OBK_SRCS)berry/modules

src/cmnds/cmd_main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,22 @@ static commandResult_t CMD_PowerSave(const void* context, const char* cmd, const
140140

141141
#if defined(PLATFORM_BEKEN)
142142
extern int bk_wlan_power_save_set_level(BK_PS_LEVEL level);
143+
144+
inline bool isBKSensitiveDriversRunning()
145+
{
146+
return PIN_FindPinIndexForRole(IOR_BL0937_CF, -1) != -1
147+
|| PIN_FindPinIndexForRole(IOR_BL0937_CF1, -1) != -1
148+
|| PIN_FindPinIndexForRole(IOR_BL0937_SEL, -1) != -1
149+
|| PIN_FindPinIndexForRole(IOR_IRRecv, -1) != -1
150+
|| PIN_FindPinIndexForRole(IOR_IRSend, -1) != -1
151+
|| PIN_FindPinIndexForRole(IOR_IRRecv_nPup, -1) != -1
152+
|| PIN_FindPinIndexForRole(IOR_RCRecv, -1) != -1
153+
|| PIN_FindPinIndexForRole(IOR_RCRecv_nPup, -1) != -1;
154+
}
155+
143156
if (bOn) {
144157
BK_PS_LEVEL level = PS_RF_SLEEP_BIT;
145-
if(PIN_FindPinIndexForRole(IOR_BL0937_CF, -1) == -1) level |= PS_MCU_SLEEP_BIT;
158+
if(!isBKSensitiveDriversRunning()) level |= PS_MCU_SLEEP_BIT;
146159
else bOn = 0;
147160
bk_wlan_power_save_set_level(level);
148161
}

src/driver/drv_ir.cpp

Lines changed: 126 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,38 @@
66
extern "C" {
77
// these cause error: conflicting declaration of 'int bk_wlan_mcu_suppress_and_sleep(unsigned int)' with 'C' linkage
88
#include "../new_common.h"
9-
9+
#include "../new_pins.h"
10+
#include "../new_cfg.h"
11+
#include "../logging/logging.h"
12+
#include "../obk_config.h"
13+
#include "../cmnds/cmd_public.h"
14+
#include "../hal/hal_hwtimer.h"
15+
#include "../hal/hal_pins.h"
16+
#include "../mqtt/new_mqtt.h"
17+
#if PLATFORM_BEKEN
1018
#include "include.h"
1119
#include "arm_arch.h"
12-
#include "../new_pins.h"
13-
#include "../new_cfg.h"
14-
#include "../logging/logging.h"
15-
#include "../obk_config.h"
16-
#include "../cmnds/cmd_public.h"
17-
#include "../hal/hal_hwtimer.h"
1820
#include "bk_timer_pub.h"
1921
#include "drv_model_pub.h"
2022

21-
// why can;t I call this?
22-
#include "../mqtt/new_mqtt.h"
23-
2423
#include <gpio_pub.h>
2524
//#include "pwm.h"
2625
#include "pwm_pub.h"
2726

2827
#include "../../beken378/func/include/net_param_pub.h"
2928
#include "../../beken378/func/user_driver/BkDriverPwm.h"
3029
#include "../../beken378/driver/gpio/gpio.h"
31-
30+
#elif PLATFORM_BL602
31+
#include "bl602_glb.h"
32+
#elif PLATFORM_LN882H || PLATFORM_LN8825
33+
#define delay_ms OS_MsDelay
34+
#elif PLATFORM_RTL8710B
35+
int __wrap_atoi(const char* str);
36+
char* _strncpy(char* dest, const char* src, size_t count);
37+
int _sscanf_patch(const char* buf, const char* fmt, ...);
38+
//#undef sscanf
39+
#undef strlen
40+
#endif
3241
#include <ctype.h>
3342

3443
unsigned long ir_counter = 0;
@@ -88,33 +97,87 @@ class Print {
8897
Print Serial;
8998

9099

91-
#define INPUT 0
92-
#define OUTPUT 1
93-
#define HIGH 1
94-
#define LOW 1
100+
typedef enum
101+
{
102+
LOW = 0,
103+
HIGH = 1,
104+
CHANGE = 2,
105+
FALLING = 3,
106+
RISING = 4,
107+
} PinStatus;
108+
109+
typedef enum
110+
{
111+
INPUT = 0x0,
112+
OUTPUT = 0x1,
113+
INPUT_PULLUP = 0x2,
114+
INPUT_PULLDOWN = 0x3,
115+
} PinModeOBK;
95116

96117

97-
void digitalToggleFast(unsigned char P) {
118+
void digitalToggleFast(unsigned char P)
119+
{
120+
#if PLATFORM_BEKEN
98121
bk_gpio_output((GPIO_INDEX)P, !bk_gpio_input((GPIO_INDEX)P));
122+
#else
123+
HAL_PIN_SetOutputValue(P, !HAL_PIN_ReadDigitalInput(P));
124+
#endif
99125
}
100126

101-
unsigned char digitalReadFast(unsigned char P) {
102-
return bk_gpio_input((GPIO_INDEX)P);
127+
unsigned char digitalReadFast(unsigned char P)
128+
{
129+
#if PLATFORM_BEKEN
130+
return bk_gpio_input((GPIO_INDEX)P);
131+
#elif PLATFORM_BL602
132+
return GLB_GPIO_Read((GLB_GPIO_Type)P);
133+
#else
134+
return HAL_PIN_ReadDigitalInput(P);
135+
#endif
103136
}
104137

105-
void digitalWriteFast(unsigned char P, unsigned char V) {
138+
void digitalWriteFast(unsigned char P, unsigned char V)
139+
{
106140
//RAW_SetPinValue(P, V);
107141
//HAL_PIN_SetOutputValue(index, iVal);
142+
#if PLATFORM_BEKEN
108143
bk_gpio_output((GPIO_INDEX)P, V);
144+
#elif PLATFORM_BL602
145+
GLB_GPIO_Write((GLB_GPIO_Type)P, V ? 1 : 0);
146+
#else
147+
HAL_PIN_SetOutputValue(P, V);
148+
#endif
109149
}
110150

111-
void pinModeFast(unsigned char P, unsigned char V) {
112-
if (V == INPUT){
151+
void pinModeFast(unsigned char P, unsigned char V)
152+
{
153+
#if PLATFORM_BEKEN
154+
if(V == INPUT_PULLUP)
155+
{
113156
bk_gpio_config_input_pup((GPIO_INDEX)P);
114157
}
158+
else if(V == INPUT_PULLDOWN)
159+
{
160+
bk_gpio_config_input_pdwn((GPIO_INDEX)P);
161+
}
162+
else if(V == INPUT)
163+
{
164+
bk_gpio_config_input((GPIO_INDEX)P);
165+
}
166+
else if(V == OUTPUT)
167+
{
168+
bk_gpio_config_output((GPIO_INDEX)P);
169+
}
170+
#else
171+
switch(V)
172+
{
173+
case INPUT_PULLUP: HAL_PIN_Setup_Input_Pulldown(P); break;
174+
case INPUT_PULLDOWN: HAL_PIN_Setup_Input_Pullup(P); break;
175+
case INPUT: HAL_PIN_Setup_Input(P); break;
176+
case OUTPUT: HAL_PIN_Setup_Output(P); break;
177+
}
178+
#endif
115179
}
116180

117-
118181
#define EXTERNAL_IR_TIMER_ISR
119182

120183
//////////////////////////////////////////
@@ -194,6 +257,7 @@ class myIRsend : public IRsend {
194257
public:
195258
myIRsend(uint_fast8_t aSendPin){
196259
//IRsend::IRsend(aSendPin); - has been called already?
260+
sendPin = aSendPin;
197261
our_us = 0;
198262
our_ms = 0;
199263
resetsendqueue();
@@ -202,9 +266,15 @@ class myIRsend : public IRsend {
202266

203267
void enableIROut(uint_fast8_t aFrequencyKHz){
204268
// just setup variables for use in ISR
269+
#if PLATFORM_BEKEN
205270
pwmfrequency = ((uint32_t)aFrequencyKHz) * 1000;
206271
pwmperiod = (26000000 / pwmfrequency);
207272
pwmduty = pwmperiod/2;
273+
#else
274+
HAL_PIN_PWM_Start(sendPin, ((uint32_t)aFrequencyKHz) * 1000);
275+
pwmduty = 50;
276+
HAL_PIN_PWM_Update(sendPin, pwmduty);
277+
#endif
208278
}
209279

210280
uint32_t millis(){
@@ -275,9 +345,11 @@ class myIRsend : public IRsend {
275345
int currentbitval;
276346

277347
uint8_t sendPin;
348+
#if PLATFORM_BEKEN
278349
uint8_t pwmIndex;
279350
uint32_t pwmfrequency;
280351
uint32_t pwmperiod;
352+
#endif
281353
uint32_t pwmduty;
282354

283355
uint32_t our_ms;
@@ -329,7 +401,11 @@ IRrecv *ourReceiver = NULL;
329401
// it is called every 50us, so we need to work on making it as efficient as possible.
330402
extern "C" void DRV_IR_ISR(void* arg){
331403
int sending = 0;
332-
if (pIRsend && (pIRsend->pwmIndex >= 0)){
404+
if (pIRsend
405+
#if PLATFORM_BEKEN
406+
&& (pIRsend->pwmIndex >= 0)
407+
#endif
408+
){
333409
pIRsend->our_us += 50;
334410
if (pIRsend->our_us > 1000){
335411
pIRsend->our_ms++;
@@ -374,15 +450,23 @@ extern "C" void DRV_IR_ISR(void* arg){
374450
uint32_t duty = pIRsend->pwmduty;
375451
if (!pinval){
376452
if (gIRPinPolarity){
453+
#if PLATFORM_BEKEN
377454
duty = pIRsend->pwmperiod;
455+
#else
456+
duty = 50;
457+
#endif
378458
} else {
379459
duty = 0;
380460
}
381461
}
462+
#if PLATFORM_BEKEN
382463
#if PLATFORM_BK7231N && !PLATFORM_BEKEN_NEW
383464
bk_pwm_update_param((bk_pwm_t)pIRsend->pwmIndex, pIRsend->pwmperiod, duty,0,0);
384465
#else
385466
bk_pwm_update_param((bk_pwm_t)pIRsend->pwmIndex, pIRsend->pwmperiod, duty);
467+
#endif
468+
#else
469+
HAL_PIN_PWM_Update(pIRsend->sendPin, duty);
386470
#endif
387471
}
388472

@@ -570,10 +654,16 @@ extern "C" void DRV_IR_Init(){
570654

571655
int pin = -1; //9;// PWM3/25
572656
int txpin = -1; //24;// PWM3/25
657+
bool pup = true;
573658

574659
// allow user to change them
575-
pin = PIN_FindPinIndexForRole(IOR_IRRecv,pin);
576-
txpin = PIN_FindPinIndexForRole(IOR_IRSend,txpin);
660+
pin = PIN_FindPinIndexForRole(IOR_IRRecv, pin);
661+
if(pin == -1)
662+
{
663+
pin = PIN_FindPinIndexForRole(IOR_IRRecv_nPup, pin);
664+
if(pin >= 0) pup = false;
665+
}
666+
txpin = PIN_FindPinIndexForRole(IOR_IRSend, txpin);
577667

578668
if (ourReceiver){
579669
IRrecv *temp = ourReceiver;
@@ -589,7 +679,8 @@ extern "C" void DRV_IR_Init(){
589679

590680
if (pin > 0){
591681
// setup IRrecv pin as input
592-
bk_gpio_config_input_pup((GPIO_INDEX)pin);
682+
//bk_gpio_config_input_pup((GPIO_INDEX)pin);
683+
pinModeFast(pin, pup == true ? INPUT_PULLUP : INPUT);
593684

594685
ourReceiver = new IRrecv(pin);
595686
ourReceiver->start();
@@ -602,28 +693,24 @@ extern "C" void DRV_IR_Init(){
602693
}
603694

604695
if (txpin > 0){
605-
int pwmIndex = PIN_GetPWMIndexForPinIndex(txpin);
606696
// is this pin capable of PWM?
607-
if(pwmIndex != -1) {
697+
if(HAL_PIN_CanThisPinBePWM(txpin)) {
608698
uint32_t pwmfrequency = 38000;
699+
myIRsend* pIRsendTemp = new myIRsend((uint_fast8_t)txpin);
700+
pIRsendTemp->resetsendqueue();
701+
HAL_PIN_PWM_Start(txpin, pwmfrequency);
702+
#if PLATFORM_BEKEN
703+
int pwmIndex = PIN_GetPWMIndexForPinIndex(txpin);
609704
uint32_t period = (26000000 / pwmfrequency);
610705
uint32_t duty = period/2;
611-
#if PLATFORM_BK7231N && !PLATFORM_BEKEN_NEW
612-
// OSStatus bk_pwm_initialize(bk_pwm_t pwm, uint32_t frequency, uint32_t duty_cycle);
613-
bk_pwm_initialize((bk_pwm_t)pwmIndex, period, duty, 0, 0);
614-
#else
615-
bk_pwm_initialize((bk_pwm_t)pwmIndex, period, duty);
616-
#endif
617-
bk_pwm_start((bk_pwm_t)pwmIndex);
618-
myIRsend *pIRsendTemp = new myIRsend((uint_fast8_t) txpin);
619-
pIRsendTemp->resetsendqueue();
620706
pIRsendTemp->pwmIndex = pwmIndex;
621707
pIRsendTemp->pwmfrequency = pwmfrequency;
622708
pIRsendTemp->pwmperiod = period;
623709
pIRsendTemp->pwmduty = duty;
624-
710+
#else
711+
pIRsendTemp->pwmduty = 50;
712+
#endif
625713
pIRsend = pIRsendTemp;
626-
//bk_pwm_stop((bk_pwm_t)pIRsend->pwmIndex);
627714

628715
//cmddetail:{"name":"IRSend","args":"[PROT-ADDR-CMD-REP-BITS]",
629716
//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",

src/hal/w800/hal_pins_w800.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void HAL_PIN_PWM_Start(int index, int freq) {
213213
return;
214214

215215
pwm_demo_multiplex_config(channel, index);
216-
ret = tls_pwm_init(channel, 1000, 0, 0);
216+
ret = tls_pwm_init(channel, freq, 0, 0);
217217
if (ret != WM_SUCCESS)
218218
return;
219219
tls_pwm_start(channel);

src/obk_config.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@
114114
#define ENABLE_DRIVER_NEO6M 1
115115
#define ENABLE_TIME_SUNRISE_SUNSET 1
116116
#define ENABLE_TIME_DST 1
117-
118117
#define ENABLE_DRIVER_LTR_ALS 1
119118
#define ENABLE_DRIVER_SM16703P 1
120119
#define ENABLE_DRIVER_PIXELANIM 1
121-
#define ENABLE_DRIVER_IRREMOTEESP 1
122120

123121
#elif WINDOWS
124122

@@ -516,7 +514,7 @@
516514
#define ENABLE_OBK_BERRY 1
517515
#endif
518516

519-
#if PLATFORM_RTL87X0C || PLATFORM_REALTEK_NEW || PLATFORM_RTL8720D || PLATFORM_RTL8710B
517+
#if PLATFORM_RTL87X0C || PLATFORM_REALTEK_NEW || PLATFORM_RTL8720D
520518
#undef ENABLE_DRIVER_DDP
521519
#define ENABLE_DRIVER_IRREMOTEESP 1
522520
#endif
@@ -652,5 +650,10 @@
652650
// #define ENABLE_BL_MOVINGAVG 1
653651
#endif
654652

653+
// ensure that there would be no conflicts
654+
#if ENABLE_DRIVER_IRREMOTEESP
655+
#undef ENABLE_DRIVER_IR
656+
#endif
657+
655658
// closing OBK_CONFIG_H
656659
#endif

0 commit comments

Comments
 (0)