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.
  • Loading branch information
ShaharHD committed Oct 28, 2023
1 parent bc43e89 commit 91a4ef0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 17 additions & 15 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 @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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, \
Expand All @@ -425,12 +422,17 @@ 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; \
\
DEVICE_DT_INST_DEFINE(inst, &auxdisplay_serlcd_init, NULL, &auxdisplay_serlcd_data_##inst, \
&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)
10 changes: 10 additions & 0 deletions dts/bindings/auxdisplay/sparkfun,serlcd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 91a4ef0

Please sign in to comment.