OSDN Git Service

Updated the lcd interface.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 22:09:44 +0000 (07:09 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 22:09:44 +0000 (07:09 +0900)
firm/bare_metal/lcd.c
firm/bare_metal/lcd.h
firm/bare_metal/uzume.c

index aff64dd..7730b22 100644 (file)
@@ -1,5 +1,6 @@
 
 #include <cdefBF592-A.h>
+#include <stdlib.h>
 #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;
index 0c99928..29cbe20 100644 (file)
@@ -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);
 
index e404e1a..1cc5867 100644 (file)
@@ -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) {