Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mipi_dbi.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
21#ifndef ZEPHYR_INCLUDE_DRIVERS_MIPI_DBI_H_
22#define ZEPHYR_INCLUDE_DRIVERS_MIPI_DBI_H_
23
31#include <zephyr/device.h>
34#include <zephyr/drivers/spi.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
57#define MIPI_DBI_MODE_SPI_3WIRE 0x1
78#define MIPI_DBI_MODE_SPI_4WIRE 0x2
79
91#define MIPI_DBI_SPI_CONFIG_DT(node_id, operation_, delay_) \
92 { \
93 .frequency = DT_PROP(node_id, mipi_max_frequency), \
94 .operation = (operation_) | \
95 DT_PROP(node_id, duplex), \
96 COND_CODE_1(DT_PROP(node_id, mipi_cpol), SPI_MODE_CPOL, (0)) | \
97 COND_CODE_1(DT_PROP(node_id, mipi_cpha), SPI_MODE_CPHA, (0)) | \
98 COND_CODE_1(DT_PROP(node_id, mipi_hold_cs), SPI_HOLD_ON_CS, (0)), \
99 .slave = DT_REG_ADDR(node_id), \
100 .cs = { \
101 .gpio = GPIO_DT_SPEC_GET_BY_IDX_OR(DT_PHANDLE(DT_PARENT(node_id), \
102 spi_dev), cs_gpios, \
103 DT_REG_ADDR(node_id), \
104 {}), \
105 .delay = (delay_), \
106 }, \
107 }
108
119};
120
121
123__subsystem struct mipi_dbi_driver_api {
124 int (*command_write)(const struct device *dev,
125 const struct mipi_dbi_config *config, uint8_t cmd,
126 const uint8_t *data, size_t len);
127 int (*command_read)(const struct device *dev,
128 const struct mipi_dbi_config *config, uint8_t *cmds,
129 size_t num_cmds, uint8_t *response, size_t len);
130 int (*write_display)(const struct device *dev,
131 const struct mipi_dbi_config *config,
132 const uint8_t *framebuf,
133 struct display_buffer_descriptor *desc,
134 enum display_pixel_format pixfmt);
135 int (*reset)(const struct device *dev, uint32_t delay);
136};
137
156static inline int mipi_dbi_command_write(const struct device *dev,
157 const struct mipi_dbi_config *config,
158 uint8_t cmd, const uint8_t *data,
159 size_t len)
160{
161 const struct mipi_dbi_driver_api *api =
162 (const struct mipi_dbi_driver_api *)dev->api;
163
164 if (api->command_write == NULL) {
165 return -ENOSYS;
166 }
167 return api->command_write(dev, config, cmd, data, len);
168}
169
187static inline int mipi_dbi_command_read(const struct device *dev,
188 const struct mipi_dbi_config *config,
189 uint8_t *cmds, size_t num_cmd,
190 uint8_t *response, size_t len)
191{
192 const struct mipi_dbi_driver_api *api =
193 (const struct mipi_dbi_driver_api *)dev->api;
194
195 if (api->command_read == NULL) {
196 return -ENOSYS;
197 }
198 return api->command_read(dev, config, cmds, num_cmd, response, len);
199}
200
220static inline int mipi_dbi_write_display(const struct device *dev,
221 const struct mipi_dbi_config *config,
222 const uint8_t *framebuf,
223 struct display_buffer_descriptor *desc,
224 enum display_pixel_format pixfmt)
225{
226 const struct mipi_dbi_driver_api *api =
227 (const struct mipi_dbi_driver_api *)dev->api;
228
229 if (api->write_display == NULL) {
230 return -ENOSYS;
231 }
232 return api->write_display(dev, config, framebuf, desc, pixfmt);
233}
234
246static inline int mipi_dbi_reset(const struct device *dev, uint32_t delay)
247{
248 const struct mipi_dbi_driver_api *api =
249 (const struct mipi_dbi_driver_api *)dev->api;
250
251 if (api->reset == NULL) {
252 return -ENOSYS;
253 }
254 return api->reset(dev, delay);
255}
256
257#ifdef __cplusplus
258}
259#endif
260
265#endif /* ZEPHYR_INCLUDE_DRIVERS_MIPI_DBI_H_ */
Public API for display drivers and applications.
Public API for SPI drivers and applications.
display_pixel_format
Display pixel formats.
Definition: display.h:40
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
static int mipi_dbi_reset(const struct device *dev, uint32_t delay)
Resets attached display controller.
Definition: mipi_dbi.h:246
static int mipi_dbi_write_display(const struct device *dev, const struct mipi_dbi_config *config, const uint8_t *framebuf, struct display_buffer_descriptor *desc, enum display_pixel_format pixfmt)
Write a display buffer to the display controller.
Definition: mipi_dbi.h:220
static int mipi_dbi_command_write(const struct device *dev, const struct mipi_dbi_config *config, uint8_t cmd, const uint8_t *data, size_t len)
Write a command to the display controller.
Definition: mipi_dbi.h:156
static int mipi_dbi_command_read(const struct device *dev, const struct mipi_dbi_config *config, uint8_t *cmds, size_t num_cmd, uint8_t *response, size_t len)
Read a command response from the display controller.
Definition: mipi_dbi.h:187
#define ENOSYS
Function not implemented.
Definition: errno.h:83
Display definitions for MIPI devices.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
void * data
Address of the device instance private data.
Definition: device.h:397
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
const void * config
Address of device instance config information.
Definition: device.h:391
Structure to describe display data buffer layout.
Definition: display.h:119
MIPI DBI controller configuration.
Definition: mipi_dbi.h:114
uint8_t mode
MIPI DBI mode (SPI 3 wire or 4 wire)
Definition: mipi_dbi.h:116
struct spi_config config
SPI configuration.
Definition: mipi_dbi.h:118
MIPI-DBI host driver API.
Definition: mipi_dbi.h:123
int(* reset)(const struct device *dev, uint32_t delay)
Definition: mipi_dbi.h:135
int(* command_read)(const struct device *dev, const struct mipi_dbi_config *config, uint8_t *cmds, size_t num_cmds, uint8_t *response, size_t len)
Definition: mipi_dbi.h:127
int(* command_write)(const struct device *dev, const struct mipi_dbi_config *config, uint8_t cmd, const uint8_t *data, size_t len)
Definition: mipi_dbi.h:124
int(* write_display)(const struct device *dev, const struct mipi_dbi_config *config, const uint8_t *framebuf, struct display_buffer_descriptor *desc, enum display_pixel_format pixfmt)
Definition: mipi_dbi.h:130
SPI controller configuration structure.
Definition: spi.h:299