Skip to content

Commit b1d1b70

Browse files
danieldegrassekartben
authored andcommitted
drivers: mipi_dbi: add support for mipi_dbi_configure_te
Many MIPI DBI displays support a "tearing effect" signal, which can be configured to signal each v-sync or h-sync interval. This signal can be used by the MIPI DBI controller to synchronize writes with the controller, and avoid tearing effects on the screen (which occur when the write pointer from the MCU overlaps with the panel's read pointer in the display controller's graphics RAM). Add the `mipi_dbi_configure_te` API, which allows display controllers to configure MIPI DBI controller to wait for a TE edge before streaming display data. Allow the tearing enable parameters to be configured via devicetree settings, since these will vary based on the MIPI DBI controller and display controller in use. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent a073d30 commit b1d1b70

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

dts/bindings/mipi-dbi/mipi-dbi-device.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@ properties:
2626
- "MIPI_DBI_MODE_8080_BUS_16_BIT"
2727
- "MIPI_DBI_MODE_8080_BUS_9_BIT"
2828
- "MIPI_DBI_MODE_8080_BUS_8_BIT"
29+
30+
te-mode:
31+
type: string
32+
default: "MIPI_DBI_TE_NO_EDGE"
33+
description: |
34+
MIPI DBI tearing enable signal mode. Defaults to disabled.
35+
enum:
36+
- "MIPI_DBI_TE_NO_EDGE"
37+
- "MIPI_DBI_TE_RISING_EDGE"
38+
- "MIPI_DBI_TE_FALLING_EDGE"
39+
40+
te-delay:
41+
type: int
42+
default: 0
43+
description: |
44+
Delay in microseconds to wait before transmitting display data after a
45+
tearing enable synchronization signal is seen. Defaults to 0 since most
46+
controllers will not need a delay.

include/zephyr/drivers/mipi_dbi.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ extern "C" {
112112
#define MIPI_DBI_CONFIG_DT_INST(inst, operation_, delay_) \
113113
MIPI_DBI_CONFIG_DT(DT_DRV_INST(inst), operation_, delay_)
114114

115+
/**
116+
* @brief Get the MIPI DBI TE mode from devicetree
117+
*
118+
* Gets the MIPI DBI TE mode from a devicetree property.
119+
* @param node_id Devicetree node identifier for the MIPI DBI device with the
120+
* TE mode property
121+
* @param edge_prop Property name for the TE mode that should be read from
122+
* devicetree
123+
*/
124+
#define MIPI_DBI_TE_MODE_DT(node_id, edge_prop) \
125+
DT_STRING_UPPER_TOKEN(node_id, edge_prop)
126+
127+
/**
128+
* @brief Get the MIPI DBI TE mode for device instance
129+
*
130+
* Gets the MIPI DBI TE mode from a devicetree property. Equivalent to
131+
* MIPI_DBI_TE_MODE_DT(DT_DRV_INST(inst), edge_mode).
132+
* @param inst Instance of the device to get the TE mode for
133+
* @param edge_prop Property name for the TE mode that should be read from
134+
* devicetree
135+
*/
136+
#define MIPI_DBI_TE_MODE_DT_INST(inst, edge_prop) \
137+
DT_STRING_UPPER_TOKEN(DT_DRV_INST(inst), edge_prop)
138+
115139
/**
116140
* @brief MIPI DBI controller configuration
117141
*
@@ -141,6 +165,9 @@ __subsystem struct mipi_dbi_driver_api {
141165
int (*reset)(const struct device *dev, k_timeout_t delay);
142166
int (*release)(const struct device *dev,
143167
const struct mipi_dbi_config *config);
168+
int (*configure_te)(const struct device *dev,
169+
uint8_t edge,
170+
k_timeout_t delay);
144171
};
145172

146173
/**
@@ -293,6 +320,45 @@ static inline int mipi_dbi_release(const struct device *dev,
293320
return api->release(dev, config);
294321
}
295322

323+
/**
324+
* @brief Configures MIPI DBI tearing effect signal
325+
*
326+
* Many displays provide a tearing effect signal, which can be configured
327+
* to pulse at each vsync interval or each hsync interval. This signal can be
328+
* used by the MCU to determine when to transmit a new frame so that the
329+
* read pointer of the display never overlaps with the write pointer from the
330+
* MCU. This function configures the MIPI DBI controller to delay transmitting
331+
* display frames until the selected tearing effect signal edge occurs.
332+
*
333+
* The delay will occur on the on each call to @ref mipi_dbi_write_display
334+
* where the ``frame_incomplete`` flag was set within the buffer descriptor
335+
* provided with the prior call, as this indicates the buffer being written
336+
* in this call is the first buffer of a new frame.
337+
*
338+
* Note that most display controllers will need to enable the TE signal
339+
* using vendor specific commands before the MIPI DBI controller can react
340+
* to it.
341+
*
342+
* @param dev mipi dbi controller
343+
* @param edge which edge of the TE signal to start transmitting on
344+
* @param delay_us how many microseconds after TE edge to start transmission
345+
* @retval -EIO I/O error
346+
* @retval -ENOSYS not implemented
347+
* @retval -ENOTSUP not supported
348+
*/
349+
static inline int mipi_dbi_configure_te(const struct device *dev,
350+
uint8_t edge,
351+
uint32_t delay_us)
352+
{
353+
const struct mipi_dbi_driver_api *api =
354+
(const struct mipi_dbi_driver_api *)dev->api;
355+
356+
if (api->configure_te == NULL) {
357+
return -ENOSYS;
358+
}
359+
return api->configure_te(dev, edge, K_USEC(delay_us));
360+
}
361+
296362
#ifdef __cplusplus
297363
}
298364
#endif

include/zephyr/dt-bindings/mipi_dbi/mipi_dbi.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,40 @@
110110
#define MIPI_DBI_MODE_8080_BUS_9_BIT 0x7
111111
#define MIPI_DBI_MODE_8080_BUS_8_BIT 0x8
112112

113+
/** MIPI DBI tearing enable synchronization is disabled. */
114+
#define MIPI_DBI_TE_NO_EDGE 0x0
115+
116+
/**
117+
* MIPI DBI tearing enable synchronization on rising edge of TE signal.
118+
* The controller will only send display write data on a rising edge of TE.
119+
* This should be used when the controller can send a frame worth of data
120+
* data to the display panel faster than the display panel can read a frame
121+
* from its RAM
122+
*
123+
* .------. .------.
124+
* TE -----' '------------------------' '-------------
125+
* -----. .----------------------.
126+
* CS '--------' '--------------------
127+
*/
128+
#define MIPI_DBI_TE_RISING_EDGE 0x1
129+
130+
/**
131+
* MIPI DBI tearing enable synchronization on falling edge of TE signal.
132+
* The controller will only send display write data on a falling edge of TE.
133+
* This should be used when the controller sends a frame worth of data
134+
* data to the display panel slower than the display panel can read a frame
135+
* from its RAM. TE synchronization in this mode will only work if the
136+
* controller can complete the write before the display panel completes 2
137+
* read cycles, otherwise the read pointer will "catch up" with the write
138+
* pointer.
139+
*
140+
* .------. .------.
141+
* TE -----' '------------------------' '-------------
142+
* ------------. .-----
143+
* CS '---------------------------------------'
144+
*/
145+
#define MIPI_DBI_TE_FALLING_EDGE 0x2
146+
113147
/**
114148
* SPI transfer of DBI commands as 8-bit blocks, the default behaviour in
115149
* SPI 4 wire (Type C3) mode. The clocking diagram corresponds exactly to

0 commit comments

Comments
 (0)