• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <driver/hal/hal_gpio_types.h>
18 #include "jpeg_hw.h"
19 #include <driver/hal/hal_jpeg_types.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define JPEG_LL_REG_BASE(_jpeg_unit_id)    (JPEG_R_BASE)
26 
27 #define JPEG_GPIO_PIN_NUMBER    12
28 #define JPEG_GPIO_MAP \
29 {\
30 	{GPIO_27, GPIO_DEV_JPEG_MCLK},\
31 	{GPIO_29, GPIO_DEV_JPEG_PCLK},\
32 	{GPIO_30, GPIO_DEV_JPEG_HSYNC},\
33 	{GPIO_31, GPIO_DEV_JPEG_VSYNC},\
34 	{GPIO_32, GPIO_DEV_JPEG_PXDATA0},\
35 	{GPIO_33, GPIO_DEV_JPEG_PXDATA1},\
36 	{GPIO_34, GPIO_DEV_JPEG_PXDATA2},\
37 	{GPIO_35, GPIO_DEV_JPEG_PXDATA3},\
38 	{GPIO_36, GPIO_DEV_JPEG_PXDATA4},\
39 	{GPIO_37, GPIO_DEV_JPEG_PXDATA5},\
40 	{GPIO_38, GPIO_DEV_JPEG_PXDATA6},\
41 	{GPIO_39, GPIO_DEV_JPEG_PXDATA7},\
42 }
43 
44 #define JPEG_GPIO_AUXS GPIO_27
45 
46 void jpeg_ll_init_quant_table(jpeg_hw_t *hw);
47 
jpeg_ll_reset_config_to_default(jpeg_hw_t * hw)48 static inline void jpeg_ll_reset_config_to_default(jpeg_hw_t *hw)
49 {
50 	/* 1.reset REG_0x0
51 	 * 2.clear int_status(REG_0x6)
52 	 */
53 	REG_WRITE(JPEG_R_INT_EN, 0);
54 	REG_WRITE(JPEG_R_INT_STATUS, REG_READ(JPEG_R_INT_STATUS));
55 }
56 
jpeg_ll_init(jpeg_hw_t * hw)57 static inline void jpeg_ll_init(jpeg_hw_t *hw)
58 {
59 	jpeg_ll_reset_config_to_default(hw);
60 }
61 
jpeg_ll_clear_config(jpeg_hw_t * hw)62 static inline void jpeg_ll_clear_config(jpeg_hw_t *hw)
63 {
64 	hw->cfg.v = 0;
65 }
66 
jpeg_ll_enable(jpeg_hw_t * hw)67 static inline void jpeg_ll_enable(jpeg_hw_t *hw)
68 {
69 	hw->cfg.jpeg_enc_en = 1;
70 }
71 
jpeg_ll_disable(jpeg_hw_t * hw)72 static inline void jpeg_ll_disable(jpeg_hw_t *hw)
73 {
74 	hw->cfg.jpeg_enc_en = 0;
75 }
76 
jpeg_ll_set_x_pixel(jpeg_hw_t * hw,uint32_t x_pixel)77 static inline void jpeg_ll_set_x_pixel(jpeg_hw_t *hw, uint32_t x_pixel)
78 {
79 	hw->cfg.v &= (~(JPEG_F_X_PIXEL_M << JPEG_F_X_PIXEL_S));
80 	hw->cfg.v |= ((x_pixel & JPEG_F_X_PIXEL_M) << JPEG_F_X_PIXEL_S);
81 }
82 
jpeg_ll_set_y_pixel(jpeg_hw_t * hw,uint32_t y_pixel)83 static inline void jpeg_ll_set_y_pixel(jpeg_hw_t *hw, uint32_t y_pixel)
84 {
85 	hw->cfg.v &= (~(JPEG_F_Y_PIXEL_M << JPEG_F_Y_PIXEL_S));
86 	hw->cfg.v |= ((y_pixel & JPEG_F_Y_PIXEL_M) << JPEG_F_Y_PIXEL_S);
87 }
88 
jpeg_ll_set_yuv_mode(jpeg_hw_t * hw,uint32_t mode)89 static inline void jpeg_ll_set_yuv_mode(jpeg_hw_t *hw, uint32_t mode)
90 {
91 	if (mode == 1)
92 		hw->cfg.yuvbuf_mode = 1;
93 	else
94 		hw->cfg.yuvbuf_mode = 0;
95 }
96 
jpeg_ll_enable_end_yuv_int(jpeg_hw_t * hw)97 static inline void jpeg_ll_enable_end_yuv_int(jpeg_hw_t *hw)
98 {
99 	hw->int_en.int_en |= BIT(0);
100 }
101 
jpeg_ll_disable_end_yuv_int(jpeg_hw_t * hw)102 static inline void jpeg_ll_disable_end_yuv_int(jpeg_hw_t *hw)
103 {
104 	hw->int_en.int_en &= ~BIT(0);
105 }
106 
jpeg_ll_enable_head_output_int(jpeg_hw_t * hw)107 static inline void jpeg_ll_enable_head_output_int(jpeg_hw_t *hw)
108 {
109 	hw->int_en.int_en |= BIT(1);
110 }
111 
jpeg_ll_disable_head_output_int(jpeg_hw_t * hw)112 static inline void jpeg_ll_disable_head_output_int(jpeg_hw_t *hw)
113 {
114 	hw->int_en.int_en &= ~BIT(1);
115 }
116 
jpeg_ll_enable_start_frame_int(jpeg_hw_t * hw)117 static inline void jpeg_ll_enable_start_frame_int(jpeg_hw_t *hw)
118 {
119 	hw->int_en.int_en |= BIT(2);
120 }
121 
jpeg_ll_disable_start_frame_int(jpeg_hw_t * hw)122 static inline void jpeg_ll_disable_start_frame_int(jpeg_hw_t *hw)
123 {
124 	hw->int_en.int_en &= ~BIT(2);
125 }
126 
jpeg_ll_enable_end_frame_int(jpeg_hw_t * hw)127 static inline void jpeg_ll_enable_end_frame_int(jpeg_hw_t *hw)
128 {
129 	hw->int_en.int_en |= BIT(3);
130 }
131 
jpeg_ll_disable_end_frame_int(jpeg_hw_t * hw)132 static inline void jpeg_ll_disable_end_frame_int(jpeg_hw_t *hw)
133 {
134 	hw->int_en.int_en &= ~BIT(3);
135 }
136 
jpeg_ll_enable_vsync_negedge_int(jpeg_hw_t * hw)137 static inline void jpeg_ll_enable_vsync_negedge_int(jpeg_hw_t *hw)
138 {
139 	hw->int_en.vsync_int_en = 1;
140 }
141 
jpeg_ll_disable_vsync_negedge_int(jpeg_hw_t * hw)142 static inline void jpeg_ll_disable_vsync_negedge_int(jpeg_hw_t *hw)
143 {
144 	hw->int_en.vsync_int_en =0;
145 }
146 
jpeg_ll_set_mclk_div(jpeg_hw_t * hw,uint32_t value)147 static inline void jpeg_ll_set_mclk_div(jpeg_hw_t *hw, uint32_t value)
148 {
149     hw->int_en.mclk_div = value;
150 }
151 
jpeg_ll_enable_enc_size(jpeg_hw_t * hw)152 static inline void jpeg_ll_enable_enc_size(jpeg_hw_t *hw)
153 {
154 	hw->cfg.jpeg_enc_size = 1;
155 }
156 
jpeg_ll_disable_enc_size(jpeg_hw_t * hw)157 static inline void jpeg_ll_disable_enc_size(jpeg_hw_t *hw)
158 {
159 	hw->cfg.jpeg_enc_size = 0;
160 }
161 
jpeg_ll_enable_yuv_word_reverse(jpeg_hw_t * hw)162 static inline void jpeg_ll_enable_yuv_word_reverse(jpeg_hw_t *hw)
163 {
164 	hw->cfg.yuv_word_reverse = 1;
165 }
166 
jpeg_ll_disable_yuv_word_reverse(jpeg_hw_t * hw)167 static inline void jpeg_ll_disable_yuv_word_reverse(jpeg_hw_t *hw)
168 {
169 	hw->cfg.yuv_word_reverse = 0;
170 }
171 
jpeg_ll_yuv_fml_sel(jpeg_hw_t * hw,uint32_t value)172 static inline void jpeg_ll_yuv_fml_sel(jpeg_hw_t *hw, uint32_t value)
173 {
174 	hw->cfg.yuv_fmt_sel = value;
175 }
176 
jpeg_ll_enable_video_byte_reverse(jpeg_hw_t * hw)177 static inline void jpeg_ll_enable_video_byte_reverse(jpeg_hw_t *hw)
178 {
179 	hw->cfg.video_byte_reverse = 1;
180 }
181 
jpeg_ll_disable_video_byte_reverse(jpeg_hw_t * hw)182 static inline void jpeg_ll_disable_video_byte_reverse(jpeg_hw_t *hw)
183 {
184 	hw->cfg.video_byte_reverse = 0;
185 }
186 
jpeg_ll_set_target_high_byte(jpeg_hw_t * hw,uint32_t high_byte)187 static inline void jpeg_ll_set_target_high_byte(jpeg_hw_t *hw, uint32_t high_byte)
188 {
189 	hw->target_byte_h = high_byte;
190 }
191 
jpeg_ll_get_target_high_byte(jpeg_hw_t * hw)192 static inline uint32_t jpeg_ll_get_target_high_byte(jpeg_hw_t *hw)
193 {
194 	return hw->target_byte_h;
195 }
196 
jpeg_ll_set_target_low_byte(jpeg_hw_t * hw,uint32_t low_byte)197 static inline void jpeg_ll_set_target_low_byte(jpeg_hw_t *hw, uint32_t low_byte)
198 {
199 	hw->target_byte_l = low_byte;
200 }
201 
jpeg_ll_get_target_low_byte(jpeg_hw_t * hw)202 static inline uint32_t jpeg_ll_get_target_low_byte(jpeg_hw_t *hw)
203 {
204 	return hw->target_byte_l;
205 }
206 
jpeg_ll_set_bitrate_step(jpeg_hw_t * hw,uint32_t step)207 static inline void jpeg_ll_set_bitrate_step(jpeg_hw_t *hw, uint32_t step)
208 {
209 	hw->cfg.bitrate_step = step;
210 }
211 
jpeg_ll_set_default_bitrate_step(jpeg_hw_t * hw)212 static inline void jpeg_ll_set_default_bitrate_step(jpeg_hw_t *hw)
213 {
214 	hw->cfg.bitrate_step = 3;
215 }
216 
jpeg_ll_set_bitrate_mode(jpeg_hw_t * hw,uint32_t mode)217 static inline void jpeg_ll_set_bitrate_mode(jpeg_hw_t *hw, uint32_t mode)
218 {
219 	hw->cfg.bitrate_mode = mode;
220 }
221 
jpeg_ll_enable_bitrate_ctrl(jpeg_hw_t * hw,uint32_t value)222 static inline void jpeg_ll_enable_bitrate_ctrl(jpeg_hw_t *hw, uint32_t value)
223 {
224 	hw->cfg.bitrate_ctrl = value;
225 }
226 
jpeg_ll_get_frame_byte_number(jpeg_hw_t * hw)227 static inline uint32_t jpeg_ll_get_frame_byte_number(jpeg_hw_t *hw)
228 {
229 	return hw->byte_count_pfrm;
230 }
231 
jpeg_ll_get_interrupt_status(jpeg_hw_t * hw)232 static inline uint32_t jpeg_ll_get_interrupt_status(jpeg_hw_t *hw)
233 {
234 	return hw->int_status.int_status;
235 }
236 
jpeg_ll_clear_interrupt_status(jpeg_hw_t * hw,uint32_t int_status)237 static inline void jpeg_ll_clear_interrupt_status(jpeg_hw_t *hw, uint32_t int_status)
238 {
239 	REG_WRITE(JPEG_R_INT_STATUS, int_status);
240 }
241 
jpeg_ll_is_frame_start_int_triggered(jpeg_hw_t * hw,uint32_t int_status)242 static inline bool jpeg_ll_is_frame_start_int_triggered(jpeg_hw_t *hw, uint32_t int_status)
243 {
244 	return int_status & BIT(0);
245 }
246 
jpeg_ll_is_frame_end_int_triggered(jpeg_hw_t * hw,uint32_t int_status)247 static inline bool jpeg_ll_is_frame_end_int_triggered(jpeg_hw_t *hw, uint32_t int_status)
248 {
249 	return int_status & BIT(1);
250 }
251 
jpeg_ll_is_head_output_int_triggered(jpeg_hw_t * hw,uint32_t int_status)252 static inline bool jpeg_ll_is_head_output_int_triggered(jpeg_hw_t *hw, uint32_t int_status)
253 {
254 	return int_status & BIT(2);
255 }
256 
jpeg_ll_is_yuv_end_int_triggered(jpeg_hw_t * hw,uint32_t int_status)257 static inline bool jpeg_ll_is_yuv_end_int_triggered(jpeg_hw_t *hw, uint32_t int_status)
258 {
259 	return int_status & BIT(3);
260 }
261 
jpeg_ll_is_vsync_negedge_int_triggered(jpeg_hw_t * hw,uint32_t int_status)262 static inline bool jpeg_ll_is_vsync_negedge_int_triggered(jpeg_hw_t *hw, uint32_t int_status)
263 {
264 	return int_status & BIT(4);
265 }
266 
jpeg_ll_set_em_base_addr(jpeg_hw_t * hw,uint32_t value)267 static inline void jpeg_ll_set_em_base_addr(jpeg_hw_t *hw, uint32_t value)
268 {
269 	hw->em_base_addr.em_base_addr = ((value >> 16) | (0x20 << 16));
270 }
271 
jpeg_ll_set_x_partial_offset_l(jpeg_hw_t * hw,uint32_t value)272 static inline void jpeg_ll_set_x_partial_offset_l(jpeg_hw_t *hw, uint32_t value)
273 {
274 	hw->x_partial.x_partial_offset_l = value;
275 }
276 
jpeg_ll_set_x_partial_offset_r(jpeg_hw_t * hw,uint32_t value)277 static inline void jpeg_ll_set_x_partial_offset_r(jpeg_hw_t *hw, uint32_t value)
278 {
279 	hw->x_partial.x_partial_offset_r = value;
280 }
281 
jpeg_ll_enable_partial_display(jpeg_hw_t * hw)282 static inline void jpeg_ll_enable_partial_display(jpeg_hw_t *hw)
283 {
284 	hw->x_partial.partial_display_en = 1;
285 }
286 
jpeg_ll_disable_partial_display(jpeg_hw_t * hw)287 static inline void jpeg_ll_disable_partial_display(jpeg_hw_t *hw)
288 {
289 	hw->x_partial.partial_display_en = 0;
290 }
291 
jpeg_ll_enable_sync_edge_dect(jpeg_hw_t * hw)292 static inline void jpeg_ll_enable_sync_edge_dect(jpeg_hw_t *hw)
293 {
294 	hw->x_partial.sync_edge_dect_en = 1;
295 }
296 
jpeg_ll_disable_sync_edge_dect(jpeg_hw_t * hw)297 static inline void jpeg_ll_disable_sync_edge_dect(jpeg_hw_t *hw)
298 {
299 	hw->x_partial.sync_edge_dect_en = 0;
300 }
301 
jpeg_ll_set_y_partial_offset_l(jpeg_hw_t * hw,uint32_t value)302 static inline void jpeg_ll_set_y_partial_offset_l(jpeg_hw_t *hw, uint32_t value)
303 {
304 	hw->y_partial.y_partial_offset_l = value;
305 }
306 
jpeg_ll_set_y_partial_offset_r(jpeg_hw_t * hw,uint32_t value)307 static inline void jpeg_ll_set_y_partial_offset_r(jpeg_hw_t *hw, uint32_t value)
308 {
309 	hw->y_partial.y_partial_offset_r = value;
310 }
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 
316