aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tdisp/HD44780/tdisp_lld.c
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2013-04-12 09:12:00 +0200
committerJoel Bodenmann <joel@unormal.org>2013-04-12 09:12:00 +0200
commitdf5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497 (patch)
tree20daa1a25af18bbd585630bd868b3e3e97eafe40 /drivers/tdisp/HD44780/tdisp_lld.c
parentffabd740c6d929c14b912ce07d2cc796b7223135 (diff)
downloaduGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.tar.gz
uGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.tar.bz2
uGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.zip
TDISP fixes - by Frysk
Diffstat (limited to 'drivers/tdisp/HD44780/tdisp_lld.c')
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld.c110
1 files changed, 82 insertions, 28 deletions
diff --git a/drivers/tdisp/HD44780/tdisp_lld.c b/drivers/tdisp/HD44780/tdisp_lld.c
index 76557d1d..b68d1f55 100644
--- a/drivers/tdisp/HD44780/tdisp_lld.c
+++ b/drivers/tdisp/HD44780/tdisp_lld.c
@@ -32,21 +32,23 @@
#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/
-/* Include the hardware interface details */
-#if defined(BOARD_OLIMEX_STM32_E407)
+/* check first if the user has defined his/her own lowlevel-board file */
+#if defined(TDISP_USE_CUSTOM_BOARD) && TDISP_USE_CUSTOM_BOARD
+ /* Include the user supplied board definitions */
+ #include "tdisp_lld_board.h"
+#elif defined(BOARD_OLIMEX_STM32_E407)
#include "tdisp_lld_board_olimex_e407.h"
#elif defined(BOARD_ST_STM32F4_DISCOVERY)
- #include "tdisp_lld_board_st_stm32f4_discovery.h"
-#else
#include "tdisp_lld_board_example.h"
#endif
+
/* The user may override the default display size */
#ifndef TDISP_COLUMNS
#define TDISP_COLUMNS 16
#endif
#ifndef TDISP_ROWS
- #define TDISP_ROWS 2
+ #define TDISP_ROWS 2
#endif
/* Controller Specific Properties */
@@ -56,15 +58,15 @@
/* Define the properties of our controller */
tdispStruct TDISP = {
- TDISP_COLUMNS, TDISP_ROWS, /* cols, rows */
+ TDISP_COLUMNS, TDISP_ROWS, /* cols, rows */
CUSTOM_CHAR_XBITS, CUSTOM_CHAR_YBITS, /* charBitsX, charBitsY */
- CUSTOM_CHAR_COUNT /* maxCustomChars */
+ CUSTOM_CHAR_COUNT /* maxCustomChars */
};
/* Our display control */
-#define DISPLAY_ON 0x04
-#define CURSOR_ON 0x02
-#define CURSOR_BLINK 0x01
+#define TDISP_DISPLAY_ON 0x04
+#define TDISP_CURSOR_ON 0x02
+#define TDISP_CURSOR_BLINK 0x01
static uint8_t displaycontrol;
@@ -72,28 +74,77 @@ static uint8_t displaycontrol;
bool_t tdisp_lld_init(void) {
/* initialise hardware */
init_board();
-
- /* wait some time */
- chThdSleepMilliseconds(50);
-
- write_cmd(0x38);
- chThdSleepMilliseconds(64);
-
- displaycontrol = DISPLAY_ON | CURSOR_ON | CURSOR_BLINK; // The default displaycontrol
- write_cmd(0x08 | displaycontrol);
- chThdSleepMicroseconds(50);
-
- write_cmd(0x01); // Clear the screen
- chThdSleepMilliseconds(5);
-
+
+ /* The first part is the initialing code.
+ * In this part only the lower nibble of the
+ * byte is written directly to the display, thus
+ * without write_cmd, which sends both high and
+ * low nibble.
+ */
+
+ /* Give the LCD a little time to wake up */
+ chThdSleepMilliseconds(15);
+
+ /* write three times 0x03 to display
+ * with RS = low.
+ */
+ palClearPad(PORT_CTRL, PIN_RS);
+ #if BUS_4BITS
+ writeToLCD(0x03); // 1x
+ writeToLCD(0x03); // 2x
+ writeToLCD(0x03); // 3x
+ /* Put display in 4-bit mode by
+ * write 0x02 to display.
+ */
+ writeToLCD(0x02); // 4bit-modus
+ #else
+ writeToLCD(0x30); // 1x
+ writeToLCD(0x30); // 2x
+ writeToLCD(0x30); // 3x
+ #endif
+
+ /* From this point on, the LCD accepts
+ * bytes sent with highnibbel first and than
+ *the lownibble.
+ */
+
+ /* 4-bit modus, 2 lines en 5x7 characters */
+ write_cmd(0x28);
+
+ displaycontrol = TDISP_DISPLAY_ON;
+
+ /* set display on, cursor off and no blinking */
+ write_cmd(0x0C);
+ /* set cursor move direction */
write_cmd(0x06);
- chThdSleepMicroseconds(50);
+ /* END OF INITIALISATION */
+
+// /* wait some time */
+// chThdSleepMilliseconds(50);
+//
+// write_cmd(0x38);
+// chThdSleepMilliseconds(64);
+//
+// displaycontrol = DISPLAY_ON | CURSOR_ON | CURSOR_BLINK; // The default displaycontrol
+// write_cmd(0x08 | displaycontrol);
+// chThdSleepMicroseconds(50);
+//
+// write_cmd(0x01); // Clear the screen
+// chThdSleepMilliseconds(5);
+//
+// write_cmd(0x06);
+// chThdSleepMicroseconds(50);
return TRUE;
}
+/* Clears the display. The display needs
+ * a long time to process this command. So
+ * an extra delay is insterted.
+ */
void tdisp_lld_clear(void) {
write_cmd(0x01);
+// chThdSleepMilliseconds(LONG_DELAY_MS);
}
void tdisp_lld_draw_char(char c) {
@@ -122,11 +173,14 @@ void tdisp_lld_create_char(uint8_t address, uint8_t *charmap) {
int i;
write_cmd(0x40 | (address << 3));
- for(i = 0; i < CUSTOM_CHAR_YBITS; i++)
+ for(i = 0; i < CUSTOM_CHAR_YBITS; i++) {
write_data(charmap[i]);
+ }
+
}
-void tdisp_lld_control(uint16_t what, void *value) {
+void tdisp_lld_control(uint16_t what, uint16_t value) {
+
switch(what) {
case TDISP_CTRL_BACKLIGHT:
if ((uint8_t)value)
@@ -136,7 +190,7 @@ void tdisp_lld_control(uint16_t what, void *value) {
write_cmd(0x08 | displaycontrol);
break;
case TDISP_CTRL_CURSOR:
- switch((cursorshape)value) {
+ switch((uint8_t)value) {
case cursorOff:
displaycontrol &= ~CURSOR_ON;
break;