rfid: allow RST-unconnected mode (no hard reset) and add optional self-test skip for clone readers
This commit is contained in:
@@ -22,11 +22,18 @@ static const char *TAG = "rfid";
|
|||||||
#define RC522_TASK_PRIORITY (4)
|
#define RC522_TASK_PRIORITY (4)
|
||||||
|
|
||||||
/* Conservative clock for MFRC522 clones. If the FIFO self-test still
|
/* Conservative clock for MFRC522 clones. If the FIFO self-test still
|
||||||
* reports a mismatch error, lower further (e.g. 1000000) or check
|
* complains, lower further or check power/wiring. */
|
||||||
* power/wiring. Many clone readers glitch at 4MHz on a shared bus. */
|
|
||||||
#define RC522_SPI_CLK_HZ (1000000)
|
#define RC522_SPI_CLK_HZ (1000000)
|
||||||
#define RC522_START_ATTEMPTS (3)
|
#define RC522_START_ATTEMPTS (3)
|
||||||
|
|
||||||
|
/* Some clone MFRC522 modules (esp. those wired with RST left floating and
|
||||||
|
* only an IRQ header exposed) fail the library's strict PCD rw self-test even
|
||||||
|
* though scanning works fine. Setting this to 1 skips that gate and starts
|
||||||
|
* the polling task anyway. */
|
||||||
|
#ifndef CONFIG_MTG_RFID_SKIP_SELFTEST
|
||||||
|
#define CONFIG_MTG_RFID_SKIP_SELFTEST (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
static rc522_driver_handle_t s_driver;
|
static rc522_driver_handle_t s_driver;
|
||||||
static rc522_handle_t s_scanner;
|
static rc522_handle_t s_scanner;
|
||||||
|
|
||||||
@@ -80,7 +87,10 @@ esp_err_t rfid_manager_init(void)
|
|||||||
.clock_speed_hz = RC522_SPI_CLK_HZ,
|
.clock_speed_hz = RC522_SPI_CLK_HZ,
|
||||||
},
|
},
|
||||||
.dma_chan = SPI_DMA_CH_AUTO,
|
.dma_chan = SPI_DMA_CH_AUTO,
|
||||||
.rst_io_num = HW_RC522_RST_GPIO,
|
/* RST left unconnected (-1): the module comes up on its own power-on
|
||||||
|
* reset and uses the library soft-reset. Wire RST=GPIO22 and set this
|
||||||
|
* to HW_RC522_RST_GPIO if your module needs the hard-reset line. */
|
||||||
|
.rst_io_num = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
esp_err_t ret = rc522_spi_create(&driver_config, &s_driver);
|
esp_err_t ret = rc522_spi_create(&driver_config, &s_driver);
|
||||||
@@ -122,12 +132,21 @@ esp_err_t rfid_manager_start(void)
|
|||||||
vTaskDelay(pdMS_TO_TICKS(250));
|
vTaskDelay(pdMS_TO_TICKS(250));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_MTG_RFID_SKIP_SELFTEST
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "MFRC522 self-test failed (%s) - continuing anyway "
|
||||||
|
"(clone readers often scan fine; the polling task stays up).",
|
||||||
|
esp_err_to_name(ret));
|
||||||
|
ret = ESP_OK;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (ret != ESP_OK) {
|
if (ret != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "MFRC522 self-test failed (%s). Check: reader powered "
|
ESP_LOGE(TAG, "MFRC522 self-test failed (%s). Check: reader powered "
|
||||||
"(3.3V), SPI wiring (SCK=18/MOSI=23/MISO=19, CS=5, RST=22), "
|
"(3.3V), SPI wiring (SCK=16/MOSI=17/MISO=13, CS=26, RST=22), "
|
||||||
"and if it is a clone try lowering RC522_SPI_CLK_HZ", esp_err_to_name(ret));
|
"and if it is a clone try lowering RC522_SPI_CLK_HZ", esp_err_to_name(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Pin the library's polling task to Core 0 so that RFID I/O never
|
/* Pin the library's polling task to Core 0 so that RFID I/O never
|
||||||
* competes with the UI renderer on Core 1. */
|
* competes with the UI renderer on Core 1. */
|
||||||
|
|||||||
Reference in New Issue
Block a user