diff options
Diffstat (limited to 'drivers/tdisp')
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld.c | 211 | ||||
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld_board_example.h | 23 | ||||
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h | 27 | ||||
-rw-r--r-- | drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h | 27 |
4 files changed, 197 insertions, 91 deletions
diff --git a/drivers/tdisp/HD44780/tdisp_lld.c b/drivers/tdisp/HD44780/tdisp_lld.c index 6ffadc65..31169703 100644 --- a/drivers/tdisp/HD44780/tdisp_lld.c +++ b/drivers/tdisp/HD44780/tdisp_lld.c @@ -1,9 +1,22 @@ /* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ /** * @file drivers/tdisp/HD44780/tdisp_lld.c @@ -13,9 +26,11 @@ * @{ */ +#include "ch.h" +#include "hal.h" #include "gfx.h" -#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/ +#if GFX_USE_TDISP || defined(__DOXYGEN__) /* check first if the user has defined his/her own lowlevel-board file */ #if defined(TDISP_USE_CUSTOM_BOARD) && TDISP_USE_CUSTOM_BOARD @@ -27,15 +42,6 @@ #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 -#endif - /* Controller Specific Properties */ #define CUSTOM_CHAR_COUNT 8 #define CUSTOM_CHAR_XBITS 5 @@ -48,13 +54,21 @@ tdispStruct TDISP = { CUSTOM_CHAR_COUNT /* maxCustomChars */ }; -/* Our display control */ +/* display control settings */ #define TDISP_DISPLAY_ON 0x04 #define TDISP_CURSOR_ON 0x02 #define TDISP_CURSOR_BLINK 0x01 -static uint8_t displaycontrol; +/* cursor movement settings */ +#define TDISP_SHIFT_ON 0x01 +#define TDISP_CURSOR_INC 0x02 +/* display scroll settings */ +#define TDISP_SCROLL_DISPLAY 0x08 +#define TDISP_SCROLL_RIGHT 0x04 + +static uint8_t displaycontrol; +static uint8_t cursorcontrol; bool_t tdisp_lld_init(void) { /* initialise hardware */ @@ -68,58 +82,55 @@ bool_t tdisp_lld_init(void) { */ /* Give the LCD a little time to wake up */ - gfxSleepMilliseconds(15); + chThdSleepMilliseconds(15); - /* write three times 0x03 to display - * with RS = low. - */ + /* clear the RS-line to the display */ palClearPad(PORT_CTRL, PIN_RS); - #if BUS_4BITS +// #if BUS_4BITS + /* write three times 0x03 to display (4-bit mode only) + * with RS = low. + */ writeToLCD(0x03); // 1x + chThdSleepMilliseconds(20); writeToLCD(0x03); // 2x +// chThdSleepMilliseconds(20); writeToLCD(0x03); // 3x +// chThdSleepMilliseconds(20); /* 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 +// chThdSleepMilliseconds(20); +// #else + /* write three times 0x30 to display (8-bit mode only) + * with RS = low. + */ +// 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. + *the lownibble if working in 4-bit mode. + * In 8-bit mode bytes are written in 1 action. */ /* 4-bit modus, 2 lines en 5x7 characters */ write_cmd(0x28); - - displaycontrol = TDISP_DISPLAY_ON; +// chThdSleepMilliseconds(20); /* set display on, cursor off and no blinking */ write_cmd(0x0C); - /* set cursor move direction */ +// chThdSleepMilliseconds(20); + /* set cursor increase and direction */ write_cmd(0x06); +// chThdSleepMilliseconds(20); + + displaycontrol = TDISP_DISPLAY_ON; + cursorcontrol = TDISP_CURSOR_INC; /* END OF INITIALISATION */ -// /* wait some time */ -// gfxSleepMilliseconds(50); -// -// write_cmd(0x38); -// gfxSleepMilliseconds(64); -// -// displaycontrol = TDISP_DISPLAY_ON | TDISP_CURSOR_ON | TDISP_CURSOR_BLINK; // The default displaycontrol -// write_cmd(0x08 | displaycontrol); -// gfxSleepMicroseconds(50); -// -// write_cmd(0x01); // Clear the screen -// gfxSleepMilliseconds(5); -// -// write_cmd(0x06); -// gfxSleepMicroseconds(50); - return TRUE; } @@ -129,13 +140,14 @@ bool_t tdisp_lld_init(void) { */ void tdisp_lld_clear(void) { write_cmd(0x01); -// gfxSleepMilliseconds(LONG_DELAY_MS); } +/* Writes a character to the display */ void tdisp_lld_draw_char(char c) { write_data(c); } +/* Set cursor position */ void tdisp_lld_set_cursor(coord_t col, coord_t row) { static const uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; @@ -152,8 +164,10 @@ void tdisp_lld_set_cursor(coord_t col, coord_t row) { // } write_cmd(0x80 | (col + row_offsets[row])); +// write_cmd(0x80 | (0x40 + col)); } +/* Create a custom character to the display */ void tdisp_lld_create_char(uint8_t address, uint8_t *charmap) { int i; @@ -164,38 +178,91 @@ void tdisp_lld_create_char(uint8_t address, uint8_t *charmap) { } +/* Write display control commands to the display */ void tdisp_lld_control(uint16_t what, uint16_t value) { - switch(what) { - case TDISP_CTRL_BACKLIGHT: - if ((uint8_t)value) - displaycontrol |= TDISP_DISPLAY_ON; - else - displaycontrol &= ~TDISP_DISPLAY_ON; - write_cmd(0x08 | displaycontrol); - break; - case TDISP_CTRL_CURSOR: - switch((uint8_t)value) { - case cursorOff: - displaycontrol &= ~TDISP_CURSOR_ON; + case TDISP_CTRL_DISPLAY: + switch (value) { + case displayOff: + displaycontrol &= ~TDISP_DISPLAY_ON; + break; + case displayOn: + displaycontrol |= TDISP_DISPLAY_ON; + break; + } + write_cmd(0x08 | displaycontrol); break; - case cursorBlock: - case cursorUnderline: - case cursorBar: - displaycontrol = (displaycontrol | TDISP_CURSOR_ON) & ~TDISP_CURSOR_BLINK; + case TDISP_CTRL_CURSOR: + switch (value) { + case cursorBlinkingBlock: + case cursorBlinkingUnderline: + case cursorBlinkingBar: + displaycontrol |= TDISP_CURSOR_ON + TDISP_CURSOR_BLINK; + break; + case cursorBlock: + case cursorUnderline: + case cursorBar: + displaycontrol = (displaycontrol | TDISP_CURSOR_ON) & ~TDISP_CURSOR_BLINK; + break; + case cursorOff: + default: + displaycontrol &= ~(TDISP_CURSOR_ON | TDISP_CURSOR_BLINK); // zet alleen de cursor uit. Bewaar de overige instellingen + break; + } + write_cmd(0x08 | displaycontrol); break; - case cursorBlinkingBlock: - case cursorBlinkingUnderline: - case cursorBlinkingBar: - default: - displaycontrol |= (TDISP_CURSOR_ON | TDISP_CURSOR_BLINK); + case TDISP_CTRL_MOVE: + switch (value) { + case cursorIncrease: + cursorcontrol |= TDISP_CURSOR_INC; // increase cursor position + break; + case cursorDecrease: + cursorcontrol &= ~TDISP_CURSOR_INC; // decrease cursor position + break; + } + write_cmd(0x04 | cursorcontrol); + break; + case TDISP_CTRL_SHIFT: + switch (value) { + case shiftOn: + cursorcontrol |= TDISP_SHIFT_ON; + break; + case shiftOff: + cursorcontrol &= ~TDISP_SHIFT_ON; + break; + } + write_cmd(0x04 | cursorcontrol); break; - } - write_cmd(0x08 | displaycontrol); - break; } } +/* Scrolls the display in a particular direction with an amount of characters and delays the scroll between each scroll step */ +void tdisp_lld_scroll(uint16_t direction, uint16_t amount, uint16_t delay) { + uint16_t scrollcontrol = 0; + uint16_t i; + + switch (direction) { + case displayScrollLeft: + scrollcontrol = TDISP_SCROLL_DISPLAY; + break; + case displayScrollRight: + scrollcontrol = TDISP_SCROLL_DISPLAY | TDISP_SCROLL_RIGHT; + break; + } + + for(i = 0; i < amount; i++) { + write_cmd(0x10 | scrollcontrol); + chThdSleepMilliseconds(delay); + } +} + +#if TDISP_USE_BACKLIGHT +/* sets the brightness of the display backlight */ +void tdisp_lld_set_backlight(uint16_t percentage) { + set_backlight(percentage); +} +#endif + #endif /* GFX_USE_TDISP */ /** @} */ diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_example.h b/drivers/tdisp/HD44780/tdisp_lld_board_example.h index f37bf2cb..fbf3f172 100644 --- a/drivers/tdisp/HD44780/tdisp_lld_board_example.h +++ b/drivers/tdisp/HD44780/tdisp_lld_board_example.h @@ -1,9 +1,22 @@ /* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ /** * @file drivers/tdisp/HD44780/tdisp_lld_board_example.h diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h b/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h index 7b1789cf..e8b1752d 100644 --- a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h +++ b/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h @@ -1,9 +1,22 @@ /*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
/**
* @file drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
@@ -33,9 +46,9 @@ static void init_board(void) { static void writeToLCD(uint8_t data) {
palWritePort(PORT_DATA, data);
palSetPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(1);
+ chThdSleepMicroseconds(1);
palClearPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(5);
+ chThdSleepMicroseconds(5);
}
static void write_cmd(uint8_t data) {
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 4b7dfacb..1fe222dc 100644 --- a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h +++ b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h @@ -1,9 +1,22 @@ /*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
/**
* @file drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
@@ -69,10 +82,10 @@ static void init_board(void) { static void writeToLCD(uint8_t data) {
palWritePort(PORT_DATA, data<<hardware_offset);
palSetPad(PORT_CTRL, PIN_EN);
- gfxSleepMicroseconds(1);
+ chThdSleepMicroseconds(1);
palClearPad(PORT_CTRL, PIN_EN);
/* wait a little while so that de display can process the data */
- gfxSleepMicroseconds(5);
+ chThdSleepMicroseconds(5);
}
/* Writes a command to the display. The
|