forked from squix78/m5cam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.h
178 lines (145 loc) · 5.17 KB
/
sensor.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
/*
* This file is part of the OpenMV project.
* Copyright (c) 2013/2014 Ibrahim Abdelkader <i.abdalkader@gmail.com>
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Sensor abstraction layer.
*
*/
#ifndef __SENSOR_H__
#define __SENSOR_H__
#include <stdint.h>
#define OV9650_PID (0x96)
#define OV2640_PID (0x26)
#define OV7725_PID (0x77)
typedef struct {
uint8_t MIDH;
uint8_t MIDL;
uint8_t PID;
uint8_t VER;
} sensor_id_t;
typedef enum {
PIXFORMAT_RGB565, // 2BPP/RGB565
PIXFORMAT_YUV422, // 2BPP/YUV422
PIXFORMAT_GRAYSCALE, // 1BPP/GRAYSCALE
PIXFORMAT_JPEG, // JPEG/COMPRESSED
} pixformat_t;
typedef enum {
FRAMESIZE_40x30, // 40x30
FRAMESIZE_64x32, // 64x32
FRAMESIZE_64x64, // 64x64
FRAMESIZE_QQCIF, // 88x72
FRAMESIZE_QQVGA, // 160x120
FRAMESIZE_QQVGA2, // 128x160
FRAMESIZE_QCIF, // 176x144
FRAMESIZE_HQVGA, // 220x160
FRAMESIZE_QVGA, // 320x240
FRAMESIZE_CIF, // 352x288
FRAMESIZE_VGA, // 640x480
FRAMESIZE_SVGA, // 800x600
FRAMESIZE_SXGA, // 1280x1024
FRAMESIZE_UXGA, // 1600x1200
} framesize_t;
typedef enum {
FRAMERATE_2FPS =0x9F,
FRAMERATE_8FPS =0x87,
FRAMERATE_15FPS=0x83,
FRAMERATE_30FPS=0x81,
FRAMERATE_60FPS=0x80,
} framerate_t;
typedef enum {
GAINCEILING_2X,
GAINCEILING_4X,
GAINCEILING_8X,
GAINCEILING_16X,
GAINCEILING_32X,
GAINCEILING_64X,
GAINCEILING_128X,
} gainceiling_t;
typedef enum {
SDE_NORMAL,
SDE_NEGATIVE,
} sde_t;
typedef enum {
ATTR_CONTRAST=0,
ATTR_BRIGHTNESS,
ATTR_SATURATION,
ATTR_GAINCEILING,
} sensor_attr_t;
typedef enum {
ACTIVE_LOW,
ACTIVE_HIGH
} reset_polarity_t;
typedef void (*line_filter_t) (uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, void *args);
#define SENSOR_HW_FLAGS_VSYNC (0) // vertical sync polarity.
#define SENSOR_HW_FLAGS_HSYNC (1) // horizontal sync polarity.
#define SENSOR_HW_FLAGS_PIXCK (2) // pixel clock edge.
#define SENSOR_HW_FLAGS_FSYNC (3) // hardware frame sync.
#define SENSOR_HW_FLAGS_JPEGE (4) // hardware JPEG encoder.
#define SENSOR_HW_FLAGS_GET(s, x) ((s)->hw_flags & (1<<x))
#define SENSOR_HW_FLAGS_SET(s, x, v) ((s)->hw_flags |= (v<<x))
#define SENSOR_HW_FLAGS_CLR(s, x) ((s)->hw_flags &= ~(1<<x))
typedef struct _sensor sensor_t;
typedef struct _sensor {
sensor_id_t id; // Sensor ID.
uint8_t slv_addr; // Sensor I2C slave address.
uint32_t hw_flags; // Hardware flags (clock polarities/hw capabilities)
// Line pre-processing function and args
void *line_filter_args;
line_filter_t line_filter_func;
reset_polarity_t reset_pol; // Reset polarity (TODO move to hw_flags)
// Sensor state
sde_t sde; // Special digital effects
pixformat_t pixformat; // Pixel format
framesize_t framesize; // Frame size
framerate_t framerate; // Frame rate
gainceiling_t gainceiling; // AGC gainceiling
// Sensor function pointers
int (*reset) (sensor_t *sensor);
int (*set_pixformat) (sensor_t *sensor, pixformat_t pixformat);
int (*set_framesize) (sensor_t *sensor, framesize_t framesize);
int (*set_framerate) (sensor_t *sensor, framerate_t framerate);
int (*set_contrast) (sensor_t *sensor, int level);
int (*set_brightness) (sensor_t *sensor, int level);
int (*set_saturation) (sensor_t *sensor, int level);
int (*set_gainceiling) (sensor_t *sensor, gainceiling_t gainceiling);
int (*set_quality) (sensor_t *sensor, int quality);
int (*set_colorbar) (sensor_t *sensor, int enable);
int (*set_whitebal) (sensor_t *sensor, int enable);
int (*set_gain_ctrl) (sensor_t *sensor, int enable);
int (*set_exposure_ctrl) (sensor_t *sensor, int enable);
int (*set_hmirror) (sensor_t *sensor, int enable);
int (*set_vflip) (sensor_t *sensor, int enable);
int (*set_special_effect) (sensor_t *sensor, sde_t sde);
} sensor_t;
// Resolution table
extern const int resolution[][2];
// Initialize the sensor hardware and probe the image sensor.
int sensor_init();
// Initialize the sensor state.
void sensor_init0();
// Reset the sensor to its default state.
int sensor_reset();
// Return sensor PID.
int sensor_get_id();
// Read a sensor register.
int sensor_read_reg(uint8_t reg);
// Write a sensor register.
int sensor_write_reg(uint8_t reg, uint8_t val);
// Set the sensor pixel format.
int sensor_set_pixformat(pixformat_t pixformat);
// Set the sensor frame size.
int sensor_set_framesize(framesize_t framesize);
// Enable/disable the colorbar mode.
int sensor_set_colorbar(int enable);
// Enable/disable the whitebal mode.
int sensor_set_whitebal(int enable);
// Enable/disable the agc mode.
int sensor_set_gain_ctrl(int enable);
// Enable/disable the aec mode.
int sensor_set_exposure_ctrl(int enable);
// Enable/disable the hmirror mode.
int sensor_set_hmirror(int enable);
// Enable/disable the vflip mode.
int sensor_set_vflip(int enable);
#endif /* __SENSOR_H__ */