Skip to content

Commit 8f8595f

Browse files
authored
Pics Or It Didn’t Happen
As of now, all resolutions work correctly. DCMI operation improved, data buffer returns only JPEG file.
1 parent cb9ac32 commit 8f8595f

4 files changed

Lines changed: 1000 additions & 970 deletions

File tree

Inc/ov2640.h

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
/**
2-
* ov2640.h
3-
*
4-
* Created on: 23.02.2019
5-
* Modified on: 23.02.2021
6-
*
7-
* Copyright 2021 SimpleMethod
8-
*
9-
*Permission is hereby granted, free of charge, to any person obtaining a copy of
10-
*this software and associated documentation files (the "Software"), to deal in
11-
*the Software without restriction, including without limitation the rights to
12-
*use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13-
*of the Software, and to permit persons to whom the Software is furnished to do
14-
*so, subject to the following conditions:
15-
*
16-
*The above copyright notice and this permission notice shall be included in all
17-
*copies or substantial portions of the Software.
18-
*
19-
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
*THE SOFTWARE.
26-
******************************************************************************
27-
*/
28-
29-
#ifndef OV2640_H_
30-
#define OV2640_H_
31-
32-
#include "main.h"
33-
#include "stm32f7xx.h"
34-
35-
36-
37-
enum specialEffect{Antique=0, Bluish=1, Greenish=2, Reddish=3, BlackWhite=4, Negative=5, NegativeBlackWhite=6,Normal=7};
38-
enum imageResolution{RES_160X120=15533,RES_320X240=15534,RES_640X480=15535,RES_800x600=25535,RES_1024x768=45535,RES_1280x960=65535};
39-
enum imageContrast{Contrast2=2,Contrast1=1,Contrast0=0,Contrast_1=3,Contrast_2=4};
40-
enum imageSaturation{Saturation2=2,Saturation1=1,Saturation0=0,Saturation_1=3,Saturation_2=4};
41-
enum imageBrightness{Brightness2=2,Brightness1=1,Brightness0=0,Brightness_1=3,Brightness_2=4};
42-
enum imageLightMode{Auto=0,Sunny=1,Cloudy=2,Office=3,Home=4};
43-
44-
short SCCB_Read(uint8_t reg_addr, uint8_t *pdata);
45-
short SCCB_Write(uint8_t reg_addr, uint8_t data);
46-
47-
48-
void OV2640_StopDCMI(void);
49-
void OV2640_CaptureSnapshot(uint32_t buf_addr, int len);
50-
void OV2640_ResolutionOptions(uint16_t opt);
51-
void OV2640_ResolutionConfiguration(short opt);
52-
void OV2640_Init(I2C_HandleTypeDef *p_hi2c, DCMI_HandleTypeDef *p_hdcmi);
53-
void OV2640_Configuration(const unsigned char arr[][2]);
54-
void OV2640_SpecialEffect(short specialEffect);
55-
void OV2640_Contrast(short contrast);
56-
void OV2640_Saturation(short saturation);
57-
void OV2640_Brightness(short brightness);
58-
void OV2640_LightMode(short lightMode);
59-
void OV2640_SimpleWhiteBalance();
60-
void OV2640_AdvancedWhiteBalance();
61-
62-
#endif /* OV2640_H_ */
1+
/**
2+
* ov2640.h
3+
*
4+
* Created on: 23.02.2019
5+
* Modified on: 23.02.2021
6+
*
7+
* Copyright 2021 SimpleMethod
8+
*
9+
*Permission is hereby granted, free of charge, to any person obtaining a copy of
10+
*this software and associated documentation files (the "Software"), to deal in
11+
*the Software without restriction, including without limitation the rights to
12+
*use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13+
*of the Software, and to permit persons to whom the Software is furnished to do
14+
*so, subject to the following conditions:
15+
*
16+
*The above copyright notice and this permission notice shall be included in all
17+
*copies or substantial portions of the Software.
18+
*
19+
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
*THE SOFTWARE.
26+
******************************************************************************
27+
*/
28+
29+
#ifndef OV2640_H_
30+
#define OV2640_H_
31+
32+
#include "main.h"
33+
#include "stm32f7xx.h"
34+
35+
36+
37+
enum specialEffect{Antique=0, Bluish=1, Greenish=2, Reddish=3, BlackWhite=4, Negative=5, NegativeBlackWhite=6,Normal=7};
38+
enum imageResolution{RES_160X120=15533,RES_320X240=15534,RES_640X480=15535,RES_800x600=25535,RES_1024x768=45535,RES_1280x960=65535};
39+
enum imageContrast{Contrast2=2,Contrast1=1,Contrast0=0,Contrast_1=3,Contrast_2=4};
40+
enum imageSaturation{Saturation2=2,Saturation1=1,Saturation0=0,Saturation_1=3,Saturation_2=4};
41+
enum imageBrightness{Brightness2=2,Brightness1=1,Brightness0=0,Brightness_1=3,Brightness_2=4};
42+
enum imageLightMode{Auto=0,Sunny=1,Cloudy=2,Office=3,Home=4};
43+
44+
short SCCB_Read(uint8_t reg_addr, uint8_t *pdata);
45+
short SCCB_Write(uint8_t reg_addr, uint8_t data);
46+
47+
48+
void OV2640_StopDCMI(void);
49+
void OV2640_CaptureSnapshot(uint32_t buf_addr, int len);
50+
void OV2640_ResolutionOptions(uint16_t opt);
51+
void OV2640_ResolutionConfiguration(short opt);
52+
void OV2640_Init(I2C_HandleTypeDef *p_hi2c, DCMI_HandleTypeDef *p_hdcmi);
53+
void OV2640_Configuration(const unsigned char arr[][2]);
54+
void OV2640_SpecialEffect(short specialEffect);
55+
void OV2640_Contrast(short contrast);
56+
void OV2640_Saturation(short saturation);
57+
void OV2640_Brightness(short brightness);
58+
void OV2640_LightMode(short lightMode);
59+
void OV2640_SimpleWhiteBalance();
60+
void OV2640_AdvancedWhiteBalance();
61+
62+
#endif /* OV2640_H_ */

Src/main.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
* Code debugging option
5555
*/
5656
//#define DEBUG
57-
5857
/* USER CODE END PD */
5958

6059
/* Private macro -------------------------------------------------------------*/
@@ -80,10 +79,10 @@ DMA_HandleTypeDef hdma_usart3_tx;
8079

8180
//#define RES160X120
8281
//#define RES320X240
83-
#define RES640X480
82+
//#define RES640X480
8483
//#define RES800x600
8584
//#define RES1024x768
86-
//#define RES1280x960
85+
#define RES1280x960
8786

8887
#ifdef RES160X120
8988
enum imageResolution imgRes=RES_160X120;
@@ -115,8 +114,9 @@ enum imageResolution imgRes = RES_1280x960;
115114
uint8_t frameBuffer[RES_1280x960] = { 0 };
116115
#endif
117116

118-
short mutex = 0;
119-
117+
ushort mutex = 0;
118+
uint16_t bufferPointer = 0;
119+
ushort headerFound = 0;
120120
/* USER CODE END PV */
121121

122122
/* Private function prototypes -----------------------------------------------*/
@@ -202,23 +202,50 @@ int main(void) {
202202
#ifdef DEBUG
203203
my_printf("Finishing configuration \r\n");
204204
#endif
205+
205206
/* USER CODE END 2 */
206207

207208
/* Infinite loop */
208209
/* USER CODE BEGIN WHILE */
209210

210211
/**
211-
* Pressing button (B1) on the nucleo board will take a picture and return a JPEG via the serial port.
212+
* Pressing button (B1) on the Nucleo board will take a picture and return JPEG via the serial port.
212213
*/
213214
while (1) {
214215
if (HAL_GPIO_ReadPin(USER_Btn_GPIO_Port, USER_Btn_Pin)) {
215216
if (mutex == 1) {
216217
memset(frameBuffer, 0, sizeof frameBuffer);
217218
OV2640_CaptureSnapshot((uint32_t) frameBuffer, imgRes);
218-
HAL_Delay(2000);
219219

220-
//HAL_UART_Transmit(&huart3, framebuf,imgRes, 3000);
221-
HAL_UART_Transmit_DMA(&huart3, frameBuffer, imgRes); //Use of DMA may be necessary for larger data streams.
220+
while (1) {
221+
if (headerFound == 0 && frameBuffer[bufferPointer] == 0xFF
222+
&& frameBuffer[bufferPointer + 1] == 0xD8) {
223+
headerFound = 1;
224+
#ifdef DEBUG
225+
my_printf("Found header of JPEG file \r\n");
226+
#endif
227+
}
228+
if (headerFound == 1 && frameBuffer[bufferPointer] == 0xFF
229+
&& frameBuffer[bufferPointer + 1] == 0xD9) {
230+
bufferPointer = bufferPointer + 2;
231+
#ifdef DEBUG
232+
my_printf("Found EOF of JPEG file \r\n");
233+
#endif
234+
headerFound = 0;
235+
break;
236+
}
237+
238+
if (bufferPointer >= 65535) {
239+
break;
240+
}
241+
bufferPointer++;
242+
}
243+
#ifdef DEBUG
244+
my_printf("Image size: %d bytes \r\n",bufferPointer);
245+
#endif
246+
247+
HAL_UART_Transmit_DMA(&huart3, frameBuffer, bufferPointer); //Use of DMA may be necessary for larger data streams.
248+
bufferPointer = 0;
222249
mutex = 0;
223250
}
224251
} else {

0 commit comments

Comments
 (0)