10static constexpr uint8_t CRC6_AS_CRC8_POLY = 0x0C;
13 if (
crc8(frame, 3, 0x00, CRC6_AS_CRC8_POLY,
true) != 0)
17 status = (bits >> 6) & 0x0F;
22 if (valid_frames < PROBE_MIN_VALID)
32 for (uint8_t i = 0; i < PROBE_FRAMES && (
valid < PROBE_MIN_VALID || !nonzero); i++) {
41 this->
mark_failed(LOG_STR(
"no valid frame received, check the wiring and CS pin"));
44 ESP_LOGW(TAG,
"Every frame read zero: the data line may be stuck low");
52 ESP_LOGCONFIG(TAG,
"MT6701 (SSI/SPI):");
53 LOG_PIN(
" CS Pin: ", this->
cs_);
55 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
60 uint8_t
buffer[3] = {0, 0, 0};
void mark_failed()
Mark this component as failed.
void dump_config() override
bool read_count(uint16_t &count) override
void spi_setup() override
void read_array(uint8_t *data, size_t length)
ESPHOME_LOG_TAG(TAG, "mt6701_spi.binary_sensor")
@ PROBE_RESULT_NO_ENCODER
bool decode_frame(const uint8_t frame[3], uint16_t &count, uint8_t &status)
Decode a 24-bit SSI frame (14-bit angle, 4 status bits, 6-bit CRC); false when the CRC fails.
ProbeResult probe_result(uint8_t valid_frames, bool any_nonzero)
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.