font support, inconsolata

master
Clyne Sullivan 7 years ago
parent 92d50d4d83
commit f90c71412c

@ -3,9 +3,13 @@
#include <stdint.h> #include <stdint.h>
#define LCD_WIDTH 480 #define LCD_WIDTH 320
#define LCD_HEIGHT 320 #define LCD_HEIGHT 480
#define COLOR_MAX 31
uint16_t dsp_color(uint8_t r, uint8_t g, uint8_t b);
void dsp_write_cmd(uint8_t data);
void dsp_write_data(uint8_t data); void dsp_write_data(uint8_t data);
void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); void dsp_set_addr(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void dsp_init(void); void dsp_init(void);

@ -38,6 +38,7 @@ void gpio_init(void);
void gpio_pupd(GPIO_TypeDef *port, uint8_t pin, uint8_t pupd); void gpio_pupd(GPIO_TypeDef *port, uint8_t pin, uint8_t pupd);
void gpio_type(GPIO_TypeDef *port, uint8_t pin, uint8_t type); void gpio_type(GPIO_TypeDef *port, uint8_t pin, uint8_t type);
void gpio_speed(GPIO_TypeDef *port, uint8_t pin, uint8_t speed);
void gpio_mode(GPIO_TypeDef *port, uint8_t pin, uint8_t mode); void gpio_mode(GPIO_TypeDef *port, uint8_t pin, uint8_t mode);
void gpio_dout(GPIO_TypeDef *port, uint8_t pin, uint8_t val); void gpio_dout(GPIO_TypeDef *port, uint8_t pin, uint8_t val);
uint8_t gpio_din(GPIO_TypeDef *port, uint8_t pin); uint8_t gpio_din(GPIO_TypeDef *port, uint8_t pin);

@ -21,6 +21,17 @@
// bbbbbggg gggrrrrr // bbbbbggg gggrrrrr
// 00000000
uint16_t dsp_color(uint8_t r, uint8_t g, uint8_t b)
{
r &= 0x1F;
g &= 0x3F;
b &= 0x1F;
uint16_t c = (b << 11) | (g << 5) | r;
return c;
}
void dsp_write_data(uint8_t data) void dsp_write_data(uint8_t data)
{ {
gpio_dout(LCD_D0, data & 0x01); gpio_dout(LCD_D0, data & 0x01);
@ -72,7 +83,20 @@ void dsp_init(void)
gpio_mode(LCD_D5, OUTPUT); gpio_mode(LCD_D5, OUTPUT);
gpio_mode(LCD_D6, OUTPUT); gpio_mode(LCD_D6, OUTPUT);
gpio_mode(LCD_D7, OUTPUT); gpio_mode(LCD_D7, OUTPUT);
gpio_dout(LCD_CS, 1); gpio_speed(LCD_CS, LOW);
gpio_speed(LCD_RS, LOW);
gpio_speed(LCD_RD, LOW);
gpio_speed(LCD_WR, LOW);
gpio_speed(LCD_RST, LOW);
gpio_speed(LCD_D0, LOW);
gpio_speed(LCD_D1, LOW);
gpio_speed(LCD_D2, LOW);
gpio_speed(LCD_D3, LOW);
gpio_speed(LCD_D4, LOW);
gpio_speed(LCD_D5, LOW);
gpio_speed(LCD_D6, LOW);
gpio_speed(LCD_D7, LOW);
gpio_dout(LCD_CS, 0);
gpio_dout(LCD_RS, 1); gpio_dout(LCD_RS, 1);
gpio_dout(LCD_RD, 1); gpio_dout(LCD_RD, 1);
gpio_dout(LCD_WR, 1); gpio_dout(LCD_WR, 1);
@ -120,15 +144,24 @@ void dsp_init(void)
dsp_write_data(0x11); dsp_write_data(0x11);
dsp_write_cmd(0xC5); // frame rate/inversion ctl dsp_write_cmd(0xC5); // frame rate/inversion ctl
dsp_write_data(0x03); dsp_write_data(0x03);
// backlight
dsp_write_cmd(0x55);
dsp_write_data(0x01);
dsp_write_cmd(0x53);
dsp_write_data(0x2C);
dsp_write_cmd(0x51);
dsp_write_data(0x01);
dsp_write_cmd(0x36); // rot. and stuff dsp_write_cmd(0x36); // rot. and stuff
dsp_write_data(0x41); dsp_write_data(0x41);
dsp_write_cmd(0x3A); // set pixel format dsp_write_cmd(0x3A); // set pixel format
dsp_write_data(0x55); dsp_write_data(0x65);
dsp_write_cmd(0x11); dsp_write_cmd(0x11);
delay(150); delay(150);
dsp_write_cmd(0x29); // set display on dsp_write_cmd(0x29); // set display on
delay(500); delay(500);
dsp_write_cmd(0x33); // set scroll area /*dsp_write_cmd(0x33); // set scroll area
dsp_write_data(0x00); dsp_write_data(0x00);
dsp_write_data(0x00); dsp_write_data(0x00);
dsp_write_data(LCD_HEIGHT >> 8); dsp_write_data(LCD_HEIGHT >> 8);
@ -137,7 +170,7 @@ void dsp_init(void)
dsp_write_data(0x00); dsp_write_data(0x00);
dsp_write_cmd(0x37); dsp_write_cmd(0x37);
dsp_write_data(0x00); dsp_write_data(0x00);
dsp_write_data(0x00); dsp_write_data(0x00);*/
dsp_set_addr(0, 0, LCD_WIDTH, LCD_HEIGHT); dsp_set_addr(0, 0, LCD_WIDTH, LCD_HEIGHT);
} }

@ -0,0 +1,29 @@
#include <display.h>
static unsigned int curx = 0;
static unsigned int cury = 0;
extern const unsigned char inconsolata24[192 * 156 * 2 + 1];
void dsp_putchar(int c)
{
unsigned int start = ((c - ' ') / 16 * 192 * 26 + (c % 16) * 12) * 2;
dsp_set_addr(curx * 12, cury * 26, curx * 12 + 11, cury * 26 + 25);
// for each row
for (unsigned int i = 0; i < 26; i++) {
// for each column
for (int j = 12 * 2 - 1; j >= 0; j--)
dsp_write_data(inconsolata24[start + (i * 192 * 2) + j]);
}
if (++curx == 26)
curx = 0, cury++;
}
void dsp_puts(const char *s)
{
unsigned int i = 0;
while (s[i])
dsp_putchar(s[i++]);
}

File diff suppressed because it is too large Load Diff

@ -102,12 +102,19 @@ void kmain(void)
asm("cpsie i"); asm("cpsie i");
dsp_init(); dsp_init();
dsp_set_addr(0, 0, LCD_WIDTH, LCD_HEIGHT); //uint16_t c = 0x38;
int w = LCD_WIDTH * LCD_HEIGHT; uint16_t c = 0;
for (int i = 0; i < LCD_HEIGHT; i++) {
dsp_set_addr(0, i, LCD_WIDTH - 1, i);
int w = LCD_WIDTH - 1;
do { do {
dsp_write_data(0);//c >> 8); dsp_write_data(c);//c >> 8);
dsp_write_data(0);//c & 0xFF); dsp_write_data(c);//c & 0xFF);
} while (w--); } while (w--);
}
extern void dsp_puts(const char *);
dsp_puts("Hello, world! My name is Clyne.");
//task_start(lcd_handler, 128); //task_start(lcd_handler, 128);
//delay(200); //delay(200);

Loading…
Cancel
Save