66extern " 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 {
8897Print 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.
330402extern " 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",
0 commit comments