Use separate configuration header
This commit is contained in:
parent
d6932ae70c
commit
e43202a113
9
src/config.h
Normal file
9
src/config.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
||||||
|
// dithering.
|
||||||
|
#define CONFIG_USE_2D_DITHERING
|
||||||
|
|
||||||
|
// Use a primitive autoexposure by shifting each frames luminosity based on the
|
||||||
|
// ratio of white to black pixels in the previous frames
|
||||||
|
// #define CONFIG_USE_EXPOSURE_CORRECTION
|
13
src/ov7670.c
13
src/ov7670.c
|
@ -1,6 +1,7 @@
|
||||||
#include "ov7670.h"
|
#include "ov7670.h"
|
||||||
#include "pinning.h"
|
#include "pinning.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define REG_GAIN 0x00
|
#define REG_GAIN 0x00
|
||||||
#define REG_BLUE 0x01
|
#define REG_BLUE 0x01
|
||||||
|
@ -156,7 +157,7 @@ static volatile int FrameCount = 0;
|
||||||
volatile int Camera_Captured = 0;
|
volatile int Camera_Captured = 0;
|
||||||
static unsigned int BlackPixels = 0;
|
static unsigned int BlackPixels = 0;
|
||||||
|
|
||||||
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
|
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
|
||||||
static volatile int ExposureCorrection = 0;
|
static volatile int ExposureCorrection = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -327,7 +328,7 @@ void TIM1_CC_IRQHandler(void)
|
||||||
CurrentLine = 0;
|
CurrentLine = 0;
|
||||||
FrameCount++;
|
FrameCount++;
|
||||||
|
|
||||||
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
|
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
|
||||||
// Correct exposure across frames
|
// Correct exposure across frames
|
||||||
ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16;
|
ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16;
|
||||||
#endif
|
#endif
|
||||||
|
@ -361,7 +362,7 @@ void TIM3_IRQHandler(void)
|
||||||
DMA1_Channel6->CCR = DMA_CCR_PL | DMA_CCR_MINC | DMA_CCR_EN;
|
DMA1_Channel6->CCR = DMA_CCR_PL | DMA_CCR_MINC | DMA_CCR_EN;
|
||||||
TIM3->DIER |= TIM_DIER_CC1DE;
|
TIM3->DIER |= TIM_DIER_CC1DE;
|
||||||
|
|
||||||
#ifdef CAMERA_USE_2D_DITHERING
|
#ifdef CONFIG_USE_2D_DITHERING
|
||||||
static int8_t y_errors[CAMERA_IMAGE_WIDTH + 2] = {0};
|
static int8_t y_errors[CAMERA_IMAGE_WIDTH + 2] = {0};
|
||||||
|
|
||||||
if(CurrentLine == 0)
|
if(CurrentLine == 0)
|
||||||
|
@ -374,7 +375,7 @@ void TIM3_IRQHandler(void)
|
||||||
&& (CurrentLine / 2 < CAMERA_IMAGE_HEIGHT))
|
&& (CurrentLine / 2 < CAMERA_IMAGE_HEIGHT))
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef CAMERA_USE_2D_DITHERING
|
#ifdef CONFIG_USE_2D_DITHERING
|
||||||
// Apply errors propagated from the previous line. Since y_errors is
|
// Apply errors propagated from the previous line. Since y_errors is
|
||||||
// overwritten during x error diffusion, this is done now.
|
// overwritten during x error diffusion, this is done now.
|
||||||
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
||||||
|
@ -388,7 +389,7 @@ void TIM3_IRQHandler(void)
|
||||||
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
for(int i = 0; i < CAMERA_IMAGE_WIDTH; i++)
|
||||||
{
|
{
|
||||||
int pixel = LineBuffer[i + 15] + x_error;
|
int pixel = LineBuffer[i + 15] + x_error;
|
||||||
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
|
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
|
||||||
if(ExposureCorrection < 0)
|
if(ExposureCorrection < 0)
|
||||||
{
|
{
|
||||||
if(pixel < -ExposureCorrection)
|
if(pixel < -ExposureCorrection)
|
||||||
|
@ -421,7 +422,7 @@ void TIM3_IRQHandler(void)
|
||||||
~(0x80 >> (i % 8));
|
~(0x80 >> (i % 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CAMERA_USE_2D_DITHERING
|
#ifdef CONFIG_USE_2D_DITHERING
|
||||||
// Error propagated to the next pixel in the same line
|
// Error propagated to the next pixel in the same line
|
||||||
x_error = error * 7 / 16;
|
x_error = error * 7 / 16;
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,6 @@
|
||||||
#define CAMERA_IMAGE_HEIGHT 144
|
#define CAMERA_IMAGE_HEIGHT 144
|
||||||
#define CAMERA_PIXELS (CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT)
|
#define CAMERA_PIXELS (CAMERA_IMAGE_WIDTH * CAMERA_IMAGE_HEIGHT)
|
||||||
|
|
||||||
// Use 2D Floyd-Steinberg dithering. Uncomment to use simple line-wise
|
|
||||||
// dithering.
|
|
||||||
#define CAMERA_USE_2D_DITHERING
|
|
||||||
|
|
||||||
// Use a primitive autoexposure by shifting each frames luminosity based on the
|
|
||||||
// ratio of white to black pixels in the previous frames
|
|
||||||
// #define CAMERA_USE_EXPOSURE_CORRECTION
|
|
||||||
|
|
||||||
extern volatile int Camera_Captured;
|
extern volatile int Camera_Captured;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue