Skip to content

Commit c6cf9b9

Browse files
danieldegrassefabiobaltieri
authored andcommitted
drivers: mipi_dbi: mipi_dbi_nxp_lcdic: fix reset pulse calculation
Reset pulse count can be up to 512 before we would be unable to support it using the peripheral. Use a uint32_t for the count, so that even long reset pulses will still be calculated correctly. Add code to warn about reset pulse requests that are too long. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent c0e5769 commit c6cf9b9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/mipi_dbi/mipi_dbi_nxp_lcdic.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ enum lcdic_cmd_type {
3838
#define LCDIC_MAX_XFER 0x40000
3939
/* Max reset width (in terms of Timer0_Period, see RST_CTRL register) */
4040
#define LCDIC_MAX_RST_WIDTH 0x3F
41+
/* Max reset pulse count */
42+
#define LCDIC_MAX_RST_PULSE_COUNT 0x7
4143

4244
/* Descriptor for LCDIC command */
4345
union lcdic_trx_cmd {
@@ -580,7 +582,7 @@ static int mipi_dbi_lcdic_reset(const struct device *dev, k_timeout_t delay)
580582
LCDIC_Type *base = config->base;
581583
uint32_t lcdic_freq;
582584
uint32_t delay_ms = k_ticks_to_ms_ceil32(delay.ticks);
583-
uint8_t rst_width, pulse_cnt;
585+
uint32_t rst_width, pulse_cnt;
584586

585587
/* Calculate delay based off timer0 ratio. Formula given
586588
* by RM is as follows:
@@ -598,6 +600,12 @@ static int mipi_dbi_lcdic_reset(const struct device *dev, k_timeout_t delay)
598600
pulse_cnt = ((rst_width + (LCDIC_MAX_RST_WIDTH - 1)) / LCDIC_MAX_RST_WIDTH);
599601
rst_width = MIN(LCDIC_MAX_RST_WIDTH, rst_width);
600602

603+
if ((pulse_cnt - 1) > LCDIC_MAX_RST_PULSE_COUNT) {
604+
/* Still issue reset pulse, but warn user */
605+
LOG_WRN("Reset pulse is too long for configured timer0 ratio");
606+
pulse_cnt = LCDIC_MAX_RST_PULSE_COUNT + 1;
607+
}
608+
601609
/* Start the reset signal */
602610
base->RST_CTRL = LCDIC_RST_CTRL_RST_WIDTH(rst_width - 1) |
603611
LCDIC_RST_CTRL_RST_SEQ_NUM(pulse_cnt - 1) |

0 commit comments

Comments
 (0)