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
STM32_BusIO

Small STM32 HAL (C++) helpers for talking to SPI devices: STM32SPIDevice wraps one SPI_HandleTypeDef plus a chip-select pin with automatic CS bracketing, and STM32BusIORegister reads a single addressable register on top of it.

Modeled on the hardware-SPI subset of Adafruit's Adafruit_BusIO as a design reference. It is an independent STM32 HAL implementation, not a direct port. Software (bit-banged) SPI, I2C, and register writes are not included.

Requirements

  • STM32 HAL with main.h providing the HAL headers (CubeMX/CubeIDE generated project)
  • C++ enabled in the project
  • An SPI peripheral already configured by CubeMX (mode, speed and bit order are NOT set by this library) and a GPIO output for chip select

Adding it to a project (git submodule)

git submodule add git@github.com:jpgroulx/STM32_BusIO.git STM32BusIO

Cloning a project that already includes it:

git clone --recurse-submodules <project-url>

If you forgot the flag, the STM32BusIO/ folder is empty; run git submodule update --init to fill it.

Then in STM32CubeIDE, add the folder as a source location and add ../STM32BusIO to the include paths for both C and C++ (Project > Properties > C/C++ Build > Settings).

Using it from a CubeIDE main.c

The classes in this library are C++, but STM32CubeIDE generates main.c as plain C, and you should not rename it to main.cpp (CubeMX regenerates main.c, not main.cpp). Keep main.c as C and reach the library through a small C-callable wrapper:

  1. Enable C++ in the project first (right-click the project, Convert to C++).
  2. Declare wrapper functions inside extern "C" in a header.
  3. Implement them in a .cpp file that creates the STM32SPIDevice object (or the driver built on it, such as STM32_TSC2046) with new after MX_SPIx_Init() has run (not as a global, which would construct too early).
  4. Call the wrapper functions from main.c, and put those calls only inside CubeMX's "safe areas": the code between the /* USER CODE BEGIN ... */ and /* USER CODE END ... */ markers. CubeMX overwrites everything outside those markers whenever it regenerates main.c.

The tutorial STM32 C++ Code Integration with STM32CubeIDE walks through this step by step.

Thread safety

Not thread-safe or ISR-safe. Each transaction asserts CS, transfers, then deasserts with no locking. Use from a single context, or add your own mutex/critical section.

Building the documentation

The API docs are generated with Doxygen and are not committed to the repo. From this folder, run:

doxygen

The HTML is written to docs/ (open docs/html/index.html). Graphviz is optional, for call graphs; see the commented HAVE_DOT lines in Doxyfile.

License

MIT. Portions of the API shape are derived from Adafruit_BusIO, Copyright (c) 2017 Adafruit Industries (MIT). See LICENSE.