Struct NfcBricklet

Source
pub struct NfcBricklet { /* private fields */ }
Expand description

NFC tag read/write, NFC P2P and Card Emulation

Implementations§

Source§

impl NfcBricklet

Source

pub const DEVICE_IDENTIFIER: u16 = 286u16

Source

pub const DEVICE_DISPLAY_NAME: &'static str = "NFC Bricklet"

Source

pub fn new(uid: Uid, connection: AsyncIpConnection) -> NfcBricklet

Creates an object with the unique device ID uid. This object can then be used after the IP Connection ip_connection is connected.

Source

pub fn get_response_expected( &mut self, fun: NfcBrickletFunction, ) -> Result<bool, GetResponseExpectedError>

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by set_response_expected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

See set_response_expected for the list of function ID constants available for this function.

Source

pub fn set_response_expected( &mut self, fun: NfcBrickletFunction, response_expected: bool, ) -> Result<(), SetResponseExpectedError>

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

Source

pub fn set_response_expected_all(&mut self, response_expected: bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

Source

pub fn get_api_version(&self) -> [u8; 3]

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

Source

pub async fn get_reader_state_changed_callback_receiver( &mut self, ) -> impl Stream<Item = ReaderStateChangedEvent>

This receiver is called if the reader state of the NFC Bricklet changes. See reader_get_state for more information about the possible states.

Source

pub async fn get_cardemu_state_changed_callback_receiver( &mut self, ) -> impl Stream<Item = CardemuStateChangedEvent>

This receiver is called if the cardemu state of the NFC Bricklet changes. See [cardemu_get_state] for more information about the possible states.

Source

pub async fn get_p2p_state_changed_callback_receiver( &mut self, ) -> impl Stream<Item = P2pStateChangedEvent>

This receiver is called if the P2P state of the NFC Bricklet changes. See [p2p_get_state] for more information about the possible states.

Source

pub async fn set_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError>

Sets the mode. The NFC Bricklet supports four modes:

  • Off
  • Card Emulation (Cardemu): Emulates a tag for other readers
  • Peer to Peer (P2P): Exchange data with other readers
  • Reader: Reads and writes tags
  • Simple: Automatically reads tag IDs

If you change a mode, the Bricklet will reconfigure the hardware for this mode. Therefore, you can only use functions corresponding to the current mode. For example, in Reader mode you can only use Reader functions.

Associated constants:

  • NFC_BRICKLET_MODE_OFF
  • NFC_BRICKLET_MODE_CARDEMU
  • NFC_BRICKLET_MODE_P2P
  • NFC_BRICKLET_MODE_READER
  • NFC_BRICKLET_MODE_SIMPLE
Source

pub async fn get_mode(&mut self) -> Result<u8, TinkerforgeError>

Returns the mode as set by [set_mode].

Associated constants:

  • NFC_BRICKLET_MODE_OFF
  • NFC_BRICKLET_MODE_CARDEMU
  • NFC_BRICKLET_MODE_P2P
  • NFC_BRICKLET_MODE_READER
  • NFC_BRICKLET_MODE_SIMPLE
Source

pub async fn reader_request_tag_id(&mut self) -> Result<(), TinkerforgeError>

After you call [reader_request_tag_id] the NFC Bricklet will try to read the tag ID from the tag. After this process is done the state will change. You can either register the [get_reader_state_changed_callback_receiver] receiver or you can poll [reader_get_state] to find out about the state change.

If the state changes to ReaderRequestTagIDError it means that either there was no tag present or that the tag has an incompatible type. If the state changes to ReaderRequestTagIDReady it means that a compatible tag was found and that the tag ID has been saved. You can now read out the tag ID by calling [reader_get_tag_id].

If two tags are in the proximity of the NFC Bricklet, this function will cycle through the tags. To select a specific tag you have to call [reader_request_tag_id] until the correct tag ID is found.

In case of any ReaderError state the selection is lost and you have to start again by calling [reader_request_tag_id].

Source

pub async fn reader_get_tag_id_low_level( &mut self, ) -> Result<ReaderGetTagIdLowLevel, TinkerforgeError>

Returns the tag type and the tag ID. This function can only be called if the NFC Bricklet is currently in one of the ReaderReady states. The returned tag ID is the tag ID that was saved through the last call of [reader_request_tag_id].

To get the tag ID of a tag the approach is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to ReaderRequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. Call [reader_get_tag_id]

Associated constants:

  • NFC_BRICKLET_TAG_TYPE_MIFARE_CLASSIC
  • NFC_BRICKLET_TAG_TYPE_TYPE1
  • NFC_BRICKLET_TAG_TYPE_TYPE2
  • NFC_BRICKLET_TAG_TYPE_TYPE3
  • NFC_BRICKLET_TAG_TYPE_TYPE4
Source

pub async fn reader_get_state( &mut self, ) -> Result<ReaderGetState, TinkerforgeError>

Returns the current reader state of the NFC Bricklet.

On startup the Bricklet will be in the ReaderInitialization state. The initialization will only take about 20ms. After that it changes to ReaderIdle.

The Bricklet is also reinitialized if the mode is changed, see [set_mode].

The functions of this Bricklet can be called in the ReaderIdle state and all of the ReaderReady and ReaderError states.

Example: If you call [reader_request_page], the state will change to ReaderRequestPage until the reading of the page is finished. Then it will change to either ReaderRequestPageReady if it worked or to ReaderRequestPageError if it didn’t. If the request worked you can get the page by calling [reader_read_page].

The same approach is used analogously for the other API functions.

Associated constants:

  • NFC_BRICKLET_READER_STATE_INITIALIZATION
  • NFC_BRICKLET_READER_STATE_IDLE
  • NFC_BRICKLET_READER_STATE_ERROR
  • NFC_BRICKLET_READER_STATE_REQUEST_TAG_ID
  • NFC_BRICKLET_READER_STATE_REQUEST_TAG_ID_READY
  • NFC_BRICKLET_READER_STATE_REQUEST_TAG_ID_ERROR
  • NFC_BRICKLET_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE
  • NFC_BRICKLET_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_READY
  • NFC_BRICKLET_READER_STATE_AUTHENTICATE_MIFARE_CLASSIC_PAGE_ERROR
  • NFC_BRICKLET_READER_STATE_WRITE_PAGE
  • NFC_BRICKLET_READER_STATE_WRITE_PAGE_READY
  • NFC_BRICKLET_READER_STATE_WRITE_PAGE_ERROR
  • NFC_BRICKLET_READER_STATE_REQUEST_PAGE
  • NFC_BRICKLET_READER_STATE_REQUEST_PAGE_READY
  • NFC_BRICKLET_READER_STATE_REQUEST_PAGE_ERROR
  • NFC_BRICKLET_READER_STATE_WRITE_NDEF
  • NFC_BRICKLET_READER_STATE_WRITE_NDEF_READY
  • NFC_BRICKLET_READER_STATE_WRITE_NDEF_ERROR
  • NFC_BRICKLET_READER_STATE_REQUEST_NDEF
  • NFC_BRICKLET_READER_STATE_REQUEST_NDEF_READY
  • NFC_BRICKLET_READER_STATE_REQUEST_NDEF_ERROR
Source

pub async fn reader_write_ndef_low_level( &mut self, ndef_length: u16, ndef_chunk_offset: u16, ndef_chunk_data: &[u8; 60], ) -> Result<ReaderWriteNdefLowLevel, TinkerforgeError>

Writes NDEF formated data.

This function currently supports NFC Forum Type 2 and 4.

The general approach for writing a NDEF message is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to ReaderRequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. If looking for a specific tag then call [reader_get_tag_id] and check if the expected tag was found, if it was not found got back to step 1
  4. Call [reader_write_ndef] with the NDEF message that you want to write
  5. Wait for state to change to ReaderWriteNDEFReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
Source

pub async fn reader_request_ndef(&mut self) -> Result<(), TinkerforgeError>

Reads NDEF formated data from a tag.

This function currently supports NFC Forum Type 1, 2, 3 and 4.

The general approach for reading a NDEF message is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to RequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. If looking for a specific tag then call [reader_get_tag_id] and check if the expected tag was found, if it was not found got back to step 1
  4. Call [reader_request_ndef]
  5. Wait for state to change to ReaderRequestNDEFReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  6. Call [reader_read_ndef] to retrieve the NDEF message from the buffer
Source

pub async fn reader_read_ndef_low_level( &mut self, ) -> Result<ReaderReadNdefLowLevel, TinkerforgeError>

Returns the NDEF data from an internal buffer. To fill the buffer with a NDEF message you have to call [reader_request_ndef] beforehand.

Source

pub async fn reader_authenticate_mifare_classic_page( &mut self, page: u16, key_number: u8, key: &[u8; 6], ) -> Result<(), TinkerforgeError>

Mifare Classic tags use authentication. If you want to read from or write to a Mifare Classic page you have to authenticate it beforehand. Each page can be authenticated with two keys: A (key_number = 0) and B (key_number = 1). A new Mifare Classic tag that has not yet been written to can be accessed with key A and the default key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF].

The approach to read or write a Mifare Classic page is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to ReaderRequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. If looking for a specific tag then call [reader_get_tag_id] and check if the expected tag was found, if it was not found got back to step 1
  4. Call [reader_authenticate_mifare_classic_page] with page and key for the page
  5. Wait for state to change to ReaderAuthenticatingMifareClassicPageReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  6. Call [reader_request_page] or [reader_write_page] to read/write page

The authentication will always work for one whole sector (4 pages).

Associated constants:

  • NFC_BRICKLET_KEY_A
  • NFC_BRICKLET_KEY_B
Source

pub async fn reader_write_page_low_level( &mut self, page: u16, data_length: u16, data_chunk_offset: u16, data_chunk_data: &[u8; 58], ) -> Result<ReaderWritePageLowLevel, TinkerforgeError>

Writes a maximum of 8192 bytes starting from the given page. How many pages are written depends on the tag type. The page sizes are as follows:

  • Mifare Classic page size: 16 byte
  • NFC Forum Type 1 page size: 8 byte
  • NFC Forum Type 2 page size: 4 byte
  • NFC Forum Type 3 page size: 16 byte
  • NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)

The general approach for writing to a tag is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to ReaderRequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. If looking for a specific tag then call [reader_get_tag_id] and check if the expected tag was found, if it was not found got back to step 1
  4. Call [reader_write_page] with page number and data
  5. Wait for state to change to ReaderWritePageReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)

If you use a Mifare Classic tag you have to authenticate a page before you can write to it. See [reader_authenticate_mifare_classic_page].

NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.

Choose CC by setting page to 3 or NDEF by setting page to 4.

Associated constants:

  • NFC_BRICKLET_READER_WRITE_TYPE4_CAPABILITY_CONTAINER
  • NFC_BRICKLET_READER_WRITE_TYPE4_NDEF
Source

pub async fn reader_request_page( &mut self, page: u16, length: u16, ) -> Result<(), TinkerforgeError>

Reads a maximum of 8192 bytes starting from the given page and stores them into a buffer. The buffer can then be read out with [reader_read_page]. How many pages are read depends on the tag type. The page sizes are as follows:

  • Mifare Classic page size: 16 byte
  • NFC Forum Type 1 page size: 8 byte
  • NFC Forum Type 2 page size: 4 byte
  • NFC Forum Type 3 page size: 16 byte
  • NFC Forum Type 4: No pages, page = file selection (CC or NDEF, see below)

The general approach for reading a tag is as follows:

  1. Call [reader_request_tag_id]
  2. Wait for state to change to RequestTagIDReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  3. If looking for a specific tag then call [reader_get_tag_id] and check if the expected tag was found, if it was not found got back to step 1
  4. Call [reader_request_page] with page number
  5. Wait for state to change to ReaderRequestPageReady (see [reader_get_state] or [get_reader_state_changed_callback_receiver] receiver)
  6. Call [reader_read_page] to retrieve the page from the buffer

If you use a Mifare Classic tag you have to authenticate a page before you can read it. See [reader_authenticate_mifare_classic_page].

NFC Forum Type 4 tags are not organized into pages but different files. We currently support two files: Capability Container file (CC) and NDEF file.

Choose CC by setting page to 3 or NDEF by setting page to 4.

Associated constants:

  • NFC_BRICKLET_READER_REQUEST_TYPE4_CAPABILITY_CONTAINER
  • NFC_BRICKLET_READER_REQUEST_TYPE4_NDEF
Source

pub async fn reader_read_page_low_level( &mut self, ) -> Result<ReaderReadPageLowLevel, TinkerforgeError>

Returns the page data from an internal buffer. To fill the buffer with specific pages you have to call [reader_request_page] beforehand.

Source

pub async fn cardemu_get_state( &mut self, ) -> Result<CardemuGetState, TinkerforgeError>

Returns the current cardemu state of the NFC Bricklet.

On startup the Bricklet will be in the CardemuInitialization state. The initialization will only take about 20ms. After that it changes to CardemuIdle.

The Bricklet is also reinitialized if the mode is changed, see [set_mode].

The functions of this Bricklet can be called in the CardemuIdle state and all of the CardemuReady and CardemuError states.

Example: If you call [cardemu_start_discovery], the state will change to CardemuDiscover until the discovery is finished. Then it will change to either CardemuDiscoverReady if it worked or to CardemuDiscoverError if it didn’t.

The same approach is used analogously for the other API functions.

Associated constants:

  • NFC_BRICKLET_CARDEMU_STATE_INITIALIZATION
  • NFC_BRICKLET_CARDEMU_STATE_IDLE
  • NFC_BRICKLET_CARDEMU_STATE_ERROR
  • NFC_BRICKLET_CARDEMU_STATE_DISCOVER
  • NFC_BRICKLET_CARDEMU_STATE_DISCOVER_READY
  • NFC_BRICKLET_CARDEMU_STATE_DISCOVER_ERROR
  • NFC_BRICKLET_CARDEMU_STATE_TRANSFER_NDEF
  • NFC_BRICKLET_CARDEMU_STATE_TRANSFER_NDEF_READY
  • NFC_BRICKLET_CARDEMU_STATE_TRANSFER_NDEF_ERROR
Source

pub async fn cardemu_start_discovery(&mut self) -> Result<(), TinkerforgeError>

Starts the discovery process. If you call this function while a NFC reader device is near to the NFC Bricklet the state will change from CardemuDiscovery to CardemuDiscoveryReady.

If no NFC reader device can be found or if there is an error during discovery the cardemu state will change to CardemuDiscoveryError. In this case you have to restart the discovery process.

If the cardemu state changes to CardemuDiscoveryReady you can start the NDEF message transfer with [cardemu_write_ndef] and [cardemu_start_transfer].

Source

pub async fn cardemu_write_ndef_low_level( &mut self, ndef_length: u16, ndef_chunk_offset: u16, ndef_chunk_data: &[u8; 60], ) -> Result<CardemuWriteNdefLowLevel, TinkerforgeError>

Writes the NDEF message that is to be transferred to the NFC peer.

The maximum supported NDEF message size in Cardemu mode is 255 byte.

You can call this function at any time in Cardemu mode. The internal buffer will not be overwritten until you call this function again or change the mode.

Source

pub async fn cardemu_start_transfer( &mut self, transfer: u8, ) -> Result<(), TinkerforgeError>

You can start the transfer of a NDEF message if the cardemu state is CardemuDiscoveryReady.

Before you call this function to start a write transfer, the NDEF message that is to be transferred has to be written via [cardemu_write_ndef] first.

After you call this function the state will change to CardemuTransferNDEF. It will change to CardemuTransferNDEFReady if the transfer was successful or CardemuTransferNDEFError if it wasn’t.

Associated constants:

  • NFC_BRICKLET_CARDEMU_TRANSFER_ABORT
  • NFC_BRICKLET_CARDEMU_TRANSFER_WRITE
Source

pub async fn p2p_get_state(&mut self) -> Result<P2pGetState, TinkerforgeError>

Returns the current P2P state of the NFC Bricklet.

On startup the Bricklet will be in the P2PInitialization state. The initialization will only take about 20ms. After that it changes to P2PIdle.

The Bricklet is also reinitialized if the mode is changed, see [set_mode].

The functions of this Bricklet can be called in the P2PIdle state and all of the P2PReady and P2PError states.

Example: If you call [p2p_start_discovery], the state will change to P2PDiscover until the discovery is finished. Then it will change to either P2PDiscoverReady* if it worked or to P2PDiscoverError if it didn’t.

The same approach is used analogously for the other API functions.

Associated constants:

  • NFC_BRICKLET_P2P_STATE_INITIALIZATION
  • NFC_BRICKLET_P2P_STATE_IDLE
  • NFC_BRICKLET_P2P_STATE_ERROR
  • NFC_BRICKLET_P2P_STATE_DISCOVER
  • NFC_BRICKLET_P2P_STATE_DISCOVER_READY
  • NFC_BRICKLET_P2P_STATE_DISCOVER_ERROR
  • NFC_BRICKLET_P2P_STATE_TRANSFER_NDEF
  • NFC_BRICKLET_P2P_STATE_TRANSFER_NDEF_READY
  • NFC_BRICKLET_P2P_STATE_TRANSFER_NDEF_ERROR
Source

pub async fn p2p_start_discovery(&mut self) -> Result<(), TinkerforgeError>

Starts the discovery process. If you call this function while another NFC P2P enabled device is near to the NFC Bricklet the state will change from P2PDiscovery to P2PDiscoveryReady.

If no NFC P2P enabled device can be found or if there is an error during discovery the P2P state will change to P2PDiscoveryError. In this case you have to restart the discovery process.

If the P2P state changes to P2PDiscoveryReady you can start the NDEF message transfer with [p2p_start_transfer].

Source

pub async fn p2p_write_ndef_low_level( &mut self, ndef_length: u16, ndef_chunk_offset: u16, ndef_chunk_data: &[u8; 60], ) -> Result<P2pWriteNdefLowLevel, TinkerforgeError>

Writes the NDEF message that is to be transferred to the NFC peer.

The maximum supported NDEF message size for P2P transfer is 255 byte.

You can call this function at any time in P2P mode. The internal buffer will not be overwritten until you call this function again, change the mode or use P2P to read an NDEF messages.

Source

pub async fn p2p_start_transfer( &mut self, transfer: u8, ) -> Result<(), TinkerforgeError>

You can start the transfer of a NDEF message if the P2P state is P2PDiscoveryReady.

Before you call this function to start a write transfer, the NDEF message that is to be transferred has to be written via [p2p_write_ndef] first.

After you call this function the P2P state will change to P2PTransferNDEF. It will change to P2PTransferNDEFReady if the transfer was successfull or P2PTransferNDEFError if it wasn’t.

If you started a write transfer you are now done. If you started a read transfer you can now use [p2p_read_ndef] to read the NDEF message that was written by the NFC peer.

Associated constants:

  • NFC_BRICKLET_P2P_TRANSFER_ABORT
  • NFC_BRICKLET_P2P_TRANSFER_WRITE
  • NFC_BRICKLET_P2P_TRANSFER_READ
Source

pub async fn p2p_read_ndef_low_level( &mut self, ) -> Result<P2pReadNdefLowLevel, TinkerforgeError>

Returns the NDEF message that was written by a NFC peer in NFC P2P mode.

The NDEF message is ready if you called [p2p_start_transfer] with a read transfer and the P2P state changed to P2PTransferNDEFReady.

Source

pub async fn set_detection_led_config( &mut self, config: u8, ) -> Result<(), TinkerforgeError>

Sets the detection LED configuration. By default the LED shows if a card/reader is detected.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is off.

Associated constants:

  • NFC_BRICKLET_DETECTION_LED_CONFIG_OFF
  • NFC_BRICKLET_DETECTION_LED_CONFIG_ON
  • NFC_BRICKLET_DETECTION_LED_CONFIG_SHOW_HEARTBEAT
  • NFC_BRICKLET_DETECTION_LED_CONFIG_SHOW_DETECTION
Source

pub async fn get_detection_led_config(&mut self) -> Result<u8, TinkerforgeError>

Returns the configuration as set by [set_detection_led_config]

Associated constants:

  • NFC_BRICKLET_DETECTION_LED_CONFIG_OFF
  • NFC_BRICKLET_DETECTION_LED_CONFIG_ON
  • NFC_BRICKLET_DETECTION_LED_CONFIG_SHOW_HEARTBEAT
  • NFC_BRICKLET_DETECTION_LED_CONFIG_SHOW_DETECTION
Source

pub async fn set_maximum_timeout( &mut self, timeout: u16, ) -> Result<(), TinkerforgeError>

Sets the maximum timeout.

This is a global maximum used for all internal state timeouts. The timeouts depend heavily on the used tags etc. For example: If you use a Type 2 tag and you want to detect if it is present, you have to use [reader_request_tag_id] and wait for the state to change to either the error state or the ready state.

With the default configuration this takes 2-3 seconds. By setting the maximum timeout to 100ms you can reduce this time to ~150-200ms. For Type 2 this would also still work with a 20ms timeout (a Type 2 tag answers usually within 10ms). A type 4 tag can take up to 500ms in our tests.

If you need a fast response time to discover if a tag is present or not you can find a good timeout value by trial and error for your specific tag.

By default we use a very conservative timeout, to be sure that any tag can always answer in time.

.. versionadded:: 2.0.1$nbsp;(Plugin)

Source

pub async fn get_maximum_timeout(&mut self) -> Result<u16, TinkerforgeError>

Returns the timeout as set by [set_maximum_timeout]

.. versionadded:: 2.0.1$nbsp;(Plugin)

Source

pub async fn simple_get_tag_id_low_level( &mut self, index: u8, ) -> Result<SimpleGetTagIdLowLevel, TinkerforgeError>

.. versionadded:: 2.0.6$nbsp;(Plugin)

Associated constants:

  • NFC_BRICKLET_TAG_TYPE_MIFARE_CLASSIC
  • NFC_BRICKLET_TAG_TYPE_TYPE1
  • NFC_BRICKLET_TAG_TYPE_TYPE2
  • NFC_BRICKLET_TAG_TYPE_TYPE3
  • NFC_BRICKLET_TAG_TYPE_TYPE4
Source

pub async fn get_spitfp_error_count( &mut self, ) -> Result<SpitfpErrorCount, TinkerforgeError>

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

Source

pub async fn set_bootloader_mode( &mut self, mode: u8, ) -> Result<u8, TinkerforgeError>

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Associated constants:

  • NFC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE
  • NFC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
  • NFC_BRICKLET_BOOTLOADER_STATUS_OK
  • NFC_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
  • NFC_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
  • NFC_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
  • NFC_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
  • NFC_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
Source

pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError>

Returns the current bootloader mode, see [set_bootloader_mode].

Associated constants:

  • NFC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE
  • NFC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
  • NFC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
Source

pub async fn set_write_firmware_pointer( &mut self, pointer: u32, ) -> Result<(), TinkerforgeError>

Sets the firmware pointer for [write_firmware]. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Source

pub async fn write_firmware( &mut self, data: &[u8; 64], ) -> Result<u8, TinkerforgeError>

Writes 64 Bytes of firmware at the position as written by [set_write_firmware_pointer] before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Source

pub async fn set_status_led_config( &mut self, config: u8, ) -> Result<(), TinkerforgeError>

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

Associated constants:

  • NFC_BRICKLET_STATUS_LED_CONFIG_OFF
  • NFC_BRICKLET_STATUS_LED_CONFIG_ON
  • NFC_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
  • NFC_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
Source

pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError>

Returns the configuration as set by [set_status_led_config]

Associated constants:

  • NFC_BRICKLET_STATUS_LED_CONFIG_OFF
  • NFC_BRICKLET_STATUS_LED_CONFIG_ON
  • NFC_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
  • NFC_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
Source

pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError>

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

Source

pub async fn reset(&mut self) -> Result<(), TinkerforgeError>

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

Source

pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError>

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

Source

pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError>

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

Source

pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError>

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position ‘z’.

The device identifier numbers can be found here. |device_identifier_constant|

Trait Implementations§

Source§

impl Clone for NfcBricklet

Source§

fn clone(&self) -> NfcBricklet

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.