8#include "STM32BusIORegister.hpp"
11constexpr uint8_t kAddrBit8HighToRead = 0x80;
15 : _spiDevice(spiDevice), _regAddr(regAddr), _width(width), _addressWidth(addressWidth) {
19 uint8_t addrBuffer[4] = {
20 static_cast<uint8_t
>((_regAddr & 0xFF) | kAddrBit8HighToRead),
21 static_cast<uint8_t
>((_regAddr >> 8) & 0xFF),
22 static_cast<uint8_t
>((_regAddr >> 16) & 0xFF),
23 static_cast<uint8_t
>((_regAddr >> 24) & 0xFF),
26 uint8_t dataBuffer[4] = {0};
27 if (!_spiDevice->
writeThenRead(addrBuffer, _addressWidth, dataBuffer, _width)) {
32 for (
size_t i = 0; i < _width; i++) {
34 value |= dataBuffer[i];
uint32_t read()
Sends the (address-bit-set) register address, then reads back width bytes MSB-first and returns them ...
STM32BusIORegister(STM32SPIDevice *spiDevice, uint32_t regAddr, size_t width=1, size_t addressWidth=1)
Constructs a view over one register.
Wraps one SPI peripheral + chip-select pin into read/write/transfer operations, mirroring the hardwar...
bool writeThenRead(const uint8_t *writeBuffer, size_t writeLen, uint8_t *readBuffer, size_t readLen, uint8_t sendValue=0xFF)
Writes writeLen bytes, then reads readLen bytes, all within a single chip-select assert/deassert brac...