2024-01-14 08:42:50 +01:00
|
|
|
/*
|
2024-03-15 15:12:00 +01:00
|
|
|
* NFC Operations
|
2024-01-14 08:42:50 +01:00
|
|
|
* WHowe <github.com/whowechina>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NFC_H
|
|
|
|
#define NFC_H
|
|
|
|
|
2024-03-15 15:12:00 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2024-01-14 08:42:50 +01:00
|
|
|
#include "hardware/i2c.h"
|
2024-03-16 03:25:27 +01:00
|
|
|
#include "hardware/spi.h"
|
2024-01-14 08:42:50 +01:00
|
|
|
|
|
|
|
typedef enum {
|
2024-01-21 05:59:47 +01:00
|
|
|
NFC_CARD_NONE = 0,
|
2024-01-14 08:42:50 +01:00
|
|
|
NFC_CARD_MIFARE,
|
|
|
|
NFC_CARD_FELICA,
|
|
|
|
NFC_CARD_VICINITY,
|
|
|
|
} nfc_card_type;
|
|
|
|
|
2024-01-21 05:59:47 +01:00
|
|
|
const char *nfc_card_name(nfc_card_type card_type);
|
|
|
|
|
2024-01-14 08:42:50 +01:00
|
|
|
typedef void (*nfc_wait_loop_t)();
|
|
|
|
typedef struct {
|
|
|
|
nfc_card_type card_type;
|
|
|
|
uint16_t len;
|
2024-01-14 12:44:18 +01:00
|
|
|
union {
|
|
|
|
uint8_t uid[8];
|
|
|
|
uint8_t idm[8];
|
|
|
|
};
|
2024-01-14 08:42:50 +01:00
|
|
|
uint8_t pmm[8];
|
|
|
|
uint8_t syscode[2];
|
|
|
|
} nfc_card_t;
|
|
|
|
|
2024-03-16 08:43:10 +01:00
|
|
|
/* should init or attach i2c and spi port before init */
|
|
|
|
void nfc_attach_i2c(i2c_inst_t *port);
|
2024-03-16 09:06:35 +01:00
|
|
|
void nfc_attach_spi(spi_inst_t *port, uint8_t rst, uint8_t nss, uint8_t busy);
|
|
|
|
|
2024-03-16 08:43:10 +01:00
|
|
|
void nfc_init_i2c(i2c_inst_t *port, uint8_t scl, uint8_t sda, uint32_t freq);
|
|
|
|
void nfc_init_spi(spi_inst_t *port, uint8_t miso, uint8_t sck, uint8_t mosi,
|
2024-03-16 03:25:27 +01:00
|
|
|
uint8_t rst, uint8_t nss, uint8_t busy);
|
|
|
|
|
|
|
|
void nfc_init();
|
|
|
|
|
|
|
|
/* should be called only after init */
|
2024-03-15 15:04:25 +01:00
|
|
|
void nfc_set_wait_loop(nfc_wait_loop_t loop);
|
|
|
|
|
2024-03-10 15:45:20 +01:00
|
|
|
void nfc_rf_field(bool on);
|
|
|
|
|
2024-01-14 08:42:50 +01:00
|
|
|
nfc_card_t nfc_detect_card();
|
2024-03-10 15:45:20 +01:00
|
|
|
void display_card(const nfc_card_t *card);
|
|
|
|
|
2024-01-21 05:59:47 +01:00
|
|
|
const char *nfc_module_name();
|
|
|
|
|
2024-01-14 12:44:18 +01:00
|
|
|
bool nfc_mifare_auth(const uint8_t uid[4], uint8_t block_id, uint8_t key_id, const uint8_t *key);
|
|
|
|
bool nfc_mifare_read(uint8_t block_id, uint8_t block_data[16]);
|
|
|
|
|
2024-01-14 08:42:50 +01:00
|
|
|
#endif
|