OV7670 Support
Fork of BSP_DISCO_F746NG by
Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_camera.c@10:27e6daa4f2fe, 2017-03-20 (annotated)
- Committer:
- buyukesmeli
- Date:
- Mon Mar 20 10:19:17 2017 +0000
- Revision:
- 10:27e6daa4f2fe
- Parent:
- 9:cd90418a750e
Camera interrupt added
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bcostm | 6:e1d9da7fe856 | 1 | /** |
| bcostm | 6:e1d9da7fe856 | 2 | ****************************************************************************** |
| bcostm | 6:e1d9da7fe856 | 3 | * @file stm32746g_discovery_camera.c |
| bcostm | 6:e1d9da7fe856 | 4 | * @author MCD Application Team |
| bcostm | 6:e1d9da7fe856 | 5 | * @version V1.1.1 |
| bcostm | 6:e1d9da7fe856 | 6 | * @date 02-June-2016 |
| bcostm | 6:e1d9da7fe856 | 7 | * @brief This file includes the driver for Camera modules mounted on |
| bcostm | 6:e1d9da7fe856 | 8 | * STM32746G-Discovery board. |
| bcostm | 6:e1d9da7fe856 | 9 | @verbatim |
| bcostm | 6:e1d9da7fe856 | 10 | How to use this driver: |
| bcostm | 6:e1d9da7fe856 | 11 | ------------------------ |
| bcostm | 6:e1d9da7fe856 | 12 | - This driver is used to drive the camera. |
| bcostm | 6:e1d9da7fe856 | 13 | - The OV9655 component driver MUST be included with this driver. |
| bcostm | 6:e1d9da7fe856 | 14 | |
| bcostm | 6:e1d9da7fe856 | 15 | Driver description: |
| bcostm | 6:e1d9da7fe856 | 16 | ------------------- |
| bcostm | 6:e1d9da7fe856 | 17 | + Initialization steps: |
| bcostm | 6:e1d9da7fe856 | 18 | o Initialize the camera using the BSP_CAMERA_Init() function. |
| bcostm | 6:e1d9da7fe856 | 19 | o Start the camera capture/snapshot using the CAMERA_Start() function. |
| bcostm | 6:e1d9da7fe856 | 20 | o Suspend, resume or stop the camera capture using the following functions: |
| bcostm | 6:e1d9da7fe856 | 21 | - BSP_CAMERA_Suspend() |
| bcostm | 6:e1d9da7fe856 | 22 | - BSP_CAMERA_Resume() |
| bcostm | 6:e1d9da7fe856 | 23 | - BSP_CAMERA_Stop() |
| bcostm | 6:e1d9da7fe856 | 24 | |
| bcostm | 6:e1d9da7fe856 | 25 | + Options |
| bcostm | 6:e1d9da7fe856 | 26 | o Increase or decrease on the fly the brightness and/or contrast |
| bcostm | 6:e1d9da7fe856 | 27 | using the following function: |
| bcostm | 6:e1d9da7fe856 | 28 | - BSP_CAMERA_ContrastBrightnessConfig |
| bcostm | 6:e1d9da7fe856 | 29 | o Add a special effect on the fly using the following functions: |
| bcostm | 6:e1d9da7fe856 | 30 | - BSP_CAMERA_BlackWhiteConfig() |
| bcostm | 6:e1d9da7fe856 | 31 | - BSP_CAMERA_ColorEffectConfig() |
| bcostm | 6:e1d9da7fe856 | 32 | @endverbatim |
| bcostm | 6:e1d9da7fe856 | 33 | ****************************************************************************** |
| bcostm | 6:e1d9da7fe856 | 34 | * @attention |
| bcostm | 6:e1d9da7fe856 | 35 | * |
| bcostm | 6:e1d9da7fe856 | 36 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
| bcostm | 6:e1d9da7fe856 | 37 | * |
| bcostm | 6:e1d9da7fe856 | 38 | * Redistribution and use in source and binary forms, with or without modification, |
| bcostm | 6:e1d9da7fe856 | 39 | * are permitted provided that the following conditions are met: |
| bcostm | 6:e1d9da7fe856 | 40 | * 1. Redistributions of source code must retain the above copyright notice, |
| bcostm | 6:e1d9da7fe856 | 41 | * this list of conditions and the following disclaimer. |
| bcostm | 6:e1d9da7fe856 | 42 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| bcostm | 6:e1d9da7fe856 | 43 | * this list of conditions and the following disclaimer in the documentation |
| bcostm | 6:e1d9da7fe856 | 44 | * and/or other materials provided with the distribution. |
| bcostm | 6:e1d9da7fe856 | 45 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| bcostm | 6:e1d9da7fe856 | 46 | * may be used to endorse or promote products derived from this software |
| bcostm | 6:e1d9da7fe856 | 47 | * without specific prior written permission. |
| bcostm | 6:e1d9da7fe856 | 48 | * |
| bcostm | 6:e1d9da7fe856 | 49 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| bcostm | 6:e1d9da7fe856 | 50 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| bcostm | 6:e1d9da7fe856 | 51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| bcostm | 6:e1d9da7fe856 | 52 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| bcostm | 6:e1d9da7fe856 | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| bcostm | 6:e1d9da7fe856 | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| bcostm | 6:e1d9da7fe856 | 55 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| bcostm | 6:e1d9da7fe856 | 56 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| bcostm | 6:e1d9da7fe856 | 57 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| bcostm | 6:e1d9da7fe856 | 58 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| bcostm | 6:e1d9da7fe856 | 59 | * |
| bcostm | 6:e1d9da7fe856 | 60 | ****************************************************************************** |
| bcostm | 6:e1d9da7fe856 | 61 | */ |
| bcostm | 6:e1d9da7fe856 | 62 | |
| bcostm | 6:e1d9da7fe856 | 63 | /* Includes ------------------------------------------------------------------*/ |
| bcostm | 6:e1d9da7fe856 | 64 | #include "stm32746g_discovery_camera.h" |
| bcostm | 6:e1d9da7fe856 | 65 | #include "stm32746g_discovery.h" |
| bcostm | 6:e1d9da7fe856 | 66 | |
| bcostm | 6:e1d9da7fe856 | 67 | /** @addtogroup BSP |
| bcostm | 6:e1d9da7fe856 | 68 | * @{ |
| bcostm | 6:e1d9da7fe856 | 69 | */ |
| bcostm | 6:e1d9da7fe856 | 70 | |
| bcostm | 6:e1d9da7fe856 | 71 | /** @addtogroup STM32746G_DISCOVERY |
| bcostm | 6:e1d9da7fe856 | 72 | * @{ |
| bcostm | 6:e1d9da7fe856 | 73 | */ |
| bcostm | 6:e1d9da7fe856 | 74 | |
| bcostm | 6:e1d9da7fe856 | 75 | /** @addtogroup STM32746G_DISCOVERY_CAMERA |
| bcostm | 6:e1d9da7fe856 | 76 | * @{ |
| bcostm | 6:e1d9da7fe856 | 77 | */ |
| bcostm | 6:e1d9da7fe856 | 78 | |
| bcostm | 6:e1d9da7fe856 | 79 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Private_TypesDefinitions STM32746G_DISCOVERY_CAMERA Private Types Definitions |
| bcostm | 6:e1d9da7fe856 | 80 | * @{ |
| bcostm | 6:e1d9da7fe856 | 81 | */ |
| bcostm | 6:e1d9da7fe856 | 82 | /** |
| bcostm | 6:e1d9da7fe856 | 83 | * @} |
| bcostm | 6:e1d9da7fe856 | 84 | */ |
| bcostm | 6:e1d9da7fe856 | 85 | |
| bcostm | 6:e1d9da7fe856 | 86 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Private_Defines STM32746G_DISCOVERY_CAMERA Private Defines |
| bcostm | 6:e1d9da7fe856 | 87 | * @{ |
| bcostm | 6:e1d9da7fe856 | 88 | */ |
| bcostm | 6:e1d9da7fe856 | 89 | #define CAMERA_VGA_RES_X 640 |
| bcostm | 6:e1d9da7fe856 | 90 | #define CAMERA_VGA_RES_Y 480 |
| bcostm | 6:e1d9da7fe856 | 91 | #define CAMERA_480x272_RES_X 480 |
| bcostm | 6:e1d9da7fe856 | 92 | #define CAMERA_480x272_RES_Y 272 |
| bcostm | 6:e1d9da7fe856 | 93 | #define CAMERA_QVGA_RES_X 320 |
| bcostm | 6:e1d9da7fe856 | 94 | #define CAMERA_QVGA_RES_Y 240 |
| bcostm | 6:e1d9da7fe856 | 95 | #define CAMERA_QQVGA_RES_X 160 |
| bcostm | 6:e1d9da7fe856 | 96 | #define CAMERA_QQVGA_RES_Y 120 |
| bcostm | 6:e1d9da7fe856 | 97 | /** |
| bcostm | 6:e1d9da7fe856 | 98 | * @} |
| bcostm | 6:e1d9da7fe856 | 99 | */ |
| bcostm | 6:e1d9da7fe856 | 100 | |
| bcostm | 6:e1d9da7fe856 | 101 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Private_Macros STM32746G_DISCOVERY_CAMERA Private Macros |
| bcostm | 6:e1d9da7fe856 | 102 | * @{ |
| bcostm | 6:e1d9da7fe856 | 103 | */ |
| bcostm | 6:e1d9da7fe856 | 104 | /** |
| bcostm | 6:e1d9da7fe856 | 105 | * @} |
| bcostm | 6:e1d9da7fe856 | 106 | */ |
| bcostm | 6:e1d9da7fe856 | 107 | |
| bcostm | 6:e1d9da7fe856 | 108 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Private_Variables STM32746G_DISCOVERY_CAMERA Private Variables |
| bcostm | 6:e1d9da7fe856 | 109 | * @{ |
| bcostm | 6:e1d9da7fe856 | 110 | */ |
| bcostm | 6:e1d9da7fe856 | 111 | DCMI_HandleTypeDef hDcmiHandler; |
| bcostm | 6:e1d9da7fe856 | 112 | CAMERA_DrvTypeDef *camera_drv; |
| bcostm | 6:e1d9da7fe856 | 113 | /* Camera current resolution naming (QQVGA, VGA, ...) */ |
| bcostm | 6:e1d9da7fe856 | 114 | static uint32_t CameraCurrentResolution; |
| bcostm | 6:e1d9da7fe856 | 115 | |
| bcostm | 6:e1d9da7fe856 | 116 | /* Camera module I2C HW address */ |
| buyukesmeli | 9:cd90418a750e | 117 | //static uint32_t CameraHwAddress; |
| buyukesmeli | 9:cd90418a750e | 118 | uint32_t CameraHwAddress; |
| bcostm | 6:e1d9da7fe856 | 119 | /** |
| bcostm | 6:e1d9da7fe856 | 120 | * @} |
| bcostm | 6:e1d9da7fe856 | 121 | */ |
| bcostm | 6:e1d9da7fe856 | 122 | |
| bcostm | 6:e1d9da7fe856 | 123 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Private_FunctionPrototypes STM32746G_DISCOVERY_CAMERA Private Function Prototypes |
| bcostm | 6:e1d9da7fe856 | 124 | * @{ |
| bcostm | 6:e1d9da7fe856 | 125 | */ |
| bcostm | 6:e1d9da7fe856 | 126 | static uint32_t GetSize(uint32_t resolution); |
| bcostm | 6:e1d9da7fe856 | 127 | /** |
| bcostm | 6:e1d9da7fe856 | 128 | * @} |
| bcostm | 6:e1d9da7fe856 | 129 | */ |
| bcostm | 6:e1d9da7fe856 | 130 | |
| bcostm | 6:e1d9da7fe856 | 131 | /** @defgroup STM32746G_DISCOVERY_CAMERA_Exported_Functions STM32746G_DISCOVERY_CAMERA Exported Functions |
| bcostm | 6:e1d9da7fe856 | 132 | * @{ |
| bcostm | 6:e1d9da7fe856 | 133 | */ |
| bcostm | 6:e1d9da7fe856 | 134 | |
| bcostm | 6:e1d9da7fe856 | 135 | /** |
| bcostm | 6:e1d9da7fe856 | 136 | * @brief Initializes the camera. |
| bcostm | 6:e1d9da7fe856 | 137 | * @param Resolution : camera sensor requested resolution (x, y) : standard resolution |
| bcostm | 6:e1d9da7fe856 | 138 | * naming QQVGA, QVGA, VGA ... |
| bcostm | 6:e1d9da7fe856 | 139 | * @retval Camera status |
| bcostm | 6:e1d9da7fe856 | 140 | */ |
| bcostm | 6:e1d9da7fe856 | 141 | uint8_t BSP_CAMERA_Init(uint32_t Resolution) |
| bcostm | 6:e1d9da7fe856 | 142 | { |
| buyukesmeli | 8:ff634d7a9d9f | 143 | |
| bcostm | 6:e1d9da7fe856 | 144 | DCMI_HandleTypeDef *phdcmi; |
| bcostm | 6:e1d9da7fe856 | 145 | uint8_t status = CAMERA_ERROR; |
| bcostm | 6:e1d9da7fe856 | 146 | |
| bcostm | 6:e1d9da7fe856 | 147 | /* Get the DCMI handle structure */ |
| bcostm | 6:e1d9da7fe856 | 148 | phdcmi = &hDcmiHandler; |
| bcostm | 6:e1d9da7fe856 | 149 | |
| bcostm | 6:e1d9da7fe856 | 150 | /*** Configures the DCMI to interface with the camera module ***/ |
| bcostm | 6:e1d9da7fe856 | 151 | /* DCMI configuration */ |
| bcostm | 6:e1d9da7fe856 | 152 | phdcmi->Init.CaptureRate = DCMI_CR_ALL_FRAME; |
| bcostm | 6:e1d9da7fe856 | 153 | phdcmi->Init.HSPolarity = DCMI_HSPOLARITY_LOW; |
| bcostm | 6:e1d9da7fe856 | 154 | phdcmi->Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; |
| bcostm | 6:e1d9da7fe856 | 155 | phdcmi->Init.VSPolarity = DCMI_VSPOLARITY_HIGH; |
| bcostm | 6:e1d9da7fe856 | 156 | phdcmi->Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; |
| bcostm | 6:e1d9da7fe856 | 157 | phdcmi->Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; |
| bcostm | 6:e1d9da7fe856 | 158 | phdcmi->Instance = DCMI; |
| bcostm | 6:e1d9da7fe856 | 159 | |
| bcostm | 6:e1d9da7fe856 | 160 | /* Power up camera */ |
| bcostm | 6:e1d9da7fe856 | 161 | BSP_CAMERA_PwrUp(); |
| bcostm | 6:e1d9da7fe856 | 162 | |
| bcostm | 6:e1d9da7fe856 | 163 | /* Read ID of Camera module via I2C */ |
| bcostm | 6:e1d9da7fe856 | 164 | if(ov9655_ReadID(CAMERA_I2C_ADDRESS) == OV9655_ID) |
| bcostm | 6:e1d9da7fe856 | 165 | { |
| bcostm | 6:e1d9da7fe856 | 166 | /* Initialize the camera driver structure */ |
| bcostm | 6:e1d9da7fe856 | 167 | camera_drv = &ov9655_drv; |
| bcostm | 6:e1d9da7fe856 | 168 | CameraHwAddress = CAMERA_I2C_ADDRESS; |
| bcostm | 6:e1d9da7fe856 | 169 | |
| bcostm | 6:e1d9da7fe856 | 170 | /* DCMI Initialization */ |
| bcostm | 6:e1d9da7fe856 | 171 | BSP_CAMERA_MspInit(&hDcmiHandler, NULL); |
| bcostm | 6:e1d9da7fe856 | 172 | HAL_DCMI_Init(phdcmi); |
| bcostm | 6:e1d9da7fe856 | 173 | |
| bcostm | 6:e1d9da7fe856 | 174 | /* Camera Module Initialization via I2C to the wanted 'Resolution' */ |
| bcostm | 6:e1d9da7fe856 | 175 | if (Resolution == CAMERA_R480x272) |
| bcostm | 6:e1d9da7fe856 | 176 | { /* For 480x272 resolution, the OV9655 sensor is set to VGA resolution |
| bcostm | 6:e1d9da7fe856 | 177 | * as OV9655 doesn't supports 480x272 resolution, |
| bcostm | 6:e1d9da7fe856 | 178 | * then DCMI is configured to output a 480x272 cropped window */ |
| bcostm | 6:e1d9da7fe856 | 179 | camera_drv->Init(CameraHwAddress, CAMERA_R640x480); |
| bcostm | 6:e1d9da7fe856 | 180 | HAL_DCMI_ConfigCROP(phdcmi, /* Crop in the middle of the VGA picture */ |
| bcostm | 6:e1d9da7fe856 | 181 | (CAMERA_VGA_RES_X - CAMERA_480x272_RES_X)/2, |
| bcostm | 6:e1d9da7fe856 | 182 | (CAMERA_VGA_RES_Y - CAMERA_480x272_RES_Y)/2, |
| bcostm | 6:e1d9da7fe856 | 183 | (CAMERA_480x272_RES_X * 2) - 1, |
| bcostm | 6:e1d9da7fe856 | 184 | CAMERA_480x272_RES_Y - 1); |
| bcostm | 6:e1d9da7fe856 | 185 | HAL_DCMI_EnableCROP(phdcmi); |
| bcostm | 6:e1d9da7fe856 | 186 | } |
| bcostm | 6:e1d9da7fe856 | 187 | else |
| bcostm | 6:e1d9da7fe856 | 188 | { |
| bcostm | 6:e1d9da7fe856 | 189 | camera_drv->Init(CameraHwAddress, Resolution); |
| bcostm | 6:e1d9da7fe856 | 190 | HAL_DCMI_DisableCROP(phdcmi); |
| bcostm | 6:e1d9da7fe856 | 191 | } |
| bcostm | 6:e1d9da7fe856 | 192 | |
| bcostm | 6:e1d9da7fe856 | 193 | CameraCurrentResolution = Resolution; |
| bcostm | 6:e1d9da7fe856 | 194 | |
| bcostm | 6:e1d9da7fe856 | 195 | /* Return CAMERA_OK status */ |
| bcostm | 6:e1d9da7fe856 | 196 | status = CAMERA_OK; |
| bcostm | 6:e1d9da7fe856 | 197 | } |
| buyukesmeli | 8:ff634d7a9d9f | 198 | |
| buyukesmeli | 8:ff634d7a9d9f | 199 | else if(ov7670_ReadID(CAMERA_OV7670_I2C_ADDRESS) == OV7670_ID) |
| buyukesmeli | 8:ff634d7a9d9f | 200 | { |
| buyukesmeli | 8:ff634d7a9d9f | 201 | /* Initialize the camera driver structure */ |
| buyukesmeli | 8:ff634d7a9d9f | 202 | camera_drv = &ov7670_drv; |
| buyukesmeli | 8:ff634d7a9d9f | 203 | CameraHwAddress = CAMERA_OV7670_I2C_ADDRESS; |
| buyukesmeli | 8:ff634d7a9d9f | 204 | |
| buyukesmeli | 8:ff634d7a9d9f | 205 | /* DCMI Initialization */ |
| buyukesmeli | 8:ff634d7a9d9f | 206 | BSP_CAMERA_MspInit(&hDcmiHandler, NULL); |
| buyukesmeli | 8:ff634d7a9d9f | 207 | HAL_DCMI_Init(phdcmi); |
| buyukesmeli | 8:ff634d7a9d9f | 208 | |
| buyukesmeli | 8:ff634d7a9d9f | 209 | /* Camera Module Initialization via I2C to the wanted 'Resolution' */ |
| buyukesmeli | 8:ff634d7a9d9f | 210 | if (Resolution == CAMERA_R480x272) |
| buyukesmeli | 8:ff634d7a9d9f | 211 | { /* For 480x272 resolution, the OV9655 sensor is set to VGA resolution |
| buyukesmeli | 8:ff634d7a9d9f | 212 | * as OV9655 doesn't supports 480x272 resolution, |
| buyukesmeli | 8:ff634d7a9d9f | 213 | * then DCMI is configured to output a 480x272 cropped window */ |
| buyukesmeli | 8:ff634d7a9d9f | 214 | camera_drv->Init(CameraHwAddress, CAMERA_R640x480); |
| buyukesmeli | 8:ff634d7a9d9f | 215 | HAL_DCMI_ConfigCROP(phdcmi, /* Crop in the middle of the VGA picture */ |
| buyukesmeli | 8:ff634d7a9d9f | 216 | (CAMERA_VGA_RES_X - CAMERA_480x272_RES_X)/2, |
| buyukesmeli | 8:ff634d7a9d9f | 217 | (CAMERA_VGA_RES_Y - CAMERA_480x272_RES_Y)/2, |
| buyukesmeli | 8:ff634d7a9d9f | 218 | (CAMERA_480x272_RES_X * 2) - 1, |
| buyukesmeli | 8:ff634d7a9d9f | 219 | CAMERA_480x272_RES_Y - 1); |
| buyukesmeli | 8:ff634d7a9d9f | 220 | HAL_DCMI_EnableCROP(phdcmi); |
| buyukesmeli | 8:ff634d7a9d9f | 221 | } |
| buyukesmeli | 8:ff634d7a9d9f | 222 | else |
| buyukesmeli | 8:ff634d7a9d9f | 223 | { |
| buyukesmeli | 8:ff634d7a9d9f | 224 | camera_drv->Init(CameraHwAddress, Resolution); |
| buyukesmeli | 8:ff634d7a9d9f | 225 | HAL_DCMI_DisableCROP(phdcmi); |
| buyukesmeli | 8:ff634d7a9d9f | 226 | } |
| buyukesmeli | 8:ff634d7a9d9f | 227 | |
| buyukesmeli | 8:ff634d7a9d9f | 228 | CameraCurrentResolution = Resolution; |
| buyukesmeli | 8:ff634d7a9d9f | 229 | |
| buyukesmeli | 8:ff634d7a9d9f | 230 | /* Return CAMERA_OK status */ |
| buyukesmeli | 8:ff634d7a9d9f | 231 | status = CAMERA_OK; |
| buyukesmeli | 8:ff634d7a9d9f | 232 | } |
| buyukesmeli | 8:ff634d7a9d9f | 233 | |
| bcostm | 6:e1d9da7fe856 | 234 | else |
| bcostm | 6:e1d9da7fe856 | 235 | { |
| bcostm | 6:e1d9da7fe856 | 236 | /* Return CAMERA_NOT_SUPPORTED status */ |
| bcostm | 6:e1d9da7fe856 | 237 | status = CAMERA_NOT_SUPPORTED; |
| bcostm | 6:e1d9da7fe856 | 238 | } |
| bcostm | 6:e1d9da7fe856 | 239 | |
| bcostm | 6:e1d9da7fe856 | 240 | return status; |
| bcostm | 6:e1d9da7fe856 | 241 | } |
| bcostm | 6:e1d9da7fe856 | 242 | |
| bcostm | 6:e1d9da7fe856 | 243 | /** |
| bcostm | 6:e1d9da7fe856 | 244 | * @brief DeInitializes the camera. |
| bcostm | 6:e1d9da7fe856 | 245 | * @retval Camera status |
| bcostm | 6:e1d9da7fe856 | 246 | */ |
| bcostm | 6:e1d9da7fe856 | 247 | uint8_t BSP_CAMERA_DeInit(void) |
| bcostm | 6:e1d9da7fe856 | 248 | { |
| bcostm | 6:e1d9da7fe856 | 249 | hDcmiHandler.Instance = DCMI; |
| bcostm | 6:e1d9da7fe856 | 250 | |
| bcostm | 6:e1d9da7fe856 | 251 | HAL_DCMI_DeInit(&hDcmiHandler); |
| bcostm | 6:e1d9da7fe856 | 252 | BSP_CAMERA_MspDeInit(&hDcmiHandler, NULL); |
| bcostm | 6:e1d9da7fe856 | 253 | return CAMERA_OK; |
| bcostm | 6:e1d9da7fe856 | 254 | } |
| bcostm | 6:e1d9da7fe856 | 255 | |
| bcostm | 6:e1d9da7fe856 | 256 | /** |
| bcostm | 6:e1d9da7fe856 | 257 | * @brief Starts the camera capture in continuous mode. |
| bcostm | 6:e1d9da7fe856 | 258 | * @param buff: pointer to the camera output buffer |
| bcostm | 6:e1d9da7fe856 | 259 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 260 | */ |
| bcostm | 6:e1d9da7fe856 | 261 | void BSP_CAMERA_ContinuousStart(uint8_t *buff) |
| bcostm | 6:e1d9da7fe856 | 262 | { |
| bcostm | 6:e1d9da7fe856 | 263 | /* Start the camera capture */ |
| bcostm | 6:e1d9da7fe856 | 264 | HAL_DCMI_Start_DMA(&hDcmiHandler, DCMI_MODE_CONTINUOUS, (uint32_t)buff, GetSize(CameraCurrentResolution)); |
| bcostm | 6:e1d9da7fe856 | 265 | } |
| bcostm | 6:e1d9da7fe856 | 266 | |
| bcostm | 6:e1d9da7fe856 | 267 | /** |
| bcostm | 6:e1d9da7fe856 | 268 | * @brief Starts the camera capture in snapshot mode. |
| bcostm | 6:e1d9da7fe856 | 269 | * @param buff: pointer to the camera output buffer |
| bcostm | 6:e1d9da7fe856 | 270 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 271 | */ |
| bcostm | 6:e1d9da7fe856 | 272 | void BSP_CAMERA_SnapshotStart(uint8_t *buff) |
| bcostm | 6:e1d9da7fe856 | 273 | { |
| bcostm | 6:e1d9da7fe856 | 274 | /* Start the camera capture */ |
| bcostm | 6:e1d9da7fe856 | 275 | HAL_DCMI_Start_DMA(&hDcmiHandler, DCMI_MODE_SNAPSHOT, (uint32_t)buff, GetSize(CameraCurrentResolution)); |
| bcostm | 6:e1d9da7fe856 | 276 | } |
| bcostm | 6:e1d9da7fe856 | 277 | |
| bcostm | 6:e1d9da7fe856 | 278 | /** |
| bcostm | 6:e1d9da7fe856 | 279 | * @brief Suspend the CAMERA capture |
| bcostm | 6:e1d9da7fe856 | 280 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 281 | */ |
| bcostm | 6:e1d9da7fe856 | 282 | void BSP_CAMERA_Suspend(void) |
| bcostm | 6:e1d9da7fe856 | 283 | { |
| bcostm | 6:e1d9da7fe856 | 284 | /* Suspend the Camera Capture */ |
| bcostm | 6:e1d9da7fe856 | 285 | HAL_DCMI_Suspend(&hDcmiHandler); |
| bcostm | 6:e1d9da7fe856 | 286 | } |
| bcostm | 6:e1d9da7fe856 | 287 | |
| bcostm | 6:e1d9da7fe856 | 288 | /** |
| bcostm | 6:e1d9da7fe856 | 289 | * @brief Resume the CAMERA capture |
| bcostm | 6:e1d9da7fe856 | 290 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 291 | */ |
| bcostm | 6:e1d9da7fe856 | 292 | void BSP_CAMERA_Resume(void) |
| bcostm | 6:e1d9da7fe856 | 293 | { |
| bcostm | 6:e1d9da7fe856 | 294 | /* Start the Camera Capture */ |
| bcostm | 6:e1d9da7fe856 | 295 | HAL_DCMI_Resume(&hDcmiHandler); |
| bcostm | 6:e1d9da7fe856 | 296 | } |
| bcostm | 6:e1d9da7fe856 | 297 | |
| bcostm | 6:e1d9da7fe856 | 298 | /** |
| bcostm | 6:e1d9da7fe856 | 299 | * @brief Stop the CAMERA capture |
| bcostm | 6:e1d9da7fe856 | 300 | * @retval Camera status |
| bcostm | 6:e1d9da7fe856 | 301 | */ |
| bcostm | 6:e1d9da7fe856 | 302 | uint8_t BSP_CAMERA_Stop(void) |
| bcostm | 6:e1d9da7fe856 | 303 | { |
| bcostm | 6:e1d9da7fe856 | 304 | uint8_t status = CAMERA_ERROR; |
| bcostm | 6:e1d9da7fe856 | 305 | |
| bcostm | 6:e1d9da7fe856 | 306 | if(HAL_DCMI_Stop(&hDcmiHandler) == HAL_OK) |
| bcostm | 6:e1d9da7fe856 | 307 | { |
| bcostm | 6:e1d9da7fe856 | 308 | status = CAMERA_OK; |
| bcostm | 6:e1d9da7fe856 | 309 | } |
| bcostm | 6:e1d9da7fe856 | 310 | |
| bcostm | 6:e1d9da7fe856 | 311 | /* Set Camera in Power Down */ |
| bcostm | 6:e1d9da7fe856 | 312 | BSP_CAMERA_PwrDown(); |
| bcostm | 6:e1d9da7fe856 | 313 | |
| bcostm | 6:e1d9da7fe856 | 314 | return status; |
| bcostm | 6:e1d9da7fe856 | 315 | } |
| bcostm | 6:e1d9da7fe856 | 316 | |
| bcostm | 6:e1d9da7fe856 | 317 | /** |
| bcostm | 6:e1d9da7fe856 | 318 | * @brief CANERA power up |
| bcostm | 6:e1d9da7fe856 | 319 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 320 | */ |
| bcostm | 6:e1d9da7fe856 | 321 | void BSP_CAMERA_PwrUp(void) |
| bcostm | 6:e1d9da7fe856 | 322 | { |
| bcostm | 6:e1d9da7fe856 | 323 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 6:e1d9da7fe856 | 324 | |
| bcostm | 6:e1d9da7fe856 | 325 | /* Enable GPIO clock */ |
| bcostm | 6:e1d9da7fe856 | 326 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 327 | |
| bcostm | 6:e1d9da7fe856 | 328 | /*** Configure the GPIO ***/ |
| bcostm | 6:e1d9da7fe856 | 329 | /* Configure DCMI GPIO as alternate function */ |
| bcostm | 6:e1d9da7fe856 | 330 | gpio_init_structure.Pin = GPIO_PIN_13; |
| bcostm | 6:e1d9da7fe856 | 331 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
| bcostm | 6:e1d9da7fe856 | 332 | gpio_init_structure.Pull = GPIO_NOPULL; |
| bcostm | 6:e1d9da7fe856 | 333 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 334 | HAL_GPIO_Init(GPIOH, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 335 | |
| bcostm | 6:e1d9da7fe856 | 336 | /* De-assert the camera POWER_DOWN pin (active high) */ |
| bcostm | 6:e1d9da7fe856 | 337 | HAL_GPIO_WritePin(GPIOH, GPIO_PIN_13, GPIO_PIN_RESET); |
| bcostm | 6:e1d9da7fe856 | 338 | |
| bcostm | 6:e1d9da7fe856 | 339 | HAL_Delay(3); /* POWER_DOWN de-asserted during 3ms */ |
| bcostm | 6:e1d9da7fe856 | 340 | } |
| bcostm | 6:e1d9da7fe856 | 341 | |
| bcostm | 6:e1d9da7fe856 | 342 | /** |
| bcostm | 6:e1d9da7fe856 | 343 | * @brief CAMERA power down |
| bcostm | 6:e1d9da7fe856 | 344 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 345 | */ |
| bcostm | 6:e1d9da7fe856 | 346 | void BSP_CAMERA_PwrDown(void) |
| bcostm | 6:e1d9da7fe856 | 347 | { |
| bcostm | 6:e1d9da7fe856 | 348 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 6:e1d9da7fe856 | 349 | |
| bcostm | 6:e1d9da7fe856 | 350 | /* Enable GPIO clock */ |
| bcostm | 6:e1d9da7fe856 | 351 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 352 | |
| bcostm | 6:e1d9da7fe856 | 353 | /*** Configure the GPIO ***/ |
| bcostm | 6:e1d9da7fe856 | 354 | /* Configure DCMI GPIO as alternate function */ |
| bcostm | 6:e1d9da7fe856 | 355 | gpio_init_structure.Pin = GPIO_PIN_13; |
| bcostm | 6:e1d9da7fe856 | 356 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
| bcostm | 6:e1d9da7fe856 | 357 | gpio_init_structure.Pull = GPIO_NOPULL; |
| bcostm | 6:e1d9da7fe856 | 358 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 359 | HAL_GPIO_Init(GPIOH, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 360 | |
| bcostm | 6:e1d9da7fe856 | 361 | /* Assert the camera POWER_DOWN pin (active high) */ |
| bcostm | 6:e1d9da7fe856 | 362 | HAL_GPIO_WritePin(GPIOH, GPIO_PIN_13, GPIO_PIN_SET); |
| bcostm | 6:e1d9da7fe856 | 363 | } |
| bcostm | 6:e1d9da7fe856 | 364 | |
| bcostm | 6:e1d9da7fe856 | 365 | /** |
| bcostm | 6:e1d9da7fe856 | 366 | * @brief Configures the camera contrast and brightness. |
| bcostm | 6:e1d9da7fe856 | 367 | * @param contrast_level: Contrast level |
| bcostm | 6:e1d9da7fe856 | 368 | * This parameter can be one of the following values: |
| bcostm | 6:e1d9da7fe856 | 369 | * @arg CAMERA_CONTRAST_LEVEL4: for contrast +2 |
| bcostm | 6:e1d9da7fe856 | 370 | * @arg CAMERA_CONTRAST_LEVEL3: for contrast +1 |
| bcostm | 6:e1d9da7fe856 | 371 | * @arg CAMERA_CONTRAST_LEVEL2: for contrast 0 |
| bcostm | 6:e1d9da7fe856 | 372 | * @arg CAMERA_CONTRAST_LEVEL1: for contrast -1 |
| bcostm | 6:e1d9da7fe856 | 373 | * @arg CAMERA_CONTRAST_LEVEL0: for contrast -2 |
| bcostm | 6:e1d9da7fe856 | 374 | * @param brightness_level: Contrast level |
| bcostm | 6:e1d9da7fe856 | 375 | * This parameter can be one of the following values: |
| bcostm | 6:e1d9da7fe856 | 376 | * @arg CAMERA_BRIGHTNESS_LEVEL4: for brightness +2 |
| bcostm | 6:e1d9da7fe856 | 377 | * @arg CAMERA_BRIGHTNESS_LEVEL3: for brightness +1 |
| bcostm | 6:e1d9da7fe856 | 378 | * @arg CAMERA_BRIGHTNESS_LEVEL2: for brightness 0 |
| bcostm | 6:e1d9da7fe856 | 379 | * @arg CAMERA_BRIGHTNESS_LEVEL1: for brightness -1 |
| bcostm | 6:e1d9da7fe856 | 380 | * @arg CAMERA_BRIGHTNESS_LEVEL0: for brightness -2 |
| bcostm | 6:e1d9da7fe856 | 381 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 382 | */ |
| bcostm | 6:e1d9da7fe856 | 383 | void BSP_CAMERA_ContrastBrightnessConfig(uint32_t contrast_level, uint32_t brightness_level) |
| bcostm | 6:e1d9da7fe856 | 384 | { |
| bcostm | 6:e1d9da7fe856 | 385 | if(camera_drv->Config != NULL) |
| bcostm | 6:e1d9da7fe856 | 386 | { |
| bcostm | 6:e1d9da7fe856 | 387 | camera_drv->Config(CameraHwAddress, CAMERA_CONTRAST_BRIGHTNESS, contrast_level, brightness_level); |
| bcostm | 6:e1d9da7fe856 | 388 | } |
| bcostm | 6:e1d9da7fe856 | 389 | } |
| bcostm | 6:e1d9da7fe856 | 390 | |
| bcostm | 6:e1d9da7fe856 | 391 | /** |
| bcostm | 6:e1d9da7fe856 | 392 | * @brief Configures the camera white balance. |
| bcostm | 6:e1d9da7fe856 | 393 | * @param Mode: black_white mode |
| bcostm | 6:e1d9da7fe856 | 394 | * This parameter can be one of the following values: |
| bcostm | 6:e1d9da7fe856 | 395 | * @arg CAMERA_BLACK_WHITE_BW |
| bcostm | 6:e1d9da7fe856 | 396 | * @arg CAMERA_BLACK_WHITE_NEGATIVE |
| bcostm | 6:e1d9da7fe856 | 397 | * @arg CAMERA_BLACK_WHITE_BW_NEGATIVE |
| bcostm | 6:e1d9da7fe856 | 398 | * @arg CAMERA_BLACK_WHITE_NORMAL |
| bcostm | 6:e1d9da7fe856 | 399 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 400 | */ |
| bcostm | 6:e1d9da7fe856 | 401 | void BSP_CAMERA_BlackWhiteConfig(uint32_t Mode) |
| bcostm | 6:e1d9da7fe856 | 402 | { |
| bcostm | 6:e1d9da7fe856 | 403 | if(camera_drv->Config != NULL) |
| bcostm | 6:e1d9da7fe856 | 404 | { |
| bcostm | 6:e1d9da7fe856 | 405 | camera_drv->Config(CameraHwAddress, CAMERA_BLACK_WHITE, Mode, 0); |
| bcostm | 6:e1d9da7fe856 | 406 | } |
| bcostm | 6:e1d9da7fe856 | 407 | } |
| bcostm | 6:e1d9da7fe856 | 408 | |
| bcostm | 6:e1d9da7fe856 | 409 | /** |
| bcostm | 6:e1d9da7fe856 | 410 | * @brief Configures the camera color effect. |
| bcostm | 6:e1d9da7fe856 | 411 | * @param Effect: Color effect |
| bcostm | 6:e1d9da7fe856 | 412 | * This parameter can be one of the following values: |
| bcostm | 6:e1d9da7fe856 | 413 | * @arg CAMERA_COLOR_EFFECT_ANTIQUE |
| bcostm | 6:e1d9da7fe856 | 414 | * @arg CAMERA_COLOR_EFFECT_BLUE |
| bcostm | 6:e1d9da7fe856 | 415 | * @arg CAMERA_COLOR_EFFECT_GREEN |
| bcostm | 6:e1d9da7fe856 | 416 | * @arg CAMERA_COLOR_EFFECT_RED |
| bcostm | 6:e1d9da7fe856 | 417 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 418 | */ |
| bcostm | 6:e1d9da7fe856 | 419 | void BSP_CAMERA_ColorEffectConfig(uint32_t Effect) |
| bcostm | 6:e1d9da7fe856 | 420 | { |
| bcostm | 6:e1d9da7fe856 | 421 | if(camera_drv->Config != NULL) |
| bcostm | 6:e1d9da7fe856 | 422 | { |
| bcostm | 6:e1d9da7fe856 | 423 | camera_drv->Config(CameraHwAddress, CAMERA_COLOR_EFFECT, Effect, 0); |
| bcostm | 6:e1d9da7fe856 | 424 | } |
| bcostm | 6:e1d9da7fe856 | 425 | } |
| bcostm | 6:e1d9da7fe856 | 426 | |
| bcostm | 6:e1d9da7fe856 | 427 | /** |
| bcostm | 6:e1d9da7fe856 | 428 | * @brief Get the capture size in pixels unit. |
| bcostm | 6:e1d9da7fe856 | 429 | * @param resolution: the current resolution. |
| bcostm | 6:e1d9da7fe856 | 430 | * @retval capture size in pixels unit. |
| bcostm | 6:e1d9da7fe856 | 431 | */ |
| bcostm | 6:e1d9da7fe856 | 432 | static uint32_t GetSize(uint32_t resolution) |
| bcostm | 6:e1d9da7fe856 | 433 | { |
| bcostm | 6:e1d9da7fe856 | 434 | uint32_t size = 0; |
| bcostm | 6:e1d9da7fe856 | 435 | |
| bcostm | 6:e1d9da7fe856 | 436 | /* Get capture size */ |
| bcostm | 6:e1d9da7fe856 | 437 | switch (resolution) |
| bcostm | 6:e1d9da7fe856 | 438 | { |
| bcostm | 6:e1d9da7fe856 | 439 | case CAMERA_R160x120: |
| bcostm | 6:e1d9da7fe856 | 440 | { |
| bcostm | 6:e1d9da7fe856 | 441 | size = 0x2580; |
| bcostm | 6:e1d9da7fe856 | 442 | } |
| bcostm | 6:e1d9da7fe856 | 443 | break; |
| bcostm | 6:e1d9da7fe856 | 444 | case CAMERA_R320x240: |
| bcostm | 6:e1d9da7fe856 | 445 | { |
| bcostm | 6:e1d9da7fe856 | 446 | size = 0x9600; |
| bcostm | 6:e1d9da7fe856 | 447 | } |
| bcostm | 6:e1d9da7fe856 | 448 | break; |
| bcostm | 6:e1d9da7fe856 | 449 | case CAMERA_R480x272: |
| bcostm | 6:e1d9da7fe856 | 450 | { |
| bcostm | 6:e1d9da7fe856 | 451 | size = 0xFF00; |
| bcostm | 6:e1d9da7fe856 | 452 | } |
| bcostm | 6:e1d9da7fe856 | 453 | break; |
| bcostm | 6:e1d9da7fe856 | 454 | case CAMERA_R640x480: |
| bcostm | 6:e1d9da7fe856 | 455 | { |
| bcostm | 6:e1d9da7fe856 | 456 | size = 0x25800; |
| bcostm | 6:e1d9da7fe856 | 457 | } |
| bcostm | 6:e1d9da7fe856 | 458 | break; |
| bcostm | 6:e1d9da7fe856 | 459 | default: |
| bcostm | 6:e1d9da7fe856 | 460 | { |
| bcostm | 6:e1d9da7fe856 | 461 | break; |
| bcostm | 6:e1d9da7fe856 | 462 | } |
| bcostm | 6:e1d9da7fe856 | 463 | } |
| bcostm | 6:e1d9da7fe856 | 464 | |
| bcostm | 6:e1d9da7fe856 | 465 | return size; |
| bcostm | 6:e1d9da7fe856 | 466 | } |
| bcostm | 6:e1d9da7fe856 | 467 | |
| bcostm | 6:e1d9da7fe856 | 468 | /** |
| bcostm | 6:e1d9da7fe856 | 469 | * @brief Initializes the DCMI MSP. |
| bcostm | 6:e1d9da7fe856 | 470 | * @param hdcmi: HDMI handle |
| bcostm | 6:e1d9da7fe856 | 471 | * @param Params |
| bcostm | 6:e1d9da7fe856 | 472 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 473 | */ |
| bcostm | 6:e1d9da7fe856 | 474 | __weak void BSP_CAMERA_MspInit(DCMI_HandleTypeDef *hdcmi, void *Params) |
| bcostm | 6:e1d9da7fe856 | 475 | { |
| bcostm | 6:e1d9da7fe856 | 476 | static DMA_HandleTypeDef hdma_handler; |
| bcostm | 6:e1d9da7fe856 | 477 | GPIO_InitTypeDef gpio_init_structure; |
| bcostm | 6:e1d9da7fe856 | 478 | |
| bcostm | 6:e1d9da7fe856 | 479 | /*** Enable peripherals and GPIO clocks ***/ |
| bcostm | 6:e1d9da7fe856 | 480 | /* Enable DCMI clock */ |
| bcostm | 6:e1d9da7fe856 | 481 | __HAL_RCC_DCMI_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 482 | |
| bcostm | 6:e1d9da7fe856 | 483 | /* Enable DMA2 clock */ |
| bcostm | 6:e1d9da7fe856 | 484 | __HAL_RCC_DMA2_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 485 | |
| bcostm | 6:e1d9da7fe856 | 486 | /* Enable GPIO clocks */ |
| bcostm | 6:e1d9da7fe856 | 487 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 488 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 489 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 490 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 491 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| bcostm | 6:e1d9da7fe856 | 492 | |
| bcostm | 6:e1d9da7fe856 | 493 | /*** Configure the GPIO ***/ |
| bcostm | 6:e1d9da7fe856 | 494 | /* Configure DCMI GPIO as alternate function */ |
| bcostm | 6:e1d9da7fe856 | 495 | gpio_init_structure.Pin = GPIO_PIN_4 | GPIO_PIN_6; |
| bcostm | 6:e1d9da7fe856 | 496 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 6:e1d9da7fe856 | 497 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 6:e1d9da7fe856 | 498 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 499 | gpio_init_structure.Alternate = GPIO_AF13_DCMI; |
| bcostm | 6:e1d9da7fe856 | 500 | HAL_GPIO_Init(GPIOA, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 501 | |
| bcostm | 6:e1d9da7fe856 | 502 | gpio_init_structure.Pin = GPIO_PIN_3; |
| bcostm | 6:e1d9da7fe856 | 503 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 6:e1d9da7fe856 | 504 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 6:e1d9da7fe856 | 505 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 506 | gpio_init_structure.Alternate = GPIO_AF13_DCMI; |
| bcostm | 6:e1d9da7fe856 | 507 | HAL_GPIO_Init(GPIOD, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 508 | |
| bcostm | 6:e1d9da7fe856 | 509 | gpio_init_structure.Pin = GPIO_PIN_5 | GPIO_PIN_6; |
| bcostm | 6:e1d9da7fe856 | 510 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 6:e1d9da7fe856 | 511 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 6:e1d9da7fe856 | 512 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 513 | gpio_init_structure.Alternate = GPIO_AF13_DCMI; |
| bcostm | 6:e1d9da7fe856 | 514 | HAL_GPIO_Init(GPIOE, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 515 | |
| bcostm | 6:e1d9da7fe856 | 516 | gpio_init_structure.Pin = GPIO_PIN_9; |
| bcostm | 6:e1d9da7fe856 | 517 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 6:e1d9da7fe856 | 518 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 6:e1d9da7fe856 | 519 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 520 | gpio_init_structure.Alternate = GPIO_AF13_DCMI; |
| bcostm | 6:e1d9da7fe856 | 521 | HAL_GPIO_Init(GPIOG, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 522 | |
| bcostm | 6:e1d9da7fe856 | 523 | gpio_init_structure.Pin = GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |\ |
| bcostm | 6:e1d9da7fe856 | 524 | GPIO_PIN_12 | GPIO_PIN_14; |
| bcostm | 6:e1d9da7fe856 | 525 | gpio_init_structure.Mode = GPIO_MODE_AF_PP; |
| bcostm | 6:e1d9da7fe856 | 526 | gpio_init_structure.Pull = GPIO_PULLUP; |
| bcostm | 6:e1d9da7fe856 | 527 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; |
| bcostm | 6:e1d9da7fe856 | 528 | gpio_init_structure.Alternate = GPIO_AF13_DCMI; |
| bcostm | 6:e1d9da7fe856 | 529 | HAL_GPIO_Init(GPIOH, &gpio_init_structure); |
| bcostm | 6:e1d9da7fe856 | 530 | |
| bcostm | 6:e1d9da7fe856 | 531 | /*** Configure the DMA ***/ |
| bcostm | 6:e1d9da7fe856 | 532 | /* Set the parameters to be configured */ |
| bcostm | 6:e1d9da7fe856 | 533 | hdma_handler.Init.Channel = DMA_CHANNEL_1; |
| bcostm | 6:e1d9da7fe856 | 534 | hdma_handler.Init.Direction = DMA_PERIPH_TO_MEMORY; |
| bcostm | 6:e1d9da7fe856 | 535 | hdma_handler.Init.PeriphInc = DMA_PINC_DISABLE; |
| bcostm | 6:e1d9da7fe856 | 536 | hdma_handler.Init.MemInc = DMA_MINC_ENABLE; |
| bcostm | 6:e1d9da7fe856 | 537 | hdma_handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; |
| bcostm | 6:e1d9da7fe856 | 538 | hdma_handler.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; |
| bcostm | 6:e1d9da7fe856 | 539 | hdma_handler.Init.Mode = DMA_CIRCULAR; |
| bcostm | 6:e1d9da7fe856 | 540 | hdma_handler.Init.Priority = DMA_PRIORITY_HIGH; |
| bcostm | 6:e1d9da7fe856 | 541 | hdma_handler.Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
| bcostm | 6:e1d9da7fe856 | 542 | hdma_handler.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; |
| bcostm | 6:e1d9da7fe856 | 543 | hdma_handler.Init.MemBurst = DMA_MBURST_SINGLE; |
| bcostm | 6:e1d9da7fe856 | 544 | hdma_handler.Init.PeriphBurst = DMA_PBURST_SINGLE; |
| bcostm | 6:e1d9da7fe856 | 545 | |
| bcostm | 6:e1d9da7fe856 | 546 | hdma_handler.Instance = DMA2_Stream1; |
| bcostm | 6:e1d9da7fe856 | 547 | |
| bcostm | 6:e1d9da7fe856 | 548 | /* Associate the initialized DMA handle to the DCMI handle */ |
| bcostm | 6:e1d9da7fe856 | 549 | __HAL_LINKDMA(hdcmi, DMA_Handle, hdma_handler); |
| bcostm | 6:e1d9da7fe856 | 550 | |
| bcostm | 6:e1d9da7fe856 | 551 | /*** Configure the NVIC for DCMI and DMA ***/ |
| bcostm | 6:e1d9da7fe856 | 552 | /* NVIC configuration for DCMI transfer complete interrupt */ |
| bcostm | 6:e1d9da7fe856 | 553 | HAL_NVIC_SetPriority(DCMI_IRQn, 0x0F, 0); |
| bcostm | 6:e1d9da7fe856 | 554 | HAL_NVIC_EnableIRQ(DCMI_IRQn); |
| bcostm | 6:e1d9da7fe856 | 555 | |
| bcostm | 6:e1d9da7fe856 | 556 | /* NVIC configuration for DMA2D transfer complete interrupt */ |
| bcostm | 6:e1d9da7fe856 | 557 | HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0x0F, 0); |
| bcostm | 6:e1d9da7fe856 | 558 | HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); |
| bcostm | 6:e1d9da7fe856 | 559 | |
| bcostm | 6:e1d9da7fe856 | 560 | /* Configure the DMA stream */ |
| bcostm | 6:e1d9da7fe856 | 561 | HAL_DMA_Init(hdcmi->DMA_Handle); |
| bcostm | 6:e1d9da7fe856 | 562 | } |
| bcostm | 6:e1d9da7fe856 | 563 | |
| bcostm | 6:e1d9da7fe856 | 564 | |
| bcostm | 6:e1d9da7fe856 | 565 | /** |
| bcostm | 6:e1d9da7fe856 | 566 | * @brief DeInitializes the DCMI MSP. |
| bcostm | 6:e1d9da7fe856 | 567 | * @param hdcmi: HDMI handle |
| bcostm | 6:e1d9da7fe856 | 568 | * @param Params |
| bcostm | 6:e1d9da7fe856 | 569 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 570 | */ |
| bcostm | 6:e1d9da7fe856 | 571 | __weak void BSP_CAMERA_MspDeInit(DCMI_HandleTypeDef *hdcmi, void *Params) |
| bcostm | 6:e1d9da7fe856 | 572 | { |
| bcostm | 6:e1d9da7fe856 | 573 | /* Disable NVIC for DCMI transfer complete interrupt */ |
| bcostm | 6:e1d9da7fe856 | 574 | HAL_NVIC_DisableIRQ(DCMI_IRQn); |
| bcostm | 6:e1d9da7fe856 | 575 | |
| bcostm | 6:e1d9da7fe856 | 576 | /* Disable NVIC for DMA2 transfer complete interrupt */ |
| bcostm | 6:e1d9da7fe856 | 577 | HAL_NVIC_DisableIRQ(DMA2_Stream1_IRQn); |
| bcostm | 6:e1d9da7fe856 | 578 | |
| bcostm | 6:e1d9da7fe856 | 579 | /* Configure the DMA stream */ |
| bcostm | 6:e1d9da7fe856 | 580 | HAL_DMA_DeInit(hdcmi->DMA_Handle); |
| bcostm | 6:e1d9da7fe856 | 581 | |
| bcostm | 6:e1d9da7fe856 | 582 | /* Disable DCMI clock */ |
| bcostm | 6:e1d9da7fe856 | 583 | __HAL_RCC_DCMI_CLK_DISABLE(); |
| bcostm | 6:e1d9da7fe856 | 584 | |
| bcostm | 6:e1d9da7fe856 | 585 | /* GPIO pins clock and DMA clock can be shut down in the application |
| bcostm | 6:e1d9da7fe856 | 586 | by surcharging this __weak function */ |
| bcostm | 6:e1d9da7fe856 | 587 | } |
| bcostm | 6:e1d9da7fe856 | 588 | |
| bcostm | 6:e1d9da7fe856 | 589 | /** |
| bcostm | 6:e1d9da7fe856 | 590 | * @brief Line event callback |
| bcostm | 6:e1d9da7fe856 | 591 | * @param hdcmi: pointer to the DCMI handle |
| bcostm | 6:e1d9da7fe856 | 592 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 593 | */ |
| bcostm | 6:e1d9da7fe856 | 594 | void HAL_DCMI_LineEventCallback(DCMI_HandleTypeDef *hdcmi) |
| bcostm | 6:e1d9da7fe856 | 595 | { |
| bcostm | 6:e1d9da7fe856 | 596 | BSP_CAMERA_LineEventCallback(); |
| bcostm | 6:e1d9da7fe856 | 597 | } |
| bcostm | 6:e1d9da7fe856 | 598 | |
| bcostm | 6:e1d9da7fe856 | 599 | /** |
| bcostm | 6:e1d9da7fe856 | 600 | * @brief Line Event callback. |
| bcostm | 6:e1d9da7fe856 | 601 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 602 | */ |
| bcostm | 6:e1d9da7fe856 | 603 | __weak void BSP_CAMERA_LineEventCallback(void) |
| bcostm | 6:e1d9da7fe856 | 604 | { |
| bcostm | 6:e1d9da7fe856 | 605 | /* NOTE : This function Should not be modified, when the callback is needed, |
| bcostm | 6:e1d9da7fe856 | 606 | the HAL_DCMI_LineEventCallback could be implemented in the user file |
| bcostm | 6:e1d9da7fe856 | 607 | */ |
| bcostm | 6:e1d9da7fe856 | 608 | } |
| bcostm | 6:e1d9da7fe856 | 609 | |
| bcostm | 6:e1d9da7fe856 | 610 | /** |
| bcostm | 6:e1d9da7fe856 | 611 | * @brief VSYNC event callback |
| bcostm | 6:e1d9da7fe856 | 612 | * @param hdcmi: pointer to the DCMI handle |
| bcostm | 6:e1d9da7fe856 | 613 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 614 | */ |
| bcostm | 6:e1d9da7fe856 | 615 | void HAL_DCMI_VsyncEventCallback(DCMI_HandleTypeDef *hdcmi) |
| bcostm | 6:e1d9da7fe856 | 616 | { |
| bcostm | 6:e1d9da7fe856 | 617 | BSP_CAMERA_VsyncEventCallback(); |
| bcostm | 6:e1d9da7fe856 | 618 | } |
| bcostm | 6:e1d9da7fe856 | 619 | |
| bcostm | 6:e1d9da7fe856 | 620 | /** |
| bcostm | 6:e1d9da7fe856 | 621 | * @brief VSYNC Event callback. |
| bcostm | 6:e1d9da7fe856 | 622 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 623 | */ |
| bcostm | 6:e1d9da7fe856 | 624 | __weak void BSP_CAMERA_VsyncEventCallback(void) |
| bcostm | 6:e1d9da7fe856 | 625 | { |
| bcostm | 6:e1d9da7fe856 | 626 | /* NOTE : This function Should not be modified, when the callback is needed, |
| bcostm | 6:e1d9da7fe856 | 627 | the HAL_DCMI_VsyncEventCallback could be implemented in the user file |
| bcostm | 6:e1d9da7fe856 | 628 | */ |
| bcostm | 6:e1d9da7fe856 | 629 | } |
| bcostm | 6:e1d9da7fe856 | 630 | |
| bcostm | 6:e1d9da7fe856 | 631 | /** |
| bcostm | 6:e1d9da7fe856 | 632 | * @brief Frame event callback |
| bcostm | 6:e1d9da7fe856 | 633 | * @param hdcmi: pointer to the DCMI handle |
| bcostm | 6:e1d9da7fe856 | 634 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 635 | */ |
| bcostm | 6:e1d9da7fe856 | 636 | void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) |
| bcostm | 6:e1d9da7fe856 | 637 | { |
| bcostm | 6:e1d9da7fe856 | 638 | BSP_CAMERA_FrameEventCallback(); |
| bcostm | 6:e1d9da7fe856 | 639 | } |
| bcostm | 6:e1d9da7fe856 | 640 | |
| bcostm | 6:e1d9da7fe856 | 641 | /** |
| bcostm | 6:e1d9da7fe856 | 642 | * @brief Frame Event callback. |
| bcostm | 6:e1d9da7fe856 | 643 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 644 | */ |
| bcostm | 6:e1d9da7fe856 | 645 | __weak void BSP_CAMERA_FrameEventCallback(void) |
| bcostm | 6:e1d9da7fe856 | 646 | { |
| bcostm | 6:e1d9da7fe856 | 647 | /* NOTE : This function Should not be modified, when the callback is needed, |
| bcostm | 6:e1d9da7fe856 | 648 | the HAL_DCMI_FrameEventCallback could be implemented in the user file |
| bcostm | 6:e1d9da7fe856 | 649 | */ |
| bcostm | 6:e1d9da7fe856 | 650 | } |
| bcostm | 6:e1d9da7fe856 | 651 | |
| bcostm | 6:e1d9da7fe856 | 652 | /** |
| bcostm | 6:e1d9da7fe856 | 653 | * @brief Error callback |
| bcostm | 6:e1d9da7fe856 | 654 | * @param hdcmi: pointer to the DCMI handle |
| bcostm | 6:e1d9da7fe856 | 655 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 656 | */ |
| bcostm | 6:e1d9da7fe856 | 657 | void HAL_DCMI_ErrorCallback(DCMI_HandleTypeDef *hdcmi) |
| bcostm | 6:e1d9da7fe856 | 658 | { |
| bcostm | 6:e1d9da7fe856 | 659 | BSP_CAMERA_ErrorCallback(); |
| bcostm | 6:e1d9da7fe856 | 660 | } |
| bcostm | 6:e1d9da7fe856 | 661 | |
| bcostm | 6:e1d9da7fe856 | 662 | /** |
| bcostm | 6:e1d9da7fe856 | 663 | * @brief Error callback. |
| bcostm | 6:e1d9da7fe856 | 664 | * @retval None |
| bcostm | 6:e1d9da7fe856 | 665 | */ |
| bcostm | 6:e1d9da7fe856 | 666 | __weak void BSP_CAMERA_ErrorCallback(void) |
| bcostm | 6:e1d9da7fe856 | 667 | { |
| bcostm | 6:e1d9da7fe856 | 668 | /* NOTE : This function Should not be modified, when the callback is needed, |
| bcostm | 6:e1d9da7fe856 | 669 | the HAL_DCMI_ErrorCallback could be implemented in the user file |
| bcostm | 6:e1d9da7fe856 | 670 | */ |
| bcostm | 6:e1d9da7fe856 | 671 | } |
| buyukesmeli | 10:27e6daa4f2fe | 672 | void DCMI_IRQHandler(void) // DCMI interrupt routine |
| buyukesmeli | 10:27e6daa4f2fe | 673 | { |
| buyukesmeli | 10:27e6daa4f2fe | 674 | HAL_DCMI_IRQHandler(&hDcmiHandler); |
| buyukesmeli | 10:27e6daa4f2fe | 675 | } |
| buyukesmeli | 10:27e6daa4f2fe | 676 | void DMA2_Stream1_IRQHandler(void) // DMA interrupt routine |
| buyukesmeli | 10:27e6daa4f2fe | 677 | { |
| buyukesmeli | 10:27e6daa4f2fe | 678 | HAL_DMA_IRQHandler(hDcmiHandler.DMA_Handle); |
| buyukesmeli | 10:27e6daa4f2fe | 679 | } |
| bcostm | 6:e1d9da7fe856 | 680 | /** |
| bcostm | 6:e1d9da7fe856 | 681 | * @} |
| bcostm | 6:e1d9da7fe856 | 682 | */ |
| bcostm | 6:e1d9da7fe856 | 683 | |
| bcostm | 6:e1d9da7fe856 | 684 | /** |
| bcostm | 6:e1d9da7fe856 | 685 | * @} |
| bcostm | 6:e1d9da7fe856 | 686 | */ |
| bcostm | 6:e1d9da7fe856 | 687 | |
| bcostm | 6:e1d9da7fe856 | 688 | /** |
| bcostm | 6:e1d9da7fe856 | 689 | * @} |
| bcostm | 6:e1d9da7fe856 | 690 | */ |
| bcostm | 6:e1d9da7fe856 | 691 | |
| bcostm | 6:e1d9da7fe856 | 692 | /** |
| bcostm | 6:e1d9da7fe856 | 693 | * @} |
| bcostm | 6:e1d9da7fe856 | 694 | */ |
| bcostm | 6:e1d9da7fe856 | 695 | |
| bcostm | 6:e1d9da7fe856 | 696 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
