36#ifndef ISF15ACP4_SPI_INTERFACE_HPP
37#define ISF15ACP4_SPI_INTERFACE_HPP
83static_assert((
kMaxClockHz * 150ULL) <= 1'000'000'000ULL,
"tcycle 150 ns minimum");
114template <
typename Derived>
132template <
typename Port>
134 requires { ExactHook<Port, bool(
CtrlPin,
GpioSignal)
noexcept>::Take(&Port::GpioSet); };
150template <
typename Port>
152 std::derived_from<Port, SpiInterface<Port>> && detail::HasGpioSet<Port> &&
requires {
153 detail::ExactHook<Port, bool()
noexcept>::Take(&Port::EnsureInitialized);
154 detail::ExactHook<Port, bool(
DataKind,
const uint8_t*, std::size_t)
noexcept>::Take(
161inline constexpr std::size_t kMaxCommandBytes = 33;
163inline constexpr std::size_t kDataChunkBytes = 96;
169template <SpiPort Port>
172 explicit WriteBus(Port& port) noexcept : port_(port) {}
174 Port& GetPort() &
noexcept {
180 Error Command(std::span<const uint8_t> bytes)
noexcept {
181 if (bytes.empty() || (bytes.size() > kMaxCommandBytes)) {
182 return Error::InvalidArgument;
184 return port_.Write(DataKind::Command, bytes.data(), bytes.size()) ? Error::Ok : Error::Bus;
189 Error Data(std::span<const uint8_t> bytes)
noexcept {
190 if (bytes.empty() || (bytes.size() > kDataChunkBytes)) {
191 return Error::InvalidArgument;
193 return port_.Write(DataKind::Data, bytes.data(), bytes.size()) ? Error::Ok : Error::Bus;
CRTP base of the platform SPI port.
Definition isf15acp4_spi_interface.hpp:115
SpiInterface(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface & operator=(const SpiInterface &)=delete
Ports are not copied: the driver holds a reference.
SpiInterface() noexcept=default
Only the derived port is constructed.
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exac...
Definition isf15acp4_spi_interface.hpp:151
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition isf15acp4_types.hpp:41
Compile-time helpers of the ISF15ACP4 driver: typed integer literals, exact hook matching,...
SSD1331 command set: opcodes, parameter fields, limits and timing (SSD1331 datasheet Rev 1....
Public types of the ISF15ACP4 driver: errors, Result<T>, the display and button configuration,...
The ISF15ACP4 driver: everything it declares lives here; internals in detail.
Definition isf15acp4.hpp:31
constexpr bool kMsbFirst
Each byte is clocked most significant bit first, D7 first (section 7.1.3).
Definition isf15acp4_spi_interface.hpp:62
DataKind
What a transfer carries: it sets the D/C# pin (section 7.2).
Definition isf15acp4_spi_interface.hpp:99
@ Command
D/C# low: an opcode or a parameter byte.
@ Data
D/C# high: GDDRAM data.
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition isf15acp4_spi_interface.hpp:93
@ ACTIVE
The pin function is asserted.
@ INACTIVE
The pin function is deasserted.
constexpr uint32_t kCsSetupNs
CS# low to the first SCK edge, tCSS (Table 21).
Definition isf15acp4_spi_interface.hpp:69
constexpr uint32_t kDcSetupNs
D/C# valid before the clock edge that starts a byte, tAS (Table 21).
Definition isf15acp4_spi_interface.hpp:76
constexpr bool kWriteOnly
There is no MISO: nothing can be read back.
Definition isf15acp4_spi_interface.hpp:80
constexpr bool kContinuousWord
Definition isf15acp4_spi_interface.hpp:74
constexpr uint32_t kDcHoldNs
D/C# held after the byte, tAH (Table 21).
Definition isf15acp4_spi_interface.hpp:78
constexpr uint32_t kMaxClockHz
Highest SCK frequency: tcycle 150 ns minimum (Table 21), 6.66 MHz.
Definition isf15acp4_spi_interface.hpp:64
constexpr uint8_t kSpiMode
Definition isf15acp4_spi_interface.hpp:60
constexpr uint32_t kMinCsHighNs
Definition isf15acp4_spi_interface.hpp:67
constexpr uint32_t kCsHoldNs
Last SCK edge to CS# high, tCSH (Table 21).
Definition isf15acp4_spi_interface.hpp:71
CtrlPin
The pins the port drives through GpioSet().
Definition isf15acp4_spi_interface.hpp:86
@ Reset
RES#, active low on the pin: ACTIVE holds the controller in reset.
@ VccEnable
The enable of the 15 V OLED supply (module pin 9), active high: ACTIVE = supply on.