diff --git a/src/main.cpp b/src/main.cpp index 4597f49..db93b21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,31 +3,34 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "mbed.h" -#include "mbed_events.h" DigitalOut led1(LED1); InterruptIn sw(USER_BUTTON); +EventQueue queue(32 * EVENTS_EVENT_SIZE); +Thread t; + void rise_handler(void) { + queue.call(printf, "rise_handler in context %p\n", ThisThread::get_id()); // Toggle LED led1 = !led1; } void fall_handler(void) { - printf("fall_handler in context %p\r\n", ThisThread::get_id()); + printf("rise_handler in context %p\n", ThisThread::get_id()); // Toggle LED led1 = !led1; } int main() { - // Request the shared queue - EventQueue *queue = mbed_event_queue(); + // Start the event queue + t.start(callback(&queue, &EventQueue::dispatch_forever)); printf("Starting in context %p\r\n", ThisThread::get_id()); // The 'rise' handler will execute in IRQ context sw.rise(rise_handler); - // The 'fall' handler will execute in the context of the shared queue thread - sw.fall(queue->event(fall_handler)); + // The 'fall' handler will execute in the context of thread 't' + sw.fall(queue.event(fall_handler)); }