Skip to content

Commit f727249

Browse files
more nfc
1 parent e278b44 commit f727249

File tree

1 file changed

+48
-60
lines changed

1 file changed

+48
-60
lines changed

docs/source/ria.rst

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -795,101 +795,89 @@ Applications can take control over the NFC reader for advanced usage or to
795795
assist with programming NFC tags. While the ``"NFC:"`` device is open,
796796
automatic ROM launching is suppressed.
797797

798-
.. code-block:: text
798+
.. code-block:: c
799799
800800
int fd = open("NFC:", O_RDWR);
801801
802802
The PN532 reader runs autonomously on the RIA. The 6502 arms operations via
803-
``write()`` and polls results via ``read()``. ``NFC_CMD_READ`` arms a read;
804-
``NFC_CMD_WRITE`` arms a write. Each posts to its own response slot when done.
805-
``NFC_CMD_CANCEL`` disarms both. Until a response is ready, ``read()`` returns
806-
the current NFC floor state (``NFC_RESP_NO_READER``, ``NFC_RESP_NO_CARD``, or
807-
``NFC_RESP_CARD_INSERTED``).
808-
803+
``write()`` and polls results via ``read()``. ``NFC_CMD_READ`` returns the
804+
current tag data immediately. ``NFC_CMD_WRITE`` arms a write.
805+
``NFC_CMD_CANCEL`` disarms a pending write. State changes and write
806+
completions are posted automatically to ``read()``.
809807

810808
write() -- Commands
811809
~~~~~~~~~~~~~~~~~~~
812810

811+
``write()`` is non-blocking and streaming. A call may consume less than the
812+
requested amount; resubmit any remaining bytes in a subsequent call.
813+
813814
.. list-table::
814815
:widths: 40 60
815816
:header-rows: 1
816817

817818
* - Byte
818819
- Command
819-
* - ``NFC_CMD_WRITE`` (0x01), lenLo, lenHi, tag data...
820+
* - ``NFC_CMD_WRITE`` (0x01), page, lenLo, lenHi, tag data...
820821
- Arm a write
821-
* - ``NFC_CMD_READ`` (0x02)
822-
- Arm a read
823-
* - ``NFC_CMD_CANCEL`` (0x03)
824-
- Disarm both pending read and write
822+
* - ``NFC_CMD_CANCEL`` (0x02)
823+
- Disarm pending write
824+
* - ``NFC_CMD_READ`` (0x03)
825+
- Return current tag data
825826
* - ``NFC_CMD_SUCCESS1`` (0x04)
826827
- Play success tone 1
827828
* - ``NFC_CMD_SUCCESS2`` (0x05)
828829
- Play success tone 2
829830
* - ``NFC_CMD_ERROR`` (0x06)
830831
- Play error tone
831832

832-
``NFC_CMD_WRITE`` streams the command byte + length + tag data across multiple
833-
``write()`` calls. Tag data is raw tag memory: TLV-wrapped NDEF records
834-
terminated with ``0xFE``. Once the full payload arrives, the write is armed.
835-
It executes on the current card or the next one presented. A second
836-
``NFC_CMD_WRITE`` overwrites the first (last write wins).
833+
The ``NFC_CMD_WRITE`` payload begins with the start page, a two-byte length,
834+
then tag data. ``page`` is the NTAG page to begin writing at (page 4 = start
835+
of user data). Data is written in 4-byte pages; the final page is
836+
zero-padded if the payload is not a multiple of 4. The write is armed once
837+
the full payload arrives and executes on the current card or the next one
838+
presented. A second ``NFC_CMD_WRITE`` overwrites the first (last write wins).
839+
840+
``NFC_CMD_READ`` always returns ``NFC_RESP_READ`` on the next ``read()``.
841+
If no card data is available, length is zero.
837842

838843
read() -- Responses
839844
~~~~~~~~~~~~~~~~~~~
840845

841-
Read **1 byte**. ``read()`` always returns immediately. Only ``NFC_RESP_READ``
842-
has a trailing payload.
846+
``read()`` is non-blocking and streaming. It returns 0 bytes when there is
847+
no new information. Responses may arrive split across multiple calls;
848+
callers must buffer and reassemble. State changes are sent once per
849+
change (including once after ``open()``).
843850

844851
.. list-table::
845-
:widths: 30 20 50
852+
:widths: 40 60
846853
:header-rows: 1
847854

848-
* - Result
849-
- Extra bytes
855+
* - Byte
850856
- Meaning
851857
* - ``NFC_RESP_NO_READER`` (0x01)
852-
- \-\-
853-
- Floor: no reader attached
858+
- State: no reader attached
854859
* - ``NFC_RESP_NO_CARD`` (0x02)
855-
- \-\-
856-
- Floor: no card present
860+
- State: no card present
857861
* - ``NFC_RESP_CARD_INSERTED`` (0x03)
858-
- \-\-
859-
- Floor: card present, tag data not ready
860-
* - ``NFC_RESP_WRITE`` (0x04)
861-
- \-\-
862+
- State: card present, tag data not ready
863+
* - ``NFC_RESP_CARD_READY`` (0x04)
864+
- State: card present, tag data ready
865+
* - ``NFC_RESP_WRITE`` (0x05)
862866
- Armed write complete
863-
* - ``NFC_RESP_READ`` (0x05)
864-
- 7 byte header + tag data
865-
- Armed read complete
866-
867-
``NFC_RESP_READ`` and ``NFC_RESP_WRITE`` should be followed with one or more
868-
tone commands, or the application's own sounds. The read or write will then
869-
need to be armed again as needed.
870-
871-
NFC_RESP_READ header (7 bytes)
872-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
873-
874-
.. list-table::
875-
:widths: 10 20 70
876-
:header-rows: 1
877-
878-
* - Offset
879-
- Field
880-
- Description
881-
* - 0
882-
- ``age_ds``
883-
- Data age in 0.1 s, data older than 25.5 s is lost.
884-
* - 1-4
885-
- ``CC[4]``
886-
- Capability Container from page 3. CC[2] * 8 = max NDEF bytes.
887-
* - 5-6
888-
- ``lenLo, lenHi``
889-
- Tag data length.
890-
891-
Tag data follows the header and may span multiple ``read()`` calls. It is raw
892-
tag memory: TLV-wrapped NDEF records (tag ``0x03``) terminated with ``0xFE``.
867+
* - ``NFC_RESP_READ`` (0x06), lenLo, lenHi, tag data...
868+
- Read result
869+
870+
The ``NFC_RESP_READ`` payload is a two-byte length followed by raw tag data
871+
starting from page 0, and may span multiple ``read()`` calls. Page layout:
872+
pages 0-2 = UID/lock bytes, page 3 = Capability Container (CC[2] * 8 = max
873+
NDEF bytes), pages 4+ = user data (TLV-wrapped NDEF records terminated with
874+
``0xFE``).
875+
876+
After ``NFC_RESP_READ`` or ``NFC_RESP_WRITE``, send one or more tone commands
877+
or play application sounds. Typically, reads are requested on
878+
``NFC_RESP_CARD_READY`` with writes armed on ``NFC_RESP_NO_CARD``.
879+
But you may also choose to arm writes after reading and verifying a card.
880+
The state changes give you flexibility in how you sequence operations.
893881

894882

895883
ROM File Format

0 commit comments

Comments
 (0)