Skip to content

Commit 0e3d9cc

Browse files
nzmichaelhnashif
authored andcommitted
drivers: mipi_dbi: lower ROM usage by switching reset time to k_timeout_t
Calling k_msleep() leads to a int64_t division, causing udivdi3 and similar to be linked in. Keep the outer API the same, but switch to k_timeout_t before passing to the inner API. This saves 1916 B of ROM. Signed-off-by: Michael Hope <[email protected]>
1 parent 2a46ede commit 0e3d9cc

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

drivers/mipi_dbi/mipi_dbi_nxp_flexio_lcdif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ static int mipi_dbi_flexio_lcdif_command_write(const struct device *dev,
336336

337337
}
338338

339-
static int mipi_dbi_flexio_lcdif_reset(const struct device *dev, uint32_t delay)
339+
static int mipi_dbi_flexio_lcdif_reset(const struct device *dev, k_timeout_t delay)
340340
{
341341
int err;
342342
const struct mcux_flexio_lcdif_config *config = dev->config;
@@ -357,7 +357,7 @@ static int mipi_dbi_flexio_lcdif_reset(const struct device *dev, uint32_t delay)
357357
return err;
358358
}
359359

360-
k_msleep(delay);
360+
k_sleep(delay);
361361

362362
err = gpio_pin_set_dt(&config->reset, 1);
363363
if (err < 0) {

drivers/mipi_dbi/mipi_dbi_nxp_lcdic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,13 @@ static int mipi_dbi_lcdic_write_cmd(const struct device *dev,
558558
return ret;
559559
}
560560

561-
static int mipi_dbi_lcdic_reset(const struct device *dev, uint32_t delay)
561+
static int mipi_dbi_lcdic_reset(const struct device *dev, k_timeout_t delay)
562562
{
563563
const struct mipi_dbi_lcdic_config *config = dev->config;
564564
LCDIC_Type *base = config->base;
565565
uint32_t lcdic_freq;
566566
uint8_t rst_width, pulse_cnt;
567+
uint32_t delay_ms = k_ticks_to_ms_ceil32(delay);
567568

568569
/* Calculate delay based off timer0 ratio. Formula given
569570
* by RM is as follows:
@@ -574,8 +575,7 @@ static int mipi_dbi_lcdic_reset(const struct device *dev, uint32_t delay)
574575
&lcdic_freq)) {
575576
return -EIO;
576577
}
577-
rst_width = (delay * (lcdic_freq)) /
578-
((1 << LCDIC_TIMER0_RATIO) * MSEC_PER_SEC);
578+
rst_width = (delay_ms * (lcdic_freq)) / ((1 << LCDIC_TIMER0_RATIO) * MSEC_PER_SEC);
579579
/* If rst_width is larger than max value supported by hardware,
580580
* increase the pulse count (rounding up)
581581
*/

drivers/mipi_dbi/mipi_dbi_smartbond.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void mipi_dbi_smartbond_send_single_frame(const struct device *dev)
123123
}
124124

125125
#if MIPI_DBI_SMARTBOND_IS_RESET_AVAILABLE
126-
static int mipi_dbi_smartbond_reset(const struct device *dev, uint32_t delay)
126+
static int mipi_dbi_smartbond_reset(const struct device *dev, k_timeout_t delay)
127127
{
128128
const struct mipi_dbi_smartbond_config *config = dev->config;
129129
int ret;
@@ -138,7 +138,7 @@ static int mipi_dbi_smartbond_reset(const struct device *dev, uint32_t delay)
138138
LOG_ERR("Cannot drive reset signal");
139139
return ret;
140140
}
141-
k_msleep(delay);
141+
k_sleep(delay);
142142

143143
return gpio_pin_set_dt(&config->reset, 0);
144144
}

drivers/mipi_dbi/mipi_dbi_spi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static inline bool mipi_dbi_has_pin(const struct gpio_dt_spec *spec)
250250
return spec->port != NULL;
251251
}
252252

253-
static int mipi_dbi_spi_reset(const struct device *dev, uint32_t delay)
253+
static int mipi_dbi_spi_reset(const struct device *dev, k_timeout_t delay)
254254
{
255255
const struct mipi_dbi_spi_config *config = dev->config;
256256
int ret;
@@ -263,7 +263,7 @@ static int mipi_dbi_spi_reset(const struct device *dev, uint32_t delay)
263263
if (ret < 0) {
264264
return ret;
265265
}
266-
k_msleep(delay);
266+
k_sleep(delay);
267267
return gpio_pin_set_dt(&config->reset, 0);
268268
}
269269

include/zephyr/drivers/mipi_dbi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ __subsystem struct mipi_dbi_driver_api {
138138
const uint8_t *framebuf,
139139
struct display_buffer_descriptor *desc,
140140
enum display_pixel_format pixfmt);
141-
int (*reset)(const struct device *dev, uint32_t delay);
141+
int (*reset)(const struct device *dev, k_timeout_t delay);
142142
int (*release)(const struct device *dev,
143143
const struct mipi_dbi_config *config);
144144
};
@@ -247,21 +247,21 @@ static inline int mipi_dbi_write_display(const struct device *dev,
247247
*
248248
* Resets the attached display controller.
249249
* @param dev mipi dbi controller
250-
* @param delay duration to set reset signal for, in milliseconds
250+
* @param delay_ms duration to set reset signal for, in milliseconds
251251
* @retval 0 reset succeeded
252252
* @retval -EIO I/O error
253253
* @retval -ENOSYS not implemented
254254
* @retval -ENOTSUP not supported
255255
*/
256-
static inline int mipi_dbi_reset(const struct device *dev, uint32_t delay)
256+
static inline int mipi_dbi_reset(const struct device *dev, uint32_t delay_ms)
257257
{
258258
const struct mipi_dbi_driver_api *api =
259259
(const struct mipi_dbi_driver_api *)dev->api;
260260

261261
if (api->reset == NULL) {
262262
return -ENOSYS;
263263
}
264-
return api->reset(dev, delay);
264+
return api->reset(dev, K_MSEC(delay_ms));
265265
}
266266

267267
/**

0 commit comments

Comments
 (0)