OSDN Git Service

Added font controller.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 16:52:46 +0000 (09:52 -0700)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Mon, 20 Aug 2012 16:52:46 +0000 (09:52 -0700)
firm/bare_metal/lcd.c
firm/bare_metal/lcd.h

index 0e92b2e..aff64dd 100644 (file)
@@ -168,7 +168,7 @@ void lcd_putc(char c)
 {
     RS_ON();
     write_command(c);
-    DELAY_US(40);
+    DELAY_US(46);
 }
 
 void lcd_puts(char *str)
@@ -179,3 +179,68 @@ void lcd_puts(char *str)
     }
 }
 
+void lcd_font_init(FontSet *fs)
+{
+    int i, j;
+    for (i = 0; i < LCD_FONT_CHARS; i++) {
+        for (j = 0; j < LCD_FONT_HEIGHT; j++) {
+            fs->fontlist[i].data[j] = 0x00;
+        }
+    }
+}
+
+void lcd_font_set_pixel(
+        FontSet *fs, UserFont index,
+        const int x, const int y, const int on)
+{
+    if (LCD_FONT_WIDTH <= x) {
+        return;
+    }
+    if (LCD_FONT_HEIGHT <= y) {
+        return;
+    }
+    if (on) {
+        fs->fontlist[(int)index].data[y] |=
+            (1 << (LCD_FONT_WIDTH - x - 1));
+    } else {
+        fs->fontlist[(int)index].data[y] &=
+            ~(1 << (LCD_FONT_WIDTH - x - 1));
+    }
+}
+
+void lcd_font_setup_single(FontSet *fs, UserFont index)
+{
+    uint8_t addr = 0;
+    int i = (int)index, j;
+    for (j = 0; j < LCD_FONT_HEIGHT; j++) {
+        RS_OFF();
+        write_command(0x40 | (addr & 0x3f));
+        DELAY_US(40);
+
+        RS_ON();
+        write_command(fs->fontlist[i].data[j]);
+        DELAY_US(46);
+
+        addr++;
+    }
+}
+
+void lcd_font_setup_all(FontSet *fs)
+{
+    uint8_t addr = 0;
+    int i, j;
+    for (i = 0; i < LCD_FONT_CHARS; i++) {
+        for (j = 0; j < LCD_FONT_HEIGHT; j++) {
+            RS_OFF();
+            write_command(0x40 | (addr & 0x3f));
+            DELAY_US(40);
+
+            RS_ON();
+            write_command(fs->fontlist[i].data[j]);
+            DELAY_US(46);
+
+            addr++;
+        }
+    }
+}
+
index 3a5837c..0c99928 100644 (file)
@@ -9,6 +9,29 @@ typedef enum {
     Right
 } Direction;
 
+typedef enum {
+    UserFont1,
+    UserFont2,
+    UserFont3,
+    UserFont4,
+    UserFont5,
+    UserFont6,
+    UserFont7,
+    UserFont8
+} UserFont;
+
+#define LCD_FONT_WIDTH  (5)
+#define LCD_FONT_HEIGHT (8)
+#define LCD_FONT_CHARS  (8)
+
+typedef struct {
+    unsigned char data[LCD_FONT_HEIGHT];
+} Font;
+
+typedef struct {
+    Font fontlist[LCD_FONT_CHARS];
+} FontSet;
+
 void lcd_init(void);
 void lcd_clear(void);
 void lcd_cursor_at_home(void);
@@ -19,6 +42,12 @@ void lcd_display_shift(Direction dir);
 void lcd_goto(uint8_t x, uint8_t y);
 void lcd_putc(char c);
 void lcd_puts(char *str);
+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_setup_single(FontSet *fs, UserFont index);
+void lcd_font_setup_all(FontSet *fs);
 
 #endif