various bug fixes
This commit is contained in:
@@ -23,11 +23,11 @@ static const char *TAG = "rfid";
|
||||
#define RC522_TASK_NAME "rc522_poll"
|
||||
#define RC522_POLL_INTERVAL_MS (100)
|
||||
#define RC522_TASK_STACK_SIZE (6 * 1024)
|
||||
#define RC522_TASK_PRIORITY (4)
|
||||
#define RC522_TASK_PRIORITY (1)
|
||||
|
||||
/* Conservative clock for MFRC522 clones. If the FIFO self-test still
|
||||
* complains, lower further or check power/wiring. */
|
||||
#define RC522_SPI_CLK_HZ (1000000)
|
||||
#define RC522_SPI_CLK_HZ (5000000)
|
||||
#define RC522_START_ATTEMPTS (3)
|
||||
|
||||
/* Some clone MFRC522 modules (esp. those wired with RST left floating and
|
||||
@@ -76,40 +76,12 @@ static void on_picc_state_changed(void *arg, esp_event_base_t base, int32_t even
|
||||
* hardware-CS device. Any plausible value (0x88/0x91/0x92) means the chip is
|
||||
* alive and MISO works; 0x00/0xFF means MISO/power/wiring is dead. This is a
|
||||
* pure diagnostic and does not depend on the rc522 driver's reset path. */
|
||||
static void rfid_probe_version(void)
|
||||
{
|
||||
spi_device_handle_t probe = NULL;
|
||||
spi_device_interface_config_t devcfg = {
|
||||
.clock_speed_hz = RC522_SPI_CLK_HZ,
|
||||
.mode = 0,
|
||||
.spics_io_num = HW_RC522_CS_GPIO,
|
||||
.queue_size = 1,
|
||||
.command_bits = 1, /* read/write select bit */
|
||||
.address_bits = 6, /* register address */
|
||||
.dummy_bits = 1,
|
||||
.flags = SPI_DEVICE_HALFDUPLEX, /* RX-only reads like the rc522 driver */
|
||||
};
|
||||
if (spi_bus_add_device(HW_RFID_SPI_HOST, &devcfg, &probe) != ESP_OK || probe == NULL) {
|
||||
ESP_LOGW(TAG, "probe: could not add temp SPI device on SPI3");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t version = 0;
|
||||
spi_transaction_t t = {
|
||||
.cmd = 1, /* read */
|
||||
.addr = 0x37, /* VersionReg */
|
||||
.rxlength = 8,
|
||||
.rx_buffer = &version,
|
||||
};
|
||||
esp_err_t ret = spi_device_polling_transmit(probe, &t);
|
||||
ESP_LOGI(TAG, "MFRC522 VersionReg=0x%02X (%s). 0x88/0x91/0x92=alive; 0x00/0xFF=MISO/power/wiring",
|
||||
version, esp_err_to_name(ret));
|
||||
|
||||
spi_bus_remove_device(probe);
|
||||
}
|
||||
|
||||
esp_err_t rfid_manager_init(void)
|
||||
{
|
||||
esp_log_level_set("rc522", ESP_LOG_INFO);
|
||||
|
||||
/* Dedicated SPI3_HOST (HSPI) bus for the reader - independent controller
|
||||
* so the display (SPI2_HOST) and the RFID never share bus timing. We
|
||||
* initialize SPI3 here (with a real MISO) and hand the already-initialized
|
||||
@@ -124,14 +96,12 @@ esp_err_t rfid_manager_init(void)
|
||||
ESP_LOGI(TAG, "initializing MFRC522 on SPI3_HOST (SCK=%d MOSI=%d MISO=%d CS=%d)",
|
||||
HW_RFID_SCK_GPIO, HW_RFID_MOSI_GPIO, HW_RFID_MISO_GPIO, HW_RC522_CS_GPIO);
|
||||
|
||||
esp_err_t ret = spi_bus_initialize(HW_RFID_SPI_HOST, &rfid_bus_cfg, SPI_DMA_CH_AUTO);
|
||||
esp_err_t ret = spi_bus_initialize(HW_RFID_SPI_HOST, &rfid_bus_cfg, SPI_DMA_DISABLED);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "spi_bus_initialize(SPI3) failed: %s", esp_err_to_name(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
rfid_probe_version();
|
||||
|
||||
rc522_spi_config_t driver_config = {
|
||||
.host_id = HW_RFID_SPI_HOST,
|
||||
.bus_config = NULL, /* SPI3 already initialized above */
|
||||
@@ -139,11 +109,8 @@ esp_err_t rfid_manager_init(void)
|
||||
.spics_io_num = HW_RC522_CS_GPIO,
|
||||
.clock_speed_hz = RC522_SPI_CLK_HZ,
|
||||
},
|
||||
.dma_chan = SPI_DMA_CH_AUTO,
|
||||
/* 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,
|
||||
.dma_chan = SPI_DMA_DISABLED,
|
||||
.rst_io_num = HW_RC522_RST_GPIO,
|
||||
};
|
||||
|
||||
ret = rc522_spi_create(&driver_config, &s_driver);
|
||||
|
||||
Reference in New Issue
Block a user