Skip to content

Commit c7010ab

Browse files
committed
drivers: display: ssd1306: determin sh1106 by dts compatibility
Determine sh1106 from the `compatibility` value instead of the SSD1306_CONTROLLER_TYPE setting. Change the settings in `boards/shields/ssd1306/sh1106_128x64.overlay` to follow this change. Remove the SSD1306_CONTROLLER_TYPE from its Kconfig.defconfig, and set the `compatibility` to `sinowealth,sh1106`. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent c6d030a commit c7010ab

File tree

7 files changed

+82
-60
lines changed

7 files changed

+82
-60
lines changed

boards/shields/ssd1306/Kconfig.defconfig

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ if SHIELD_SSD1306_128X64 || SHIELD_SSD1306_128X64_SPI || SHIELD_SSD1306_128X32 |
55

66
if DISPLAY
77

8-
choice SSD1306_CONTROLLER_TYPE
9-
default SSD1306_SH1106_COMPATIBLE if SHIELD_SH1106_128X64
10-
endchoice
11-
128
if LVGL
139

1410
config LV_Z_VDB_SIZE

boards/shields/ssd1306/sh1106_128x64.overlay

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
status = "okay";
1515

1616
sh1106_sh1106_128x64: ssd1306@3c {
17-
compatible = "solomon,ssd1306fb";
17+
compatible = "sinowealth,sh1106";
1818
reg = <0x3c>;
1919
width = <128>;
2020
height = <64>;

drivers/display/Kconfig.ssd1306

+3-15
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
menuconfig SSD1306
77
bool "SSD1306 display driver"
88
default y
9-
depends on DT_HAS_SOLOMON_SSD1306FB_ENABLED
9+
depends on DT_HAS_SOLOMON_SSD1306FB_ENABLED || DT_HAS_SINOWEALTH_SH1106_ENABLED
1010
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_SOLOMON_SSD1306FB),i2c)
1111
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_SOLOMON_SSD1306FB),spi)
12+
select I2C if $(dt_compat_on_bus,$(DT_COMPAT_SINOWEALTH_SH1106),i2c)
13+
select SPI if $(dt_compat_on_bus,$(DT_COMPAT_SINOWEALTH_SH1106),spi)
1214
help
1315
Enable driver for SSD1306 display driver.
1416

@@ -21,18 +23,4 @@ config SSD1306_DEFAULT_CONTRAST
2123
help
2224
SSD1306 default contrast.
2325

24-
choice SSD1306_CONTROLLER_TYPE
25-
prompt "Display controller type"
26-
default SSD1306_DEFAULT
27-
help
28-
Specify the type of the controller.
29-
30-
config SSD1306_DEFAULT
31-
bool "Default SSD1306 controller"
32-
33-
config SSD1306_SH1106_COMPATIBLE
34-
bool "SH1106 compatible mode"
35-
36-
endchoice
37-
3826
endif # SSD1306

drivers/display/ssd1306.c

+55-40
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#if defined(CONFIG_DT_HAS_SOLOMON_SSD1306FB_ENABLED)
78
#define DT_DRV_COMPAT solomon_ssd1306fb
9+
#elif defined(CONFIG_DT_HAS_SINOWEALTH_SH1106_ENABLED)
10+
#define DT_DRV_COMPAT sinowealth_sh1106
11+
#endif
812

913
#include <zephyr/logging/log.h>
1014
LOG_MODULE_REGISTER(ssd1306, CONFIG_DISPLAY_LOG_LEVEL);
@@ -48,6 +52,7 @@ struct ssd1306_config {
4852
bool com_invdir;
4953
bool com_sequential;
5054
bool color_inversion;
55+
bool sh1106_compatible;
5156
int ready_time_ms;
5257
};
5358

@@ -155,15 +160,11 @@ static inline int ssd1306_set_hardware_config(const struct device *dev)
155160

156161
static inline int ssd1306_set_charge_pump(const struct device *dev)
157162
{
163+
const struct ssd1306_config *config = dev->config;
158164
uint8_t cmd_buf[] = {
159-
#if defined(CONFIG_SSD1306_DEFAULT)
160-
SSD1306_SET_CHARGE_PUMP_ON,
161-
SSD1306_SET_CHARGE_PUMP_ON_ENABLED,
162-
#endif
163-
#if defined(CONFIG_SSD1306_SH1106_COMPATIBLE)
164-
SH1106_SET_DCDC_MODE,
165-
SH1106_SET_DCDC_ENABLED,
166-
#endif
165+
(config->sh1106_compatible ? SH1106_SET_DCDC_MODE : SSD1306_SET_CHARGE_PUMP_ON),
166+
(config->sh1106_compatible ? SH1106_SET_DCDC_ENABLED
167+
: SSD1306_SET_CHARGE_PUMP_ON_ENABLED),
167168
SSD1306_PANEL_PUMP_VOLTAGE,
168169
};
169170

@@ -188,37 +189,10 @@ static int ssd1306_suspend(const struct device *dev)
188189
return ssd1306_write_bus(dev, cmd_buf, sizeof(cmd_buf), true);
189190
}
190191

191-
static int ssd1306_write(const struct device *dev, const uint16_t x, const uint16_t y,
192-
const struct display_buffer_descriptor *desc,
193-
const void *buf)
192+
static int ssd1306_write_default(const struct device *dev, const uint16_t x, const uint16_t y,
193+
const struct display_buffer_descriptor *desc, const void *buf,
194+
const size_t buf_len)
194195
{
195-
size_t buf_len;
196-
197-
if (desc->pitch < desc->width) {
198-
LOG_ERR("Pitch is smaller then width");
199-
return -1;
200-
}
201-
202-
buf_len = MIN(desc->buf_size, desc->height * desc->width / 8);
203-
if (buf == NULL || buf_len == 0U) {
204-
LOG_ERR("Display buffer is not available");
205-
return -1;
206-
}
207-
208-
if (desc->pitch > desc->width) {
209-
LOG_ERR("Unsupported mode");
210-
return -1;
211-
}
212-
213-
if ((y & 0x7) != 0U) {
214-
LOG_ERR("Unsupported origin");
215-
return -1;
216-
}
217-
218-
LOG_DBG("x %u, y %u, pitch %u, width %u, height %u, buf_len %u",
219-
x, y, desc->pitch, desc->width, desc->height, buf_len);
220-
221-
#if defined(CONFIG_SSD1306_DEFAULT)
222196
uint8_t cmd_buf[] = {
223197
SSD1306_SET_MEM_ADDRESSING_MODE,
224198
SSD1306_ADDRESSING_MODE,
@@ -236,8 +210,12 @@ static int ssd1306_write(const struct device *dev, const uint16_t x, const uint1
236210
}
237211

238212
return ssd1306_write_bus(dev, (uint8_t *)buf, buf_len, false);
213+
}
239214

240-
#elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE)
215+
static int ssd1306_write_sh1106(const struct device *dev, const uint16_t x, const uint16_t y,
216+
const struct display_buffer_descriptor *desc, const void *buf,
217+
const size_t buf_len)
218+
{
241219
const struct ssd1306_config *config = dev->config;
242220
uint8_t x_offset = x + config->segment_offset;
243221
uint8_t cmd_buf[] = {
@@ -268,11 +246,47 @@ static int ssd1306_write(const struct device *dev, const uint16_t x, const uint1
268246
return -1;
269247
}
270248
}
271-
#endif
272249

273250
return 0;
274251
}
275252

253+
static int ssd1306_write(const struct device *dev, const uint16_t x, const uint16_t y,
254+
const struct display_buffer_descriptor *desc, const void *buf)
255+
{
256+
const struct ssd1306_config *config = dev->config;
257+
size_t buf_len;
258+
259+
if (desc->pitch < desc->width) {
260+
LOG_ERR("Pitch is smaller then width");
261+
return -1;
262+
}
263+
264+
buf_len = MIN(desc->buf_size, desc->height * desc->width / 8);
265+
if (buf == NULL || buf_len == 0U) {
266+
LOG_ERR("Display buffer is not available");
267+
return -1;
268+
}
269+
270+
if (desc->pitch > desc->width) {
271+
LOG_ERR("Unsupported mode");
272+
return -1;
273+
}
274+
275+
if ((y & 0x7) != 0U) {
276+
LOG_ERR("Unsupported origin");
277+
return -1;
278+
}
279+
280+
LOG_DBG("x %u, y %u, pitch %u, width %u, height %u, buf_len %u", x, y, desc->pitch,
281+
desc->width, desc->height, buf_len);
282+
283+
if (config->sh1106_compatible) {
284+
return ssd1306_write_sh1106(dev, x, y, desc, buf, buf_len);
285+
}
286+
287+
return ssd1306_write_default(dev, x, y, desc, buf, buf_len);
288+
}
289+
276290
static int ssd1306_read(const struct device *dev, const uint16_t x,
277291
const uint16_t y,
278292
const struct display_buffer_descriptor *desc,
@@ -438,6 +452,7 @@ static const struct ssd1306_config ssd1306_config = {
438452
.com_sequential = DT_INST_PROP(0, com_sequential),
439453
.prechargep = DT_INST_PROP(0, prechargep),
440454
.color_inversion = DT_INST_PROP(0, inversion_on),
455+
.sh1106_compatible = DT_NODE_HAS_COMPAT(0, sinowealth_sh1106),
441456
.ready_time_ms = DT_INST_PROP(0, ready_time_ms),
442457
};
443458

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2023, TOKITA Hiroshi
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: SH1106 128x64 dot-matrix display controller on I2C bus
5+
6+
compatible: "sinowealth,sh1106"
7+
8+
include: ["solomon,ssd1306fb-common.yaml", "i2c-device.yaml"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2023, TOKITA Hiroshi
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: SH1106 128x64 dot-matrix display controller on SPI bus
5+
6+
compatible: "sinowealth,sh1106"
7+
8+
include: ["solomon,ssd1306fb-common.yaml", "spi-device.yaml"]
9+
10+
properties:
11+
data_cmd-gpios:
12+
type: phandle-array
13+
required: true
14+
description: D/C# pin.

dts/bindings/vendor-prefixes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ simcom SIMCom Wireless Solutions Co., LTD
563563
simtek Cypress Semiconductor Corporation (Simtek Corporation)
564564
sinlinx Sinlinx Electronics Technology Co., LTD
565565
sinovoip SinoVoip Co., Ltd
566+
sinowealth Sino Wealth Electronic Ltd
566567
sipeed Shenzhen Sipeed Technology Co., Ltd.
567568
sirf SiRF Technology, Inc.
568569
sis Silicon Integrated Systems Corp.

0 commit comments

Comments
 (0)