From: Shinichiro Nakamura Date: Mon, 20 Aug 2012 22:09:44 +0000 (+0900) Subject: Updated the lcd interface. X-Git-Url: http://git.osdn.net/view?p=bluetank%2Fbluetank.git;a=commitdiff_plain;h=c64022da8661a7981c175a160a5f8fd8d8d3437e Updated the lcd interface. --- diff --git a/firm/bare_metal/lcd.c b/firm/bare_metal/lcd.c index aff64dd..7730b22 100644 --- a/firm/bare_metal/lcd.c +++ b/firm/bare_metal/lcd.c @@ -1,5 +1,6 @@ #include +#include #include "lcd.h" #include "bfin_util.h" @@ -208,6 +209,56 @@ void lcd_font_set_pixel( } } +#define swap(A,B) \ + do { \ + int C = A; \ + A = B; \ + B = C; \ + } while (0) + +void lcd_font_draw_line( + FontSet *fs, UserFont index, + int x1, int y1, + int x2, int y2, + int on) +{ + int x; + /* + * Bresenham's line algorithm + */ + bool steep = abs(y2 - y1) > abs(x2 - x1); + if (steep) { + swap(x1, y1); + swap(x2, y2); + } + if (x1 > x2) { + swap(x1, x2); + swap(y1, y2); + } + int deltax = x2 - x1; + int deltay = abs(y2 - y1); + int error = deltax / 2; + int ystep; + int y = y1; + if (y1 < y2) { + ystep = 1; + } else { + ystep = -1; + } + for (x = x1; x <= x2; x++) { + if (steep) { + lcd_font_set_pixel(fs, index, y, x, on); + } else { + lcd_font_set_pixel(fs, index, x, y, on); + } + error = error - deltay; + if (error < 0) { + y = y + ystep; + error = error + deltax; + } + } +} + void lcd_font_setup_single(FontSet *fs, UserFont index) { uint8_t addr = 0; diff --git a/firm/bare_metal/lcd.h b/firm/bare_metal/lcd.h index 0c99928..29cbe20 100644 --- a/firm/bare_metal/lcd.h +++ b/firm/bare_metal/lcd.h @@ -46,6 +46,11 @@ void lcd_font_init(FontSet *fs); void lcd_font_set_pixel( FontSet *fs, UserFont index, const int x, const int y, const int on); +void lcd_font_draw_line( + FontSet *fs, UserFont index, + int x1, int y1, + int x2, int y2, + int on); void lcd_font_setup_single(FontSet *fs, UserFont index); void lcd_font_setup_all(FontSet *fs); diff --git a/firm/bare_metal/uzume.c b/firm/bare_metal/uzume.c index e404e1a..1cc5867 100644 --- a/firm/bare_metal/uzume.c +++ b/firm/bare_metal/uzume.c @@ -218,8 +218,33 @@ void uzume_set_system(UZUME *p, UZUME_SYSTEM_FUNC system) void uzume_execute(UZUME *p) { + int i, j; + char lcdbuf[16]; int32_t bufidx_dma_done; + FontSet fontset; + + /* + * Initialize fontset + */ + lcd_font_init(&fontset); + for (i = 0; i < (int)LCD_FONT_CHARS; i++) { + for (j = 0; j < i + 1; j++) { + lcd_font_draw_line(&fontset, (UserFont)i, 0, (7 - j), 4, (7 - j), 1); + } + } + lcd_font_setup_all(&fontset); + + /* + * Draw the text string. + */ + for (i = 0; i < 8; i++) { + lcdbuf[i] = 0x08 + i; + } + lcdbuf[8] = 0x00; + lcd_goto(0, 0); + lcd_puts(lcdbuf); + while (1) { asm("idle;"); if (0 != data_ready) {