H753_CPP_SPI_Resistive_Touch_Screen_Controller 1.0
STM32H753 SPI resistive touchscreen (Adafruit 333 overlay + 5767 TSC2046 controller) driver and tutorial
Loading...
Searching...
No Matches
STM32BusIORegister.cpp
1/*
2 * STM32BusIORegister.cpp
3 *
4 * Created on: Sep 15, 2026
5 * Author: johng
6 */
7
8#include "STM32BusIORegister.hpp"
9
10namespace {
11constexpr uint8_t kAddrBit8HighToRead = 0x80;
12} // namespace
13
14STM32BusIORegister::STM32BusIORegister(STM32SPIDevice *spiDevice, uint32_t regAddr, size_t width, size_t addressWidth)
15 : _spiDevice(spiDevice), _regAddr(regAddr), _width(width), _addressWidth(addressWidth) {
16}
17
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),
24 };
25
26 uint8_t dataBuffer[4] = {0};
27 if (!_spiDevice->writeThenRead(addrBuffer, _addressWidth, dataBuffer, _width)) {
28 return 0xFFFFFFFF;
29 }
30
31 uint32_t value = 0;
32 for (size_t i = 0; i < _width; i++) {
33 value <<= 8;
34 value |= dataBuffer[i];
35 }
36 return value;
37}
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...