drivers: mipi_dbi: mipi_dbi_spi: require 3 wire mode use 9 bit SPI

Require that SPI config within the MIPI DBI API use 9 bit SPI mode, as 3
wire spi requires the command/data bit be packed into the start of the
SPI packet.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2024-04-30 10:58:02 -05:00 committed by Anas Nashif
parent 9b9a4eb027
commit b8049b41ae

View file

@ -66,21 +66,21 @@ static int mipi_dbi_spi_write_helper(const struct device *dev,
if (dbi_config->mode == MIPI_DBI_MODE_SPI_3WIRE &&
IS_ENABLED(CONFIG_MIPI_DBI_SPI_3WIRE)) {
struct spi_config tmp_cfg;
/* We have to emulate 3 wire mode by packing the data/command
* bit into the upper bit of the SPI transfer.
* switch SPI to 9 bit mode, and write the transfer
/* 9 bit word mode must be used, as the command/data bit
* is stored before the data word.
*/
memcpy(&tmp_cfg, &dbi_config->config, sizeof(tmp_cfg));
tmp_cfg.operation &= ~SPI_WORD_SIZE_MASK;
tmp_cfg.operation |= SPI_WORD_SET(9);
if ((dbi_config->config.operation & SPI_WORD_SIZE_MASK)
!= SPI_WORD_SET(9)) {
return -ENOTSUP;
}
buffer.buf = &data->spi_byte;
buffer.len = 1;
buffer.len = 2;
/* Send command */
if (cmd_present) {
data->spi_byte = cmd;
ret = spi_write(config->spi_dev, &tmp_cfg, &buf_set);
ret = spi_write(config->spi_dev, &dbi_config->config,
&buf_set);
if (ret < 0) {
goto out;
}
@ -88,7 +88,8 @@ static int mipi_dbi_spi_write_helper(const struct device *dev,
/* Write data, byte by byte */
for (size_t i = 0; i < len; i++) {
data->spi_byte = MIPI_DBI_DC_BIT | data_buf[i];
ret = spi_write(config->spi_dev, &tmp_cfg, &buf_set);
ret = spi_write(config->spi_dev, &dbi_config->config,
&buf_set);
if (ret < 0) {
goto out;
}