Skip to content

Commit

Permalink
drivers: mipi-dbi-spi: use string for xfr-min-bits property
Browse files Browse the repository at this point in the history
Use a string for the xfr-min-bits property over an integer value, as this
significantly improves the readability of the MIPI DBI SPI device binding.

Signed-off-by: Stephan Linz <[email protected]>
  • Loading branch information
rexut authored and kartben committed Jan 8, 2025
1 parent ee5c520 commit 7cd7c82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions drivers/mipi_dbi/mipi_dbi_spi.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2023 NXP
* Copyright 2024 TiaC Systems
* Copyright 2024-2025 TiaC Systems
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -43,8 +43,8 @@ struct mipi_dbi_spi_data {
uint32_t var = MIPI_DBI_SPI_READ_REQUIRED;

/* Expands to 1 if the node does reflect the enum in `xfr-min-bits` property */
#define _XFR_8BITS(n) (DT_INST_PROP(n, xfr_min_bits) == MIPI_DBI_SPI_XFR_8BIT) |
#define _XFR_16BITS(n) (DT_INST_PROP(n, xfr_min_bits) == MIPI_DBI_SPI_XFR_16BIT) |
#define _XFR_8BITS(n) (DT_INST_STRING_UPPER_TOKEN(n, xfr_min_bits) == MIPI_DBI_SPI_XFR_8BIT) |
#define _XFR_16BITS(n) (DT_INST_STRING_UPPER_TOKEN(n, xfr_min_bits) == MIPI_DBI_SPI_XFR_16BIT) |

/* This macros will evaluate to 1 if any of the nodes with zephyr,mipi-dbi-spi
* have the `xfr-min-bits` property to corresponding enum value. The intention
Expand Down Expand Up @@ -560,7 +560,7 @@ static DEVICE_API(mipi_dbi, mipi_dbi_spi_driver_api) = {
DT_INST_PHANDLE(n, spi_dev)), \
.cmd_data = GPIO_DT_SPEC_INST_GET_OR(n, dc_gpios, {}), \
.reset = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {}), \
.xfr_min_bits = DT_INST_PROP(n, xfr_min_bits) \
.xfr_min_bits = DT_INST_STRING_UPPER_TOKEN(n, xfr_min_bits) \
}; \
static struct mipi_dbi_spi_data mipi_dbi_spi_data_##n; \
\
Expand Down
14 changes: 5 additions & 9 deletions dts/bindings/mipi-dbi/zephyr,mipi-dbi-spi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ properties:
Reset GPIO pin. Set high to reset the display
xfr-min-bits:
type: int
default: 8
type: string
default: "MIPI_DBI_SPI_XFR_8BIT"
description:
On rare types of SPI interfaces, discrete shift registers can be found
whose task is to convert the serial SPI bit stream to the parallel MCU
interface with clock and bit accuracy. Typically, these are 16 bits wide.

Use the macros, not the actual enum value. Here is the concordance list
(see dt-bindings/mipi_dbi/mipi_dbi.h)
8 MIPI_DBI_SPI_XFR_8BIT
16 MIPI_DBI_SPI_XFR_16BIT
These definitions should match those in dt-bindings/mipi_dbi/mipi_dbi.h
enum:
- 8
- 16
- "MIPI_DBI_SPI_XFR_8BIT"
- "MIPI_DBI_SPI_XFR_16BIT"

write-only:
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion tests/drivers/build_all/display/app.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
spi-dev = <&test_spi>;
#address-cells = <1>;
#size-cells = <0>;
xfr-min-bits = <MIPI_DBI_SPI_XFR_16BIT>;
xfr-min-bits = "MIPI_DBI_SPI_XFR_16BIT";
write-only;

test_mipi_dbi_xfr_16bit_ili9342c: ili9342c@0 {
Expand Down

0 comments on commit 7cd7c82

Please sign in to comment.