From 57295d750d8b6cb79cf2b8ed7e8d95f8075638ce Mon Sep 17 00:00:00 2001 From: liushuai25 Date: Fri, 13 Jan 2023 20:07:11 +0800 Subject: [PATCH] Use C89 compatible initializer and modify code format Signed-off-by: liushuai25 Update drivers/video/mipidsi/mipi_dsi_device.c Co-authored-by: Petro Karashchenko --- drivers/video/mipidsi/mipi_dsi_device.c | 197 ++++++++++-------- .../video/mipidsi/mipi_dsi_device_driver.c | 10 - drivers/video/mipidsi/mipi_dsi_host.c | 7 +- drivers/video/mipidsi/mipi_dsi_host_driver.c | 3 +- drivers/video/mipidsi/mipi_dsi_packet.c | 92 ++++---- 5 files changed, 156 insertions(+), 153 deletions(-) diff --git a/drivers/video/mipidsi/mipi_dsi_device.c b/drivers/video/mipidsi/mipi_dsi_device.c index 4c44ddf4a6..10b8db4b05 100644 --- a/drivers/video/mipidsi/mipi_dsi_device.c +++ b/drivers/video/mipidsi/mipi_dsi_device.c @@ -81,12 +81,12 @@ ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device, return -ENOSYS; } - if (device->mode_flags & MIPI_DSI_MODE_LPM) + if ((device->mode_flags & MIPI_DSI_MODE_LPM) != 0) { msg->flags |= MIPI_DSI_MSG_USE_LPM; } - if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME) + if ((device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME) != 0) { msg->flags |= MIPI_DSI_MSG_AFTER_FRAME; } @@ -162,14 +162,19 @@ int mipi_dsi_detach(FAR struct mipi_dsi_device *device) int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device) { - struct mipi_dsi_msg msg = + struct mipi_dsi_msg msg; + uint8_t tx[2] = { - .channel = device->channel, - .type = MIPI_DSI_SHUTDOWN_PERIPHERAL, - .tx_buf = (uint8_t [2]) { 0, 0 }, - .tx_len = 2, + 0, + 0 }; + msg.channel = device->channel; + msg.type = MIPI_DSI_SHUTDOWN_PERIPHERAL; + msg.tx_buf = tx; + msg.tx_len = sizeof(tx); + msg.flags = 0; + int ret = mipi_dsi_transfer(device, &msg); return ret < 0 ? ret : 0; } @@ -191,15 +196,19 @@ int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device) int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device) { int ret; - - struct mipi_dsi_msg msg = + struct mipi_dsi_msg msg; + uint8_t tx[2] = { - .channel = device->channel, - .type = MIPI_DSI_TURN_ON_PERIPHERAL, - .tx_buf = (uint8_t [2]) { 0, 0 }, - .tx_len = 2, + 0, + 0 }; + msg.channel = device->channel; + msg.type = MIPI_DSI_TURN_ON_PERIPHERAL; + msg.tx_buf = tx; + msg.tx_len = sizeof(tx); + msg.flags = 0; + ret = mipi_dsi_transfer(device, &msg); return ret < 0 ? ret : 0; } @@ -224,15 +233,19 @@ int mipi_dsi_set_maximum_return_packet_size( FAR struct mipi_dsi_device *device, uint16_t value) { int ret; - - struct mipi_dsi_msg msg = + struct mipi_dsi_msg msg; + uint8_t tx[2] = { - .channel = device->channel, - .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, - .tx_len = 2, - .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 }, + value & 0xff, + value >> 8 }; + msg.channel = device->channel; + msg.type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE; + msg.tx_len = sizeof(tx); + msg.tx_buf = tx; + msg.flags = 0; + ret = mipi_dsi_transfer(device, &msg); return ret < 0 ? ret : 0; } @@ -260,15 +273,19 @@ int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device, /* Note: Needs updating for non-default PPS or algorithm */ int ret; - - struct mipi_dsi_msg msg = + struct mipi_dsi_msg msg; + uint8_t tx[2] = { - .channel = device->channel, - .type = MIPI_DSI_COMPRESSION_MODE, - .tx_len = 2, - .tx_buf = (uint8_t [2]) { enable & 0xff, 0 }, + enable & 0xff, + 0 }; + msg.channel = device->channel; + msg.type = MIPI_DSI_COMPRESSION_MODE; + msg.tx_len = sizeof(tx); + msg.tx_buf = tx; + msg.flags = 0; + ret = mipi_dsi_transfer(device, &msg); return ret < 0 ? ret : 0; } @@ -294,31 +311,30 @@ int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device, size_t size) { int ret; + struct mipi_dsi_msg msg; - struct mipi_dsi_msg msg = - { - .channel = device->channel, - .tx_buf = payload, - .tx_len = size - }; + msg.channel = device->channel; + msg.tx_buf = payload; + msg.tx_len = size; + msg.flags = 0; switch (size) { - case 0: - msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM; - break; + case 0: + msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM; + break; - case 1: - msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM; - break; + case 1: + msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM; + break; - case 2: - msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM; - break; + case 2: + msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM; + break; - default: - msg.type = MIPI_DSI_LONG_GENERIC_WRITE; - break; + default: + msg.type = MIPI_DSI_LONG_GENERIC_WRITE; + break; } ret = mipi_dsi_transfer(device, &msg); @@ -352,28 +368,28 @@ ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device, FAR void *data, size_t size) { - struct mipi_dsi_msg msg = - { - .channel = device->channel, - .tx_len = num_params, - .tx_buf = params, - .rx_len = size, - .rx_buf = data - }; + struct mipi_dsi_msg msg; + + msg.channel = device->channel; + msg.tx_len = num_params; + msg.tx_buf = params; + msg.rx_len = size; + msg.rx_buf = data; + msg.flags = 0; switch (num_params) { - case 0: - msg.type = MIPI_DSI_GENERIC_READ_0_PARAM; - break; - case 1: - msg.type = MIPI_DSI_GENERIC_READ_1_PARAM; - break; - case 2: - msg.type = MIPI_DSI_GENERIC_READ_2_PARAM; - break; - default: - return -EINVAL; + case 0: + msg.type = MIPI_DSI_GENERIC_READ_0_PARAM; + break; + case 1: + msg.type = MIPI_DSI_GENERIC_READ_1_PARAM; + break; + case 2: + msg.type = MIPI_DSI_GENERIC_READ_2_PARAM; + break; + default: + return -EINVAL; } return mipi_dsi_transfer(device, &msg); @@ -402,26 +418,26 @@ ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device, FAR const void *data, size_t len) { - struct mipi_dsi_msg msg = - { - .channel = device->channel, - .tx_buf = data, - .tx_len = len - }; + struct mipi_dsi_msg msg; + + msg.channel = device->channel; + msg.tx_buf = data; + msg.tx_len = len; + msg.flags = 0; switch (len) { - case 0: - return -EINVAL; - case 1: - msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM; - break; - case 2: - msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM; - break; - default: - msg.type = MIPI_DSI_DCS_LONG_WRITE; - break; + case 0: + return -EINVAL; + case 1: + msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM; + break; + case 2: + msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM; + break; + default: + msg.type = MIPI_DSI_DCS_LONG_WRITE; + break; } return mipi_dsi_transfer(device, &msg); @@ -459,7 +475,7 @@ ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device, if (len > sizeof(stack_tx) - 1) { tx = kmm_malloc(len + 1); - if (!tx) + if (tx == NULL) { return -ENOMEM; } @@ -468,7 +484,7 @@ ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device, /* concatenate the DCS command byte and the payload */ tx[0] = cmd; - if (data) + if (data != NULL) { memcpy(&tx[1], data, len); } @@ -505,15 +521,15 @@ ssize_t mipi_dsi_dcs_read(FAR struct mipi_dsi_device *device, FAR void *data, size_t len) { - struct mipi_dsi_msg msg = - { - .channel = device->channel, - .type = MIPI_DSI_DCS_READ_0_PARAM, - .tx_buf = &cmd, - .tx_len = 1, - .rx_buf = data, - .rx_len = len - }; + struct mipi_dsi_msg msg; + + msg.channel = device->channel; + msg.type = MIPI_DSI_DCS_READ_0_PARAM; + msg.tx_buf = &cmd; + msg.tx_len = 1; + msg.rx_buf = data; + msg.rx_len = len; + msg.flags = 0; return mipi_dsi_transfer(device, &msg); } @@ -559,7 +575,6 @@ int mipi_dsi_dcs_soft_reset(FAR struct mipi_dsi_device *device) int ret; ret = mipi_dsi_dcs_write(device, MIPI_DCS_SOFT_RESET, NULL, 0); - return ret < 0 ? ret : OK; } diff --git a/drivers/video/mipidsi/mipi_dsi_device_driver.c b/drivers/video/mipidsi/mipi_dsi_device_driver.c index 1dffb8787d..396e93e88f 100644 --- a/drivers/video/mipidsi/mipi_dsi_device_driver.c +++ b/drivers/video/mipidsi/mipi_dsi_device_driver.c @@ -130,44 +130,34 @@ static int dsi_dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) switch (cmd) { case MIPIDSI_GETDEVLANES: - { FAR uint16_t *planes = (FAR uint16_t *)((uintptr_t)arg); DEBUGASSERT(planes != NULL); *planes = priv->dsi_dev->lanes; - } break; case MIPIDSI_GETDEVFMT: - { FAR uint32_t *fmt = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(fmt != NULL); *fmt = priv->dsi_dev->format; - } break; case MIPIDSI_GETDEVMODE: - { FAR uint32_t *mode = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(mode != NULL); *mode = priv->dsi_dev->mode_flags; - } break; case MIPIDSI_GETDEVHSRATE: - { FAR uint32_t *hsrate = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(hsrate != NULL); *hsrate = priv->dsi_dev->hs_rate; - } break; case MIPIDSI_GETDEVLPRATE: - { FAR uint32_t *lprate = (FAR uint32_t *)((uintptr_t)arg); DEBUGASSERT(lprate != NULL); *lprate = priv->dsi_dev->lp_rate; - } break; default: ret = -ENOTTY; diff --git a/drivers/video/mipidsi/mipi_dsi_host.c b/drivers/video/mipidsi/mipi_dsi_host.c index 99b719e0cb..547398852c 100644 --- a/drivers/video/mipidsi/mipi_dsi_host.c +++ b/drivers/video/mipidsi/mipi_dsi_host.c @@ -37,7 +37,7 @@ struct mipi_dsi_hosts_s { int count; - struct mipi_dsi_host *hosts[0]; + struct mipi_dsi_host *hosts[1]; }; /**************************************************************************** @@ -106,14 +106,13 @@ int mipi_dsi_host_register(FAR struct mipi_dsi_host *host) if (g_hosts == NULL) { - g_hosts = kmm_zalloc(sizeof(struct mipi_dsi_hosts_s) + - sizeof(FAR struct mipi_dsi_host *)); + g_hosts = kmm_zalloc(sizeof(struct mipi_dsi_hosts_s)); } else { g_hosts = kmm_realloc(g_hosts, sizeof(struct mipi_dsi_hosts_s) + sizeof(FAR struct mipi_dsi_host *) * - (g_hosts->count + 1)); + g_hosts->count); } if (g_hosts == NULL) diff --git a/drivers/video/mipidsi/mipi_dsi_host_driver.c b/drivers/video/mipidsi/mipi_dsi_host_driver.c index cd383bb715..dbc445e36e 100644 --- a/drivers/video/mipidsi/mipi_dsi_host_driver.c +++ b/drivers/video/mipidsi/mipi_dsi_host_driver.c @@ -134,7 +134,7 @@ static int dsi_host_ioctl(FAR struct file *filep, int cmd, unsigned long arg) switch (cmd) { case MIPIDSI_TRANSFER: - { + /* Get the reference to the mipi_dsi_msg structure */ msg = (FAR struct mipi_dsi_msg *)((uintptr_t)arg); @@ -145,7 +145,6 @@ static int dsi_host_ioctl(FAR struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(host != NULL && msg != NULL); ret = host->ops->transfer(host, msg); - } break; default: ret = -ENOTTY; diff --git a/drivers/video/mipidsi/mipi_dsi_packet.c b/drivers/video/mipidsi/mipi_dsi_packet.c index 26012f80b9..b50d1f3def 100644 --- a/drivers/video/mipidsi/mipi_dsi_packet.c +++ b/drivers/video/mipidsi/mipi_dsi_packet.c @@ -53,13 +53,13 @@ int mipi_dsi_pixel_format_to_bpp(uint8_t fmt) { switch (fmt) { - case MIPI_DSI_FMT_RGB888: - case MIPI_DSI_FMT_RGB666: - return 24; - case MIPI_DSI_FMT_RGB666_PACKED: - return 18; - case MIPI_DSI_FMT_RGB565: - return 16; + case MIPI_DSI_FMT_RGB888: + case MIPI_DSI_FMT_RGB666: + return 24; + case MIPI_DSI_FMT_RGB666_PACKED: + return 18; + case MIPI_DSI_FMT_RGB565: + return 16; } return -EINVAL; @@ -84,28 +84,28 @@ bool mipi_dsi_packet_format_is_short(uint8_t type) { switch (type) { - case MIPI_DSI_VSYNC_START: - case MIPI_DSI_VSYNC_END: - case MIPI_DSI_HSYNC_START: - case MIPI_DSI_HSYNC_END: - case MIPI_DSI_COMPRESSION_MODE: - case MIPI_DSI_END_OF_TRANSMISSION: - case MIPI_DSI_COLOR_MODE_OFF: - case MIPI_DSI_COLOR_MODE_ON: - case MIPI_DSI_SHUTDOWN_PERIPHERAL: - case MIPI_DSI_TURN_ON_PERIPHERAL: - case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM: - case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM: - case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM: - case MIPI_DSI_GENERIC_READ_0_PARAM: - case MIPI_DSI_GENERIC_READ_1_PARAM: - case MIPI_DSI_GENERIC_READ_2_PARAM: - case MIPI_DSI_DCS_SHORT_WRITE_0_PARAM: - case MIPI_DSI_DCS_SHORT_WRITE_1_PARAM: - case MIPI_DSI_DCS_READ_0_PARAM: - case MIPI_DSI_EXECUTE_QUEUE: - case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE: - return true; + case MIPI_DSI_VSYNC_START: + case MIPI_DSI_VSYNC_END: + case MIPI_DSI_HSYNC_START: + case MIPI_DSI_HSYNC_END: + case MIPI_DSI_COMPRESSION_MODE: + case MIPI_DSI_END_OF_TRANSMISSION: + case MIPI_DSI_COLOR_MODE_OFF: + case MIPI_DSI_COLOR_MODE_ON: + case MIPI_DSI_SHUTDOWN_PERIPHERAL: + case MIPI_DSI_TURN_ON_PERIPHERAL: + case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM: + case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM: + case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM: + case MIPI_DSI_GENERIC_READ_0_PARAM: + case MIPI_DSI_GENERIC_READ_1_PARAM: + case MIPI_DSI_GENERIC_READ_2_PARAM: + case MIPI_DSI_DCS_SHORT_WRITE_0_PARAM: + case MIPI_DSI_DCS_SHORT_WRITE_1_PARAM: + case MIPI_DSI_DCS_READ_0_PARAM: + case MIPI_DSI_EXECUTE_QUEUE: + case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE: + return true; } return false; @@ -130,23 +130,23 @@ bool mipi_dsi_packet_format_is_long(uint8_t type) { switch (type) { - case MIPI_DSI_NULL_PACKET: - case MIPI_DSI_BLANKING_PACKET: - case MIPI_DSI_LONG_GENERIC_WRITE: - case MIPI_DSI_DCS_LONG_WRITE: - case MIPI_DSI_PICTURE_PARAMETER_SET: - case MIPI_DSI_COMPRESSED_PIXEL_STREAM: - case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20: - case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24: - case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16: - case MIPI_DSI_PACKED_PIXEL_STREAM_RGB30: - case MIPI_DSI_PACKED_PIXEL_STREAM_RGB36: - case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12: - case MIPI_DSI_PACKED_PIXEL_STREAM_RGB16: - case MIPI_DSI_PACKED_PIXEL_STREAM_RGB18: - case MIPI_DSI_PIXEL_STREAM_3BYTE_RGB18: - case MIPI_DSI_PACKED_PIXEL_STREAM_RGB24: - return true; + case MIPI_DSI_NULL_PACKET: + case MIPI_DSI_BLANKING_PACKET: + case MIPI_DSI_LONG_GENERIC_WRITE: + case MIPI_DSI_DCS_LONG_WRITE: + case MIPI_DSI_PICTURE_PARAMETER_SET: + case MIPI_DSI_COMPRESSED_PIXEL_STREAM: + case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20: + case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24: + case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16: + case MIPI_DSI_PACKED_PIXEL_STREAM_RGB30: + case MIPI_DSI_PACKED_PIXEL_STREAM_RGB36: + case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12: + case MIPI_DSI_PACKED_PIXEL_STREAM_RGB16: + case MIPI_DSI_PACKED_PIXEL_STREAM_RGB18: + case MIPI_DSI_PIXEL_STREAM_3BYTE_RGB18: + case MIPI_DSI_PACKED_PIXEL_STREAM_RGB24: + return true; } return false;