Expose Event Queue to NFCEEPROMDriver

pull/7822/head
Donatien Garnier 2018-08-21 15:51:43 +01:00
parent 0e2484f7f3
commit 3970f5f77a
4 changed files with 27 additions and 22 deletions

View File

@ -90,7 +90,6 @@ private:
virtual void on_size_written(bool success);
virtual void on_size_read(bool success, size_t size);
virtual void on_bytes_erased(size_t count);
virtual void on_event();
void handle_error(nfc_err_t ret);
void continue_write();
@ -117,7 +116,6 @@ private:
};
NFCEEPROMDriver *_driver;
events::EventQueue *_queue;
bool _initialized;
nfc_eeprom_operation_t _current_op;

View File

@ -96,13 +96,6 @@ public:
* @param[in] count number of bytes actually erased
*/
virtual void on_bytes_erased(size_t count) = 0;
/**
* Signal the user that the process_events() need to be called
*
* @note this function can be called in interrupt context
*/
virtual void on_event() = 0;
};
/**
@ -112,17 +105,19 @@ public:
*/
void set_delegate(Delegate *delegate);
/**
* Set the event queue that will be used to schedule event handling
*
* @param[in] queue the queue instance to use
*/
void set_event_queue(EventQueue *queue);
/**
* Reset and initialize the EEPROM.
* This method should complete synchronously.
*/
virtual void reset() = 0;
/**
* Process events raised by the driver in interrupt context.
*/
virtual void process_events();
/**
* Get the maximum memory size addressable by the EEPROM.
*/
@ -185,9 +180,11 @@ public:
protected:
Delegate *delegate();
EventQueue *event_queue();
private:
Delegate *_delegate;
EventQueue *_event_queue;
};
/**

View File

@ -21,9 +21,10 @@ using namespace mbed;
using namespace mbed::nfc;
NFCEEPROM(NFCEEPROMDriver *driver, events::EventQueue *queue, uint8_t *ndef_buffer, size_t ndef_buffer_sz) : NFCTarget(ndef_buffer, ndef_buffer_sz)
_driver(driver), _queue(queue), _initialized(false), _current_op(nfc_eeprom_idle), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN)
_driver(driver), _initialized(false), _current_op(nfc_eeprom_idle), _eeprom_address(0), _operation_result(NFC_ERR_UNKNOWN)
{
_driver->set_delegate(this);
_driver->set_event_queue(queue);
}
nfc_err_t NFCEEPROM::initialize()
@ -349,12 +350,6 @@ void NFCEEPROM::on_bytes_erased(size_t count)
}
}
void NFCEEPROM::on_event()
{
// Just schedule a task on event queue
_queue->call(_driver, NFCEEPROMDriver::process_events);
}
void NFCEEPROM::continue_write()
{
if (ac_buffer_reader_readable(&_ndef_buffer_reader) > 0) {

View File

@ -19,7 +19,7 @@
using namespace mbed;
using namespace mbed::nfc;
NFCEEPROMDriver::NFCEEPROMDriver() : _delegate(NULL)
NFCEEPROMDriver::NFCEEPROMDriver() : _delegate(NULL), _event_queue(NULL)
{
}
@ -28,3 +28,18 @@ void NFCEEPROMDriver::set_delegate(Delegate *delegate)
{
_delegate = delegate;
}
void NFCEEPROMDriver::set_event_queue(EventQueue *queue)
{
_event_queue = queue;
}
Delegate *NFCEEPROMDriver::delegate()
{
return _delegate;
}
EventQueue *NFCEEPROMDriver::event_queue()
{
return _event_queue;
}