Demonstration of possible usage of the NFC EEPROM class (including support for ST25DV NFC chip)

Dependencies:   eeprom_driver

Committer:
apalmieri
Date:
Tue Jan 28 16:08:05 2020 +0000
Revision:
6:462737ad2938
Parent:
0:86f202e07059
Add ST25DV driver support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:86f202e07059 1 /* mbed Microcontroller Library
mbed_official 0:86f202e07059 2 * Copyright (c) 2018-2018 ARM Limited
mbed_official 0:86f202e07059 3 *
mbed_official 0:86f202e07059 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 0:86f202e07059 5 * you may not use this file except in compliance with the License.
mbed_official 0:86f202e07059 6 * You may obtain a copy of the License at
mbed_official 0:86f202e07059 7 *
mbed_official 0:86f202e07059 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:86f202e07059 9 *
mbed_official 0:86f202e07059 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 0:86f202e07059 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 0:86f202e07059 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 0:86f202e07059 13 * See the License for the specific language governing permissions and
mbed_official 0:86f202e07059 14 * limitations under the License.
mbed_official 0:86f202e07059 15 */
mbed_official 0:86f202e07059 16
mbed_official 0:86f202e07059 17 #ifndef NFCCONTROLLER2EEPROMADAPTER_H_
mbed_official 0:86f202e07059 18 #define NFCCONTROLLER2EEPROMADAPTER_H_
mbed_official 0:86f202e07059 19
mbed_official 0:86f202e07059 20 #include <algorithm>
mbed_official 0:86f202e07059 21
mbed_official 0:86f202e07059 22 #include "nfc/NFCController.h"
mbed_official 0:86f202e07059 23 #include "nfc/NFCEEPROMDriver.h"
mbed_official 0:86f202e07059 24 #include "nfc/NFCRemoteInitiator.h"
mbed_official 0:86f202e07059 25
mbed_official 0:86f202e07059 26 namespace mbed {
mbed_official 0:86f202e07059 27 namespace nfc {
mbed_official 0:86f202e07059 28
mbed_official 0:86f202e07059 29 /**
mbed_official 0:86f202e07059 30 * Adapt an NFCController into an NFCEEPROMDriver.
mbed_official 0:86f202e07059 31 */
mbed_official 0:86f202e07059 32 class ControllerToEEPROMDriverAdapter :
mbed_official 0:86f202e07059 33 public NFCEEPROMDriver,
mbed_official 0:86f202e07059 34 private NFCController::Delegate,
mbed_official 0:86f202e07059 35 private NFCRemoteInitiator::Delegate
mbed_official 0:86f202e07059 36 {
mbed_official 0:86f202e07059 37 public:
mbed_official 0:86f202e07059 38 ControllerToEEPROMDriverAdapter(
mbed_official 0:86f202e07059 39 NFCController &controller,
mbed_official 0:86f202e07059 40 const Span<uint8_t> &buffer
mbed_official 0:86f202e07059 41 );
mbed_official 0:86f202e07059 42
mbed_official 0:86f202e07059 43 virtual ~ControllerToEEPROMDriverAdapter();
mbed_official 0:86f202e07059 44
mbed_official 0:86f202e07059 45 /* ------------------------------------------------------------------------
mbed_official 0:86f202e07059 46 * Implementation of NFCEEPROMDriver
mbed_official 0:86f202e07059 47 */
mbed_official 0:86f202e07059 48 virtual void reset();
mbed_official 0:86f202e07059 49
mbed_official 0:86f202e07059 50 virtual size_t read_max_size();
mbed_official 0:86f202e07059 51
mbed_official 0:86f202e07059 52 virtual void start_session(bool force);
mbed_official 0:86f202e07059 53
mbed_official 0:86f202e07059 54 virtual void end_session();
mbed_official 0:86f202e07059 55
mbed_official 0:86f202e07059 56 virtual void read_bytes(uint32_t address, uint8_t *bytes, size_t count);
mbed_official 0:86f202e07059 57
mbed_official 0:86f202e07059 58 virtual void write_bytes(uint32_t address, const uint8_t *bytes, size_t count);
mbed_official 0:86f202e07059 59
mbed_official 0:86f202e07059 60 virtual void read_size();
mbed_official 0:86f202e07059 61
mbed_official 0:86f202e07059 62 virtual void write_size(size_t count);
mbed_official 0:86f202e07059 63
mbed_official 0:86f202e07059 64 virtual void erase_bytes(uint32_t address, size_t count);
mbed_official 0:86f202e07059 65
mbed_official 0:86f202e07059 66 private:
mbed_official 0:86f202e07059 67 /* ------------------------------------------------------------------------
mbed_official 0:86f202e07059 68 * Implementation of NFCRemoteInitiator::Delegate
mbed_official 0:86f202e07059 69 */
mbed_official 0:86f202e07059 70 virtual void on_connected();
mbed_official 0:86f202e07059 71
mbed_official 0:86f202e07059 72 virtual void on_disconnected();
mbed_official 0:86f202e07059 73
mbed_official 0:86f202e07059 74 virtual void parse_ndef_message(const Span<const uint8_t> &buffer);
mbed_official 0:86f202e07059 75
mbed_official 0:86f202e07059 76 virtual size_t build_ndef_message(const Span<uint8_t> &buffer);
mbed_official 0:86f202e07059 77
mbed_official 0:86f202e07059 78 /* ------------------------------------------------------------------------
mbed_official 0:86f202e07059 79 * Implementation of NFCController::Delegate
mbed_official 0:86f202e07059 80 */
mbed_official 0:86f202e07059 81 virtual void on_discovery_terminated(
mbed_official 0:86f202e07059 82 nfc_discovery_terminated_reason_t reason
mbed_official 0:86f202e07059 83 );
mbed_official 0:86f202e07059 84
mbed_official 0:86f202e07059 85 virtual void on_nfc_initiator_discovered(
mbed_official 0:86f202e07059 86 const SharedPtr<NFCRemoteInitiator> &nfc_initiator
mbed_official 0:86f202e07059 87 );
mbed_official 0:86f202e07059 88
mbed_official 0:86f202e07059 89 NFCController& _nfc_controller;
mbed_official 0:86f202e07059 90 Span<uint8_t> _eeprom_buffer;
mbed_official 0:86f202e07059 91 size_t _current_eeprom_size;
mbed_official 0:86f202e07059 92 bool _session_opened;
mbed_official 0:86f202e07059 93 SharedPtr<NFCRemoteInitiator> _nfc_remote_initiator;
mbed_official 0:86f202e07059 94 };
mbed_official 0:86f202e07059 95
mbed_official 0:86f202e07059 96 } // namespace nfc
mbed_official 0:86f202e07059 97 } // namespace mbed
mbed_official 0:86f202e07059 98
mbed_official 0:86f202e07059 99
mbed_official 0:86f202e07059 100 #endif /* NFCCONTROLLER2EEPROMADAPTER_H_ */