Skip to content

Commit ec0d191

Browse files
event queue added
1 parent 06f6b9f commit ec0d191

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

NFCEEPROMDriver.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* FAKE HEADER SINCE IT'S NOT IN MBED OS YET */
2+
#include "EventQueue.h"
23

4+
using events::EventQueue;
35
/**
46
* The abstraction for a NFC EEPROM driver.
57
* Implementers need to derive from this class and implement its methods.
@@ -65,18 +67,8 @@ class NFCEEPROMDriver {
6567
* @param[in] success whether this operation succeeded
6668
*/
6769
virtual void on_bytes_erased(size_t count) = 0;
68-
69-
/**
70-
* Indicate to user to put handle_events on the event queue.
71-
*/
72-
virtual void on_event() = 0;
7370
};
7471

75-
/**
76-
* Process pending events (if any).
77-
*/
78-
void handle_events();
79-
8072
/**
8173
* Set the delegate that will receive events generated by this EEPROM.
8274
*
@@ -85,6 +77,16 @@ class NFCEEPROMDriver {
8577
void set_delegate(Delegate* delegate) {
8678
_delegate = delegate;
8779
}
80+
81+
/**
82+
* Set the event queue that will be used to schedule event handling
83+
*
84+
* @param[in] delegate the delegate instance to use
85+
*/
86+
void set_event_queue(EventQueue* queue) {
87+
_event_queue = queue;
88+
}
89+
8890
/**
8991
* Reset and initialize the EEPROM.
9092
* This method should complete synchronously.
@@ -94,7 +96,7 @@ class NFCEEPROMDriver {
9496
/**
9597
* Get the maximum memory size addressable by the EEPROM.
9698
*/
97-
virtual size_t get_max_size() = 0;
99+
virtual size_t read_max_size() = 0;
98100

99101
/**
100102
* Start a session of operations (reads, writes, erases, size gets/sets).
@@ -155,6 +157,10 @@ class NFCEEPROMDriver {
155157
Delegate* delegate() {
156158
return _delegate;
157159
}
160+
EventQueue* event_queue() {
161+
return _event_queue;
162+
}
158163
private:
159164
Delegate* _delegate;
165+
EventQueue* _event_queue;
160166
};

m24sr_driver.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <mbed.h>
4747
#include "I2C.h"
4848
#include "NFCEEPROMDriver.h"
49+
#include "EventQueue.h"
4950

5051
#ifdef TARGET_DISCO_L475VG_IOT01A
5152

@@ -67,6 +68,8 @@ namespace nfc {
6768
namespace vendor {
6869
namespace ST {
6970

71+
using events::EventQueue;
72+
7073
#define OPEN_SESSION_RETRIES 5
7174
#define CC_FILE_LENGTH 15
7275
#define NDEF_FILE_HEADER_SIZE 2
@@ -426,7 +429,7 @@ class M24srDriver : public NFCEEPROMDriver {
426429

427430
/** @see NFCEEPROMDriver::get_max_size
428431
*/
429-
virtual size_t get_max_size() {
432+
virtual size_t read_max_size() {
430433
return MAX_NDEF_SIZE;
431434
}
432435

@@ -566,12 +569,6 @@ class M24srDriver : public NFCEEPROMDriver {
566569
write_bytes(address, NULL, size);
567570
}
568571

569-
/** @see NFCEEPROMDriver::handle_events
570-
*/
571-
void handle_events() {
572-
manage_event();
573-
}
574-
575572
/**
576573
* Change the function to call when a command ends.
577574
* @param commandCallback Object containing the callback, if NULL it will use empty callback
@@ -597,7 +594,8 @@ class M24srDriver : public NFCEEPROMDriver {
597594

598595
private:
599596
static void nfc_interrupt_callback() {
600-
get_instance()->delegate()->on_event();
597+
M24srDriver* driver = get_instance();
598+
driver->event_queue()->call(driver, &M24srDriver::manage_event);
601599
}
602600

603601
/**

0 commit comments

Comments
 (0)