aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@unormal.org>2013-01-12 09:38:38 +0100
committerJoel Bodenmann <joel@unormal.org>2013-01-12 09:38:38 +0100
commit1c1b3c8d74b1bff02bffbec91bcdc96fce61a82e (patch)
treec18fe1827cb4fcc3823f01a2f995e08b39f485a6
parentff8e8c47d9c51c54995d2b0169d4b6d2edebdb3f (diff)
downloaduGFX-1c1b3c8d74b1bff02bffbec91bcdc96fce61a82e.tar.gz
uGFX-1c1b3c8d74b1bff02bffbec91bcdc96fce61a82e.tar.bz2
uGFX-1c1b3c8d74b1bff02bffbec91bcdc96fce61a82e.zip
TDISP: added custom character routine
-rw-r--r--demos/modules/tdisp/main.c16
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld_config.h2
-rw-r--r--include/tdisp/tdisp.h13
-rw-r--r--src/tdisp/tdisp.c13
4 files changed, 43 insertions, 1 deletions
diff --git a/demos/modules/tdisp/main.c b/demos/modules/tdisp/main.c
index b67b3b8c..4ee53c99 100644
--- a/demos/modules/tdisp/main.c
+++ b/demos/modules/tdisp/main.c
@@ -28,9 +28,11 @@ int main(void) {
tdispInit();
+ /* reset cursor position and clear the screen */
tdispHome();
tdispClear();
+ /* set cursor position and draw single characters */
tdispGotoXY(4, 0);
tdispDrawChar('H');
tdispDrawChar('D');
@@ -40,8 +42,22 @@ int main(void) {
tdispDrawChar('8');
tdispDrawChar('0');
+ /* draw a string to a given location */
tdispDrawStringLocation(0, 1, "chibios-gfx.com");
+ /* create and display a custom made character */
+ charmap[0] = 0b00000;
+ charmap[1] = 0b00100;
+ charmap[2] = 0b00010;
+ charmap[3] = 0b11111;
+ charmap[4] = 0b00010;
+ charmap[5] = 0b00100;
+ charmap[6] = 0b00000;
+ charmap[7] = 0b00000;
+ tdispCreateChar(0, charmap);
+ tdispHome();
+ tdispDrawChar(0);
+
while(TRUE) {
chThdSleepMilliseconds(250);
}
diff --git a/drivers/tdisp/HD44780/tdisp_lld_config.h b/drivers/tdisp/HD44780/tdisp_lld_config.h
index 7ea80ea2..00032eaa 100644
--- a/drivers/tdisp/HD44780/tdisp_lld_config.h
+++ b/drivers/tdisp/HD44780/tdisp_lld_config.h
@@ -38,6 +38,8 @@
#define TDISP_DRIVER_NAME "HD44780"
#define TDISP_LLD(x) tdisp_lld_##x##_HD44780
+#define TDISP_MAX_CUSTOM_CHARS 0x07
+
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_LLD_CONFIG_H */
diff --git a/include/tdisp/tdisp.h b/include/tdisp/tdisp.h
index c7dbd4a0..7bf5f69f 100644
--- a/include/tdisp/tdisp.h
+++ b/include/tdisp/tdisp.h
@@ -68,7 +68,7 @@ bool_t tdispInit(void);
/**
* @brief Control different display properties
* @note Multiple attributes can be passed using the OR operator.
- * @note Example: TDISP_DISPLAY_ON | TDISP_CURSOR_BLINK
+ * @note Example: tdispSetAttributes(TDISP_DISPLAY_ON | TDISP_CURSOR_BLINK)
*
* @param[in] attributes The attributes
*/
@@ -93,6 +93,17 @@ void tdispHome(void);
void tdispGotoXY(coord_t col, coord_t row);
/**
+ * @brief Store a custom character in the displays RAM
+ *
+ * @note This usually must be done after each power-up since most
+ * LCDs lose their RAM content.
+ *
+ * @param[in] location On which address to store the character (from 0 up to max)
+ * @param[in] char The character to be stored. This is an array.
+ */
+void tdispCreateChar(uint8_t location, char *charmap);
+
+/**
* @brief Draws a single character at the current cursor position
*
* @param[in] c The character to be drawn
diff --git a/src/tdisp/tdisp.c b/src/tdisp/tdisp.c
index d57bae56..f10b09ee 100644
--- a/src/tdisp/tdisp.c
+++ b/src/tdisp/tdisp.c
@@ -78,6 +78,19 @@ void tdispHome(void) {
TDISP_LLD(write_cmd)(0x02);
}
+void tdispCreateChar(uint8_t location, char *charmap) {
+ uint8_t i;
+
+ /* make sure we don't write somewhere we're not supposed to */
+ location &= TDISP_MAX_CUSTOM_CHARS;
+
+ TDISP_LLD(write_cmd)(0x40 | (location << 3));
+
+ for(i = 0; i < 8; i++) {
+ TDISP_LLD(write_data)(charmap[i]);
+ }
+}
+
void tdispGotoXY(coord_t col, coord_t row) {
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };