68 lines
1.5 KiB
C
Raw Normal View History

2022-04-07 18:46:57 +02:00
#define LCD_TEST
#ifdef LCD_TEST
#include <stdint.h>
#include <math.h>
#include <stdio.h>
#include "lt24.h"
#include "system.h"
#include "sys/alt_irq.h"
#define MAX_RED (2 << 5)
#define MAX_GREEN (2 << 6)
#define MAX_BLUE (2 << 5)
#define MAX_RED_V 0b11111
#define MAX_GREEN_V 0b111111
#define MAX_BLUE_V 0b11111
// Compute an image that is h + MAX_GREEN in height
void drawTestImage(uint16_t *buffer, const unsigned h, const unsigned w, const unsigned offset)
{
pixel_t p0 = {0};
int idx = 0;
float rh = 1.*MAX_RED_V;
float rw = 1.*MAX_BLUE_V;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
p0.r = (unsigned)(y*rh / h);
p0.b = (unsigned)(x*rw / w);
IOWR_16DIRECT(buffer, idx, encPixel(&p0));
idx+=2;
}
}
}
#define W (320)
#define H (240)
uint16_t *buffer = HPS_0_BRIDGES_BASE;
struct LT24 *lcd = LCDCONTROLLER_0_BASE;
void lcd_ISR()
{
LT24_clearIRQ(lcd, LT24_IRQ_CTRL_IRQ0_ACTIVE);
LT24_refresh(lcd);
}
int main()
{
LT24_initialize(lcd);
LT24_writeIRQ(lcd, LT24_IRQ_CTRL_ENABLE);
LT24_setWidth(lcd, W);
LT24_setHeight(lcd, H);
LT24_writeBase(lcd, (uint32_t)buffer);
// Register LCD refresh finished interrupt
alt_ic_isr_register(LCDCONTROLLER_0_IRQ_INTERRUPT_CONTROLLER_ID,
LCDCONTROLLER_0_IRQ, lcd_ISR, 0, 0);
drawTestImage(buffer,H,W,0);
// Initiate continuous refreshing through an initial call to the ISR
lcd_ISR();
while (1){}
return 0;
}
#endif