TDISP: added custom character routine

This commit is contained in:
Joel Bodenmann 2013-01-12 09:38:38 +01:00
parent ff8e8c47d9
commit 1c1b3c8d74
4 changed files with 43 additions and 1 deletions

View File

@ -28,9 +28,11 @@ int main(void) {
tdispInit(); tdispInit();
/* reset cursor position and clear the screen */
tdispHome(); tdispHome();
tdispClear(); tdispClear();
/* set cursor position and draw single characters */
tdispGotoXY(4, 0); tdispGotoXY(4, 0);
tdispDrawChar('H'); tdispDrawChar('H');
tdispDrawChar('D'); tdispDrawChar('D');
@ -40,8 +42,22 @@ int main(void) {
tdispDrawChar('8'); tdispDrawChar('8');
tdispDrawChar('0'); tdispDrawChar('0');
/* draw a string to a given location */
tdispDrawStringLocation(0, 1, "chibios-gfx.com"); 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) { while(TRUE) {
chThdSleepMilliseconds(250); chThdSleepMilliseconds(250);
} }

View File

@ -38,6 +38,8 @@
#define TDISP_DRIVER_NAME "HD44780" #define TDISP_DRIVER_NAME "HD44780"
#define TDISP_LLD(x) tdisp_lld_##x##_HD44780 #define TDISP_LLD(x) tdisp_lld_##x##_HD44780
#define TDISP_MAX_CUSTOM_CHARS 0x07
#endif /* GFX_USE_TDISP */ #endif /* GFX_USE_TDISP */
#endif /* _TDISP_LLD_CONFIG_H */ #endif /* _TDISP_LLD_CONFIG_H */

View File

@ -68,7 +68,7 @@ bool_t tdispInit(void);
/** /**
* @brief Control different display properties * @brief Control different display properties
* @note Multiple attributes can be passed using the OR operator. * @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 * @param[in] attributes The attributes
*/ */
@ -92,6 +92,17 @@ void tdispHome(void);
*/ */
void tdispGotoXY(coord_t col, coord_t row); 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 * @brief Draws a single character at the current cursor position
* *

View File

@ -78,6 +78,19 @@ void tdispHome(void) {
TDISP_LLD(write_cmd)(0x02); 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) { void tdispGotoXY(coord_t col, coord_t row) {
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };