Use separate configuration header

This commit is contained in:
fruchti 2024-08-24 20:46:00 +02:00
parent d6932ae70c
commit e43202a113
3 changed files with 16 additions and 13 deletions

9
src/config.h Normal file
View 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

View file

@ -1,6 +1,7 @@
#include "ov7670.h"
#include "pinning.h"
#include "debug.h"
#include "config.h"
#define REG_GAIN 0x00
#define REG_BLUE 0x01
@ -156,7 +157,7 @@ static volatile int FrameCount = 0;
volatile int Camera_Captured = 0;
static unsigned int BlackPixels = 0;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
static volatile int ExposureCorrection = 0;
#endif
@ -327,7 +328,7 @@ void TIM1_CC_IRQHandler(void)
CurrentLine = 0;
FrameCount++;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
// Correct exposure across frames
ExposureCorrection += 32 * BlackPixels / CAMERA_PIXELS - 16;
#endif
@ -361,7 +362,7 @@ void TIM3_IRQHandler(void)
DMA1_Channel6->CCR = DMA_CCR_PL | DMA_CCR_MINC | DMA_CCR_EN;
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};
if(CurrentLine == 0)
@ -374,7 +375,7 @@ void TIM3_IRQHandler(void)
&& (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
// overwritten during x error diffusion, this is done now.
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++)
{
int pixel = LineBuffer[i + 15] + x_error;
#ifdef CAMERA_USE_EXPOSURE_CORRECTION
#ifdef CONFIG_USE_EXPOSURE_CORRECTION
if(ExposureCorrection < 0)
{
if(pixel < -ExposureCorrection)
@ -421,7 +422,7 @@ void TIM3_IRQHandler(void)
~(0x80 >> (i % 8));
}
#ifdef CAMERA_USE_2D_DITHERING
#ifdef CONFIG_USE_2D_DITHERING
// Error propagated to the next pixel in the same line
x_error = error * 7 / 16;

View file

@ -7,13 +7,6 @@
#define CAMERA_IMAGE_HEIGHT 144
#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;