Skip to content

Commit f6f2c70

Browse files
committed
Eliminate self-made boost::bind.
1 parent aeab746 commit f6f2c70

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

src/Braccio++.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extern "C"
2222
{
2323
void braccio_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
2424
void braccio_read_keypad(lv_indev_drv_t * indev, lv_indev_data_t * data);
25+
void braccio_unlock_pd_semaphore_irq();
26+
void braccio_unlock_pd_semaphore();
2527
};
2628

2729
/**************************************************************************************
@@ -74,8 +76,8 @@ bool BraccioClass::begin(voidFuncPtr custom_menu)
7476

7577
static rtos::Thread th(osPriorityHigh);
7678
th.start(mbed::callback(this, &BraccioClass::pd_thread));
77-
attachInterrupt(PIN_FUSB302_INT, mbed::callback(this, &BraccioClass::unlock_pd_semaphore_irq), FALLING);
78-
_pd_timer.attach(mbed::callback(this, &BraccioClass::unlock_pd_semaphore), 10ms);
79+
attachInterrupt(PIN_FUSB302_INT, braccio_unlock_pd_semaphore_irq, FALLING);
80+
_pd_timer.attach(braccio_unlock_pd_semaphore, 10ms);
7981

8082
_PD_UFP.init_PPS(PPS_V(7.2), PPS_A(2.0));
8183

@@ -435,11 +437,11 @@ void BraccioClass::pd_thread() {
435437
auto ret = _pd_events.wait_any(0xFF);
436438
if ((ret & 1) && (millis() - start_pd_burst > 1000)) {
437439
_pd_timer.detach();
438-
_pd_timer.attach(mbed::callback(this, &BraccioClass::unlock_pd_semaphore), 5s);
440+
_pd_timer.attach(braccio_unlock_pd_semaphore, 5s);
439441
}
440442
if (ret & 2) {
441443
_pd_timer.detach();
442-
_pd_timer.attach(mbed::callback(this, &BraccioClass::unlock_pd_semaphore), 50ms);
444+
_pd_timer.attach(braccio_unlock_pd_semaphore, 50ms);
443445
}
444446
_i2c_mtx.lock();
445447
if (millis() - last_time_ask_pps > 5000) {
@@ -510,3 +512,13 @@ extern "C" void braccio_read_keypad(lv_indev_drv_t * drv, lv_indev_data_t* data)
510512

511513
data->key = last_key;
512514
}
515+
516+
void braccio_unlock_pd_semaphore_irq()
517+
{
518+
Braccio.unlock_pd_semaphore_irq();
519+
}
520+
521+
void braccio_unlock_pd_semaphore()
522+
{
523+
Braccio.unlock_pd_semaphore();
524+
}

src/Braccio++.h

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class BraccioClass
8282
}
8383

8484
void lvgl_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
85+
void unlock_pd_semaphore_irq() {
86+
start_pd_burst = millis();
87+
_pd_events.set(2);
88+
}
89+
void unlock_pd_semaphore() {
90+
_pd_events.set(1);
91+
}
8592

8693
protected:
8794

@@ -142,16 +149,6 @@ class BraccioClass
142149
mbed::Ticker _pd_timer;
143150

144151
unsigned int start_pd_burst = 0xFFFFFFFF;
145-
146-
void unlock_pd_semaphore_irq() {
147-
start_pd_burst = millis();
148-
_pd_events.set(2);
149-
}
150-
151-
void unlock_pd_semaphore() {
152-
_pd_events.set(1);
153-
}
154-
155152
void pd_thread();
156153
};
157154

@@ -184,18 +181,4 @@ class Servo
184181
int const _id;
185182
};
186183

187-
struct __callback__container__ {
188-
mbed::Callback<void()> fn;
189-
};
190-
191-
inline void attachInterrupt(pin_size_t interruptNum, mbed::Callback<void()> func, PinStatus mode) {
192-
struct __callback__container__* a = new __callback__container__();
193-
a->fn = func;
194-
auto callback = [](void* a) -> void {
195-
((__callback__container__*)a)->fn();
196-
};
197-
198-
attachInterruptParam(interruptNum, callback, mode, (void*)a);
199-
}
200-
201184
#endif //__BRACCIO_PLUSPLUS_H__

0 commit comments

Comments
 (0)