Restructure
[liquid-crystal-terminal.git] / terminal / lcd.h
diff --git a/terminal/lcd.h b/terminal/lcd.h
new file mode 100644 (file)
index 0000000..ee284e1
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef _H_LCD
+#define _H_LCD
+
+// LCD pins
+#define LCD_REGSEL  3 // Register select
+#define LCD_ENABLE  4 // Chip enable
+#define LCD_D4      5 // Data line
+#define LCD_D5      6 // Data line
+#define LCD_D6      7 // Data line
+#define LCD_D7      8 // Data line
+#define LCD_BL      2 // Backlight
+
+LiquidCrystal lcd(LCD_REGSEL, LCD_ENABLE, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
+
+enum backlight_state {
+       BL_OFF,
+       BL_ON,
+       BL_FLASH
+};
+
+struct backlight {
+       enum backlight_state state;
+       unsigned int timer;
+};
+
+#define COLS 40
+#define ROWS 2
+
+/**
+ * Special characters.
+ * See https://www.quinapalus.com/hd44780udg.html to make more.
+ * Define which ones are used (max. 8) in setup().
+ * When they need to be changed at runtime, make sure the cursor is disabled
+ * and call setCursor afterwards.
+ */
+unsigned char char_music[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00};
+unsigned char char_smile[8] = {0x00,0x00,0x0a,0x00,0x11,0x0e,0x00};
+unsigned char char_bar_1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1f};
+unsigned char char_bar_2[8] = {0x00,0x00,0x00,0x00,0x00,0x1f,0x1f};
+unsigned char char_bar_3[8] = {0x00,0x00,0x00,0x00,0x1f,0x1f,0x1f};
+unsigned char char_bar_4[8] = {0x00,0x00,0x00,0x1f,0x1f,0x1f,0x1f};
+unsigned char char_bar_5[8] = {0x00,0x00,0x1f,0x1f,0x1f,0x1f,0x1f};
+unsigned char char_bar_6[8] = {0x00,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+unsigned char char_bar_7[8] = {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
+unsigned char char_hbar_start_empty[8] = {0x1f,0x10,0x10,0x10,0x10,0x10,0x1f};
+unsigned char char_hbar_start_full[8]  = {0x1f,0x10,0x17,0x17,0x17,0x10,0x1f};
+unsigned char char_hbar_inner_empty[8] = {0x1f,0x00,0x00,0x00,0x00,0x00,0x1f};
+unsigned char char_hbar_inner_half[8]  = {0x1f,0x00,0x1c,0x1c,0x1c,0x00,0x1f};
+unsigned char char_hbar_inner_full[8]  = {0x1f,0x00,0x1f,0x1f,0x1f,0x00,0x1f};
+unsigned char char_hbar_end_empty[8]   = {0x1f,0x01,0x01,0x01,0x01,0x01,0x1f};
+unsigned char char_hbar_end_full[8]    = {0x1f,0x01,0x1d,0x1d,0x1d,0x01,0x1f};
+
+void lcd_setup(void);
+void bl_tasks(void);
+void bl_set(enum backlight_state);
+
+#endif