1 /*
2  * Copyright  2017 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_CAMERA_DEVICE_H_
10 #define _FSL_CAMERA_DEVICE_H_
11 
12 #include "fsl_common.h"
13 #include "fsl_camera.h"
14 
15 /*******************************************************************************
16  * Definitions
17  ******************************************************************************/
18 typedef struct _camera_device_handle camera_device_handle_t;
19 
20 /*! @brief Camera device control command. */
21 typedef enum _camera_device_cmd
22 {
23     kCAMERA_DeviceAutoFocus, /*!< Auto focus. */
24 #define CAMERA_AUTO_FOCUS_ON  1
25 #define CAMERA_AUTO_FOCUS_OFF 0
26 
27     kCAMERA_DeviceLightMode, /*!< Light mode. */
28 #define CAMERA_LIGHT_MODE_AUTO   0
29 #define CAMERA_LIGHT_MODE_SUNNY  1
30 #define CAMERA_LIGHT_MODE_CLOUDY 2
31 #define CAMERA_LIGHT_MODE_OFFICE 3
32 #define CAMERA_LIGHT_MODE_HOME   4
33 #define CAMERA_LIGHT_MODE_NIGHT  5
34 
35     kCAMERA_DeviceSaturation, /*!< Saturation, pass in adjust value, such as -2, -1, 0, 1, 2... */
36     kCAMERA_DeviceBrightness, /*!< Brightness, pass in adjust value, such as -2, -1, 0, 1, 2... */
37     kCAMERA_DeviceContrast,   /*!< Contrast, pass in adjust value, such as -2, -1, 0, 1, 2... */
38 
39     kCAMERA_DeviceSpecialEffect,              /*!< Special effect. */
40 #define CAMERA_SPECIAL_EFFECT_NORMAL        0 /* Normal. */
41 #define CAMERA_SPECIAL_EFFECT_BW            1 /* B & W */
42 #define CAMERA_SPECIAL_EFFECT_SEPIA         2 /* Sepia. */
43 #define CAMERA_SPECIAL_EFFECT_BLUISH        3 /* Bluish. */
44 #define CAMERA_SPECIAL_EFFECT_REDISH        4 /* Redish. */
45 #define CAMERA_SPECIAL_EFFECT_GREENISH      5 /* Greenish. */
46 #define CAMERA_SPECIAL_EFFECT_NEGTIVE       6 /* Negtive. */
47 #define CAMERA_SPECIAL_EFFECT_OVER_EXPOSURE 7 /* OverExposure. */
48 #define CAMERA_SPECIAL_EFFECT_SOLARIZE      8 /* Solarize. */
49 
50     kCAMERA_DeviceNightMode,               /*!< Night mode. */
51 #define CAMERA_NIGHT_MODE_DISABLED       0 /* Disable. */
52 #define CAMERA_NIGHT_MODE_AUTO_FR_DIVBY2 1 /* Use automatic frame rate, max reduction to 1/2 frame rate. */
53 #define CAMERA_NIGHT_MODE_AUTO_FR_DIVBY4 4 /* Use automatic frame rate, max reduction to 1/4 frame rate. */
54 #define CAMERA_NIGHT_MODE_AUTO_FR_DIVBY8 8 /* Use automatic frame rate, max reduction to 1/8 frame rate. */
55 } camera_device_cmd_t;
56 
57 /*! @brief Camera device operations. */
58 typedef struct _camera_device_operations
59 {
60     status_t (*init)(camera_device_handle_t *handle, const camera_config_t *config);
61     status_t (*deinit)(camera_device_handle_t *handle);
62     status_t (*start)(camera_device_handle_t *handle);
63     status_t (*stop)(camera_device_handle_t *handle);
64     status_t (*control)(camera_device_handle_t *handle, camera_device_cmd_t cmd, int32_t arg);
65     status_t (*init_ext)(camera_device_handle_t *handle, const camera_config_t *config, const void *specialConfig);
66 } camera_device_operations_t;
67 
68 /*! @brief Camera device handle. */
69 struct _camera_device_handle
70 {
71     void *resource;                        /*!< The resource used by the camera device, it is device specific. */
72     const camera_device_operations_t *ops; /*!< The device related operations. */
73 };
74 
75 /*******************************************************************************
76  * API
77  ******************************************************************************/
78 
79 #if defined(__cplusplus)
80 extern "C" {
81 #endif
82 
83 /*!
84  * @brief Initialize the camera device.
85  *
86  * Initialize the camera device with the user defined configuration.
87  *
88  * @param handle Camera device handle.
89  * @param config Pointer to the configuration.
90  * @return Returns @ref kStatus_Success if initialize success, otherwise returns
91  * error code.
92  */
CAMERA_DEVICE_Init(camera_device_handle_t * handle,const camera_config_t * config)93 static inline status_t CAMERA_DEVICE_Init(camera_device_handle_t *handle, const camera_config_t *config)
94 {
95     return handle->ops->init(handle, config);
96 }
97 
98 /*!
99  * @brief Initialize the camera device with more specific configuration.
100  *
101  * This is an externed API of @ref CAMERA_DEVICE_Init, it allow upper layer to
102  * pass in device specific configuration. In this case, the
103  * @ref CAMERA_DEVICE_Init uses default specific configuration.
104  *
105  * @param handle Camera device handle.
106  * @param config Pointer to the configuration.
107  * @param specialConfig Pointer to the device specific configuration.
108  * @return Returns @ref kStatus_Success if initialize success, otherwise returns
109  * error code.
110  */
CAMERA_DEVICE_InitExt(camera_device_handle_t * handle,const camera_config_t * config,const void * specialConfig)111 static inline status_t CAMERA_DEVICE_InitExt(camera_device_handle_t *handle,
112                                              const camera_config_t *config,
113                                              const void *specialConfig)
114 {
115     return handle->ops->init_ext(handle, config, specialConfig);
116 }
117 
118 /*!
119  * @brief Deinitialize the camera device.
120  *
121  * @param handle Camera device handle.
122  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
123  */
CAMERA_DEVICE_Deinit(camera_device_handle_t * handle)124 static inline status_t CAMERA_DEVICE_Deinit(camera_device_handle_t *handle)
125 {
126     return handle->ops->deinit(handle);
127 }
128 
129 /*!
130  * @brief Control the camera device.
131  *
132  * @param handle Camera device handle.
133  * @param cmd Camera device command
134  * @param arg Argument for the command.
135  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
136  */
CAMERA_DEVICE_Control(camera_device_handle_t * handle,camera_device_cmd_t cmd,int32_t arg)137 static inline status_t CAMERA_DEVICE_Control(camera_device_handle_t *handle, camera_device_cmd_t cmd, int32_t arg)
138 {
139     return handle->ops->control(handle, cmd, arg);
140 }
141 
142 /*!
143  * @brief Start the camera device to output data.
144  *
145  * @param handle Camera device handle.
146  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
147  */
CAMERA_DEVICE_Start(camera_device_handle_t * handle)148 static inline status_t CAMERA_DEVICE_Start(camera_device_handle_t *handle)
149 {
150     return handle->ops->start(handle);
151 }
152 
153 /*!
154  * @brief Stop the camera device outputing data.
155  *
156  * @param handle Camera device handle.
157  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
158  */
CAMERA_DEVICE_Stop(camera_device_handle_t * handle)159 static inline status_t CAMERA_DEVICE_Stop(camera_device_handle_t *handle)
160 {
161     return handle->ops->stop(handle);
162 }
163 
164 #if defined(__cplusplus)
165 }
166 #endif
167 
168 #endif /* _FSL_CAMERA_DEVICE_H_ */
169