Skip to content

Commit

Permalink
auxdisplay: Enhance SerLCD auxdisplay driver
Browse files Browse the repository at this point in the history
Added export of command and special command delays as configurable options.

Signed-off-by: Shahar Hadas <[email protected]>
  • Loading branch information
ShaharHD authored and fabiobaltieri committed Nov 24, 2023
1 parent 0e11bcf commit cc6bf66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
25 changes: 11 additions & 14 deletions drivers/auxdisplay/auxdisplay_serlcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -89,6 +79,8 @@ struct auxdisplay_serlcd_data {
struct auxdisplay_serlcd_config {
struct auxdisplay_capabilities capabilities;
struct i2c_dt_spec bus;
uint16_t command_delay_ms;
uint16_t special_command_delay_ms;
};

enum auxdisplay_serlcd_command {
Expand All @@ -111,7 +103,7 @@ static int auxdisplay_serlcd_send_command(const struct device *dev,

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;
}

Expand All @@ -124,7 +116,7 @@ auxdisplay_serlcd_send_special_command(const struct device *dev,

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;
}

Expand Down Expand Up @@ -269,9 +261,11 @@ static int auxdisplay_serlcd_capabilities_get(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);

k_sleep(K_MSEC(SERLCD_COMMAND_DELAY_MS));
k_sleep(K_MSEC(config->command_delay_ms));
return rc;
}

Expand Down Expand Up @@ -425,7 +419,10 @@ 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), \
.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; \
\
Expand Down
22 changes: 22 additions & 0 deletions dts/bindings/auxdisplay/sparkfun,serlcd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ description: |
reg = <0x72>;
columns = <16>;
rows = <2>;
command-delay = <10>;
special-command-delay = <50>;
};
};
Expand All @@ -32,3 +34,23 @@ properties:
enum:
- 2
- 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.

0 comments on commit cc6bf66

Please sign in to comment.