#include <stm32h747xx.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef DISPLAY_H
#define DISPLAY_H
typedef enum {
DSI_VIDEO_NON_BURST_PULSES = 0,
DSI_VIDEO_NON_BURST_EVENTS = 1,
DSI_VIDEO_BURST = 2,
} dsi_video_mode_t;
typedef struct {
uint16_t active_width;
uint16_t active_height;
uint16_t h_back_porch;
uint16_t h_front_porch;
uint16_t v_back_porch;
uint16_t v_front_porch;
// ?
/* uint16_t h_sync_lane_byte_cycles; */
uint16_t h_sync;
uint16_t v_sync;
bool h_sync_pol;
bool v_sync_pol;
bool not_data_enable_pol;
bool pixel_clock_pol;
dsi_video_mode_t video_mode;
uint8_t channel;
} display_config_t;
typedef enum {
CODING_16_BIT_1 = 0,
CODING_16_BIT_2 = 1,
CODING_16_BIT_3 = 2,
CODING_18_BIT_1 = 3,
CODING_18_BIT_2 = 4,
CODING_24_BIT = 5,
} dsi_color_coding_t;
typedef enum {
LTDC_ARGB8888 = 0,
LTDC_RGB888 = 1,
LTDC_RGB565 = 2,
LTDC_ARGB1555 = 3,
LTDC_ARGB4444 = 4,
LTDC_L8 = 5,
LTDC_AL44 = 6,
LTDC_AL88 = 7,
} ltdc_layer_pixel_format_t;
typedef struct {
uint8_t channel;
bool color_loosely_packed;
dsi_color_coding_t color_coding;
dsi_color_coding_t wrapper_color_coding;
uint8_t lp_size;
uint8_t vlp_size;
} dsi_config_t;
typedef enum {
DSI_MODE_ADAPTED_COMMAND,
DSI_MODE_VIDEO,
} dsi_mode_t;
typedef struct {
uint8_t divn;
uint8_t idf;
uint8_t odf;
uint8_t eckdiv;
} dsi_pll_config_t;
typedef struct {
bool crc_reception_enable;
bool ecc_reception_enable;
bool bta_enable;
bool eotp_reception_enable;
bool eotp_transmission_enable;
} dsi_flow_config_t;
typedef struct {
uint8_t data_lanes;
bool auto_clock_lane_control;
uint8_t clock_control;
uint8_t clock_hs2lp;
uint8_t clock_lp2hs;
uint8_t data_hs2lp;
uint8_t data_lp2hs;
uint8_t max_read_time;
uint8_t stop_wait_time;
uint8_t unit_interval;
} dsi_phy_config_t;
typedef struct {
DSI_TypeDef* dsi;
LTDC_TypeDef* ltdc;
LTDC_Layer_TypeDef* layer;
display_config_t config;
} display_t;
/**
* @brief Initialize the display struct.
* @param[in,out] display The display struct
* @param[out] dsi The dsi peripheral
* @param[out] ltdc The ltdc peripheral
* @param[out] layer The layer to draw to.
* @param[in] display_config The config parameters
*/
void display_init(display_t *display, DSI_TypeDef *dsi, LTDC_TypeDef* ltdc, LTDC_Layer_TypeDef* layer, display_config_t display_config);
/**
* @brief Start the dsi peripheral
* @param[in,out] display The display.
*/
void display_start(display_t* display);
/**
* @brief Set up the display with parameters.
* @param[in,out] display The display
* @param[in] dsi_khz Frequency of dsi physical clock.
* @param[in] ltdc_khz Frequency of ltdc clock.
* @param[in] mode The mode to use.
* @param[in] pll The pll configuration.
* @param[in] phy The phy configuration.
* @param[in] flow The flow configuratioon
* @param[in] dsi_config The dsi configuration.
*/
void display_setup(display_t *display, uint32_t dsi_khz, uint32_t ltdc_khz,
dsi_mode_t mode,
dsi_pll_config_t pll, dsi_phy_config_t phy,
dsi_flow_config_t flow, dsi_config_t dsi_config);
void display_dsi_short_write(display_t* display, uint8_t lsb, uint8_t msb, uint8_t discriminant);
void display_dsi_long_write(display_t* display, uint8_t cmd, uint8_t* data, uint16_t len, uint8_t discriminant);
void display_dsi_read(display_t* display, uint8_t* buffer);
/**
* @brief For setting the dsi transmission to low power.
* @param[in,out] display The display
* @param[in] low_power The power of low
*/
void display_set_command_mode_transmission_kind(display_t* display, bool low_power);
// Layer calls
/**
* @brief Set up layer configuration.
* @param[in,out] display The display.
* @param[out] buffer Pointer to buffer to draw
* @param[in] pixel_format The format of pixel
*/
void display_layer_setup(display_t *display, void* buffer, ltdc_layer_pixel_format_t pixel_format);
/**
* @brief Replace framebuffer of dsi.
* @param[in,out] display The display.
* @param[out] buffer Pointer to buffer to set to.
*/
void display_set_framebuffer(display_t* display, void* buffer);
/**
* @brief Refresh the display - send the framebuffer to the display.
* @param[in,out] display Description
*/
void display_refresh(display_t* display);
void display_reload(display_t *display);
#endif // DISPLAY_H