diff --git a/build-number.txt b/build-number.txt index ec8785e..3560666 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -405 +429 diff --git a/src/main.c b/src/main.c index 73897b3..caf1465 100755 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,11 @@ int main(void) // LTP1245_FeedPaper(10); // LTP1245_Cut(); + while(!Camera_Captured); + + extern uint8_t ImageBuffer[176 * 144 / 8]; + Print_Image(ImageBuffer, 176, 144); + for(;;) { } diff --git a/src/ov7670.c b/src/ov7670.c index cae9976..4b2139c 100644 --- a/src/ov7670.c +++ b/src/ov7670.c @@ -150,9 +150,11 @@ uint8_t ImageBuffer[176 * 144 / 8]; static volatile int CurrentLine = 0; -uint8_t LineBuffer1[176]; -uint8_t LineBuffer2[176]; +uint8_t LineBuffer1[176 * 2 + 40]; +uint8_t LineBuffer2[176 * 2 + 40]; int LineCount = 0; +static int FrameCount = 0; +volatile int Camera_Captured = 0; static uint8_t ReadRegister(uint8_t reg) { @@ -263,7 +265,7 @@ void Camera_Init(void) // pixel clock and should trigger DMA transfers TIM3->PSC = 0; TIM3->ARR = 1; - TIM3->CCMR1 = TIM_CCMR1_CC2S_0 | TIM_CCMR1_CC1S_0 | TIM_CCMR1_IC1PSC_0; + TIM3->CCMR1 = TIM_CCMR1_CC2S_0 | TIM_CCMR1_CC1S_0; TIM3->CCER = TIM_CCER_CC2P | TIM_CCER_CC2E | TIM_CCER_CC1E | TIM_CCER_CC1P; TIM3->DIER = TIM_DIER_CC2IE; TIM3->CR1 = TIM_CR1_CEN; @@ -271,7 +273,7 @@ void Camera_Init(void) NVIC_EnableIRQ(TIM3_IRQn); // Fetch GPIOA IDR lower byte - DMA1_Channel6->CMAR = (uint32_t)&(GPIOA->IDR); + DMA1_Channel6->CPAR = (uint32_t)&(GPIOA->IDR); // Startup delay for(volatile int i = 0; i < 1000; i++); @@ -282,8 +284,11 @@ void Camera_Init(void) // Disable timing resets WriteRegister(REG_COM6, 0x00); + // Set clock prescaler to 2 + WriteRegister(REG_CLKRC, 0x4 | 1); + // Enable scaling - WriteRegister(REG_COM3, 0x08 | 0x04); + WriteRegister(REG_COM3, 0x08); // Use QCIF output format WriteRegister(REG_COM7, 0x08); @@ -291,11 +296,9 @@ void Camera_Init(void) // Blank pixel clock during sync pulses WriteRegister(REG_COM10, 0x20); - // Set clock prescaler to 2 - WriteRegister(REG_CLKRC, 0x4 | 1); - // Enable pixel clock scaling - WriteRegister(REG_COM14, 0x10); + WriteRegister(REG_COM14, 0x18 | 2); + WriteRegister(REG_SCALING_PCLK_DIV, 2); } void TIM1_CC_IRQHandler(void) @@ -306,6 +309,12 @@ void TIM1_CC_IRQHandler(void) LineCount = CurrentLine; CurrentLine = 0; + FrameCount++; + + if(FrameCount == 10) + { + Camera_Captured = 1; + } // Dummy read TIM1->CCR2; @@ -322,20 +331,41 @@ void TIM3_IRQHandler(void) TIM3->DIER &= ~TIM_DIER_CC1DE; TIM3->SR &= ~TIM_SR_CC1IF; + uint8_t *filledbuffer; + DMA1_Channel6->CCR = 0; DMA1_Channel6->CNDTR = sizeof(LineBuffer1); if(CurrentLine & 1) { DMA1_Channel6->CMAR = (uint32_t)LineBuffer1; + filledbuffer = LineBuffer2; } else { DMA1_Channel6->CMAR = (uint32_t)LineBuffer2; + filledbuffer = LineBuffer1; } DMA1_Channel6->CCR = DMA_CCR_PL | DMA_CCR_MINC | DMA_CCR_EN; TIM3->DIER |= TIM_DIER_CC1DE; - // ImageBuffer[0] = 0; + if(!Camera_Captured) + { + int error = 0; + for(int i = 0; i < 176; i++) + { + int pixel = filledbuffer[i * 2 + 33] + error; + if(pixel < 127) + { + error = pixel; + ImageBuffer[(CurrentLine * 176 + i) / 8] |= 0x80 >> (i % 8); + } + else + { + error = pixel - 255; + ImageBuffer[(CurrentLine * 176 + i) / 8] &= ~(0x80 >> (i % 8)); + } + } + } CurrentLine++; diff --git a/src/ov7670.h b/src/ov7670.h index 51a5114..f932096 100644 --- a/src/ov7670.h +++ b/src/ov7670.h @@ -3,4 +3,6 @@ #include #include "stm32f1xx.h" +extern volatile int Camera_Captured; + void Camera_Init(void); \ No newline at end of file diff --git a/src/print.c b/src/print.c index e28dccc..32e8c24 100644 --- a/src/print.c +++ b/src/print.c @@ -1,7 +1,7 @@ #include "print.h" #include "ltp1245.h" -static uint8_t Print_Buffer[64 * LTP1245_LINE_BYTES]; +static uint8_t Print_Buffer[PRINT_BUFFER_LINES * LTP1245_LINE_BYTES]; void Print_Text(const char *text, const Font_t *font) { @@ -36,4 +36,31 @@ void Print_Text(const char *text, const Font_t *font) } LTP1245_Print(Print_Buffer, height); +} + +// Width needs to be divisible by 8 +void Print_Image(const uint8_t *data, int width, int height) +{ + int currentline = 0; + while(height) + { + int lines = PRINT_BUFFER_LINES; + if(height < lines) + { + lines = height; + } + + for(int i = 0; i < lines; i++) + { + memcpy(Print_Buffer + i * LTP1245_LINE_BYTES, + data + currentline * width / 8, + width / 8); + //memset(Print_Buffer + width / 8, 0, LTP1245_LINE_BYTES - width / 8); + currentline++; + } + + LTP1245_Print(Print_Buffer, lines); + + height -= lines; + } } \ No newline at end of file diff --git a/src/print.h b/src/print.h index 8647730..2d61190 100644 --- a/src/print.h +++ b/src/print.h @@ -7,4 +7,5 @@ #define PRINT_BUFFER_LINES 64 -void Print_Text(const char *text, const Font_t *font); \ No newline at end of file +void Print_Text(const char *text, const Font_t *font); +void Print_Image(const uint8_t *data, int width, int height); \ No newline at end of file