1111
1212#ifdef DEVICE_OV5640
1313
14- #include "stm32_ov5640.h"
15- #include "board/stm32f7/configs.h"
16- #include "device/camera/camera.h"
17- #include "device/serial/serial.h"
18- #include "stm32f7xx_hal.h"
14+ #include "board/stm32f7/configs.h"
15+ #include "device/camera/camera.h"
16+ #include "device/serial/serial.h"
1917
20- #include <stdarg.h>
21- #include <stdint.h>
22- #include <stdio.h>
18+ #include <stdarg.h>
19+ #include <stdint.h>
20+ #include <stdio.h>
2321
24- /* ============================================================================
25- * I2C COMMUNICATION LAYER (Internal - Static Functions)
26- * ============================================================================ */
22+ #include "stm32_ov5640.h"
23+ #include "stm32f7xx_hal.h"
2724
28- /* Private defines */
29- #define I2C1_TIMING ((uint32_t)0x40912732) /**< I2C timing for 100kHz at 216MHz */
25+ /* ============================================================================
26+ * I2C COMMUNICATION LAYER (Internal - Static Functions)
27+ * ============================================================================ */
28+
29+ /* Private defines */
30+ #define I2C1_TIMING ((uint32_t)0x40912732) /**< I2C timing for 100kHz at 216MHz */
3031
3132/* Private variables */
3233static I2C_HandleTypeDef hI2cCamera = {0 };
@@ -68,8 +69,7 @@ static void CAMERA_IO_Write(uint16_t DeviceAddr, uint16_t Reg, uint8_t Value)
6869{
6970 HAL_StatusTypeDef status ;
7071
71- status = HAL_I2C_Mem_Write (& hI2cCamera , DeviceAddr , Reg , I2C_MEMADD_SIZE_16BIT ,
72- & Value , 1 , 100 );
72+ status = HAL_I2C_Mem_Write (& hI2cCamera , DeviceAddr , Reg , I2C_MEMADD_SIZE_16BIT , & Value , 1 , 100 );
7373
7474 if (status != HAL_OK ) {
7575 I2C_Error (DeviceAddr );
@@ -87,8 +87,7 @@ static uint8_t CAMERA_IO_Read(uint16_t DeviceAddr, uint16_t Reg)
8787 uint8_t value = 0 ;
8888 HAL_StatusTypeDef status ;
8989
90- status = HAL_I2C_Mem_Read (& hI2cCamera , DeviceAddr , Reg , I2C_MEMADD_SIZE_16BIT ,
91- & value , 1 , 100 );
90+ status = HAL_I2C_Mem_Read (& hI2cCamera , DeviceAddr , Reg , I2C_MEMADD_SIZE_16BIT , & value , 1 , 100 );
9291
9392 if (status != HAL_OK ) {
9493 I2C_Error (DeviceAddr );
@@ -151,7 +150,7 @@ static void I2C_MspInit(void)
151150 */
152151static void I2C_Error (uint8_t Addr )
153152{
154- (void )Addr ; /* Unused parameter */
153+ (void )Addr ; /* Unused parameter */
155154
156155 /* De-initialize and re-initialize I2C to recover from error */
157156 HAL_I2C_DeInit (& hI2cCamera );
@@ -216,32 +215,52 @@ const uint16_t OV5640_Init[][2] = {
216215 * @brief Resolution configuration for 640x480 (VGA)
217216 */
218217const uint16_t OV5640_VGA [][2 ] = {
219- {0x3808 , 0x02 }, {0x3809 , 0x80 }, {0x380a , 0x01 }, {0x380b , 0xE0 },
220- {0x4300 , 0x6F }, {0x4740 , 0x22 }, {0x501F , 0x01 },
218+ {0x3808 , 0x02 },
219+ {0x3809 , 0x80 },
220+ {0x380a , 0x01 },
221+ {0x380b , 0xE0 },
222+ {0x4300 , 0x6F },
223+ {0x4740 , 0x22 },
224+ {0x501F , 0x01 },
221225};
222226
223227/**
224228 * @brief Resolution configuration for 480x272
225229 */
226230const uint16_t OV5640_480x272 [][2 ] = {
227- {0x3808 , 0x01 }, {0x3809 , 0xE0 }, {0x380a , 0x01 }, {0x380b , 0x10 },
228- {0x4300 , 0x6F }, {0x4740 , 0x22 }, {0x501f , 0x01 },
231+ {0x3808 , 0x01 },
232+ {0x3809 , 0xE0 },
233+ {0x380a , 0x01 },
234+ {0x380b , 0x10 },
235+ {0x4300 , 0x6F },
236+ {0x4740 , 0x22 },
237+ {0x501f , 0x01 },
229238};
230239
231240/**
232241 * @brief Resolution configuration for 320x240 (QVGA)
233242 */
234243const uint16_t OV5640_QVGA [][2 ] = {
235- {0x3808 , 0x01 }, {0x3809 , 0x40 }, {0x380a , 0x00 }, {0x380b , 0xF0 },
236- {0x4300 , 0x6F }, {0x4740 , 0x22 }, {0x501f , 0x01 },
244+ {0x3808 , 0x01 },
245+ {0x3809 , 0x40 },
246+ {0x380a , 0x00 },
247+ {0x380b , 0xF0 },
248+ {0x4300 , 0x6F },
249+ {0x4740 , 0x22 },
250+ {0x501f , 0x01 },
237251};
238252
239253/**
240254 * @brief Resolution configuration for 160x120 (QQVGA)
241255 */
242256const uint16_t OV5640_QQVGA [][2 ] = {
243- {0x3808 , 0x00 }, {0x3809 , 0xA0 }, {0x380a , 0x00 }, {0x380b , 0x78 },
244- {0x4300 , 0x6F }, {0x4740 , 0x22 }, {0x501f , 0x01 },
257+ {0x3808 , 0x00 },
258+ {0x3809 , 0xA0 },
259+ {0x380a , 0x00 },
260+ {0x380b , 0x78 },
261+ {0x4300 , 0x6F },
262+ {0x4740 , 0x22 },
263+ {0x501f , 0x01 },
245264};
246265
247266/**
@@ -250,7 +269,7 @@ const uint16_t OV5640_QQVGA[][2] = {
250269CAMERA_DrvTypeDef ov5640_drv = {
251270 ov5640_Init ,
252271 ov5640_ReadID ,
253- NULL , /* Config function removed */
272+ NULL , /* Config function removed */
254273};
255274
256275/**
@@ -332,7 +351,7 @@ int OV5640_SetPixelFormat(uint16_t DeviceAddr, uint32_t format)
332351{
333352 /* Validate format */
334353 if (format != 0x10 && format != 0x6F && format != 0x23 && format != 0x30 ) {
335- return -1 ; /* Invalid format */
354+ return -1 ; /* Invalid format */
336355 }
337356
338357 /* Write format to register 0x4300 (format control) */
@@ -610,12 +629,10 @@ static int camera_setRes(ImageResolution resolution)
610629/**
611630 * @brief STM32 OV5640 camera interface structure
612631 */
613- camera_t stm32_ov5640 = {
614- .init = camera_init ,
615- .capture = camera_capture ,
616- .stop = camera_stop ,
617- .setRes = camera_setRes
618- };
632+ camera_t stm32_ov5640 = {.init = camera_init ,
633+ .capture = camera_capture ,
634+ .stop = camera_stop ,
635+ .setRes = camera_setRes };
619636
620637/**
621638 * @brief DCMI frame event callback - called when a complete frame is captured
0 commit comments