NFC EEPROM sample application
NFC EEPROM Application based on X-NUCLEO-NFC04A1 expansion board
The application will write an URL to the EEPROM of the NFC tag on your board. This will be able to be read by any NFC device capable of reading NFC tags.
The example uses the EEPROM driver provided for the X-NUCLEO-NFC04A1 expansion board based on the ST25DV04K dynamic NFC/RFID tag.
source/target/NfcControllerToEEPROMAdapter.h@0:f3d7ca3d45de, 2020-09-17 (annotated)
- Committer:
- apalmieri
- Date:
- Thu Sep 17 13:44:38 2020 +0000
- Revision:
- 0:f3d7ca3d45de
Initial commit of NFC EEPROM example for X-NUCLEO-NFC04A1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apalmieri | 0:f3d7ca3d45de | 1 | /* mbed Microcontroller Library |
apalmieri | 0:f3d7ca3d45de | 2 | * Copyright (c) 2018-2018 ARM Limited |
apalmieri | 0:f3d7ca3d45de | 3 | * |
apalmieri | 0:f3d7ca3d45de | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
apalmieri | 0:f3d7ca3d45de | 5 | * you may not use this file except in compliance with the License. |
apalmieri | 0:f3d7ca3d45de | 6 | * You may obtain a copy of the License at |
apalmieri | 0:f3d7ca3d45de | 7 | * |
apalmieri | 0:f3d7ca3d45de | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
apalmieri | 0:f3d7ca3d45de | 9 | * |
apalmieri | 0:f3d7ca3d45de | 10 | * Unless required by applicable law or agreed to in writing, software |
apalmieri | 0:f3d7ca3d45de | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
apalmieri | 0:f3d7ca3d45de | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
apalmieri | 0:f3d7ca3d45de | 13 | * See the License for the specific language governing permissions and |
apalmieri | 0:f3d7ca3d45de | 14 | * limitations under the License. |
apalmieri | 0:f3d7ca3d45de | 15 | */ |
apalmieri | 0:f3d7ca3d45de | 16 | |
apalmieri | 0:f3d7ca3d45de | 17 | #ifndef NFCCONTROLLER2EEPROMADAPTER_H_ |
apalmieri | 0:f3d7ca3d45de | 18 | #define NFCCONTROLLER2EEPROMADAPTER_H_ |
apalmieri | 0:f3d7ca3d45de | 19 | |
apalmieri | 0:f3d7ca3d45de | 20 | #include <algorithm> |
apalmieri | 0:f3d7ca3d45de | 21 | |
apalmieri | 0:f3d7ca3d45de | 22 | #include "nfc/NFCController.h" |
apalmieri | 0:f3d7ca3d45de | 23 | #include "nfc/NFCEEPROMDriver.h" |
apalmieri | 0:f3d7ca3d45de | 24 | #include "nfc/NFCRemoteInitiator.h" |
apalmieri | 0:f3d7ca3d45de | 25 | |
apalmieri | 0:f3d7ca3d45de | 26 | namespace mbed { |
apalmieri | 0:f3d7ca3d45de | 27 | namespace nfc { |
apalmieri | 0:f3d7ca3d45de | 28 | |
apalmieri | 0:f3d7ca3d45de | 29 | /** |
apalmieri | 0:f3d7ca3d45de | 30 | * Adapt an NFCController into an NFCEEPROMDriver. |
apalmieri | 0:f3d7ca3d45de | 31 | */ |
apalmieri | 0:f3d7ca3d45de | 32 | class ControllerToEEPROMDriverAdapter : |
apalmieri | 0:f3d7ca3d45de | 33 | public NFCEEPROMDriver, |
apalmieri | 0:f3d7ca3d45de | 34 | private NFCController::Delegate, |
apalmieri | 0:f3d7ca3d45de | 35 | private NFCRemoteInitiator::Delegate |
apalmieri | 0:f3d7ca3d45de | 36 | { |
apalmieri | 0:f3d7ca3d45de | 37 | public: |
apalmieri | 0:f3d7ca3d45de | 38 | ControllerToEEPROMDriverAdapter( |
apalmieri | 0:f3d7ca3d45de | 39 | NFCController &controller, |
apalmieri | 0:f3d7ca3d45de | 40 | const Span<uint8_t> &buffer |
apalmieri | 0:f3d7ca3d45de | 41 | ); |
apalmieri | 0:f3d7ca3d45de | 42 | |
apalmieri | 0:f3d7ca3d45de | 43 | virtual ~ControllerToEEPROMDriverAdapter(); |
apalmieri | 0:f3d7ca3d45de | 44 | |
apalmieri | 0:f3d7ca3d45de | 45 | /* ------------------------------------------------------------------------ |
apalmieri | 0:f3d7ca3d45de | 46 | * Implementation of NFCEEPROMDriver |
apalmieri | 0:f3d7ca3d45de | 47 | */ |
apalmieri | 0:f3d7ca3d45de | 48 | virtual void reset(); |
apalmieri | 0:f3d7ca3d45de | 49 | |
apalmieri | 0:f3d7ca3d45de | 50 | virtual size_t read_max_size(); |
apalmieri | 0:f3d7ca3d45de | 51 | |
apalmieri | 0:f3d7ca3d45de | 52 | virtual void start_session(bool force); |
apalmieri | 0:f3d7ca3d45de | 53 | |
apalmieri | 0:f3d7ca3d45de | 54 | virtual void end_session(); |
apalmieri | 0:f3d7ca3d45de | 55 | |
apalmieri | 0:f3d7ca3d45de | 56 | virtual void read_bytes(uint32_t address, uint8_t *bytes, size_t count); |
apalmieri | 0:f3d7ca3d45de | 57 | |
apalmieri | 0:f3d7ca3d45de | 58 | virtual void write_bytes(uint32_t address, const uint8_t *bytes, size_t count); |
apalmieri | 0:f3d7ca3d45de | 59 | |
apalmieri | 0:f3d7ca3d45de | 60 | virtual void read_size(); |
apalmieri | 0:f3d7ca3d45de | 61 | |
apalmieri | 0:f3d7ca3d45de | 62 | virtual void write_size(size_t count); |
apalmieri | 0:f3d7ca3d45de | 63 | |
apalmieri | 0:f3d7ca3d45de | 64 | virtual void erase_bytes(uint32_t address, size_t count); |
apalmieri | 0:f3d7ca3d45de | 65 | |
apalmieri | 0:f3d7ca3d45de | 66 | private: |
apalmieri | 0:f3d7ca3d45de | 67 | /* ------------------------------------------------------------------------ |
apalmieri | 0:f3d7ca3d45de | 68 | * Implementation of NFCRemoteInitiator::Delegate |
apalmieri | 0:f3d7ca3d45de | 69 | */ |
apalmieri | 0:f3d7ca3d45de | 70 | virtual void on_connected(); |
apalmieri | 0:f3d7ca3d45de | 71 | |
apalmieri | 0:f3d7ca3d45de | 72 | virtual void on_disconnected(); |
apalmieri | 0:f3d7ca3d45de | 73 | |
apalmieri | 0:f3d7ca3d45de | 74 | virtual void parse_ndef_message(const Span<const uint8_t> &buffer); |
apalmieri | 0:f3d7ca3d45de | 75 | |
apalmieri | 0:f3d7ca3d45de | 76 | virtual size_t build_ndef_message(const Span<uint8_t> &buffer); |
apalmieri | 0:f3d7ca3d45de | 77 | |
apalmieri | 0:f3d7ca3d45de | 78 | /* ------------------------------------------------------------------------ |
apalmieri | 0:f3d7ca3d45de | 79 | * Implementation of NFCController::Delegate |
apalmieri | 0:f3d7ca3d45de | 80 | */ |
apalmieri | 0:f3d7ca3d45de | 81 | virtual void on_discovery_terminated( |
apalmieri | 0:f3d7ca3d45de | 82 | nfc_discovery_terminated_reason_t reason |
apalmieri | 0:f3d7ca3d45de | 83 | ); |
apalmieri | 0:f3d7ca3d45de | 84 | |
apalmieri | 0:f3d7ca3d45de | 85 | virtual void on_nfc_initiator_discovered( |
apalmieri | 0:f3d7ca3d45de | 86 | const SharedPtr<NFCRemoteInitiator> &nfc_initiator |
apalmieri | 0:f3d7ca3d45de | 87 | ); |
apalmieri | 0:f3d7ca3d45de | 88 | |
apalmieri | 0:f3d7ca3d45de | 89 | NFCController& _nfc_controller; |
apalmieri | 0:f3d7ca3d45de | 90 | Span<uint8_t> _eeprom_buffer; |
apalmieri | 0:f3d7ca3d45de | 91 | size_t _current_eeprom_size; |
apalmieri | 0:f3d7ca3d45de | 92 | bool _session_opened; |
apalmieri | 0:f3d7ca3d45de | 93 | SharedPtr<NFCRemoteInitiator> _nfc_remote_initiator; |
apalmieri | 0:f3d7ca3d45de | 94 | }; |
apalmieri | 0:f3d7ca3d45de | 95 | |
apalmieri | 0:f3d7ca3d45de | 96 | } // namespace nfc |
apalmieri | 0:f3d7ca3d45de | 97 | } // namespace mbed |
apalmieri | 0:f3d7ca3d45de | 98 | |
apalmieri | 0:f3d7ca3d45de | 99 | |
apalmieri | 0:f3d7ca3d45de | 100 | #endif /* NFCCONTROLLER2EEPROMADAPTER_H_ */ |