forked from analogdevicesinc/msdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.h
395 lines (348 loc) · 10.7 KB
/
camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/******************************************************************************
*
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
* Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef LIBRARIES_MISCDRIVERS_CAMERA_CAMERA_H_
#define LIBRARIES_MISCDRIVERS_CAMERA_CAMERA_H_
// includes
#include <stdio.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CAMERA_HM01B0)
#include "hm01b0_regs.h"
#elif defined(CAMERA_HM0360_MONO)
#include "hm0360_regs.h"
#elif defined(CAMERA_HM0360_COLOR)
#include "hm0360_regs.h"
#elif defined(CAMERA_OV5642)
#include "ov5642_regs.h"
#elif defined(CAMERA_OV5640)
#include "ov5640_regs.h"
#elif defined(CAMERA_OV7692)
#include "ov7692_regs.h"
#elif defined(CAMERA_PAG7920)
#include "pag7920_regs.h"
#endif
#include "debayering.h"
#include "tmr_regs.h"
#define STATUS_OK (0)
#define STATUS_ERROR (-1)
#define STATUS_ERROR_ALLOCATING (-10)
/******************************** Type Definitions ***************************/
typedef enum {
PIXFORMAT_INVALID = 0,
PIXFORMAT_GRAYSCALE, // 2BPP/GRAYSCALE
PIXFORMAT_RGB444, // 2BPP/RGB444
PIXFORMAT_RGB565, // 2BPP/RGB565
PIXFORMAT_RGB888, // 3BPP/RGB888 (expanded from rgb565 by camera interface hardware)
PIXFORMAT_YUV422, // 2BPP/YUV422
PIXFORMAT_BAYER, // 1BPP/RAW
} pixformat_t;
typedef enum { BIT_EXPAND_OFF, BIT_EXPAND_565_TO_888 } expandbitmode_t;
typedef enum {
FIFO_THREE_BYTE = 0,
FIFO_FOUR_BYTE,
} fifomode_t;
typedef enum { NO_DMA = 0, USE_DMA, STREAMING_DMA } dmamode_t;
typedef enum {
GAINCEILING_2X,
GAINCEILING_4X,
GAINCEILING_8X,
GAINCEILING_16X,
GAINCEILING_32X,
GAINCEILING_64X,
GAINCEILING_128X,
} gainceiling_t;
typedef struct _camera {
// Sensor function pointers
int (*init)(void);
int (*get_slave_address)(void);
int (*get_product_id)(int *id);
int (*get_manufacture_id)(int *id);
int (*dump_registers)(void);
int (*reset)(void);
int (*sleep)(int enable);
#if defined(CAMERA_HM01B0) || (CAMERA_HM0360_MONO) || (CAMERA_HM0360_COLOR) || \
defined(CAMERA_OV5642) || defined(CAMERA_OV5640)
int (*read_reg)(uint16_t reg_addr, uint8_t *reg_data);
int (*write_reg)(uint16_t reg_addr, uint8_t reg_data);
#else //(CAMERA_OV7692) || (CAMERA_PAG7920)
int (*read_reg)(uint8_t reg_addr, uint8_t *reg_data);
int (*write_reg)(uint8_t reg_addr, uint8_t reg_data);
#endif
int (*set_pixformat)(pixformat_t pixformat);
int (*get_pixformat)(pixformat_t *pixformat);
int (*set_framesize)(int width, int height);
int (*set_windowing)(int width, int height, int hsize, int vsize);
int (*set_contrast)(int level);
int (*set_brightness)(int level);
int (*set_saturation)(int level);
int (*set_gainceiling)(gainceiling_t gainceiling);
int (*set_colorbar)(int enable);
int (*set_hmirror)(int enable);
int (*set_vflip)(int enable);
int (*set_negateimage)(int enable);
int (*get_luminance)(int *lum);
} camera_t;
typedef struct _stream_stat {
uint32_t dma_transfer_count;
uint32_t overflow_count;
} stream_stat_t;
/******************************** Public Functions ***************************/
/**
* @brief Initialize the sensor hardware and probe the image sensor.
*
* @param freq Frequency for sensor initialization.
* @return 0 on success, otherwise an error code.
*/
int camera_init(uint32_t freq);
/**
* @brief Return sensor I2C slave address.
*
* @return Sensor I2C slave address.
*/
int camera_get_slave_address(void);
/**
* @brief Read the camera sensor's Product ID.
*
* @param id Pointer to store the Product ID.
* @return 0 on success, otherwise an error code.
*/
int camera_get_product_id(int *id);
/**
* @brief Read the camera sensor's Manufacturer ID.
*
* @param id Pointer to store the Manufacturer ID.
* @return 0 on success, otherwise an error code.
*/
int camera_get_manufacture_id(int *id);
/**
* @brief Dump all registers of the camera to 'printf'.
*
* @return 0 on success, otherwise an error code.
*/
int camera_dump_registers(void);
/**
* @brief Reset the sensor to its default state.
*
* @return 0 on success, otherwise an error code.
*/
int camera_reset(void);
/**
* @brief Set the sensor to sleep mode or wake it up.
*
* @param enable 1 to enable sleep mode, 0 to disable sleep mode.
* @return 0 on success, otherwise an error code.
*/
int camera_sleep(int enable);
/**
* @brief Shutdown the camera completely. Typically, this involves shutting down its power supply.
* All registers will be lost when.
*
* @param enable 1 to enable shutdown mode, 0 to disable.
* @return 0 on success, otherwise an error code.
*/
int camera_shutdown(int enable);
#if defined(CAMERA_HM01B0) || (CAMERA_HM0360_MONO) || (CAMERA_HM0360_COLOR) || \
defined(CAMERA_OV5642) || defined(CAMERA_OV5640)
/**
* @brief Write a sensor register.
*
* @param reg_addr Register address to write.
* @param reg_data Data to write to the register.
* @return 0 on success, otherwise an error code.
*/
int camera_write_reg(uint16_t reg_addr, uint8_t reg_data);
/**
* @brief Read a sensor register.
*
* @param reg_addr Register address to read.
* @param reg_data Pointer to store the read data.
* @return 0 on success, otherwise an error code.
*/
int camera_read_reg(uint16_t reg_addr, uint8_t *reg_data);
#else //(CAMERA_OV7692) || (CAMERA_PAG7920)
/**
* @brief Write a sensor register.
*
* @param reg_addr Register address to write.
* @param reg_data Data to write to the register.
* @return 0 on success, otherwise an error code.
*/
int camera_write_reg(uint8_t reg_addr, uint8_t reg_data);
/**
* @brief Read a sensor register.
*
* @param reg_addr Register address to read.
* @param reg_data Pointer to store the read data.
* @return 0 on success, otherwise an error code.
*/
int camera_read_reg(uint8_t reg_addr, uint8_t *reg_data);
#endif
/**
* @brief Set the sensor frame size and pixel format.
*
* @param width Frame width.
* @param height Frame height.
* @param pixformat Pixel format.
* @return 0 on success, otherwise an error code.
*/
int camera_set_frame_info(int width, int height, pixformat_t pixformat);
/**
* @brief Setup the camera parameters for capturing.
*
* @param xres X resolution.
* @param yres Y resolution.
* @param pixformat Pixel format.
* @param fifo_mode FIFO mode.
* @param dma_mode DMA mode.
* @param dma_channel DMA channel.
* @return 0 on success, otherwise an error code.
*/
int camera_setup(int xres, int yres, pixformat_t pixformat, fifomode_t fifo_mode,
dmamode_t dma_mode, int dma_channel);
/**
* @brief Setup the camera parameters for capturing and stream to TFT.
*
* @param xres X resolution.
* @param yres Y resolution.
* @param pixformat Pixel format.
* @param fifo_mode FIFO mode.
* @param dma_mode DMA mode.
* @param dma_channel DMA channel.
* @return 0 on success, otherwise an error code.
*/
int camera_setup_tft(int xres, int yres, pixformat_t pixformat, fifomode_t fifo_mode,
dmamode_t dma_mode, int dma_channel);
/**
* @brief Set the sensor contrast level.
*
* @param level Contrast level.
* @return 0 on success, otherwise an error code.
*/
int camera_set_contrast(int level);
/**
* @brief Set the sensor brightness level.
*
* @param level Brightness level.
* @return 0 on success, otherwise an error code.
*/
int camera_set_brightness(int level);
/**
* @brief Set the sensor saturation level.
*
* @param level Saturation level.
* @return 0 on success, otherwise an error code.
*/
int camera_set_saturation(int level);
/**
* @brief Set the sensor AGC gain ceiling.
*
* @param gainceiling AGC gain ceiling.
* @return 0 on success, otherwise an error code.
*/
int camera_set_gainceiling(gainceiling_t gainceiling);
/**
* @brief Enable/disable the colorbar mode.
*
* @param enable 1 to enable colorbar, 0 to disable.
* @return 0 on success, otherwise an error code.
*/
int camera_set_colorbar(int enable);
/**
* @brief Enable/disable the horizontal mirror mode.
*
* @param enable 1 to enable horizontal mirror, 0 to disable.
* @return 0 on success, otherwise an error code.
*/
int camera_set_hmirror(int enable);
/**
* @brief Enable/disable the vertical flip mode.
*
* @param enable 1 to enable vertical flip, 0 to disable.
* @return 0 on success, otherwise an error code.
*/
int camera_set_vflip(int enable);
/**
* @brief Start capturing an image.
*
* @return 0 on success, otherwise an error code.
*/
int camera_start_capture_image(void);
/**
* @brief Start capturing an image and stream to TFT.
*
* @return 0 on success, otherwise an error code.
*/
int camera_start_capture_image_tft(void);
/**
* @brief Check whether all image data has been received.
*
* @return 1 if image data received, 0 otherwise.
*/
int camera_is_image_rcv(void);
/**
* @brief Retrieve the camera pixel format.
*
* @return Pointer to the camera pixel format.
*/
uint8_t *camera_get_pixel_format(void);
/**
* @brief Get a pointer to the camera frame buffer, image length, and resolution.
*
* @param img Pointer to store the image buffer.
* @param imgLen Pointer to store the image length.
* @param w Pointer to store the image width.
* @param h Pointer to store the image height.
*/
void camera_get_image(uint8_t **img, uint32_t *imgLen, uint32_t *w, uint32_t *h);
/**
* @brief Get luminance level from the camera.
*
* @param lum Pointer to store the luminance level.
* @return 0 on success, otherwise an error code.
*/
int camera_get_luminance_level(int *lum);
/**
* @brief Get a pointer to the camera streaming buffer.
*
* @return Pointer to the camera streaming buffer.
*/
uint8_t *get_camera_stream_buffer(void);
/**
* @brief Get the size of the camera streaming buffer (in bytes).
*
* @return Size of the camera streaming buffer.
*/
int camera_get_stream_buffer_size(void);
/**
* @brief Release the camera streaming buffer.
*/
void release_camera_stream_buffer(void);
/**
* @brief Get statistics of DMA streaming mode.
*
* @return Pointer to the structure containing DMA streaming statistics.
*/
stream_stat_t *get_camera_stream_statistic(void);
#ifdef __cplusplus
}
#endif
#endif // LIBRARIES_MISCDRIVERS_CAMERA_CAMERA_H_