@@ -8,28 +8,40 @@ extern "C" {
8
8
// these cause error: conflicting declaration of 'int bk_wlan_mcu_suppress_and_sleep(unsigned int)' with 'C' linkage
9
9
#include " ../new_common.h"
10
10
11
- #include " include.h"
12
- #include " arm_arch.h"
13
11
#include " ../new_pins.h"
14
12
#include " ../new_cfg.h"
15
13
#include " ../logging/logging.h"
16
14
#include " ../obk_config.h"
17
15
#include " ../cmnds/cmd_public.h"
16
+ #include " ../hal/hal_pins.h"
17
+ #include " ../hal/hal_generic.h"
18
+
19
+ #if PLATFORM_BEKEN
20
+ #include " include.h"
21
+ #include " arm_arch.h"
18
22
#include " bk_timer_pub.h"
19
23
#include " drv_model_pub.h"
20
-
21
- // why can;t I call this?
22
- #include " ../mqtt/new_mqtt.h"
23
-
24
24
#include < gpio_pub.h>
25
25
// #include "pwm.h"
26
26
#include " pwm_pub.h"
27
-
28
27
#include " ../../beken378/func/include/net_param_pub.h"
29
28
#include " ../../beken378/func/user_driver/BkDriverPwm.h"
30
29
#include " ../../beken378/func/user_driver/BkDriverI2c.h"
31
30
#include " ../../beken378/driver/i2c/i2c1.h"
32
31
#include " ../../beken378/driver/gpio/gpio.h"
32
+ #elif PLATFORM_REALTEK
33
+ #define MBED_PERIPHERALNAMES_H
34
+ #include " timer_api.h"
35
+ #include " pwmout_api.h"
36
+ #include " ../hal/realtek/hal_pinmap_realtek.h"
37
+ void pwmout_start (pwmout_t * obj);
38
+ void pwmout_stop (pwmout_t * obj);
39
+ #endif
40
+
41
+ // why can;t I call this?
42
+ #include " ../mqtt/new_mqtt.h"
43
+
44
+
33
45
34
46
35
47
unsigned long ir_counter = 0 ;
@@ -39,6 +51,7 @@ extern "C" {
39
51
uint8_t gIRPinPolarity = 0 ;
40
52
41
53
extern int my_strnicmp (const char * a, const char * b, int len);
54
+ extern unsigned int g_timeMs;
42
55
}
43
56
44
57
@@ -59,24 +72,34 @@ typedef unsigned short uint16_t;
59
72
#define __FlashStringHelper char
60
73
61
74
// dummy functions
62
- void noInterrupts () {}
63
- void interrupts () {}
64
-
65
- unsigned long millis () {
75
+ #if PLATFORM_BEKEN
76
+ void noInterrupts () { }
77
+ void interrupts () { }
78
+ void delay (int n) { }
79
+ void delayMicroseconds (int n) { }
80
+ unsigned long millis ()
81
+ {
66
82
return 0 ;
67
83
}
68
- unsigned long micros () {
84
+ unsigned long micros ()
85
+ {
69
86
return 0 ;
70
87
}
71
-
72
-
73
- void delay (int n) {
74
- return ;
88
+ #else
89
+ void noInterrupts () { taskENTER_CRITICAL (); }
90
+ void interrupts () { taskEXIT_CRITICAL (); }
91
+ void delay (int n) { delay_ms (n); }
92
+ void delayMicroseconds (int n) { HAL_Delay_us (n); }
93
+ unsigned long millis ()
94
+ {
95
+ return g_timeMs;
75
96
}
76
-
77
- void delayMicroseconds ( int n) {
78
- return ;
97
+ unsigned long micros ()
98
+ {
99
+ return g_timeMs * 1000 ;
79
100
}
101
+ #endif
102
+
80
103
81
104
class Print {
82
105
public:
@@ -107,10 +130,21 @@ Print Serial;
107
130
// #define ISR void IR_ISR
108
131
109
132
// THIS function is defined in src/libraries/IRremoteESP8266/src/IRrecv.cpp
110
- extern " C" void DRV_IR_ISR (UINT8 t);
133
+ extern " C" void
134
+ #if PLATFORM_BEKEN
135
+ DRV_IR_ISR (UINT8 t)
136
+ #else
137
+ DRV_IR_ISR ()
138
+ #endif
139
+ ;
111
140
extern void IR_ISR ();
112
141
142
+ #if PLATFORM_BEKEN
113
143
static UINT32 ir_chan = BKTIMER0;
144
+ #elif PLATFORM_REALTEK
145
+ static gtimer_t ir_timer;
146
+ static UINT32 ir_chan = TIMER2;
147
+ #endif
114
148
static UINT32 ir_div = 1 ;
115
149
static UINT32 ir_periodus = 50 ;
116
150
@@ -121,6 +155,7 @@ void timerConfigForReceive() {
121
155
void _timerConfigForReceive () {
122
156
ir_counter = 0 ;
123
157
158
+ #if PLATFORM_BEKEN
124
159
timer_param_t params = {
125
160
(unsigned char )ir_chan,
126
161
(unsigned char )ir_div, // div
@@ -156,20 +191,31 @@ void _timerConfigForReceive() {
156
191
ADDLOG_INFO (LOG_FEATURE_IR, (char *)" ir timer setup %u" , res);
157
192
res = sddev_control ((char *)TIMER_DEV_NAME, CMD_TIMER_UNIT_ENABLE, &ir_chan);
158
193
ADDLOG_INFO (LOG_FEATURE_IR, (char *)" ir timer enabled %u" , res);
194
+ #elif PLATFORM_REALTEK
195
+ gtimer_init (&ir_timer, ir_chan);
196
+ #endif
159
197
}
160
198
161
199
static void timer_enable () {
162
200
}
163
201
static void timer_disable () {
164
202
}
165
203
static void _timer_enable () {
166
- UINT32 res;
204
+ UINT32 res = 0 ;
205
+ #if PLATFORM_BEKEN
167
206
res = sddev_control ((char *)TIMER_DEV_NAME, CMD_TIMER_UNIT_ENABLE, &ir_chan);
207
+ #elif PLATFORM_REALTEK
208
+ gtimer_start_periodical (&ir_timer, ir_periodus, (void *)&DRV_IR_ISR, (uint32_t )&ir_timer);
209
+ #endif
168
210
ADDLOG_INFO (LOG_FEATURE_IR, (char *)" ir timer enabled %u" , res);
169
211
}
170
212
static void _timer_disable () {
171
- UINT32 res;
213
+ UINT32 res = 0 ;
214
+ #if PLATFORM_BEKEN
172
215
res = sddev_control ((char *)TIMER_DEV_NAME, CMD_TIMER_UNIT_DISABLE, &ir_chan);
216
+ #elif PLATFORM_REALTEK
217
+ gtimer_stop (&ir_timer);
218
+ #endif
173
219
ADDLOG_INFO (LOG_FEATURE_IR, (char *)" ir timer disabled %u" , res);
174
220
}
175
221
@@ -197,8 +243,6 @@ SpoofIrReceiver IrReceiver;
197
243
#include " ../libraries/IRremoteESP8266/src/IRproto.h"
198
244
#include " ../libraries/IRremoteESP8266/src/digitalWriteFast.h"
199
245
200
- extern " C" int PIN_GetPWMIndexForPinIndex (int pin);
201
-
202
246
// override aspects of sending for our own interrupt driven sends
203
247
// basically, IRsend calls mark(us) and space(us) to send.
204
248
// we simply note the numbers into a rolling buffer, assume the first is a mark()
@@ -262,19 +306,10 @@ class myIRsend : public IRsend {
262
306
ADDLOG_INFO (LOG_FEATURE_IR, (char *)" enableIROut %d freq %d duty" ,(int )freq, (int )duty);
263
307
if (duty<1 )
264
308
duty=1 ;
265
- if (duty>100 )
266
- duty=100 ;
267
- // just setup variables for use in ISR
268
- // pwmfrequency = ((uint32_t)aFrequencyKHz) * 1000;
269
- pwmperiod = (26000000 / freq);
270
- pwmduty = pwmperiod / (100 /duty);
271
-
272
-
273
- #if PLATFORM_BK7231N
274
- bk_pwm_update_param ((bk_pwm_t )this ->pwmIndex , this ->pwmperiod , pwmduty, 0 , 0 );
275
- #else
276
- bk_pwm_update_param ((bk_pwm_t )this ->pwmIndex , this ->pwmperiod , pwmduty);
277
- #endif
309
+ pwmduty = duty;
310
+
311
+ HAL_PIN_PWM_Start (this ->sendPin , freq);
312
+ HAL_PIN_PWM_Update (this ->sendPin , duty);
278
313
}
279
314
280
315
void resetsendqueue () {
@@ -302,14 +337,21 @@ class myIRsend : public IRsend {
302
337
}
303
338
return val;
304
339
}
340
+ #if PLATFORM_REALTEK
341
+ void ledOff ()
342
+ {
343
+ pwmout_start (g_pins[sendPin].pwm );
344
+ }
305
345
346
+ void ledOn ()
347
+ {
348
+ pwmout_stop (g_pins[sendPin].pwm );
349
+ }
350
+ #endif
306
351
int currentsendtime;
307
352
int currentbitval;
308
353
309
354
uint8_t sendPin;
310
- uint8_t pwmIndex;
311
- uint32_t pwmfrequency;
312
- uint32_t pwmperiod;
313
355
uint32_t pwmduty;
314
356
315
357
uint32_t our_ms;
@@ -323,9 +365,15 @@ IRrecv *ourReceiver = NULL;
323
365
324
366
// this is our ISR.
325
367
// it is called every 50us, so we need to work on making it as efficient as possible.
326
- extern " C" void DRV_IR_ISR (UINT8 t) {
368
+ extern " C" void
369
+ #if PLATFORM_BEKEN
370
+ DRV_IR_ISR (UINT8 t)
371
+ #else
372
+ DRV_IR_ISR ()
373
+ #endif
374
+ {
327
375
int sending = 0 ;
328
- if (pIRsend && (pIRsend-> pwmIndex >= 0 ) ) {
376
+ if (pIRsend) {
329
377
pIRsend->our_us += 50 ;
330
378
if (pIRsend->our_us > 1000 ) {
331
379
pIRsend->our_ms ++;
@@ -373,17 +421,13 @@ extern "C" void DRV_IR_ISR(UINT8 t) {
373
421
uint32_t duty = pIRsend->pwmduty ;
374
422
if (!pinval) {
375
423
if (gIRPinPolarity ) {
376
- duty = pIRsend-> pwmperiod ;
424
+ duty = 100 ;
377
425
}
378
426
else {
379
427
duty = 0 ;
380
428
}
381
429
}
382
- #if PLATFORM_BK7231N
383
- bk_pwm_update_param ((bk_pwm_t )pIRsend->pwmIndex , pIRsend->pwmperiod , duty, 0 , 0 );
384
- #else
385
- bk_pwm_update_param ((bk_pwm_t )pIRsend->pwmIndex , pIRsend->pwmperiod , duty);
386
- #endif
430
+ HAL_PIN_PWM_Update (pIRsend->sendPin , duty);
387
431
}
388
432
389
433
// is someone really wants rx and TX at the same time, then allow it.
@@ -729,28 +773,16 @@ extern "C" void DRV_IR_Init() {
729
773
}
730
774
731
775
if (txpin > 0 ) {
732
- int pwmIndex = PIN_GetPWMIndexForPinIndex (txpin);
733
776
// is this pin capable of PWM?
734
- if (pwmIndex != - 1 ) {
777
+ if (HAL_PIN_CanThisPinBePWM (txpin) ) {
735
778
uint32_t pwmfrequency = 38000 ;
736
- uint32_t period = (26000000 / pwmfrequency);
737
- uint32_t duty = period / 2 ;
738
- #if PLATFORM_BK7231N
739
- // OSStatus bk_pwm_initialize(bk_pwm_t pwm, uint32_t frequency, uint32_t duty_cycle);
740
- bk_pwm_initialize ((bk_pwm_t )pwmIndex, period, duty, 0 , 0 );
741
- #else
742
- bk_pwm_initialize ((bk_pwm_t )pwmIndex, period, duty);
743
- #endif
744
- bk_pwm_start ((bk_pwm_t )pwmIndex);
779
+ HAL_PIN_PWM_Start (txpin, pwmfrequency);
745
780
myIRsend *pIRsendTemp = new myIRsend ((uint_fast8_t )txpin);
746
781
pIRsendTemp->resetsendqueue ();
747
- pIRsendTemp->enableIROut (pwmfrequency,50 );
748
- pIRsendTemp->pwmIndex = pwmIndex;
749
- pIRsendTemp->pwmduty = duty;
750
- pIRsendTemp->pwmperiod = period;
782
+ pIRsendTemp->enableIROut (pwmfrequency, 50 );
783
+ pIRsendTemp->pwmduty = 50 ;
751
784
752
785
pIRsend = pIRsendTemp;
753
- // bk_pwm_stop((bk_pwm_t)pIRsend->pwmIndex);
754
786
755
787
// cmddetail:{"name":"IRSend","args":"[PROT-ADDR-CMD-REP]",
756
788
// cmddetail:"descr":"Sends IR commands in the form PROT-ADDR-CMD-REP, e.g. NEC-1-1A-0",
@@ -779,6 +811,7 @@ extern "C" void DRV_IR_Init() {
779
811
if ((pin > 0 ) || (txpin > 0 )) {
780
812
// both tx and rx need the interrupt
781
813
_timerConfigForReceive ();
814
+ delay_ms (10 );
782
815
_timer_enable ();
783
816
}
784
817
}
0 commit comments