Files
kidsbox/device/components/esp-idf-rc522/rc522.h
T
Claude afbc0e5e23 Remove arduino-esp32 dependency, modernise WiFi and SPI compat
- Replace Arduino WiFi.h in Networking.cpp with native esp_wifi/esp_netif;
  uses event-driven connect with FreeRTOS EventGroup and 30 s timeout
- Remove initArduino() / Arduino.h from main.cpp
- Remove deprecated arduino-esp32 submodule (was uninitialized and marked
  deprecated since it was first added in Dec 2021)
- rc522.h: guard VSPI_HOST → SPI3_HOST for ESP-IDF 5.x compatibility
- WebInterface.cpp: drop redundant esp_wifi.h (esp_netif.h is sufficient)
- CMakeLists.txt: add esp_wifi + nvs_flash to REQUIRES

https://claude.ai/code/session_01MhAnh68DPNnTjcKqjNYDmk
2026-06-12 20:34:52 +00:00

99 lines
3.2 KiB
C

#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "driver/spi_master.h"
#define RC522_DEFAULT_MISO (25)
#define RC522_DEFAULT_MOSI (23)
#define RC522_DEFAULT_SCK (19)
#define RC522_DEFAULT_SDA (22)
/* VSPI_HOST was renamed to SPI3_HOST in ESP-IDF 5.0 */
#ifdef VSPI_HOST
# define RC522_DEFAULT_SPI_HOST (VSPI_HOST)
#else
# define RC522_DEFAULT_SPI_HOST (SPI3_HOST)
#endif
#define RC522_DEFAULT_SCAN_INTERVAL_MS (125)
#define RC522_DEFAULT_TACK_STACK_SIZE (4 * 1024)
#define RC522_DEFAULT_TACK_STACK_PRIORITY (4)
typedef void(*rc522_tag_callback_t)(uint8_t*);
/* Called when a tag is detected (url != NULL) or removed (sn == NULL, url == NULL).
* url is the NDEF URI record content, or NULL if no NDEF was found on the tag.
* The caller must NOT free sn or url — they are freed by the library. */
typedef void(*rc522_ndef_callback_t)(uint8_t* sn, const char* url);
typedef struct {
int miso_io; /*<! MFRC522 MISO gpio (Default: 25) */
int mosi_io; /*<! MFRC522 MOSI gpio (Default: 23) */
int sck_io; /*<! MFRC522 SCK gpio (Default: 19) */
int sda_io; /*<! MFRC522 SDA gpio (Default: 22) */
spi_host_device_t spi_host_id; /*<! Default VSPI_HOST (SPI3) */
rc522_tag_callback_t callback; /*<! Called with 5-byte serial number, or NULL when tag removed */
rc522_ndef_callback_t ndef_callback; /*<! Called with (sn, url) on tag change; url may be NULL */
uint16_t scan_interval_ms; /*<! How fast will ESP32 scan for nearby tags, in miliseconds. Default: 125ms */
size_t task_stack_size; /*<! Stack size of rc522 task (Default: 4 * 1024) */
uint8_t task_priority; /*<! Priority of rc522 task (Default: 4) */
} rc522_config_t;
typedef rc522_config_t rc522_start_args_t;
/**
* @brief Initialize RC522 module.
* To start scanning tags - call rc522_resume or rc522_start2 function.
* @param config Configuration
* @return ESP_OK on success
*/
esp_err_t rc522_init(rc522_config_t* config);
/**
* @brief Convert serial number (array of 5 bytes) to uint64_t number
* @param sn Serial number
* @return Serial number in number representation. If fail, 0 will be retured
*/
uint64_t rc522_sn_to_u64(uint8_t* sn);
/**
* @brief Check if RC522 is inited
* @return true if RC522 is inited
*/
bool rc522_is_inited();
/**
* @brief This function will call rc522_init function and immediately start to scan tags by calling rc522_resume function.
* @param start_args Configuration
* @return ESP_OK on success
*/
esp_err_t rc522_start(rc522_start_args_t start_args);
/**
* @brief Start to scan tags. If already started, ESP_OK will just be returned.
* @return ESP_OK on success
*/
esp_err_t rc522_start2();
/**
* @brief Start to scan tags. If already started, ESP_OK will just be returned.
* @return ESP_OK on success
*/
#define rc522_resume() rc522_start2()
/**
* @brief Pause scan tags. If already paused, ESP_OK will just be returned.
* @return ESP_OK on success
*/
esp_err_t rc522_pause();
/**
* @brief Destroy RC522 and free all resources
*/
void rc522_destroy();
#ifdef __cplusplus
}
#endif