1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
34
37
38
39
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
69
70
71
77
78
79
80
81
99
100
101
104
107
110
113
116
117
118
119
120
125
126
127
128
129
132
135
138
141
144
147
150
151
152
153
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
182
190
191
196
204
205
210
211
212
217
218
219
220
221
222
223
224
225
230
234
235
240
247
248
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
293
294
295
296
297
298
299
300
301
302
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
336
337
/* ... */
#include "camera_app.h"
#include "main.h"
#include "k_bsp.h"
#include "k_rtc.h"
#include "k_storage.h"
5 includes
/* ... */
/* ... */
Includes
extern CameraSettingsTypeDef CameraSettings;
External variables
#define BMP_PIXEL16_TO_R(pixel) ((pixel & 0x1F) << 3)
#define BMP_PIXEL16_TO_G(pixel) (((pixel >> 5) & 0x3F) << 2)
#define BMP_PIXEL16_TO_B(pixel) (((pixel >> 11) & 0x1F) << 3)
Private macros
const uint8_t BMPHeader_QQVGA24Bit[] =
{
0x42, 0x4D,
0x36, 0x84, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00,
0x36, 0x00, 0x00, 0x00,
0x28, 0x00, 0x00, 0x00,
0x40, 0x01, 0x00, 0x00,
0xF0, 0x00, 0x00, 0x00,
0x01, 0x00,
0x18, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x58, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
...};
uint32_t CameraError = CAMERA_ERROR;
Private variables
static void RGB16toRGB24(uint8_t *pDestBuffer, uint8_t *pSrcBuffer);
Private function prototypes
/* ... */
void CAMERA_Set_ContrastBrightness(uint32_t contrast_level, uint32_t brightness_level)
{
uint32_t contrast = 0, brightness = 0;
switch (contrast_level)
{
case 1:
contrast = CAMERA_CONTRAST_LEVEL0;
break;case 1:
case 2:
contrast = CAMERA_CONTRAST_LEVEL1;
break;case 2:
case 3:
contrast = CAMERA_CONTRAST_LEVEL2;
break;case 3:
case 4:
contrast = CAMERA_CONTRAST_LEVEL3;
break;case 4:
case 5:
contrast = CAMERA_CONTRAST_LEVEL4;
break;case 5:
}switch (contrast_level) { ... }
switch (brightness_level)
{
case 1:
brightness = CAMERA_BRIGHTNESS_LEVEL0;
break;case 1:
case 2:
brightness = CAMERA_BRIGHTNESS_LEVEL1;
break;case 2:
case 3:
brightness = CAMERA_BRIGHTNESS_LEVEL2;
break;case 3:
case 4:
brightness = CAMERA_BRIGHTNESS_LEVEL3;
break;case 4:
case 5:
brightness = CAMERA_BRIGHTNESS_LEVEL4;
break;case 5:
}switch (brightness_level) { ... }
BSP_CAMERA_ContrastBrightnessConfig(contrast, brightness);
}{ ... }
/* ... */
void CAMERA_SelectEffect(uint32_t effect)
{
switch (effect)
{
case 0:
CAMERA_Set_ContrastBrightness(CameraSettings.b.contrast, CameraSettings.b.brightness);
break;case 0:
case 1:
BSP_CAMERA_BlackWhiteConfig(CAMERA_BLACK_WHITE_BW);
break;case 1:
case 2:
BSP_CAMERA_BlackWhiteConfig(CAMERA_BLACK_WHITE_NEGATIVE);
break;case 2:
case 3:
BSP_CAMERA_ColorEffectConfig(CAMERA_COLOR_EFFECT_ANTIQUE);
break;case 3:
case 4:
BSP_CAMERA_ColorEffectConfig(CAMERA_COLOR_EFFECT_BLUE);
break;case 4:
case 5:
BSP_CAMERA_ColorEffectConfig(CAMERA_COLOR_EFFECT_GREEN);
break;case 5:
case 6:
BSP_CAMERA_ColorEffectConfig(CAMERA_COLOR_EFFECT_RED);
break; case 6:
}switch (effect) { ... }
}{ ... }
/* ... */
void CAMERA_Init(void)
{
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_SPEAKER, 0, 0);
AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x200, 0x0);
AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x300, 0x6010);
CameraError = BSP_CAMERA_Init(RESOLUTION_R320x240);
if( CameraError != CAMERA_ERROR)
{
GUI_Delay(100);
BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER);
CAMERA_Set_ContrastBrightness(CameraSettings.b.contrast, CameraSettings.b.brightness);
}if (CameraError != CAMERA_ERROR) { ... }
}{ ... }
/* ... */
void CAMERA_Suspend(void)
{
if( CameraError != CAMERA_ERROR)
{
BSP_CAMERA_Suspend();
}if (CameraError != CAMERA_ERROR) { ... }
}{ ... }
/* ... */
void CAMERA_Resume(void)
{
if( CameraError != CAMERA_ERROR)
{
BSP_CAMERA_Resume();
}if (CameraError != CAMERA_ERROR) { ... }
}{ ... }
/* ... */
void CAMERA_Stop(void)
{
if( CameraError != CAMERA_ERROR)
{
BSP_CAMERA_Stop();
}if (CameraError != CAMERA_ERROR) { ... }
BSP_SD_Init();
k_BspAudioInit();
}{ ... }
/* ... */
uint8_t CAMERA_GetState(void)
{
return CameraError;
}{ ... }
/* ... */
void BSP_CAMERA_ErrorCallback(void)
{
if( CameraError != CAMERA_ERROR)
{
BSP_CAMERA_Resume();
}if (CameraError != CAMERA_ERROR) { ... }
}{ ... }
/* ... */
uint8_t CAMERA_SaveToFile(uint8_t *path)
{
RTC_TimeTypeDef Time;
RTC_DateTypeDef Date;
FIL file;
uint32_t NumWrittenData;
uint8_t ret = 1;
char filename[FILEMGR_FILE_NAME_SIZE];
char fullpath[FILEMGR_FILE_NAME_SIZE];
k_GetTime(&Time);
k_GetDate(&Date);
sprintf((char *)filename, "/Camera_%02d%02d%04d_%02d%02d%02d.bmp",
Date.Date,
Date.Month,
Date.Year + 2015,
Time.Hours,
Time.Minutes,
Time.Seconds);
strcpy((char *)fullpath, (char *)path);
strcat ((char *)fullpath, (char *)filename);
BSP_CAMERA_Suspend();
if (f_open(&file, (char *)fullpath, FA_CREATE_NEW | FA_WRITE) == FR_OK)
{
if (f_write(&file, (char *)BMPHeader_QQVGA24Bit, RGB_HEADER_SIZE, (UINT *)&NumWrittenData) == FR_OK)
{
f_sync(&file);
RGB16toRGB24((uint8_t *)CAMERA_CVRT_BUFFER, (uint8_t *)CAMERA_FRAME_BUFFER);
if (f_write(&file, (char *)CAMERA_CVRT_BUFFER, MAX_IMAGE_SIZE, (UINT*)&NumWrittenData)== FR_OK)
{
ret = 0;
}if (f_write(&file, (char *)CAMERA_CVRT_BUFFER, MAX_IMAGE_SIZE, (UINT*)&NumWrittenData)== FR_OK) { ... }
}if (f_write(&file, (char *)BMPHeader_QQVGA24Bit, RGB_HEADER_SIZE, (UINT *)&NumWrittenData) == FR_OK) { ... }
f_close(&file);
}if (f_open(&file, (char *)fullpath, FA_CREATE_NEW | FA_WRITE) == FR_OK) { ... }
BSP_CAMERA_Resume();
return ret;
}{ ... }
/* ... */
static void RGB16toRGB24(uint8_t *pDestBuffer, uint8_t *pSrcBuffer)
{
uint16_t *pSrc;
uint8_t *pDest;
uint32_t i = 0, j = 0;
uint16_t value;
pSrc = (uint16_t*) & pSrcBuffer[IMAGE_BUFFER_SIZE] - IMAGE_LINE_SIZE;
pDest = (uint8_t*) & pDestBuffer[0];
for (i = IMAGE_COLUMN_SIZE; i > 0; i-- )
{
for ( j = 0; j < 2 * IMAGE_LINE_SIZE; j += 2 )
{
value = (uint16_t) * pSrc;
*pDest++ = BMP_PIXEL16_TO_R(value);
*pDest++ = BMP_PIXEL16_TO_G(value);
*pDest++ = BMP_PIXEL16_TO_B(value);
pSrc++;
}for (j = 0; j < 2 * IMAGE_LINE_SIZE; j += 2) { ... }
pSrc -= (IMAGE_LINE_SIZE * 2);
}for (i = IMAGE_COLUMN_SIZE; i > 0; i--) { ... }
}{ ... }
/* ... */
/* ... */