Print first semi-successful image

This commit is contained in:
fruchti 2018-08-23 12:30:47 +02:00
parent 116ab5d23b
commit b2b3931e81
6 changed files with 78 additions and 13 deletions

View file

@ -1 +1 @@
405 429

View file

@ -28,6 +28,11 @@ int main(void)
// LTP1245_FeedPaper(10); // LTP1245_FeedPaper(10);
// LTP1245_Cut(); // LTP1245_Cut();
while(!Camera_Captured);
extern uint8_t ImageBuffer[176 * 144 / 8];
Print_Image(ImageBuffer, 176, 144);
for(;;) for(;;)
{ {
} }

View file

@ -150,9 +150,11 @@
uint8_t ImageBuffer[176 * 144 / 8]; uint8_t ImageBuffer[176 * 144 / 8];
static volatile int CurrentLine = 0; static volatile int CurrentLine = 0;
uint8_t LineBuffer1[176]; uint8_t LineBuffer1[176 * 2 + 40];
uint8_t LineBuffer2[176]; uint8_t LineBuffer2[176 * 2 + 40];
int LineCount = 0; int LineCount = 0;
static int FrameCount = 0;
volatile int Camera_Captured = 0;
static uint8_t ReadRegister(uint8_t reg) static uint8_t ReadRegister(uint8_t reg)
{ {
@ -263,7 +265,7 @@ void Camera_Init(void)
// pixel clock and should trigger DMA transfers // pixel clock and should trigger DMA transfers
TIM3->PSC = 0; TIM3->PSC = 0;
TIM3->ARR = 1; 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->CCER = TIM_CCER_CC2P | TIM_CCER_CC2E | TIM_CCER_CC1E | TIM_CCER_CC1P;
TIM3->DIER = TIM_DIER_CC2IE; TIM3->DIER = TIM_DIER_CC2IE;
TIM3->CR1 = TIM_CR1_CEN; TIM3->CR1 = TIM_CR1_CEN;
@ -271,7 +273,7 @@ void Camera_Init(void)
NVIC_EnableIRQ(TIM3_IRQn); NVIC_EnableIRQ(TIM3_IRQn);
// Fetch GPIOA IDR lower byte // Fetch GPIOA IDR lower byte
DMA1_Channel6->CMAR = (uint32_t)&(GPIOA->IDR); DMA1_Channel6->CPAR = (uint32_t)&(GPIOA->IDR);
// Startup delay // Startup delay
for(volatile int i = 0; i < 1000; i++); for(volatile int i = 0; i < 1000; i++);
@ -282,8 +284,11 @@ void Camera_Init(void)
// Disable timing resets // Disable timing resets
WriteRegister(REG_COM6, 0x00); WriteRegister(REG_COM6, 0x00);
// Set clock prescaler to 2
WriteRegister(REG_CLKRC, 0x4 | 1);
// Enable scaling // Enable scaling
WriteRegister(REG_COM3, 0x08 | 0x04); WriteRegister(REG_COM3, 0x08);
// Use QCIF output format // Use QCIF output format
WriteRegister(REG_COM7, 0x08); WriteRegister(REG_COM7, 0x08);
@ -291,11 +296,9 @@ void Camera_Init(void)
// Blank pixel clock during sync pulses // Blank pixel clock during sync pulses
WriteRegister(REG_COM10, 0x20); WriteRegister(REG_COM10, 0x20);
// Set clock prescaler to 2
WriteRegister(REG_CLKRC, 0x4 | 1);
// Enable pixel clock scaling // Enable pixel clock scaling
WriteRegister(REG_COM14, 0x10); WriteRegister(REG_COM14, 0x18 | 2);
WriteRegister(REG_SCALING_PCLK_DIV, 2);
} }
void TIM1_CC_IRQHandler(void) void TIM1_CC_IRQHandler(void)
@ -306,6 +309,12 @@ void TIM1_CC_IRQHandler(void)
LineCount = CurrentLine; LineCount = CurrentLine;
CurrentLine = 0; CurrentLine = 0;
FrameCount++;
if(FrameCount == 10)
{
Camera_Captured = 1;
}
// Dummy read // Dummy read
TIM1->CCR2; TIM1->CCR2;
@ -322,20 +331,41 @@ void TIM3_IRQHandler(void)
TIM3->DIER &= ~TIM_DIER_CC1DE; TIM3->DIER &= ~TIM_DIER_CC1DE;
TIM3->SR &= ~TIM_SR_CC1IF; TIM3->SR &= ~TIM_SR_CC1IF;
uint8_t *filledbuffer;
DMA1_Channel6->CCR = 0; DMA1_Channel6->CCR = 0;
DMA1_Channel6->CNDTR = sizeof(LineBuffer1); DMA1_Channel6->CNDTR = sizeof(LineBuffer1);
if(CurrentLine & 1) if(CurrentLine & 1)
{ {
DMA1_Channel6->CMAR = (uint32_t)LineBuffer1; DMA1_Channel6->CMAR = (uint32_t)LineBuffer1;
filledbuffer = LineBuffer2;
} }
else else
{ {
DMA1_Channel6->CMAR = (uint32_t)LineBuffer2; DMA1_Channel6->CMAR = (uint32_t)LineBuffer2;
filledbuffer = LineBuffer1;
} }
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;
// 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++; CurrentLine++;

View file

@ -3,4 +3,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "stm32f1xx.h" #include "stm32f1xx.h"
extern volatile int Camera_Captured;
void Camera_Init(void); void Camera_Init(void);

View file

@ -1,7 +1,7 @@
#include "print.h" #include "print.h"
#include "ltp1245.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) void Print_Text(const char *text, const Font_t *font)
{ {
@ -37,3 +37,30 @@ void Print_Text(const char *text, const Font_t *font)
LTP1245_Print(Print_Buffer, height); 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;
}
}

View file

@ -8,3 +8,4 @@
#define PRINT_BUFFER_LINES 64 #define PRINT_BUFFER_LINES 64
void Print_Text(const char *text, const Font_t *font); void Print_Text(const char *text, const Font_t *font);
void Print_Image(const uint8_t *data, int width, int height);