ARMEBS4  revision-26.06.2015
stm32_camera.h
Go to the documentation of this file.
1 /************************************************************************//**
2  * \file heivs/stm32_camera.h
3  *
4  * \brief Camera interface for stm32 processors
5  * \author marc dot pignat at hevs dot ch
6  *
7  * Camera driver for a camera with an i2c control interface, and
8  * parallel data out.
9  *
10  * The camera is connected to the DCMI and to an i2c bus.
11  * \defgroup camera Camera
12  * \ingroup onboard
13  * @{
14  ***************************************************************************/
15 #ifndef HEIVS_STM32_CAMERA_H
16 #define HEIVS_STM32_CAMERA_H
17 
18 #ifdef __cplusplus
19  extern "C" {
20 #endif
21 
22 #include <stdint.h>
23 #include <stddef.h>
24 #include "heivs/error.h"
25 #include "heivs/stm32_gpio.h"
26 #include "heivs/bus.h"
27 
28 enum camera_image_mode_e
29 {
30  IMAGE_MODE_NORMAL = 0,
31  IMAGE_MODE_MONO = 1,
32  IMAGE_MODE_SEPIA = 2,
33  IMAGE_MODE_NEGATIVE = 3,
34  IMAGE_MODE_SOLAR = 4,
35  IMAGE_MODE_SOLARUV = 5,
36 };
37 
38 enum camera_auto_exposure
39 {
40  EXP_AUTO = 1,
41  EXP_FIXED = 0,
42 };
43 
44 
45 enum camera_data_format_e
46 {
47  IMAGE_FORMAT_RGB565,
48 };
49 
50 struct camera_image_options_t
51 {
52  uint32_t xres;
53  uint32_t yres;
54  uint32_t frame_rate;
55  enum camera_data_format_e format;
56 
57  enum camera_image_mode_e mode;
58  enum camera_auto_exposure exposure;
59 };
60 
61 struct camera_t;
62 
63 struct camera_funcs_t
64 {
65  /**
66  * Initialize the camera (from reset or suspended)
67  */
68  status_e (*init)(const struct camera_t *cam);
69 
70  /**
71  * Suspend the camera (to a low power state).
72  * Wake up by init (COULD be long).
73  */
74  status_e (*suspend)(const struct camera_t *cam);
75 
76  /**
77  * Start the camera for at least nr images, infinite when nr = 0
78  *
79  * Optional function, can be NULL if the camera is always running
80  */
81  status_e (*start)(const struct camera_t *cam, uint32_t nr);
82 
83  /**
84  * Setup the camera with new options
85  *
86  * The camera must be already initialized
87  */
88  status_e (*setup)(const struct camera_t *cam);
89 
90  /**
91  * Pause the camera (if possible).
92  * Wake up by start (SHOULD be fast).
93  *
94  * Optional function, can be NULL
95  */
96  status_e (*pause)(const struct camera_t *cam);
97 };
98 
99 /**
100  * Camera structure
101  */
102 struct camera_t
103 {
104  const struct gpio_t *data_pins;
105  uint32_t data_pins_count;
106  const struct gpio_t *control_pins;
107  uint32_t control_pins_count;
108  uint32_t mco_frequency;
109  struct gpio_t mco_pin;
110 
111  struct camera_image_options_t *image_options;
112 
113  const struct camera_funcs_t *funcs;
114  const void *priv;
115 };
116 
117 /**
118  * \brief Initialize camera
119  *
120  * \param cam the camera
121  * \return #NO_ERROR for no problem
122  */
123 status_e camera_init(const struct camera_t *cam);
124 
125 /**
126  * \brief Camera setup
127  * \param cam the camera
128  * \param new_options the new options
129  * \return #NO_ERROR for no problem
130  */
131 status_e camera_setup(const struct camera_t *cam, const struct camera_image_options_t *new_options);
132 
133 /**
134  * \brief Camera take one shot
135  * \param cam the camera
136  * \param done_handler the handler when image is taken, can be NULL
137  * \param dst where to put the data
138  * \param size the size of the data
139  * \return #NO_ERROR for no problem
140  */
141 status_e camera_one_shot_start(const struct camera_t *cam, void (*done_handler)(status_e, const struct camera_t *), void *dst, size_t size);
142 
143 /**
144  * \brief Camera wait one shot finished
145  * \param cam the camera
146  * \return #NO_ERROR for no problem
147  */
148 status_e camera_one_shot_wait(const struct camera_t *cam);
149 
150 /**
151  * \brief Camera wait one shot status
152  * \return ::ERROR_AGAIN when not finished, #NO_ERROR for no problem
153  */
154 status_e camera_one_shot_status(const struct camera_t *cam);
155 
156 /**
157  * \brief Start continuous capture of camera images
158  * \param *cam the camera
159  * \param *next_handler
160  * \param *done_handler
161  * \param size
162  * \return #NO_ERROR for no problem
163  */
164 status_e camera_continuous_start(const struct camera_t *cam, void *(*next_handler)(const struct camera_t *), void (*done_handler)(status_e status, const struct camera_t *), size_t size);
165 
166 /**
167  * \brief Camera stop continous capture
168  * \return #NO_ERROR for no problem
169  */
170 status_e camera_continuous_stop(const struct camera_t *cam);
171 
172 /**
173  * \brief Compute image byte size using current parameters
174  * \return byte size of the image
175  */
176 uint32_t camera_get_image_size(const struct camera_t *cam);
177 
178 #ifdef __cplusplus
179  }
180 #endif
181 
182 /**
183  * @}
184  */
185 #endif /* HEIVS_STM32_CAMERA_H */
bus abstraction
status_e camera_continuous_start(const struct camera_t *cam, void *(*next_handler)(const struct camera_t *), void(*done_handler)(status_e status, const struct camera_t *), size_t size)
Start continuous capture of camera images.
Definition: stm32_camera.c:409
status_e camera_one_shot_status(const struct camera_t *cam)
Camera wait one shot status.
Definition: stm32_camera.c:472
static struct audio_setup_t setup
Definition: audio_stm32.c:90
status_e camera_one_shot_wait(const struct camera_t *cam)
Camera wait one shot finished.
Definition: stm32_camera.c:455
status_e camera_one_shot_start(const struct camera_t *cam, void(*done_handler)(status_e, const struct camera_t *), void *dst, size_t size)
Camera take one shot.
Definition: stm32_camera.c:485
Errors definitions.
status_e camera_init(const struct camera_t *cam)
Initialize camera.
Definition: stm32_camera.c:273
board specific defines
GPIO control structure.
Definition: stm32_gpio.h:96
status_e camera_continuous_stop(const struct camera_t *cam)
Camera stop continous capture.
Definition: stm32_camera.c:373
status_e camera_setup(const struct camera_t *cam, const struct camera_image_options_t *new_options)
Camera setup.
Definition: stm32_camera.c:342
uint32_t camera_get_image_size(const struct camera_t *cam)
Compute image byte size using current parameters.
Definition: stm32_camera.c:536
status_e
Known errors.
Definition: error.h:21