29#include "isf15acp4_version.h"
45template <
typename Port>
46concept DeclaresReadSwitch =
requires(Port& port,
bool& high) { port.ReadSwitch(high); };
50template <
typename Port>
51concept HasReadSwitch =
52 requires { ExactHook<Port, bool(
bool&)
noexcept>::Take(&Port::ReadSwitch); };
55template <
typename Port>
56concept DeclaresNowMs =
requires(Port& port) { port.NowMs(); };
59template <
typename Port>
60concept HasNowMs =
requires { ExactHook<Port, uint32_t() noexcept>::Take(&Port::NowMs); };
63template <typename Port>
64concept DeclaresDelayUs = requires(Port& port) { port.DelayUs(1_u32); };
68template <
typename Port>
69concept HasDelayUs =
requires { ExactHook<Port, void(uint32_t)
noexcept>::Take(&Port::DelayUs); };
72template <
typename Port>
73concept DeclaresLog =
requires(Port& port) { port.Log(
LogLevel::Info,
""); };
76template <
typename Port>
78 requires { ExactHook<Port, void(
LogLevel,
const char*)
noexcept>::Take(&Port::Log); };
82template <
typename Port>
83void DelayUs(Port& port, uint32_t us)
noexcept {
84 if constexpr (HasDelayUs<Port>) {
87 static_assert(kAlwaysFalse<Port>,
88 "isf15acp4: the port must implement `void DelayUs(uint32_t us) noexcept`");
93template <
typename Port>
94void Log(Port& port,
LogLevel level,
const char* message)
noexcept {
95 if constexpr (HasLog<Port>) {
96 port.Log(level, message);
99 static_cast<void>(port);
100 static_cast<void>(level);
101 static_cast<void>(message);
107 std::array<uint8_t, 3> bytes{};
108 std::size_t count{0};
112constexpr std::size_t BytesPerPixel(
ColorDepth depth)
noexcept {
128constexpr bool BlueFirst(
const Config& config)
noexcept {
129 return config.red_on_segment_a != config.remap.reverse_colour_order;
133constexpr PixelBytes EncodePixel(
ColorDepth depth, Color color,
bool blue_first)
noexcept {
134 const Channels ch =
Split(color);
135 const uint32_t first = blue_first ? ch.blue : ch.red;
136 const uint32_t second = ch.green;
137 const uint32_t third = blue_first ? ch.red : ch.blue;
142 static_cast<uint8_t
>(((first >> 2U) << 5U) | ((second >> 3U) << 2U) | (third >> 3U));
146 p.bytes[0] =
static_cast<uint8_t
>((first << 3U) | (second >> 3U));
147 p.bytes[1] =
static_cast<uint8_t
>(((second & 0x07U) << 5U) | third);
151 p.bytes[0] =
static_cast<uint8_t
>(first << 1U);
152 p.bytes[1] =
static_cast<uint8_t
>(second);
153 p.bytes[2] =
static_cast<uint8_t
>(third << 1U);
163constexpr int32_t ParameterCount(uint8_t opcode)
noexcept {
225 "Table 10: the parameter counts");
227 "C first: with blue as C, red is the low five bits");
229 "C = blue is first");
258template <SpiPort Port>
261 !detail::DeclaresReadSwitch<Port> || detail::HasReadSwitch<Port>,
262 "isf15acp4: the optional ReadSwitch hook must be `bool ReadSwitch(bool& high) noexcept`");
263 static_assert(!detail::DeclaresNowMs<Port> || detail::HasNowMs<Port>,
264 "isf15acp4: the optional NowMs hook must be `uint32_t NowMs() noexcept`");
266 !detail::DeclaresDelayUs<Port> || detail::HasDelayUs<Port>,
267 "isf15acp4: the DelayUs hook must be `void DelayUs(uint32_t us) noexcept`, so that no "
268 "wait is truncated");
269 static_assert(!detail::DeclaresLog<Port> || detail::HasLog<Port>,
270 "isf15acp4: the optional Log hook must be `void Log(LogLevel, const char* message) "
280 : bus_(port), config_(config), button_(config.button),
281 multiplex_(
GeometryOf(config.variant).multiplex) {}
305 [[nodiscard]]
bool IsInitialized() const noexcept {
357 [[nodiscard]]
Output GetOutput() const noexcept {
391 [[nodiscard]]
Geometry GetGeometry() const noexcept {
500 Result<
void> SetPrechargeLevel(uint8_t level) noexcept;
506 Result<
void> SetVcomh(uint8_t level) noexcept;
513 Result<
void> SetCommandLock(
bool lock) noexcept;
542 Result<
void> WriteWindow(uint8_t x, uint8_t y, uint8_t width, uint8_t height,
543 std::span<const
Color> pixels) noexcept;
555 Result<
void> WriteWindowRaw(uint8_t x, uint8_t y, uint8_t width, uint8_t height,
556 std::span<const uint8_t> bytes) noexcept;
567 Result<
void> FillWindow(uint8_t x, uint8_t y, uint8_t width, uint8_t height,
568 Color color) noexcept;
577 Result<
void> SetPixel(uint8_t x, uint8_t y,
Color color) noexcept;
588 [[nodiscard]]
bool RamNeedsRewrite() const noexcept {
617 Color outline)
noexcept;
630 Color fill)
noexcept;
643 bool reverse =
false) noexcept;
653 Result<
void> DimWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) noexcept;
663 Result<
void> ClearWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) noexcept;
682 Result<
void> DeactivateScroll() noexcept;
685 [[nodiscard]]
bool IsScrolling() const noexcept {
723 [[nodiscard]]
bool IsButtonDown() const noexcept {
724 return button_.IsDown();
728 return button_.PressCount();
754 Result<
void> TraceCommand(uint8_t opcode, std::span<const uint8_t> parameters) noexcept;
757 [[nodiscard]] uint8_t GetLastCommandOpcode() const noexcept {
768 return shadow_doubt_;
786 Result<void> sendWindow(uint8_t col0, uint8_t row0, uint8_t col1, uint8_t row1)
noexcept;
788 Result<void> openWindow(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
noexcept;
789 void windowDone(uint8_t width, uint8_t height)
noexcept;
790 Result<void> streamPixels(uint8_t width, uint8_t height, std::span<const Color> colors,
791 Color fill)
noexcept;
792 Result<void> streamBytes(std::span<const uint8_t> bytes)
noexcept;
793 Result<void> checkWindow(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
const noexcept;
794 Result<void> engineCheck(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
795 bool ordered)
const noexcept;
797 Result<
void> setFillBit(
bool filled) noexcept;
798 Result<
void> sendRectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
Color outline,
799 Color fill) noexcept;
800 Result<
void> windowCommand(uint8_t opcode, uint8_t x0, uint8_t y0, uint8_t x1,
801 uint8_t y1) noexcept;
802 [[nodiscard]] std::array<uint8_t, 3> triple(
Color color) const noexcept;
803 Result<
void> applyIdle(uint32_t idle) noexcept;
807 [[nodiscard]] static
bool rawCommandValid(uint8_t opcode,
808 std::span<const uint8_t> parameters) noexcept;
810 void trackRawScroll(uint8_t opcode) noexcept;
812 [[nodiscard]]
bool wakeWanted(const
ButtonUpdate& u) const noexcept;
814 [[nodiscard]] static uint8_t prechargeByte(uint8_t level, const
Config& config) noexcept;
817 Result<
void> fail(
Error error, const
char* message) noexcept;
818 void touch() noexcept;
820 detail::WriteBus<Port> bus_;
822 ButtonDebouncer button_;
823 std::array<uint8_t, detail::kMaxCommandBytes> command_{};
824 std::array<uint8_t, detail::kDataChunkBytes> data_{};
825 std::size_t last_len_{0};
826 uint32_t last_activity_ms_{0};
827 uint8_t multiplex_{64};
828 std::array<uint8_t, 3> contrast_cap_{0x80, 0x80, 0x80};
829 uint8_t last_opcode_{0};
830 ScrollSetup scroll_{};
831 Output output_{Output::Off};
832 bool initialized_{
false};
835 bool scrolling_{
false};
836 bool scroll_set_{
false};
837 bool ram_rewrite_{
false};
838 bool shadow_doubt_{
false};
839 bool activity_valid_{
false};
840 bool idle_lowered_{
false};
846#include "../src/isf15acp4.ipp"
Driver for one ISF15ACP4 on a platform port.
Definition isf15acp4.hpp:259
Result< void > ApplyConfig(const Config &config) noexcept
Change the whole configuration.
Result< ButtonUpdate > Poll() noexcept
Sample the switch, debounce it and apply the idle timers.
Result< void > SetDisplayOffset(uint8_t offset) noexcept
Set the display offset, 0 to 63 (A2h).
ISF15ACP4(Port &port, const Config &config={}) noexcept
Bind the driver to a port and store the configuration. No I/O, cannot fail.
Definition isf15acp4.hpp:279
Result< void > CopyWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, Point dest, bool reverse=false) noexcept
Copy a window to another place (26h, 23h); the destination must fit in the visible area.
Result< void > SetPhasePeriods(uint8_t phase1, uint8_t phase2) noexcept
Set phase 1 and phase 2 periods, 1 to 15 DCLK each (B1h).
ISF15ACP4(const ISF15ACP4 &)=delete
One driver object per module.
Result< void > SetPowerSave(bool enable) noexcept
Enable or disable the power save mode (B0h).
ISF15ACP4 & operator=(const ISF15ACP4 &)=delete
One driver object per module.
Result< void > SetMultiplexRatio(uint8_t rows) noexcept
Set the multiplex ratio, 16 to 64 rows (A8h). Vertical scrolling needs 64. Not stored in Config: a re...
Result< void > SetContrast(uint8_t a, uint8_t b, uint8_t c) noexcept
Set the contrast of the three colours (81h, 82h, 83h).
Result< void > NotifyActivity() noexcept
Restart the idle timers from now.
Result< void > DrawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, Color color) noexcept
Draw a line with the controller's engine (21h), then wait engine_settle_us.
Result< void > SetDimSettings(const DimSettings &dim) noexcept
Set the dim mode parameters (ABh); they apply at the next DisplayDim().
Result< void > SetMasterCurrent(uint8_t step) noexcept
Set the master current attenuation, 0 to 15 (87h).
Result< void > SetDisplayMode(DisplayMode mode) noexcept
Set what the pixels show (A4h to A7h).
Result< void > Deinitialize() noexcept
The power-down: command unlock, display off, supply off, wait vcc_off_ms. Never refused.
Result< void > SetPrechargeSpeed(uint8_t a, uint8_t b, uint8_t c) noexcept
Set the second pre-charge speed of the three colours; all six bytes go out together (8Ah to 8Ch)....
Result< void > EnsureInitialized() noexcept
Power up to state 1: the controller is reset, configured and cleared, the supply is off.
const Config & GetConfig() const &noexcept
Definition isf15acp4.hpp:384
void GetConfig() const &&=delete
Not on a temporary driver: the reference would dangle (KB-CPP20-044).
Result< void > SetRemap(const Remap &remap) noexcept
Set the remap and colour depth (A0h). Changes how pixels are sent: ColorDepth, vertical_increment.
std::size_t GetLastTransferBytes() const noexcept
Definition isf15acp4.hpp:762
uint32_t GetButtonPressCount() const noexcept
Definition isf15acp4.hpp:727
Result< void > UseLinearGrayScale() noexcept
Reload the built-in linear gray scale table (B9h).
bool IsShadowInDoubt() const noexcept
Definition isf15acp4.hpp:767
Result< void > SetClock(uint8_t divide, uint8_t frequency) noexcept
Set the clock divide ratio (this + 1) and oscillator frequency, 0 to 15 each (B3h).
Result< void > SetGrayScaleTable(std::span< const uint8_t, reg::kGrayScaleEntries > widths) noexcept
Set the 32 gray scale pulse widths GS1, GS3 ... GS63, each 1 to 125 and rising (B8h)....
Result< void > FillRectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, Color outline, Color fill) noexcept
Draw a filled rectangle (26h, 22h) with an outline colour and a fill colour.
Result< void > DrawRectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, Color outline) noexcept
Draw a rectangle outline (26h, 22h), then wait engine_settle_us.
bool IsSupplyEnabled() const noexcept
Definition isf15acp4.hpp:361
Result< void > SetStartLine(uint8_t line) noexcept
Set the display start line, 0 to 63 (A1h).
bool IsLocked() const noexcept
Definition isf15acp4.hpp:771
constexpr uint8_t kScrollOff
2Eh: stop scrolling (9.2.8).
Definition isf15acp4_registers.hpp:80
constexpr uint8_t kDimWindow
24h + 4 bytes (9.2.4).
Definition isf15acp4_registers.hpp:76
constexpr uint8_t kModeInverse
A7h: GS0 <-> GS63.
Definition isf15acp4_registers.hpp:54
constexpr uint8_t kDisplayOffset
A2h + display offset (9.1.8).
Definition isf15acp4_registers.hpp:50
constexpr uint8_t kDrawRectangle
22h + 10 bytes (9.2.2).
Definition isf15acp4_registers.hpp:74
constexpr uint8_t kSetContrastA
81h + contrast of colour A (9.1.3).
Definition isf15acp4_registers.hpp:40
constexpr uint8_t kLinearGrayScale
B9h: built-in linear table (9.1.18).
Definition isf15acp4_registers.hpp:65
constexpr uint8_t kGrayScaleTable
B8h + 32 pulse widths (9.1.17).
Definition isf15acp4_registers.hpp:64
constexpr uint8_t kModeAllOn
A5h: every pixel at GS63.
Definition isf15acp4_registers.hpp:52
constexpr uint8_t kPrechargeSpeedC
8Ch + speed of colour C.
Definition isf15acp4_registers.hpp:47
constexpr uint8_t kModeNormal
A4h: normal display (9.1.9).
Definition isf15acp4_registers.hpp:51
constexpr uint8_t kDisplayOff
AEh: display off, sleep.
Definition isf15acp4_registers.hpp:59
constexpr uint8_t kSetRowAddress
75h + start, end (section 9.1.2).
Definition isf15acp4_registers.hpp:39
constexpr uint8_t kDisplayOn
AFh: display on, normal brightness.
Definition isf15acp4_registers.hpp:60
constexpr uint8_t kNopBD
BDh: no operation.
Definition isf15acp4_registers.hpp:68
constexpr uint8_t kCommandLock
FDh + 12h unlock or 16h lock (9.1.22).
Definition isf15acp4_registers.hpp:72
constexpr uint8_t kPhasePeriods
B1h + phase 1 and 2 periods (9.1.15).
Definition isf15acp4_registers.hpp:62
constexpr uint8_t kNopE3
E3h: no operation.
Definition isf15acp4_registers.hpp:71
constexpr uint8_t kSetColumnAddress
15h + start, end (section 9.1.1).
Definition isf15acp4_registers.hpp:38
constexpr uint8_t kClockDivider
B3h + divide ratio and frequency (9.1.16).
Definition isf15acp4_registers.hpp:63
constexpr uint8_t kScrollSetup
27h + 5 bytes (9.2.7).
Definition isf15acp4_registers.hpp:79
constexpr uint8_t kDisplayDim
ACh: display on in dim mode (9.1.13).
Definition isf15acp4_registers.hpp:58
constexpr uint8_t kSetContrastB
82h + contrast of colour B.
Definition isf15acp4_registers.hpp:41
constexpr uint8_t kDrawLine
21h + 7 bytes (9.2.1).
Definition isf15acp4_registers.hpp:73
constexpr uint8_t kSetContrastC
83h + contrast of colour C.
Definition isf15acp4_registers.hpp:42
constexpr uint8_t kPrechargeSpeedB
8Bh + speed of colour B.
Definition isf15acp4_registers.hpp:46
constexpr uint8_t kFillEnable
26h + fill and reverse-copy bits (9.2.6).
Definition isf15acp4_registers.hpp:78
constexpr uint8_t kMasterCurrent
87h + attenuation 0..15 (9.1.4).
Definition isf15acp4_registers.hpp:43
constexpr uint8_t kClearWindow
25h + 4 bytes (9.2.5).
Definition isf15acp4_registers.hpp:77
constexpr uint8_t kRemap
A0h + remap and colour depth (9.1.6).
Definition isf15acp4_registers.hpp:48
constexpr uint8_t kPowerSave
B0h + 1Ah enable or 0Bh disable (9.1.14).
Definition isf15acp4_registers.hpp:61
constexpr uint8_t kCopy
23h + 6 bytes (9.2.3).
Definition isf15acp4_registers.hpp:75
constexpr uint8_t kPrechargeSpeedA
8Ah + second pre-charge speed of colour A (9.1.5).
Definition isf15acp4_registers.hpp:44
constexpr uint8_t kVcomh
BEh + VCOMH level (9.1.20).
Definition isf15acp4_registers.hpp:70
constexpr uint8_t kStartLine
A1h + display start line (9.1.7).
Definition isf15acp4_registers.hpp:49
constexpr uint8_t kScrollOn
2Fh: start scrolling (9.2.9).
Definition isf15acp4_registers.hpp:81
constexpr uint8_t kNopBC
BCh: no operation (9.1.21).
Definition isf15acp4_registers.hpp:67
constexpr uint8_t kMultiplex
A8h + N = multiplex ratio - 1 (9.1.10).
Definition isf15acp4_registers.hpp:55
constexpr uint8_t kPrechargeLevel
BBh + pre-charge voltage (9.1.19).
Definition isf15acp4_registers.hpp:66
constexpr uint8_t kModeAllOff
A6h: every pixel at GS0.
Definition isf15acp4_registers.hpp:53
constexpr uint8_t kDimMode
ABh + five bytes (9.1.11).
Definition isf15acp4_registers.hpp:56
constexpr uint8_t kMasterConfig
ADh + 8Eh: external VCC (9.1.12).
Definition isf15acp4_registers.hpp:57
constexpr Color kRed
Pure red.
Definition isf15acp4_types.hpp:576
DisplayMode
What the pixels show (A4h to A7h).
Definition isf15acp4_types.hpp:192
LogLevel
Severity passed to the optional Log() hook.
Definition isf15acp4_types.hpp:170
ColorDepth
The pixel format of GDDRAM (A0h A[7:6]).
Definition isf15acp4_types.hpp:185
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition isf15acp4_types.hpp:41
constexpr Channels Split(Color c) noexcept
Split an RGB565 colour.
Definition isf15acp4_types.hpp:594
ScrollInterval
The time between two scroll steps (27h E).
Definition isf15acp4_types.hpp:207
Output
What the panel is doing, as far as the driver knows.
Definition isf15acp4_types.hpp:200
constexpr Geometry GeometryOf(Variant variant) noexcept
The geometry of a module (NKK sheets: pixel format; the column origin of the smaller panels is the ce...
Definition isf15acp4_types.hpp:262
constexpr Color kBlue
Pure blue.
Definition isf15acp4_types.hpp:580
@ Info
Lifecycle events: initialised, supply on or off.
@ Colors65k
2 bytes per pixel, format 1: C[4:0] B[5:0] A[4:0]. Reset value.
@ Colors256
1 byte per pixel: C[4:2] B[5:3] A[4:3].
@ Colors65kFormat2
3 bytes per pixel, format 2: six bits per byte (Table 9).
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....
The write-only SPI port of the ISF15ACP4 driver: the CRTP base, its pin enums, the SpiPort concept an...
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
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition isf15acp4_spi_interface.hpp:93
CtrlPin
The pins the port drives through GpioSet().
Definition isf15acp4_spi_interface.hpp:86
A colour as the RGB565 word every call takes: red in bits 15..11, green 10..5, blue 4....
Definition isf15acp4_types.hpp:554
Everything the driver sends at start-up, and its own time knobs.
Definition isf15acp4_types.hpp:322
Dim mode parameters (ABh): used when the display is on in dim mode (ACh).
Definition isf15acp4_types.hpp:241
Geometry of a module: its visible pixels inside the 96 x 64 RAM.
Definition isf15acp4_types.hpp:249
A position in the visible area.
Definition isf15acp4_types.hpp:235
The controller settings that depend on the wiring of the panel (Remap, A0h).
Definition isf15acp4_types.hpp:224
The value of a call, or why there is none.
Definition isf15acp4_types.hpp:110