auxdisplay: Enhance SerLCD auxdisplay driver

Added export of command and special command delays as configurable options.

Signed-off-by: Shahar Hadas <shaharhd@gmail.com>
This commit is contained in:
Shahar Hadas 2023-10-29 00:24:02 +03:00 committed by Fabio Baltieri
parent 0e11bcf5a0
commit cc6bf66345
2 changed files with 33 additions and 14 deletions

View file

@ -28,16 +28,6 @@ LOG_MODULE_REGISTER(auxdisplay_serlcd, CONFIG_AUXDISPLAY_LOG_LEVEL);
*/ */
#define SERLCD_BEGIN_SPECIAL_COMMAND 0xFE #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 * maximum amount of custom chars the display supports
*/ */
@ -89,6 +79,8 @@ struct auxdisplay_serlcd_data {
struct auxdisplay_serlcd_config { struct auxdisplay_serlcd_config {
struct auxdisplay_capabilities capabilities; struct auxdisplay_capabilities capabilities;
struct i2c_dt_spec bus; struct i2c_dt_spec bus;
uint16_t command_delay_ms;
uint16_t special_command_delay_ms;
}; };
enum auxdisplay_serlcd_command { enum auxdisplay_serlcd_command {
@ -111,7 +103,7 @@ static int auxdisplay_serlcd_send_command(const struct device *dev,
int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer)); int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer));
k_sleep(K_MSEC(SERLCD_COMMAND_DELAY_MS)); k_sleep(K_MSEC(config->command_delay_ms));
return rc; return rc;
} }
@ -124,7 +116,7 @@ auxdisplay_serlcd_send_special_command(const struct device *dev,
int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer)); int rc = i2c_write_dt(&config->bus, buffer, sizeof(buffer));
k_sleep(K_MSEC(SERLCD_SPECIAL_COMMAND_DELAY_MS)); k_sleep(K_MSEC(config->special_command_delay_ms));
return rc; return rc;
} }
@ -269,9 +261,11 @@ static int auxdisplay_serlcd_capabilities_get(const struct device *dev,
static int auxdisplay_serlcd_clear(const struct device *dev) static int auxdisplay_serlcd_clear(const struct device *dev)
{ {
const struct auxdisplay_serlcd_config *config = dev->config;
int rc = auxdisplay_serlcd_send_command(dev, SERLCD_COMMAND_CLEAR); int rc = auxdisplay_serlcd_send_command(dev, SERLCD_COMMAND_CLEAR);
k_sleep(K_MSEC(SERLCD_COMMAND_DELAY_MS)); k_sleep(K_MSEC(config->command_delay_ms));
return rc; return rc;
} }
@ -425,7 +419,10 @@ static const struct auxdisplay_driver_api auxdisplay_serlcd_auxdisplay_api = {
.custom_character_width = SERLCD_CUSTOM_CHAR_WIDTH, \ .custom_character_width = SERLCD_CUSTOM_CHAR_WIDTH, \
.custom_character_height = SERLCD_CUSTOM_CHAR_HEIGHT, \ .custom_character_height = SERLCD_CUSTOM_CHAR_HEIGHT, \
}, \ }, \
.bus = I2C_DT_SPEC_INST_GET(inst)}; \ .bus = I2C_DT_SPEC_INST_GET(inst), \
.command_delay_ms = DT_INST_PROP(inst, command_delay_ms), \
.special_command_delay_ms = DT_INST_PROP(inst, special_command_delay_ms), \
}; \
\ \
static struct auxdisplay_serlcd_data auxdisplay_serlcd_data_##inst; \ static struct auxdisplay_serlcd_data auxdisplay_serlcd_data_##inst; \
\ \

View file

@ -11,6 +11,8 @@ description: |
reg = <0x72>; reg = <0x72>;
columns = <16>; columns = <16>;
rows = <2>; rows = <2>;
command-delay = <10>;
special-command-delay = <50>;
}; };
}; };
@ -32,3 +34,23 @@ properties:
enum: enum:
- 2 - 2
- 4 - 4
command-delay-ms:
type: int
default: 10
description: |
Delay in milliseconds (defaults to 10ms if not set) after a normal command was sent.
The default value is based on the original SparkFun SerLCD library
implementation which assumes 100 kbps I2C configuration. This value
might require tweaking if using I2C at a higher bitrare and/or relativily
high update frequency of the display.
special-command-delay-ms:
type: int
default: 50
description: |
Delay in milliseconds (defaults to 50ms if not set) after a special command was sent.
The default value is based on the original SparkFun SerLCD library
implementation which assumes 100 kbps I2C configuration. This value
might require tweaking if using I2C at a higher bitrare and/or relativily
high update frequency of the display.