ESPHome  2022.6.3
rc522_i2c.cpp
Go to the documentation of this file.
1 #include "rc522_i2c.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace rc522_i2c {
6 
7 static const char *const TAG = "rc522_i2c";
8 
10  RC522::dump_config();
11  LOG_I2C_DEVICE(this);
12 }
13 
19 ) {
20  uint8_t value;
21  if (!read_byte(reg >> 1, &value))
22  return 0;
23  ESP_LOGVV(TAG, "read_register_(%x) -> %u", reg, value);
24  return value;
25 }
26 
32  uint8_t count,
33  uint8_t *values,
34  uint8_t rx_align
35 ) {
36  if (count == 0) {
37  return;
38  }
39 
40  uint8_t b = values[0];
41  read_bytes(reg >> 1, values, count);
42 
43  if (rx_align) // Only update bit positions rxAlign..7 in values[0]
44  {
45  // Create bit mask for bit positions rxAlign..7
46  uint8_t mask = 0xFF << rx_align;
47  // Apply mask to both current value of values[0] and the new data in values array.
48  values[0] = (b & ~mask) | (values[0] & mask);
49  }
50 }
51 
53  uint8_t value
54 ) {
55  this->write_byte(reg >> 1, value);
56 }
57 
63  uint8_t count,
64  uint8_t *values
65 ) {
66  write_bytes(reg >> 1, values, count);
67 }
68 
69 } // namespace rc522_i2c
70 } // namespace esphome
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
Definition: i2c.h:96
I2CRegister reg(uint8_t a_register)
Definition: i2c.h:46
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Definition: i2c.h:68
void pcd_write_register(PcdRegister reg, uint8_t value) override
Definition: rc522_i2c.cpp:52
uint8_t pcd_read_register(PcdRegister reg) override
Reads a uint8_t from the specified register in the MFRC522 chip.
Definition: rc522_i2c.cpp:18
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Definition: i2c.h:123
Definition: a4988.cpp:4
void dump_config() override
Definition: rc522_i2c.cpp:9
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)
Definition: i2c.h:109