11static const uint8_t WAIT_I_RQ = 0x30;
13static const char *
const TAG =
"rc522";
15static const uint8_t RESET_COUNT = 5;
26 ESP_LOGV(TAG,
"Power down mode detected. Hard resetting");
49 ESP_LOGV(TAG,
"Initialize");
76 ESP_LOGCONFIG(TAG,
"RC522:");
77 switch (this->error_code_) {
81 ESP_LOGE(TAG,
"Reset command failed");
87 LOG_UPDATE_INTERVAL(
this);
90 LOG_BINARY_SENSOR(
" ",
"Tag", child);
102 ESP_LOGW(TAG,
"Communication takes longer than update interval: %d", state_);
129 ESP_LOGV(TAG,
"finished communication status: %d, state: %d",
status, state_);
137 ESP_LOGV(TAG,
"CMD_REQA -> TIMEOUT (no tag present) %d",
status);
140 ESP_LOGW(TAG,
"CMD_REQA -> Not OK %d",
status);
143 ESP_LOGW(TAG,
"CMD_REQA -> OK, but unexpected back_length_ of %d",
back_length_);
155 ESP_LOGV(TAG,
"STATE_READ_SERIAL (%d)",
status);
167 ESP_LOGE(TAG,
"uid_idx_ invalid, uid_idx_ = %d",
uid_idx_);
192 ESP_LOGV(TAG,
"STATE_READ_SERIAL_DONE -> TIMEOUT (no tag present) %d",
status);
194 ESP_LOGW(TAG,
"Unexpected response. Read status is %d. Read bytes: %d (%s)",
status,
back_length_,
207 for (uint8_t i = 2 + cascade; i < 6; i++)
225 if (tag->process(rfid_uid)) {
237 trigger->process(rfid_uid);
240 ESP_LOGD(TAG,
"Found new tag '%s'",
format_hex_pretty(rfid_uid,
'-',
false).c_str());
272 ESP_LOGI(TAG,
"Soft reset");
280 ESP_LOGI(TAG,
"Device online");
287 ESP_LOGE(TAG,
"Unable to reset");
299 if ((value & 0x03) != 0x03) {
309 if ((value & 0x03) != 0x00) {
370 if (!(n & WAIT_I_RQ)) {
375 ESP_LOGW(TAG,
"Communication with the MFRC522 might be down, reset in %d",
387 if (error_reg_value & 0x13) {
399 uint8_t valid_bits_local =
404 if (error_reg_value & 0x08) {
405 ESP_LOGW(TAG,
"collision error, received %d bytes + %d bits (but anticollision not implemented)",
406 back_length_ - (valid_bits_local > 0), valid_bits_local);
410 if (valid_bits_local) {
411 ESP_LOGW(TAG,
"only %d valid bits received, tag distance to high? Error code is 0x%x", valid_bits_local,
430 ESP_LOGVV(TAG,
"pcd_calculate_crc_(..., %d, ...)",
length);
453 ESP_LOGVV(TAG,
"pcd_calculate_crc_() STATUS_OK");
459 ESP_LOGD(TAG,
"pcd_calculate_crc_() TIMEOUT");
466 if (data.size() != this->uid_.size()) {
469 for (
size_t i = 0; i < data.size(); i++) {
470 if (data[i] != this->
uid_[i]) {
virtual void mark_failed()
Mark this component as failed.
virtual void pin_mode(gpio::Flags flags)=0
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
void publish_state(bool new_state)
Publish a new state to the front-end.
bool process(std::vector< uint8_t > &data)
std::vector< uint8_t > uid_
std::vector< RC522Trigger * > triggers_ontagremoved_
void dump_config() override
virtual uint8_t pcd_read_register(PcdRegister reg)=0
enum esphome::rc522::RC522::RC522Error NONE
void pcd_transceive_data_(uint8_t send_len)
Transfers data to the MFRC522 FIFO, executes a command, waits for completion and transfers data back ...
std::vector< RC522Trigger * > triggers_ontag_
void pcd_reset_()
Performs a soft reset on the MFRC522 chip and waits for it to be ready again.
uint32_t awaiting_comm_time_
std::vector< RC522BinarySensor * > binary_sensors_
void pcd_antenna_off_()
Turns the antenna off by disabling pins TX1 and TX2.
uint8_t back_length_
In: Max number of uint8_ts to write to *backData. Out: The number of uint8_ts returned.
StatusCode await_transceive_()
void pcd_antenna_on_()
Turns the antenna on by enabling pins TX1 and TX2.
void pcd_set_register_bit_mask_(PcdRegister reg, uint8_t mask)
Sets the bits given in mask in register reg.
void pcd_calculate_crc_(uint8_t *data, uint8_t length)
Use the CRC coprocessor in the MFRC522 to calculate a CRC_A.
std::vector< uint8_t > current_uid_
void pcd_clear_register_bit_mask_(PcdRegister reg, uint8_t mask)
Clears the bits given in mask from register reg.
uint8_t buffer_[9]
buffer for communication, the first bits [0..back_idx-1] are for tx , [back_idx..back_idx+back_len] f...
virtual void pcd_write_register(PcdRegister reg, uint8_t value)=0
@ STATE_SELECT_SERIAL_DONE
void process(std::vector< uint8_t > &data)
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.
uint32_t IRAM_ATTR HOT millis()