diff options
Diffstat (limited to 'src/display_draw.c')
-rw-r--r-- | src/display_draw.c | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/src/display_draw.c b/src/display_draw.c index f52cd8e..0d26e9a 100644 --- a/src/display_draw.c +++ b/src/display_draw.c @@ -1,15 +1,54 @@ +#include <display_draw.h> #include <display.h> +#include <task.h> +#include <clock.h> + +volatile uint8_t lock = 0; +#define LOCK while (lock) { delay(5); } lock = 1 +#define UNLOCK lock = 0 static unsigned int curx = 0; static unsigned int cury = 0; +static unsigned int curxo = 0; +static unsigned int curyo = 0; extern const unsigned char inconsolata24[192 * 156 * 2 + 1]; +void task_cursor(void) +{ + while (1) { + int x = curxo + curx * 12; + int y = curyo + cury * 26; + dsp_rect(x, y + 24, 12, 1, 0xFFFF); + delay(300); + dsp_rect(x, y + 24, 12, 1, 0); + delay(300); + } +} + +void dsp_cursoron(void) +{ + task_start(task_cursor, 512); +} + void dsp_putchar(int c) { + if (c == '\n') { + curx = 0; + if (++cury == 12) { + UNLOCK; + dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0); + LOCK; + cury = 0; + } + return; + } + unsigned int start = ((c - ' ') / 16 * 192 * 26 + (c % 16) * 12) * 2; - dsp_set_addr(curx * 12, cury * 26, curx * 12 + 11, cury * 26 + 25); + unsigned int x = curxo + curx * 12; + unsigned int y = curyo + cury * 26; + dsp_set_addr(x, y, x + 11, y + 25); // for each row for (unsigned int i = 0; i < 26; i++) { // for each column @@ -19,16 +58,22 @@ void dsp_putchar(int c) if (++curx == 40) { curx = 0; - if (++cury == 10) + if (++cury == 12) { + UNLOCK; + dsp_rect(0, 0, LCD_WIDTH, LCD_HEIGHT, 0); + LOCK; cury = 0; + } } } void dsp_puts(const char *s) { unsigned int i = 0; + LOCK; while (s[i]) dsp_putchar(s[i++]); + UNLOCK; } void dsp_cpos(int x, int y) @@ -37,12 +82,55 @@ void dsp_cpos(int x, int y) cury = y; } +void dsp_coff(int x, int y) +{ + curxo = x; + curyo = y; +} + void dsp_rect(int x, int y, int w, int h, uint16_t color) { + LOCK; dsp_set_addr(x, y, x + w - 1, y + h - 1); int countdown = w * h; do { dsp_write_data(color >> 8); dsp_write_data(color & 0xFF); } while (countdown--); + UNLOCK; +} + +void dsp_line(int x, int y, int i, int j, uint16_t color) +{ + int dx = i - x; + int sx = dx >= 0 ? 1 : -1; + int dy = j - y; + int sy = dy >= 0 ? 1 : -1; + + if (dx < 0) + dx *= -1; + if (dy < 0) + dy *= -1; + int err = (dx > dy ? dx : -dy) / 2; + int e2; + + LOCK; + while (1) { + dsp_set_addr(x, y, x, y); + dsp_write_data(color >> 8); + dsp_write_data(color & 0xFF); + if (x == i && y == j) + break; + e2 = err; + if (e2 > -dx) { + err -= dy; + x += sx; + } + if (e2 < dy) { + err += dx; + y += sy; + } + } + UNLOCK; } + |