Skip to content

Commit 2d98a72

Browse files
Leon Mariottokartben
authored andcommitted
drivers/auxdisplay: add support for dfrobot LCD1602 I2C module
Move backlight i2c controller address into DTS configuration to be able to use jhd1313 driver for dfrobot's LCD1602. Signed-off-by: Leon Mariotto <[email protected]>
1 parent 7e09335 commit 2d98a72

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

drivers/auxdisplay/auxdisplay_jhd1313.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
LOG_MODULE_REGISTER(auxdisplay_jhd1313, CONFIG_AUXDISPLAY_LOG_LEVEL);
2121

22-
#define JHD1313_BACKLIGHT_ADDR (0x62)
23-
2422
/* Defines for the JHD1313_CMD_CURSOR_SHIFT */
2523
#define JHD1313_CS_DISPLAY_SHIFT (1 << 3)
2624
#define JHD1313_CS_RIGHT_SHIFT (1 << 2)
@@ -73,6 +71,7 @@ struct auxdisplay_jhd1313_data {
7371
struct auxdisplay_jhd1313_config {
7472
struct auxdisplay_capabilities capabilities;
7573
struct i2c_dt_spec bus;
74+
uint8_t backlight_addr;
7675
};
7776

7877
static const uint8_t colour_define[][4] = {
@@ -83,11 +82,13 @@ static const uint8_t colour_define[][4] = {
8382
{ 0, 0, 255 }, /* Blue */
8483
};
8584

86-
static void auxdisplay_jhd1313_reg_set(const struct device *i2c, uint8_t addr, uint8_t data)
85+
static void auxdisplay_jhd1313_reg_set(const struct device *dev, uint8_t addr, uint8_t data)
8786
{
87+
const struct auxdisplay_jhd1313_config *config = dev->config;
88+
const struct device *i2c = config->bus.bus;
8889
uint8_t command[2] = { addr, data };
8990

90-
i2c_write(i2c, command, sizeof(command), JHD1313_BACKLIGHT_ADDR);
91+
i2c_write(i2c, command, sizeof(command), config->backlight_addr);
9192
}
9293

9394
static int auxdisplay_jhd1313_print(const struct device *dev, const uint8_t *data, uint16_t size)
@@ -202,7 +203,6 @@ static void auxdisplay_jhd1313_input_state_set(const struct device *dev, uint8_t
202203

203204
static int auxdisplay_jhd1313_backlight_set(const struct device *dev, uint8_t colour)
204205
{
205-
const struct auxdisplay_jhd1313_config *config = dev->config;
206206
struct auxdisplay_jhd1313_data *data = dev->data;
207207

208208
if (colour >= ARRAY_SIZE(colour_define)) {
@@ -212,9 +212,9 @@ static int auxdisplay_jhd1313_backlight_set(const struct device *dev, uint8_t co
212212

213213
data->backlight = colour;
214214

215-
auxdisplay_jhd1313_reg_set(config->bus.bus, JHD1313_LED_REG_R, colour_define[colour][0]);
216-
auxdisplay_jhd1313_reg_set(config->bus.bus, JHD1313_LED_REG_G, colour_define[colour][1]);
217-
auxdisplay_jhd1313_reg_set(config->bus.bus, JHD1313_LED_REG_B, colour_define[colour][2]);
215+
auxdisplay_jhd1313_reg_set(dev, JHD1313_LED_REG_R, colour_define[colour][0]);
216+
auxdisplay_jhd1313_reg_set(dev, JHD1313_LED_REG_G, colour_define[colour][1]);
217+
auxdisplay_jhd1313_reg_set(dev, JHD1313_LED_REG_B, colour_define[colour][2]);
218218

219219
return 0;
220220
}
@@ -296,9 +296,9 @@ static int auxdisplay_jhd1313_initialize(const struct device *dev)
296296

297297
/* Now power on the background RGB control */
298298
LOG_INF("Configuring the RGB background");
299-
auxdisplay_jhd1313_reg_set(config->bus.bus, 0x00, 0x00);
300-
auxdisplay_jhd1313_reg_set(config->bus.bus, 0x01, 0x05);
301-
auxdisplay_jhd1313_reg_set(config->bus.bus, 0x08, 0xAA);
299+
auxdisplay_jhd1313_reg_set(dev, 0x00, 0x00);
300+
auxdisplay_jhd1313_reg_set(dev, 0x01, 0x05);
301+
auxdisplay_jhd1313_reg_set(dev, 0x08, 0xAA);
302302

303303
/* Now set the background colour to black */
304304
LOG_DBG("Background set to off");
@@ -361,6 +361,7 @@ static DEVICE_API(auxdisplay, auxdisplay_jhd1313_auxdisplay_api) = {
361361
.custom_characters = 0, \
362362
}, \
363363
.bus = I2C_DT_SPEC_INST_GET(inst), \
364+
.backlight_addr = DT_INST_PROP(inst, backlight_addr), \
364365
}; \
365366
static struct auxdisplay_jhd1313_data auxdisplay_jhd1313_data_##inst = { \
366367
.power = true, \

dts/bindings/auxdisplay/jhd,jhd1313.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ description: Jinghua Display JHD1313
99
compatible: "jhd,jhd1313"
1010

1111
include: [auxdisplay-device.yaml, i2c-device.yaml]
12+
13+
properties:
14+
backlight-addr:
15+
type: int
16+
default: 0x62
17+
description: I2C address for RGB backlight controller. (JHD1313 default value)

0 commit comments

Comments
 (0)