mirror of https://github.com/ARMmbed/mbed-os.git
Callback: Adopt better use of assignment/call operators
parent
ed6fec2811
commit
417524f562
|
|
@ -27,8 +27,8 @@ InterruptIn::InterruptIn(PinName pin) : gpio(),
|
||||||
_fall() {
|
_fall() {
|
||||||
// No lock needed in the constructor
|
// No lock needed in the constructor
|
||||||
|
|
||||||
_rise.attach(donothing);
|
_rise = donothing;
|
||||||
_fall.attach(donothing);
|
_fall = donothing;
|
||||||
|
|
||||||
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
||||||
gpio_init_in(&gpio, pin);
|
gpio_init_in(&gpio, pin);
|
||||||
|
|
@ -53,10 +53,10 @@ void InterruptIn::mode(PinMode pull) {
|
||||||
void InterruptIn::rise(Callback<void()> func) {
|
void InterruptIn::rise(Callback<void()> func) {
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
if (func) {
|
if (func) {
|
||||||
_rise.attach(func);
|
_rise = func;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||||
} else {
|
} else {
|
||||||
_rise.attach(donothing);
|
_rise = donothing;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
|
@ -65,10 +65,10 @@ void InterruptIn::rise(Callback<void()> func) {
|
||||||
void InterruptIn::fall(Callback<void()> func) {
|
void InterruptIn::fall(Callback<void()> func) {
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
if (func) {
|
if (func) {
|
||||||
_fall.attach(func);
|
_fall = func;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||||
} else {
|
} else {
|
||||||
_fall.attach(donothing);
|
_fall = donothing;
|
||||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
|
@ -77,8 +77,8 @@ void InterruptIn::fall(Callback<void()> func) {
|
||||||
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
||||||
InterruptIn *handler = (InterruptIn*)id;
|
InterruptIn *handler = (InterruptIn*)id;
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case IRQ_RISE: handler->_rise.call(); break;
|
case IRQ_RISE: handler->_rise(); break;
|
||||||
case IRQ_FALL: handler->_fall.call(); break;
|
case IRQ_FALL: handler->_fall(); break;
|
||||||
case IRQ_NONE: break;
|
case IRQ_NONE: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
|
||||||
// No lock needed in the constructor
|
// No lock needed in the constructor
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
|
for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
|
||||||
_irq[i].attach(donothing);
|
_irq[i] = donothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
serial_init(&_serial, tx, rx);
|
serial_init(&_serial, tx, rx);
|
||||||
|
|
@ -73,10 +73,10 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
|
||||||
// Disable interrupts when attaching interrupt handler
|
// Disable interrupts when attaching interrupt handler
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
if (func) {
|
if (func) {
|
||||||
_irq[type].attach(func);
|
_irq[type] = func;
|
||||||
serial_irq_set(&_serial, (SerialIrq)type, 1);
|
serial_irq_set(&_serial, (SerialIrq)type, 1);
|
||||||
} else {
|
} else {
|
||||||
_irq[type].attach(donothing);
|
_irq[type] = donothing;
|
||||||
serial_irq_set(&_serial, (SerialIrq)type, 0);
|
serial_irq_set(&_serial, (SerialIrq)type, 0);
|
||||||
}
|
}
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
|
@ -85,7 +85,7 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
|
||||||
|
|
||||||
void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
|
void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
|
||||||
SerialBase *handler = (SerialBase*)id;
|
SerialBase *handler = (SerialBase*)id;
|
||||||
handler->_irq[irq_type].call();
|
handler->_irq[irq_type]();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SerialBase::_base_getc() {
|
int SerialBase::_base_getc() {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace mbed {
|
||||||
void Ticker::detach() {
|
void Ticker::detach() {
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
remove();
|
remove();
|
||||||
_function.attach(0);
|
_function = 0;
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ void Ticker::setup(timestamp_t t) {
|
||||||
|
|
||||||
void Ticker::handler() {
|
void Ticker::handler() {
|
||||||
insert(event.timestamp + _delay);
|
insert(event.timestamp + _delay);
|
||||||
_function.call();
|
_function();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ public:
|
||||||
* @param t the time between calls in micro-seconds
|
* @param t the time between calls in micro-seconds
|
||||||
*/
|
*/
|
||||||
void attach_us(Callback<void()> func, timestamp_t t) {
|
void attach_us(Callback<void()> func, timestamp_t t) {
|
||||||
_function.attach(func);
|
_function = func;
|
||||||
setup(t);
|
setup(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ nsapi_error_t Socket::open(NetworkStack *stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
_event.attach(this, &Socket::event);
|
_event = callback(this, &Socket::event);
|
||||||
_stack->socket_attach(_socket, Callback<void()>::thunk, &_event);
|
_stack->socket_attach(_socket, Callback<void()>::thunk, &_event);
|
||||||
|
|
||||||
_lock.unlock();
|
_lock.unlock();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue