1 /* 2 * Copyright (c) 2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef _HPM_PANEL_H 9 #define _HPM_PANEL_H 10 11 #include <stdint.h> 12 #include <string.h> 13 #include <stdbool.h> 14 15 struct hpm_panel; 16 typedef struct hpm_panel hpm_panel_t; 17 18 typedef struct hpm_panel_timing { 19 uint32_t pixel_clock_khz; /*!< pixel clocl,UINT: KHz */ 20 uint32_t hactive; /*!< Horizontal active video */ 21 uint32_t hfront_porch; /*!< Horizontal Front Porch */ 22 uint32_t hback_porch; /*!< Horizontal Back Porch */ 23 uint32_t hsync_len; /*!< Horizontal sync len */ 24 25 uint32_t vactive; /*!< Vertical active video */ 26 uint32_t vfront_porch; /*!< Vertical Front Porch */ 27 uint32_t vback_porch; /*!< Vertical Back Porch */ 28 uint32_t vsync_len; /*!< Vertical sync len */ 29 uint32_t hsync_pol :1; /*!< Horizontal Synchronization Signal Polarity, 0: High Active, 1: Low Active */ 30 uint32_t vsync_pol :1; /*!< Vertical Synchronization Signal Polarity, 0: High Active, 1: Low Active */ 31 uint32_t de_pol :1; /*!< Data Enable Signal Polarity, 0: High Active, 1: Low Active */ 32 uint32_t pixel_clk_pol :1; /*!< Pixel Clock Signal Polarity, 0: High Active, 1: Low Active */ 33 uint32_t pixel_data_pol :1;/*!< Pixel Data Signal Polarity, 0: High Active, 1: Low Active */ 34 } hpm_panel_timing_t; 35 36 typedef enum hpm_panel_mipi_format { 37 HPM_PANEL_MIPI_FORMAT_RGB888, 38 HPM_PANEL_MIPI_FORMAT_RGB666, 39 HPM_PANEL_MIPI_FORMAT_RGB666_PACKED, 40 HPM_PANEL_MIPI_FORMAT_RGB565 41 } hpm_panel_mipi_format; 42 43 typedef struct hpm_panel_hw_interface { 44 uint32_t lcdc_pixel_clk_khz; 45 void (*set_reset_pin_level)(uint8_t level); 46 void (*set_backlight)(uint16_t percent); 47 void (*set_video_router)(void); 48 union { 49 struct { 50 hpm_panel_mipi_format format; 51 void *mipi_host_base; 52 void *mipi_phy_base; 53 } mipi; 54 struct { 55 uint32_t channel_di_index :8; 56 uint32_t channel_index :8; 57 void *lvb_base; 58 } lvds; 59 } video; 60 } hpm_panel_hw_interface_t; 61 62 typedef struct hpm_panel_funcs { 63 void (*reset)(hpm_panel_t *panel); 64 void (*init)(hpm_panel_t *panel); 65 void (*power_on)(hpm_panel_t *panel); 66 void (*power_off)(hpm_panel_t *panel); 67 } hpm_panel_funcs_t; 68 69 typedef enum hpm_panel_if_type { 70 HPM_PANEL_IF_TYPE_RGB, 71 HPM_PANEL_IF_TYPE_LVDS_SINGLE, 72 HPM_PANEL_IF_TYPE_LVDS_SPLIT, 73 HPM_PANEL_IF_TYPE_MIPI, 74 } hpm_panel_if_type_t; 75 76 typedef enum hpm_panel_state_power { 77 HPM_PANEL_STATE_POWER_OFF, 78 HPM_PANEL_STATE_POWER_ON 79 } hpm_panel_power_state_t; 80 81 typedef struct hpm_panel_state { 82 uint8_t backlight_percent; 83 uint8_t power_state; 84 } hpm_panel_state_t; 85 86 struct hpm_panel { 87 const char *name; 88 hpm_panel_if_type_t if_type; 89 const hpm_panel_timing_t timing; 90 hpm_panel_state_t state; 91 hpm_panel_hw_interface_t hw_if; 92 hpm_panel_funcs_t funcs; 93 }; 94 95 #ifdef __cplusplus 96 extern "C" { 97 #endif 98 99 /** 100 * @brief Find default panel 101 * 102 * @return pointer of panel instance 103 */ 104 hpm_panel_t *hpm_panel_find_device_default(void); 105 106 /** 107 * @brief Find panel for name 108 * 109 * @param [in] name of panel 110 * 111 * @return pointer of panel instance 112 */ 113 hpm_panel_t *hpm_panel_find_device(const char *name); 114 115 /** 116 * @brief Get panel name 117 * 118 * @param panel pointer of panel instance 119 * 120 * @return panel name 121 */ 122 const char *hpm_panel_get_name(hpm_panel_t *panel); 123 124 /** 125 * @brief Get panel timing 126 * 127 * @param panel pointer of panel instance 128 * 129 * @return pointer of timing 130 */ 131 const hpm_panel_timing_t *hpm_panel_get_timing(hpm_panel_t *panel); 132 133 /** 134 * @brief Get panel interface type 135 * 136 * @param [in] panel pointer of panel instance 137 * 138 * @return panel interface type @ref hpm_panel_if_type_t 139 */ 140 hpm_panel_if_type_t hpm_panel_get_if_type(hpm_panel_t *panel); 141 142 /** 143 * @brief Register platform level hardware interface 144 * 145 * @param [in] panel pointer of panel instance 146 * @param [in] hw_if pointer of hardware interface 147 */ 148 void hpm_panel_register_interface(hpm_panel_t *panel, hpm_panel_hw_interface_t *hw_if); 149 150 /** 151 * @brief Reset the panel 152 * 153 * @param [in] panel pointer of panel instance 154 */ 155 void hpm_panel_reset(hpm_panel_t *panel); 156 157 /** 158 * @brief Initialize the panel 159 * 160 * @param [in] panel pointer of panel instance 161 */ 162 void hpm_panel_init(hpm_panel_t *panel); 163 164 /** 165 * @brief Power on the panel 166 * 167 * @param [in] panel pointer of panel instance 168 */ 169 void hpm_panel_power_on(hpm_panel_t *panel); 170 171 /** 172 * @brief Power off the panel 173 * 174 * @param [in] panel pointer of panel instance 175 */ 176 void hpm_panel_power_off(hpm_panel_t *panel); 177 178 /** 179 * @brief Set backlight value 180 * 181 * @param [in] panel pointer of panel instance 182 * @param [in] percent percent of backlight [0 - 100] 183 */ 184 void hpm_panel_set_backlight(hpm_panel_t *panel, uint16_t percent); 185 186 /** 187 * 188 * @brief Get backlight value 189 * 190 * @param [in] panel pointer of panel instance 191 * @return percent of backlight [0 - 100] 192 */ 193 uint8_t hpm_panel_get_backlight(hpm_panel_t *panel); 194 195 /** 196 * @brief Delay specified milliseconds 197 * 198 * @param [in] ms expected delay interval in milliseconds 199 */ 200 void hpm_panel_delay_ms(uint32_t ms); 201 202 /** 203 * @brief Delay specified microseconds 204 * 205 * @param [in] us expected delay interval in microseconds 206 */ 207 void hpm_panel_delay_us(uint32_t us); 208 209 #ifdef __cplusplus 210 } 211 #endif 212 213 #endif /* _HPM_PANEL_H */