• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_OV5640_H
9 #define HPM_OV5640_H
10 
11 #include "hpm_common.h"
12 #include "hpm_camera_config.h"
13 
14 #define OV5640_ACTIVE_IMAGE_WIDTH  (2592U)
15 #define OV5640_ACTIVE_IMAGE_HEIGHT (1944U)
16 #define OV5640_I2C_ADDR (0x3CU)
17 #define OV5640_CHIP_ID_HIGH_BYTE_ADDR             (0x300A)
18 #define OV5640_CHIP_ID_HIGH_BYTE_VALUE            (0x56)
19 #define OV5640_CHIP_ID_LOW_BYTE_ADDR              (0x300B)
20 #define OV5640_CHIP_ID_LOW_BYTE_VALUE             (0x40)
21 
22 #define OV5640_RST_ACTIVE    0
23 #define OV5640_RST_INACTIVE  1
24 #define OV5640_PWDN_ACTIVE   1
25 #define OV5640_PWDN_INACTIVE 0
26 
27 /* Camera clock configuration elements. */
28 typedef struct {
29     uint32_t resolution;
30     uint8_t fps;
31     uint8_t pllctrl1;
32     uint8_t pllctrl2;
33     uint8_t vfifoctrl0c;
34     uint8_t pclkdiv;
35     uint8_t pclkperiod;
36 } ov5640_clock_config_t;
37 
38 typedef struct {
39     uint8_t lightmode;
40     uint8_t awbctrl;
41     uint8_t awbr_h;
42     uint8_t awbr_l;
43     uint8_t awbg_h;
44     uint8_t awbg_l;
45     uint8_t awbb_h;
46     uint8_t awbb_l;
47 } ov5640_light_mode_config_t;
48 
49 typedef struct {
50     uint8_t effect;
51     uint8_t sdectrl0;
52     uint8_t sdectrl3;
53     uint8_t sdectrl4;
54 } ov5640_special_effect_config_t;
55 
56 typedef struct {
57     uint16_t regaddr;
58     uint8_t regval;
59 } ov5640_reg_val_t;
60 
61 typedef struct {
62     uint32_t resolution; /*!< Resolution. */
63     ov5640_reg_val_t param[]; /*!< register value from 0x3800 to 0x3813. */
64 } ov5640_resolution_param_t;
65 
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 /*
72  * ov5640 initialization
73  */
74 hpm_stat_t ov5640_init(camera_context_t *context, camera_config_t *ov_config);
75 
76 /*
77  * ov5640 read register
78  */
79 hpm_stat_t ov5640_read_register(camera_context_t *context, uint16_t reg, uint8_t *buf);
80 
81 /*
82  * ov5640 write register
83  */
84 hpm_stat_t ov5640_write_register(camera_context_t *context, uint16_t reg, uint8_t val);
85 
86 /*
87  * ov5640 write multi register
88  */
89 hpm_stat_t ov5640_write_multi_registers(camera_context_t *context, const ov5640_reg_val_t regval[], uint32_t len);
90 
91 /*
92  * ov5640 softreset
93  */
94 hpm_stat_t ov5640_software_reset(camera_context_t *context);
95 
96 /*
97  * ov5640 set pixel format
98  */
99 hpm_stat_t ov5640_set_pixel_format(camera_context_t *context, display_pixel_format_t pixel_format);
100 
101 /*
102  * ov5640 check chip id
103  */
104 hpm_stat_t ov5640_check_chip_id(camera_context_t *context);
105 
106 /*
107  * ov5640 set image size
108  */
109 hpm_stat_t ov5640_set_image_size(camera_context_t *context, camera_config_t *ov_config);
110 
111 /*
112  * ov5640 set clock config
113  */
114 hpm_stat_t ov5640_set_clock_config(camera_context_t *context, camera_config_t *ov_config);
115 
116 /*
117  * ov5640 set interface
118  */
119 hpm_stat_t ov5640_set_interface(camera_context_t *context, camera_config_t *ov_config);
120 
121 /**
122  * @brief set ov5640 flip
123  *
124  * @param context @ref camera_context_t
125  * @return hpm_stat_t
126  */
127 hpm_stat_t ov5640_flip(camera_context_t *context);
128 
129 /*
130  * ov5640 start
131  */
132 hpm_stat_t ov5640_start(camera_context_t *context);
133 
134 /*
135  * ov5640 stop
136  */
137 hpm_stat_t ov5640_stop(camera_context_t *context);
138 
139 /*
140  * ov5640 set brightness
141  */
142 hpm_stat_t ov5640_set_brightness(camera_context_t *context, int32_t brightness);
143 
144 /*
145  * ov5640 set contrast
146  */
147 hpm_stat_t ov5640_set_contrast(camera_context_t *context, int32_t contrast);
148 
149 /*
150  * ov5640 set saturation
151  */
152 hpm_stat_t ov5640_set_saturation(camera_context_t *context, int32_t saturation);
153 
154 /*
155  * ov5640 set environment light mode
156  */
157 hpm_stat_t ov5640_set_light_mode(camera_context_t *context, int32_t lightmode);
158 
159 /*
160  * ov5640 set special effect
161  */
162 hpm_stat_t ov5640_set_special_effect(camera_context_t *context, int32_t effect);
163 
164 /**
165  * @brief ov5640 power up
166  *
167  * @param [in] context camera_context_t
168  */
169 void ov5640_power_up(camera_context_t *context);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif /* HPM_OV5640_H */
175