drivers: display: Introduce SSD1351
This introduces ssd1351 128x128 RGB PMOLED controller Signed-off-by: Camille BAUD <mail@massdriver.space>
This commit is contained in:
parent
09ab462e10
commit
90f57f8b7d
5 changed files with 472 additions and 0 deletions
|
@ -23,6 +23,7 @@ zephyr_library_sources_ifdef(CONFIG_SSD1327 ssd1327.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_SSD16XX ssd16xx.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_SSD1322 ssd1322.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_SSD1331 display_ssd1331.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_SSD1351 display_ssd1351.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ST75256 display_st75256.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ST7567 display_st7567.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ST7789V display_st7789v.c)
|
||||
|
|
|
@ -33,6 +33,7 @@ source "drivers/display/Kconfig.ssd1327"
|
|||
source "drivers/display/Kconfig.ssd16xx"
|
||||
source "drivers/display/Kconfig.ssd1322"
|
||||
source "drivers/display/Kconfig.ssd1331"
|
||||
source "drivers/display/Kconfig.ssd1351"
|
||||
source "drivers/display/Kconfig.st75256"
|
||||
source "drivers/display/Kconfig.st7567"
|
||||
source "drivers/display/Kconfig.st7735r"
|
||||
|
|
43
drivers/display/Kconfig.ssd1351
Normal file
43
drivers/display/Kconfig.ssd1351
Normal file
|
@ -0,0 +1,43 @@
|
|||
# SSD1351 display controller configuration options
|
||||
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig SSD1351
|
||||
bool "SSD1351 display controller driver"
|
||||
default y
|
||||
depends on DT_HAS_SOLOMON_SSD1351_ENABLED
|
||||
select MIPI_DBI
|
||||
help
|
||||
Enable driver for SSD1351 display controller.
|
||||
|
||||
if SSD1351
|
||||
|
||||
config SSD1351_DEFAULT_CONTRAST
|
||||
int "SSD1351 default contrast"
|
||||
default 100
|
||||
range 0 255
|
||||
help
|
||||
SSD1351 default contrast.
|
||||
|
||||
config SSD1351_CONTRASTA
|
||||
int "SSD1351 contrast multiplier for seg A"
|
||||
default 145
|
||||
range 0 255
|
||||
help
|
||||
Contrast multiplier for seg A
|
||||
|
||||
config SSD1351_CONTRASTB
|
||||
int "SSD1351 contrast multiplier for seg B"
|
||||
default 80
|
||||
range 0 255
|
||||
help
|
||||
Contrast multiplier for seg B
|
||||
|
||||
config SSD1351_CONTRASTC
|
||||
int "SSD1351 contrast multiplier for seg C"
|
||||
default 125
|
||||
range 0 255
|
||||
help
|
||||
Contrast multiplier for seg C
|
||||
|
||||
endif # SSD1351
|
351
drivers/display/display_ssd1351.c
Normal file
351
drivers/display/display_ssd1351.c
Normal file
|
@ -0,0 +1,351 @@
|
|||
/*
|
||||
* Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(ssd1351, CONFIG_DISPLAY_LOG_LEVEL);
|
||||
|
||||
#include <string.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/drivers/display.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/mipi_dbi.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#define SSD1351_DISPLAY_OFF 0xAE
|
||||
#define SSD1351_DISPLAY_ON 0xAF
|
||||
#define SSD1351_SET_NORMAL_DISPLAY 0xA6
|
||||
#define SSD1351_SET_REVERSE_DISPLAY 0xA7
|
||||
|
||||
#define SSD1351_SET_COLUMN_ADDR 0x15
|
||||
#define SSD1351_SET_ROW_ADDR 0x75
|
||||
|
||||
#define SSD1351_SET_DISPLAY_START_LINE 0xA1
|
||||
#define SSD1351_SET_DISPLAY_OFFSET 0xA2
|
||||
#define SSD1351_SET_MULTIPLEX_RATIO 0xCA
|
||||
#define SSD1351_SET_PHASE_LENGTH 0xB1
|
||||
#define SSD1351_SET_OSC_FREQ 0xB3
|
||||
#define SSD1351_SET_PRECHARGE_V 0xBB
|
||||
#define SSD1351_SET_VCOMH 0xBE
|
||||
#define SSD1351_SET_CURRENT_ATT 0xC7
|
||||
#define SSD1351_SET_PRECHARGE_P 0xB6
|
||||
#define SSD1351_SET_REMAP 0xA0
|
||||
#define SSD1351_STOP_SCROLL 0x9E
|
||||
#define SSD1351_SET_LINEAR_LUT 0xB9
|
||||
|
||||
#define SSD1351_CONTRAST 0xC1
|
||||
|
||||
#define SSD1351_SET_LOCK 0xFD
|
||||
#define SSD1351_UNLOCK_1 0x12
|
||||
#define SSD1351_UNLOCK_2 0xB1
|
||||
#define SSD1351_LOCK_1 0x16
|
||||
#define SSD1351_LOCK_2 0xB0
|
||||
|
||||
#define SSD1351_WRITE 0x5C
|
||||
|
||||
#define SSD1351_RESET_DELAY 10
|
||||
|
||||
struct ssd1351_config {
|
||||
const struct device *mipi_dev;
|
||||
const struct mipi_dbi_config dbi_config;
|
||||
uint16_t height;
|
||||
uint16_t width;
|
||||
uint8_t start_line;
|
||||
uint8_t display_offset;
|
||||
uint8_t multiplex_ratio;
|
||||
uint8_t phase_length;
|
||||
uint8_t oscillator_freq;
|
||||
uint8_t precharge_voltage;
|
||||
uint8_t precharge_time;
|
||||
uint8_t vcomh_voltage;
|
||||
uint8_t current_att;
|
||||
uint8_t remap_value;
|
||||
bool color_inversion;
|
||||
};
|
||||
|
||||
static inline int ssd1351_set_hardware_config(const struct device *dev)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
uint8_t tmp;
|
||||
|
||||
tmp = SSD1351_UNLOCK_1;
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_LOCK, &tmp,
|
||||
1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
tmp = SSD1351_UNLOCK_2;
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_LOCK, &tmp,
|
||||
1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_OSC_FREQ,
|
||||
&config->oscillator_freq, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config,
|
||||
SSD1351_SET_MULTIPLEX_RATIO, &config->multiplex_ratio, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config,
|
||||
SSD1351_SET_DISPLAY_OFFSET, &config->display_offset, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_REMAP,
|
||||
&config->remap_value, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config,
|
||||
SSD1351_SET_DISPLAY_START_LINE, &config->start_line, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config,
|
||||
SSD1351_SET_PHASE_LENGTH, &config->phase_length, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_VCOMH,
|
||||
&config->vcomh_voltage, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_CURRENT_ATT,
|
||||
&config->current_att, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_PRECHARGE_V,
|
||||
&config->precharge_voltage, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_PRECHARGE_P,
|
||||
&config->precharge_time, 1);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_STOP_SCROLL,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
static int ssd1351_resume(const struct device *dev)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_DISPLAY_ON,
|
||||
NULL, 0);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
return mipi_dbi_release(config->mipi_dev, &config->dbi_config);
|
||||
}
|
||||
|
||||
static int ssd1351_suspend(const struct device *dev)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_DISPLAY_OFF,
|
||||
NULL, 0);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
return mipi_dbi_release(config->mipi_dev, &config->dbi_config);
|
||||
}
|
||||
|
||||
static int ssd1351_write(const struct device *dev, const uint16_t x, const uint16_t y,
|
||||
const struct display_buffer_descriptor *desc, const void *buf)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
size_t buf_len;
|
||||
struct display_buffer_descriptor mipi_desc = *desc;
|
||||
uint8_t x_position[] = {x, x + desc->width - 1};
|
||||
uint8_t y_position[] = {y, y + desc->height - 1};
|
||||
|
||||
if (desc->pitch != desc->width) {
|
||||
LOG_ERR("Pitch is not width");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Following the datasheet, two segment are split in one register */
|
||||
buf_len = MIN(desc->buf_size, desc->height * desc->width * 2);
|
||||
if (buf == NULL || buf_len == 0U) {
|
||||
LOG_ERR("Display buffer is not available");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
LOG_DBG("x %u, y %u, pitch %u, width %u, height %u, buf_len %u", x, y, desc->pitch,
|
||||
desc->width, desc->height, buf_len);
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_COLUMN_ADDR,
|
||||
x_position, 2);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_SET_ROW_ADDR,
|
||||
y_position, 2);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_WRITE, NULL, 0);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mipi_dbi_write_display(config->mipi_dev, &config->dbi_config, buf, &mipi_desc,
|
||||
PIXEL_FORMAT_RGB_565);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
return mipi_dbi_release(config->mipi_dev, &config->dbi_config);
|
||||
}
|
||||
|
||||
static int ssd1351_set_contrast(const struct device *dev, const uint8_t contrast)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
uint8_t tmp[3];
|
||||
|
||||
tmp[0] = (contrast * CONFIG_SSD1351_CONTRASTA) / 0xFF;
|
||||
tmp[1] = (contrast * CONFIG_SSD1351_CONTRASTB) / 0xFF;
|
||||
tmp[2] = (contrast * CONFIG_SSD1351_CONTRASTC) / 0xFF;
|
||||
return mipi_dbi_command_write(config->mipi_dev, &config->dbi_config, SSD1351_CONTRAST, tmp,
|
||||
3);
|
||||
}
|
||||
|
||||
static void ssd1351_get_capabilities(const struct device *dev, struct display_capabilities *caps)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
|
||||
memset(caps, 0, sizeof(struct display_capabilities));
|
||||
caps->x_resolution = config->width;
|
||||
caps->y_resolution = config->height;
|
||||
caps->supported_pixel_formats = PIXEL_FORMAT_RGB_565;
|
||||
caps->current_pixel_format = PIXEL_FORMAT_RGB_565;
|
||||
caps->screen_info = 0;
|
||||
}
|
||||
|
||||
static int ssd1351_set_pixel_format(const struct device *dev, const enum display_pixel_format pf)
|
||||
{
|
||||
if (pf == PIXEL_FORMAT_RGB_565) {
|
||||
return 0;
|
||||
}
|
||||
LOG_ERR("Unsupported pixel format");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int ssd1351_init_device(const struct device *dev)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
|
||||
/* Turn display off */
|
||||
err = ssd1351_suspend(dev);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ssd1351_set_hardware_config(dev);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ssd1351_set_contrast(dev, CONFIG_SSD1351_DEFAULT_CONTRAST);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mipi_dbi_command_write(config->mipi_dev, &config->dbi_config,
|
||||
config->color_inversion ? SSD1351_SET_REVERSE_DISPLAY
|
||||
: SSD1351_SET_NORMAL_DISPLAY,
|
||||
NULL, 0);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ssd1351_resume(dev);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return mipi_dbi_release(config->mipi_dev, &config->dbi_config);
|
||||
}
|
||||
|
||||
static int ssd1351_init(const struct device *dev)
|
||||
{
|
||||
const struct ssd1351_config *config = dev->config;
|
||||
int err;
|
||||
|
||||
LOG_DBG("Initializing device");
|
||||
|
||||
if (!device_is_ready(config->mipi_dev)) {
|
||||
LOG_ERR("MIPI Device not ready!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = mipi_dbi_reset(config->mipi_dev, SSD1351_RESET_DELAY);
|
||||
if (err < 0) {
|
||||
LOG_ERR("Failed to reset device!");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ssd1351_init_device(dev);
|
||||
if (err < 0) {
|
||||
LOG_ERR("Failed to initialize device! %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DEVICE_API(display, ssd1351_driver_api) = {
|
||||
.blanking_on = ssd1351_suspend,
|
||||
.blanking_off = ssd1351_resume,
|
||||
.write = ssd1351_write,
|
||||
.set_contrast = ssd1351_set_contrast,
|
||||
.get_capabilities = ssd1351_get_capabilities,
|
||||
.set_pixel_format = ssd1351_set_pixel_format,
|
||||
};
|
||||
|
||||
#define SSD1351_WORD_SIZE(inst) \
|
||||
((DT_STRING_UPPER_TOKEN(inst, mipi_mode) == MIPI_DBI_MODE_SPI_4WIRE) ? SPI_WORD_SET(8) \
|
||||
: SPI_WORD_SET(9))
|
||||
|
||||
#define SSD1351_DEFINE_MIPI(node_id) \
|
||||
static const struct ssd1351_config config##node_id = { \
|
||||
.mipi_dev = DEVICE_DT_GET(DT_PARENT(node_id)), \
|
||||
.dbi_config = MIPI_DBI_CONFIG_DT( \
|
||||
node_id, SSD1351_WORD_SIZE(node_id) | SPI_OP_MODE_MASTER, 0), \
|
||||
.height = DT_PROP(node_id, height), \
|
||||
.width = DT_PROP(node_id, width), \
|
||||
.display_offset = DT_PROP(node_id, display_offset), \
|
||||
.start_line = DT_PROP(node_id, start_line), \
|
||||
.multiplex_ratio = DT_PROP(node_id, multiplex_ratio), \
|
||||
.phase_length = DT_PROP(node_id, phase_length), \
|
||||
.oscillator_freq = DT_PROP(node_id, oscillator_freq), \
|
||||
.precharge_time = DT_PROP(node_id, precharge_time), \
|
||||
.precharge_voltage = DT_PROP(node_id, precharge_voltage), \
|
||||
.vcomh_voltage = DT_PROP(node_id, vcomh_voltage), \
|
||||
.current_att = DT_PROP(node_id, current_att), \
|
||||
.color_inversion = DT_PROP(node_id, inversion_on), \
|
||||
.remap_value = DT_PROP(node_id, remap_value), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_DEFINE(node_id, ssd1351_init, NULL, NULL, &config##node_id, \
|
||||
POST_KERNEL, CONFIG_DISPLAY_INIT_PRIORITY, &ssd1351_driver_api);
|
||||
|
||||
DT_FOREACH_STATUS_OKAY(solomon_ssd1351, SSD1351_DEFINE_MIPI)
|
76
dts/bindings/display/solomon,ssd1351.yaml
Normal file
76
dts/bindings/display/solomon,ssd1351.yaml
Normal file
|
@ -0,0 +1,76 @@
|
|||
# Copyright (c) 2025 MASSDRIVER EI (massdriver.space)
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: SSD1351 display controller
|
||||
|
||||
compatible: "solomon,ssd1351"
|
||||
|
||||
include: [mipi-dbi-spi-device.yaml, display-controller.yaml]
|
||||
|
||||
properties:
|
||||
display-offset:
|
||||
type: int
|
||||
required: true
|
||||
description: Vertical offset by com from 0 ~ 127. Typically 128 - height.
|
||||
|
||||
start-line:
|
||||
type: int
|
||||
required: true
|
||||
description: Start line of display RAM to be displayed by selecting a value from 0 to 127.
|
||||
Typically 0.
|
||||
|
||||
multiplex-ratio:
|
||||
type: int
|
||||
required: true
|
||||
description: Multiplex ratio from 16MUX to 128MUX, ranges from 15 to 127.
|
||||
Typically same value as height - 1.
|
||||
|
||||
phase-length:
|
||||
type: int
|
||||
required: true
|
||||
description: Phase 2 Period (7:4) and Phase 1 Period (3:0).
|
||||
|
||||
oscillator-freq:
|
||||
type: int
|
||||
required: true
|
||||
description: Front clock divider (3:0) / oscillator frequency (7:4).
|
||||
If you get weird scanlines, increase oscillator frequency and play with phase length values,
|
||||
for example set this to 0xF1. Note this increases power consumption.
|
||||
|
||||
precharge-time:
|
||||
type: int
|
||||
required: true
|
||||
description: Set 2nd precharge time for segments from 0 DCLK to 15 DCLK, 0 is invalid. A[3:0].
|
||||
Typically 0x8.
|
||||
|
||||
precharge-voltage:
|
||||
type: int
|
||||
required: true
|
||||
description: Set precharge voltage. A[4:0], from 0 (0.20 x VCC) to 0x1F (0.6 x VCC)
|
||||
|
||||
vcomh-voltage:
|
||||
type: int
|
||||
required: true
|
||||
description: Set COM deselect voltage. A[2:0]. From 0.72xVCC to 0.86xVCC.
|
||||
|
||||
current-att:
|
||||
type: int
|
||||
required: true
|
||||
description: Set Master current attenuation. A[3:0], from 1/16 to 16/16.
|
||||
|
||||
remap-value:
|
||||
type: int
|
||||
required: true
|
||||
description: Remap register
|
||||
|
||||
Has multiple configurations (see each bit setting in the datasheet)
|
||||
- A[0] HTiled or VTiled. Must be 0 for this driver.
|
||||
- A[1] Invert segment order
|
||||
- A[2] Invert ABC segment order
|
||||
- A[4] Invert COM order
|
||||
- A[5] Stripped odd/even display
|
||||
- A[7:6] Set color format. Must be 0x0 for this driver.
|
||||
|
||||
inversion-on:
|
||||
type: boolean
|
||||
description: Turn on display color inverting
|
Loading…
Add table
Add a link
Reference in a new issue