21 std::optional<std::array<uint8_t, 2>>
send_command(uint8_t address,
23 uint8_t tx_buf = address | command;
24 std::array<uint8_t, 2> rx_buf;
26 if (!uart_.transmit(&tx_buf, 1, 5)) {
29 if (!uart_.receive(rx_buf.data(), rx_buf.size(), 5)) {
32 if (!test_checksum(rx_buf[0], rx_buf[1])) {
39 std::array<uint8_t, 2> buf{
static_cast<uint8_t
>(address | 0x02), command};
41 if (!uart_.transmit(buf.data(), buf.size(), 5)) {
48 peripheral::UartBase &uart_;
50 static inline bool test_checksum(uint8_t l, uint8_t h) {
51 bool k1 = !(bit(h, 5) ^ bit(h, 3) ^ bit(h, 1) ^ bit(l, 7) ^ bit(l, 5) ^
52 bit(l, 3) ^ bit(l, 1));
53 bool k0 = !(bit(h, 4) ^ bit(h, 2) ^ bit(h, 0) ^ bit(l, 6) ^ bit(l, 4) ^
54 bit(l, 2) ^ bit(l, 0));
55 return (k1 == bit(h, 7)) && (k0 == bit(h, 6));
58 static inline bool bit(uint8_t x, uint8_t i) {
return ((x >> i) & 1) == 1; }