From 91a4ef0fae083d16f6d8003c2f2b484d63766b3a Mon Sep 17 00:00:00 2001 From: Shahar Hadas Date: Sun, 29 Oct 2023 00:24:02 +0300 Subject: [PATCH] auxdisplay: Enhance SerLCD auxdisplay driver Added export of command and special command delays as configurable options. --- drivers/auxdisplay/auxdisplay_serlcd.c | 32 +++++++++++--------- dts/bindings/auxdisplay/sparkfun,serlcd.yaml | 10 ++++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/auxdisplay/auxdisplay_serlcd.c b/drivers/auxdisplay/auxdisplay_serlcd.c index f3c0e76486932c2..b9b82f87f37c3e9 100644 --- a/drivers/auxdisplay/auxdisplay_serlcd.c +++ b/drivers/auxdisplay/auxdisplay_serlcd.c @@ -28,16 +28,6 @@ LOG_MODULE_REGISTER(auxdisplay_serlcd, CONFIG_AUXDISPLAY_LOG_LEVEL); */ #define SERLCD_BEGIN_SPECIAL_COMMAND 0xFE -/* - * delay in milliseconds after a normal command was sent - */ -#define SERLCD_COMMAND_DELAY_MS 10 - -/* - * delay in milliseconds after a special command was sent - */ -#define SERLCD_SPECIAL_COMMAND_DELAY_MS 50 - /* * maximum amount of custom chars the display supports */ @@ -84,6 +74,8 @@ struct auxdisplay_serlcd_data { bool blinking; uint16_t cursor_x; uint16_t cursor_y; + int command_delay_ms; + int special_command_delay_ms; }; struct auxdisplay_serlcd_config { @@ -107,11 +99,12 @@ static int auxdisplay_serlcd_send_command(const struct device *dev, const enum auxdisplay_serlcd_command command) { const struct auxdisplay_serlcd_config *config = dev->config; + const struct auxdisplay_serlcd_data *data = dev->data; const uint8_t buffer[2] = {SERLCD_BEGIN_COMMAND, command}; int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer)); - k_sleep(K_MSEC(SERLCD_COMMAND_DELAY_MS)); + k_sleep(K_MSEC(data->command_delay_ms)); return rc; } @@ -120,11 +113,12 @@ auxdisplay_serlcd_send_special_command(const struct device *dev, const enum auxdisplay_serlcd_special_command command) { const struct auxdisplay_serlcd_config *config = dev->config; + const struct auxdisplay_serlcd_data *data = dev->data; const uint8_t buffer[2] = {SERLCD_BEGIN_SPECIAL_COMMAND, command}; int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer)); - k_sleep(K_MSEC(SERLCD_SPECIAL_COMMAND_DELAY_MS)); + k_sleep(K_MSEC(data->special_command_delay_ms)); return rc; } @@ -269,9 +263,11 @@ static int auxdisplay_serlcd_capabilities_get(const struct device *dev, static int auxdisplay_serlcd_clear(const struct device *dev) { + const struct auxdisplay_serlcd_data *data = dev->data; + int rc = auxdisplay_serlcd_send_command(dev, SERLCD_COMMAND_CLEAR); - k_sleep(K_MSEC(SERLCD_COMMAND_DELAY_MS)); + k_sleep(K_MSEC(data->command_delay_ms)); return rc; } @@ -413,7 +409,8 @@ static const struct auxdisplay_driver_api auxdisplay_serlcd_auxdisplay_api = { #define AUXDISPLAY_SERLCD_INST(inst) \ static const struct auxdisplay_serlcd_config auxdisplay_serlcd_config_##inst = { \ - .capabilities = { \ + .capabilities = \ + { \ .columns = DT_INST_PROP(inst, columns), \ .rows = DT_INST_PROP(inst, rows), \ .mode = 0, \ @@ -425,7 +422,8 @@ static const struct auxdisplay_driver_api auxdisplay_serlcd_auxdisplay_api = { .custom_character_width = SERLCD_CUSTOM_CHAR_WIDTH, \ .custom_character_height = SERLCD_CUSTOM_CHAR_HEIGHT, \ }, \ - .bus = I2C_DT_SPEC_INST_GET(inst)}; \ + .bus = I2C_DT_SPEC_INST_GET(inst), \ + }; \ \ static struct auxdisplay_serlcd_data auxdisplay_serlcd_data_##inst; \ \ @@ -433,4 +431,8 @@ static const struct auxdisplay_driver_api auxdisplay_serlcd_auxdisplay_api = { &auxdisplay_serlcd_config_##inst, POST_KERNEL, \ CONFIG_AUXDISPLAY_INIT_PRIORITY, &auxdisplay_serlcd_auxdisplay_api); +static struct auxdisplay_serlcd_data auxdisplay_serlcd_data_##inst = { + .command_delay_ms = DT_INST_PROP(inst, command_delay), + .special_command_delay_ms = DT_INST_PROP(inst, special_command_delay), +}; DT_INST_FOREACH_STATUS_OKAY(AUXDISPLAY_SERLCD_INST) diff --git a/dts/bindings/auxdisplay/sparkfun,serlcd.yaml b/dts/bindings/auxdisplay/sparkfun,serlcd.yaml index 1a4d5734f369ad8..ae2246685c7fff6 100644 --- a/dts/bindings/auxdisplay/sparkfun,serlcd.yaml +++ b/dts/bindings/auxdisplay/sparkfun,serlcd.yaml @@ -32,3 +32,13 @@ properties: enum: - 2 - 4 + + command-delay: + type: int + default: 10 + description: "Delay in milliseconds after a normal command was sent" + + special-command-delay: + type: int + default: 50 + description: "Delay in milliseconds after a special command was sent"