summaryrefslogtreecommitdiff
path: root/drivers/painter/ssd1351
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2022-04-13 18:00:18 +1000
committerGitHub <noreply@github.com>2022-04-13 18:00:18 +1000
commit1f2b1dedccdf21b629c45ece80b4ca32f6653296 (patch)
treea4283b928fe11c6662be10067314531f12774152 /drivers/painter/ssd1351
parent1dbbd2b6b068b9f921ebc0341c890df16a491007 (diff)
Quantum Painter (#10174)
* Install dependencies before executing unit tests. * Split out UTF-8 decoder. * Fixup python formatting rules. * Add documentation for QGF/QFF and the RLE format used. * Add CLI commands for converting images and fonts. * Add stub rules.mk for QP. * Add stream type. * Add base driver and comms interfaces. * Add support for SPI, SPI+D/C comms drivers. * Include <qp.h> when enabled. * Add base support for SPI+D/C+RST panels, as well as concrete implementation of ST7789. * Add support for GC9A01. * Add support for ILI9341. * Add support for ILI9163. * Add support for SSD1351. * Implement qp_setpixel, including pixdata buffer management. * Implement qp_line. * Implement qp_rect. * Implement qp_circle. * Implement qp_ellipse. * Implement palette interpolation. * Allow for streams to work with either flash or RAM. * Image loading. * Font loading. * QGF palette loading. * Progressive decoder of pixel data supporting Raw+RLE, 1-,2-,4-,8-bpp monochrome and palette-based images. * Image drawing. * Animations. * Font rendering. * Check against 256 colours, dump out the loaded palette if debugging enabled. * Fix build. * AVR is not the intended audience. * `qmk format-c` * Generation fix. * First batch of docs. * More docs and examples. * Review comments. * Public API documentation.
Diffstat (limited to 'drivers/painter/ssd1351')
-rw-r--r--drivers/painter/ssd1351/qp_ssd1351.c125
-rw-r--r--drivers/painter/ssd1351/qp_ssd1351.h37
-rw-r--r--drivers/painter/ssd1351/qp_ssd1351_opcodes.h48
3 files changed, 210 insertions, 0 deletions
diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c
new file mode 100644
index 0000000000..970e7e67f3
--- /dev/null
+++ b/drivers/painter/ssd1351/qp_ssd1351.c
@@ -0,0 +1,125 @@
+// Copyright 2021 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "qp_internal.h"
+#include "qp_comms.h"
+#include "qp_ssd1351.h"
+#include "qp_ssd1351_opcodes.h"
+#include "qp_tft_panel.h"
+
+#ifdef QUANTUM_PAINTER_SSD1351_SPI_ENABLE
+# include "qp_comms_spi.h"
+#endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Common
+
+// Driver storage
+tft_panel_dc_reset_painter_device_t ssd1351_drivers[SSD1351_NUM_DEVICES] = {0};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Initialization
+
+bool qp_ssd1351_init(painter_device_t device, painter_rotation_t rotation) {
+ tft_panel_dc_reset_painter_device_t *driver = (tft_panel_dc_reset_painter_device_t *)device;
+
+ // clang-format off
+ const uint8_t ssd1351_init_sequence[] = {
+ // Command, Delay, N, Data[N]
+ SSD1351_COMMANDLOCK, 5, 1, 0x12,
+ SSD1351_COMMANDLOCK, 5, 1, 0xB1,
+ SSD1351_DISPLAYOFF, 5, 0,
+ SSD1351_CLOCKDIV, 5, 1, 0xF1,
+ SSD1351_MUXRATIO, 5, 1, 0x7F,
+ SSD1351_DISPLAYOFFSET, 5, 1, 0x00,
+ SSD1351_SETGPIO, 5, 1, 0x00,
+ SSD1351_FUNCTIONSELECT, 5, 1, 0x01,
+ SSD1351_PRECHARGE, 5, 1, 0x32,
+ SSD1351_VCOMH, 5, 1, 0x05,
+ SSD1351_NORMALDISPLAY, 5, 0,
+ SSD1351_CONTRASTABC, 5, 3, 0xC8, 0x80, 0xC8,
+ SSD1351_CONTRASTMASTER, 5, 1, 0x0F,
+ SSD1351_SETVSL, 5, 3, 0xA0, 0xB5, 0x55,
+ SSD1351_PRECHARGE2, 5, 1, 0x01,
+ SSD1351_DISPLAYON, 5, 0,
+ };
+ // clang-format on
+ qp_comms_bulk_command_sequence(device, ssd1351_init_sequence, sizeof(ssd1351_init_sequence));
+
+ // Configure the rotation (i.e. the ordering and direction of memory writes in GRAM)
+ const uint8_t madctl[] = {
+ [QP_ROTATION_0] = SSD1351_MADCTL_BGR | SSD1351_MADCTL_MY,
+ [QP_ROTATION_90] = SSD1351_MADCTL_BGR | SSD1351_MADCTL_MX | SSD1351_MADCTL_MY | SSD1351_MADCTL_MV,
+ [QP_ROTATION_180] = SSD1351_MADCTL_BGR | SSD1351_MADCTL_MX,
+ [QP_ROTATION_270] = SSD1351_MADCTL_BGR | SSD1351_MADCTL_MV,
+ };
+ qp_comms_command_databyte(device, SSD1351_SETREMAP, madctl[rotation]);
+ qp_comms_command_databyte(device, SSD1351_STARTLINE, (rotation == QP_ROTATION_0 || rotation == QP_ROTATION_90) ? driver->base.panel_height : 0);
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Driver vtable
+
+const struct tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable = {
+ .base =
+ {
+ .init = qp_ssd1351_init,
+ .power = qp_tft_panel_power,
+ .clear = qp_tft_panel_clear,
+ .flush = qp_tft_panel_flush,
+ .pixdata = qp_tft_panel_pixdata,
+ .viewport = qp_tft_panel_viewport,
+ .palette_convert = qp_tft_panel_palette_convert,
+ .append_pixels = qp_tft_panel_append_pixels,
+ },
+ .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped,
+ .num_window_bytes = 1,
+ .swap_window_coords = true,
+ .opcodes =
+ {
+ .display_on = SSD1351_DISPLAYON,
+ .display_off = SSD1351_DISPLAYOFF,
+ .set_column_address = SSD1351_SETCOLUMN,
+ .set_row_address = SSD1351_SETROW,
+ .enable_writes = SSD1351_WRITERAM,
+ },
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// SPI
+
+#ifdef QUANTUM_PAINTER_SSD1351_SPI_ENABLE
+
+// Factory function for creating a handle to the SSD1351 device
+painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode) {
+ for (uint32_t i = 0; i < SSD1351_NUM_DEVICES; ++i) {
+ tft_panel_dc_reset_painter_device_t *driver = &ssd1351_drivers[i];
+ if (!driver->base.driver_vtable) {
+ driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ssd1351_driver_vtable;
+ driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
+ driver->base.panel_width = panel_width;
+ driver->base.panel_height = panel_height;
+ driver->base.rotation = QP_ROTATION_0;
+ driver->base.offset_x = 0;
+ driver->base.offset_y = 0;
+ driver->base.native_bits_per_pixel = 16; // RGB565
+
+ // SPI and other pin configuration
+ driver->base.comms_config = &driver->spi_dc_reset_config;
+ driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
+ driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
+ driver->spi_dc_reset_config.spi_config.lsb_first = false;
+ driver->spi_dc_reset_config.spi_config.mode = spi_mode;
+ driver->spi_dc_reset_config.dc_pin = dc_pin;
+ driver->spi_dc_reset_config.reset_pin = reset_pin;
+ return (painter_device_t)driver;
+ }
+ }
+ return NULL;
+}
+
+#endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/drivers/painter/ssd1351/qp_ssd1351.h b/drivers/painter/ssd1351/qp_ssd1351.h
new file mode 100644
index 0000000000..0df34f204d
--- /dev/null
+++ b/drivers/painter/ssd1351/qp_ssd1351.h
@@ -0,0 +1,37 @@
+// Copyright 2021 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "gpio.h"
+#include "qp_internal.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter SSD1351 configurables (add to your keyboard's config.h)
+
+#ifndef SSD1351_NUM_DEVICES
+/**
+ * @def This controls the maximum number of SSD1351 devices that Quantum Painter can communicate with at any one time.
+ * Increasing this number allows for multiple displays to be used.
+ */
+# define SSD1351_NUM_DEVICES 1
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter SSD1351 device factories
+
+#ifdef QUANTUM_PAINTER_SSD1351_SPI_ENABLE
+/**
+ * Factory method for an SSD1351 SPI OLED device.
+ *
+ * @param panel_width[in] the width of the display panel
+ * @param panel_height[in] the height of the display panel
+ * @param chip_select_pin[in] the GPIO pin used for SPI chip select
+ * @param dc_pin[in] the GPIO pin used for D/C control
+ * @param reset_pin[in] the GPIO pin used for RST
+ * @param spi_divisor[in] the SPI divisor to use when communicating with the display
+ * @param spi_mode[in] the SPI mode to use when communicating with the display
+ * @return the device handle used with all drawing routines in Quantum Painter
+ */
+painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode);
+#endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE
diff --git a/drivers/painter/ssd1351/qp_ssd1351_opcodes.h b/drivers/painter/ssd1351/qp_ssd1351_opcodes.h
new file mode 100644
index 0000000000..48ed2a3a7c
--- /dev/null
+++ b/drivers/painter/ssd1351/qp_ssd1351_opcodes.h
@@ -0,0 +1,48 @@
+// Copyright 2021 Nick Brassel (@tzarc)
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter SSD1351 command opcodes
+
+// System function commands
+#define SSD1351_SETCOLUMN 0x15
+#define SSD1351_SETROW 0x75
+#define SSD1351_WRITERAM 0x5C
+#define SSD1351_READRAM 0x5D
+#define SSD1351_SETREMAP 0xA0
+#define SSD1351_STARTLINE 0xA1
+#define SSD1351_DISPLAYOFFSET 0xA2
+#define SSD1351_DISPLAYALLOFF 0xA4
+#define SSD1351_DISPLAYALLON 0xA5
+#define SSD1351_NORMALDISPLAY 0xA6
+#define SSD1351_INVERTDISPLAY 0xA7
+#define SSD1351_FUNCTIONSELECT 0xAB
+#define SSD1351_DISPLAYOFF 0xAE
+#define SSD1351_DISPLAYON 0xAF
+#define SSD1351_PRECHARGE 0xB1
+#define SSD1351_DISPLAYENHANCE 0xB2
+#define SSD1351_CLOCKDIV 0xB3
+#define SSD1351_SETVSL 0xB4
+#define SSD1351_SETGPIO 0xB5
+#define SSD1351_PRECHARGE2 0xB6
+#define SSD1351_SETGRAY 0xB8
+#define SSD1351_USELUT 0xB9
+#define SSD1351_PRECHARGELEVEL 0xBB
+#define SSD1351_VCOMH 0xBE
+#define SSD1351_CONTRASTABC 0xC1
+#define SSD1351_CONTRASTMASTER 0xC7
+#define SSD1351_MUXRATIO 0xCA
+#define SSD1351_COMMANDLOCK 0xFD
+#define SSD1351_HORIZSCROLL 0x96
+#define SSD1351_STOPSCROLL 0x9E
+#define SSD1351_STARTSCROLL 0x9F
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// SETREMAP (MADCTL) Flags
+#define SSD1351_MADCTL_MY 0b00010000
+#define SSD1351_MADCTL_MX 0b00000010
+#define SSD1351_MADCTL_MV 0b00000001
+#define SSD1351_MADCTL_RGB 0b01100000
+#define SSD1351_MADCTL_BGR 0b01100100