Skip to content

Commit 0380fa3

Browse files
committed
Init function done.
1 parent c62884f commit 0380fa3

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

drivers/display/display_co5300.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ LOG_MODULE_REGISTER(co5300, CONFIG_DISPLAY_LOG_LEVEL);
2121
#include <fsl_lcdif.h>
2222
#include <fsl_mipi_dsi.h>
2323

24+
/* display command structure passed to mipi to control the display */
2425
struct display_cmds {
2526
uint8_t *cmd_code;
2627
uint8_t size;
@@ -499,11 +500,16 @@ static int co5300_init(const struct device *dev)
499500
const struct co5300_config *config = dev->config;
500501
struct co5300_data *data = dev->data;
501502
struct mipi_dsi_device mdev = {0};
503+
struct display_cmds lcm_init_settings = {0};
504+
uint8_t* ptr_to_curr_cmd = 0;
505+
uint8_t* ptr_to_last_cmd = 0;
506+
uint8_t cmd_params = 0;
507+
uint8_t cmd_param_size = 0;
508+
uint8_t curr_cmd = 0;
502509

503510
/* Attach to MIPI DSI host */
504511
mdev.data_lanes = config->num_of_lanes;
505512
mdev.pixfmt = data->pixel_format;
506-
507513
int ret = mipi_dsi_attach(config->mipi_dsi, config->channel, &mdev);
508514
if (ret < 0) {
509515
LOG_ERR("Could not attach to MIPI-DSI host");
@@ -550,45 +556,38 @@ static int co5300_init(const struct device *dev)
550556
}
551557

552558
/* Set the LCM init settings. */
553-
struct display_cmds lcm_init_settings = {};
554559
lcm_init_settings.cmd_code = lcm_init_cmds;
555560
lcm_init_settings.size = ARRAY_SIZE(lcm_init_cmds);
556-
uint8_t* curr_cmd = lcm_init_settings.cmd_code;
557-
558-
while (curr_cmd != (lcm_init_settings.cmd_code + lcm_init_settings.size)) {
559-
if (curr_cmd > (lcm_init_settings.cmd_code + lcm_init_settings.size)) {
560-
LOG_ERR("Logical error when sending mipi command code.");
561-
return -EILSEQ;
562-
}
563-
564-
uint32_t cmd_code = (uint32_t)*curr_cmd++;
565-
uint32_t param_size = *curr_cmd++;
566-
uint32_t param = *curr_cmd;
567-
curr_cmd += param_size;
561+
ptr_to_curr_cmd = lcm_init_settings.cmd_code;
562+
ptr_to_last_cmd = lcm_init_settings.cmd_code + lcm_init_settings.size;
563+
while (ptr_to_curr_cmd < ptr_to_last_cmd) {
564+
/* Walk through the display_cmds array, incrementing the ptr by the param size */
565+
curr_cmd = *ptr_to_curr_cmd++;
566+
cmd_param_size = *ptr_to_curr_cmd++;
567+
cmd_params = *ptr_to_curr_cmd;
568+
ptr_to_curr_cmd += cmd_param_size;
568569

569570
ret = mipi_dsi_dcs_write(config->mipi_dsi, config->channel,
570-
cmd_code, &param, param_size);
571+
curr_cmd, &cmd_params, cmd_param_size);
571572
if (ret < 0) {
572573
return ret;
573574
}
574575
}
575576

576577
/* Set pixel format */
577-
int param = 0;
578578
if (data->pixel_format == MIPI_DSI_PIXFMT_RGB888) {
579-
param = MIPI_DCS_PIXEL_FORMAT_24BIT;
579+
cmd_params = (uint8_t)MIPI_DCS_PIXEL_FORMAT_24BIT;
580580
data->bytes_per_pixel = 3;
581581
} else if (data->pixel_format == MIPI_DSI_PIXFMT_RGB565) {
582-
param = MIPI_DCS_PIXEL_FORMAT_16BIT;
582+
cmd_params = (uint8_t)MIPI_DCS_PIXEL_FORMAT_16BIT;
583583
data->bytes_per_pixel = 2;
584584
} else {
585585
/* Unsupported pixel format */
586586
LOG_ERR("Pixel format not supported");
587587
return -ENOTSUP;
588588
}
589589
ret = mipi_dsi_dcs_write(config->mipi_dsi, config->channel,
590-
MIPI_DCS_SET_PIXEL_FORMAT, &param, 1);
591-
590+
MIPI_DCS_SET_PIXEL_FORMAT, &cmd_params, 1);
592591
if (ret < 0) {
593592
return ret;
594593
}
@@ -601,8 +600,7 @@ static int co5300_init(const struct device *dev)
601600
return ret;
602601
}
603602

604-
605-
/* Commands after the monitor is directed to go to sleep should be delayed 150ms */
603+
/* After the monitor is directed to go to sleep, commands should be delayed 150ms */
606604
k_sleep(K_MSEC(150));
607605

608606
/* Setup backlight */
@@ -614,7 +612,7 @@ static int co5300_init(const struct device *dev)
614612
}
615613
}
616614

617-
/* Setup tear effect pin */
615+
/* Setup tear effect pin and callback */
618616
if (config->tear_effect_gpio.port != NULL) {
619617
ret = gpio_pin_configure_dt(&config->tear_effect_gpio, GPIO_INPUT);
620618
if (ret < 0) {
@@ -629,7 +627,6 @@ static int co5300_init(const struct device *dev)
629627
return ret;
630628
}
631629

632-
/* Init and install GPIO callback */
633630
gpio_init_callback(&data->tear_effect_gpio_cb, co5300_tear_effect_isr_handler,
634631
BIT(config->tear_effect_gpio.pin));
635632
ret = gpio_add_callback(config->tear_effect_gpio.port, &data->tear_effect_gpio_cb);

0 commit comments

Comments
 (0)