diff options
author | Joel Bodenmann <joel@unormal.org> | 2013-04-12 09:12:00 +0200 |
---|---|---|
committer | Joel Bodenmann <joel@unormal.org> | 2013-04-12 09:12:00 +0200 |
commit | df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497 (patch) | |
tree | 20daa1a25af18bbd585630bd868b3e3e97eafe40 /drivers/tdisp | |
parent | ffabd740c6d929c14b912ce07d2cc796b7223135 (diff) | |
download | uGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.tar.gz uGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.tar.bz2 uGFX-df5c3fd6dd9fdc82f15f1a44e71e98d6a1a1c497.zip |
TDISP fixes - by Frysk
Diffstat (limited to 'drivers/tdisp')
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld.c | 110 | ||||
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h | 81 |
2 files changed, 154 insertions, 37 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; diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h index ceae7a4d..1fe222dc 100644 --- a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h +++ b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h @@ -30,41 +30,104 @@ #define _TDISP_LLD_BOARD_H
/* Configure these to match the hardware connections on your board */
-#define BUS_4BITS FALSE
-#define PORT_DATA GPIOG
-#define PORT_CTRL GPIOE
+#define BUS_4BITS TRUE
+
+/* Configure the bitoffset in the dataport so they match with the
+ * hardware pins. An offset of 0 means bit0 stays at bit0 of the dataport.
+ * If the offset is set to 3, bit0 of the nibble will be positioned at
+ * P[A..G]3 of the hardware-port.
+ */
+#define hardware_offset 3
+
+/* The port where the data is sent to. In the
+ * low-leveldriver het hardware_offset is taken
+ * into account. If for example the hardware_offset
+ * is set to 3, then de data will be sent to
+ * PE3, PE4, PE5 en PE6, if the dataport where GPIOE.
+ */
+#define PORT_DATA GPIOE
+
+/* The port used to controle the controle lines of
+ * the display.
+ */
+#define PORT_CTRL GPIOD
+/* Pin to controle the R/S-line of the display */
#define PIN_RS 0
-#define PIN_RW 1
-#define PIN_EN 2
+/* Pin to controle the EN-line of the display */
+#define PIN_EN 1
+/* Pin to controle the R/W-pin of the display.
+ * If reading of the display is not used disable
+ * reading in the gfxconf.h and put a dummy value here
+ * as it will not be used.
+ */
+#define PIN_RW 7
+
static void init_board(void) {
+ /* Initialize the ports for data and controle-lines */
palSetGroupMode(PORT_CTRL, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
palSetGroupMode(PORT_DATA, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palClearPad(PORT_CTRL, PIN_RW);
+ /* Set alle controle pins to low */
+ palClearPad(PORT_CTRL, PIN_RS);
+ palClearPad(PORT_CTRL, PIN_EN);
+ #if TDISP_NEED_READ
+ palClearPad(PORT_CTRL, PIN_RW);
+ #endif
}
+/* This is the low-level routine for sending the bits
+ * to the LCD-display. This routine shifts
+ * the bits so they match the hardware port.
+ */
static void writeToLCD(uint8_t data) {
- palWritePort(PORT_DATA, data);
+ palWritePort(PORT_DATA, data<<hardware_offset);
palSetPad(PORT_CTRL, PIN_EN);
chThdSleepMicroseconds(1);
palClearPad(PORT_CTRL, PIN_EN);
+ /* wait a little while so that de display can process the data */
chThdSleepMicroseconds(5);
}
+/* Writes a command to the display. The
+ * RS-line is pulled low and than the
+ * data is send.
+ */
static void write_cmd(uint8_t data) {
palClearPad(PORT_CTRL, PIN_RS);
#if BUS_4BITS
+ /* first send the high-nibble */
writeToLCD(data>>4);
#endif
- writeToLCD(data);
+ /* send the low-nibble */
+ #if BUS_4BITS
+ /* in 4-bit mode the high-nibble is zeroed out */
+ writeToLCD(data & 0x0F);
+ #else
+ writeToLCD(data);
+ #endif
}
+// static void write_initcmd(uint8_t data) {
+// write_cmd(data);
+// }
+
+/* Write data to the display. The
+ * RS-line is pulled high and than the
+ * data is send.
+ */
static void write_data(uint8_t data) {
palSetPad(PORT_CTRL, PIN_RS);
#if BUS_4BITS
+ /* first send the high-nibble */
writeToLCD(data>>4);
#endif
- writeToLCD(data);
+ /* send the low-nibble */
+ #if BUS_4BITS
+ /* in 4-bit mode the high-nibble is zeroed out */
+ writeToLCD(data & 0x0F);
+ #else
+ writeToLCD(data);
+ #endif
}
#endif /* _TDISP_LLD_BOARD_H */
|