Display: introduce display_writechar().

You see where the journey is going? This is the equivalent to the
function to write a character to the serial line, so we can
basically swap these two in other functions.
This commit is contained in:
Markus Hitter 2016-04-25 01:16:30 +02:00
parent bb8d6e0ad2
commit 6577578051
4 changed files with 39 additions and 27 deletions

View File

@ -13,4 +13,18 @@
#include "display_ssd1306.c"
#undef TEACUP_C_INCLUDE
/* No common code so far. */
#ifdef DISPLAY
void display_writestr_P(PGM_P data_P) {
uint8_t r, i = 0;
// Yes, this is *supposed* to be assignment rather than comparison, so we
// break when r is assigned zero.
while ((r = pgm_read_byte(&data_P[i]))) {
display_writechar(r);
i++;
}
}
#endif /* DISPLAY */

View File

@ -36,6 +36,8 @@ void display_init(void);
void display_clear(void);
void display_set_cursor(uint8_t line, uint8_t column);
void display_text_P(PGM_P message_P);
void display_writechar(uint8_t data);
void display_writestr_P(PGM_P data_P);
#endif /* _DISPLAY_H */

View File

@ -99,18 +99,15 @@ void display_set_cursor(uint8_t line, uint8_t column) {
}
/**
Prints the text at the current cursor position.
Prints a character at the current cursor position.
\param message Zero terminated string of the text to be displayed, stored
in program memory.
\param data The character to be displayed.
*/
void display_text_P(PGM_P message) {
uint8_t i, index;
void display_writechar(uint8_t data) {
uint8_t i, index = data - 0x20;
// Render text to bitmap to display.
// Write pixels command.
displaybus_write(0x40, 0);
while ((index = pgm_read_byte(message))) {
index -= 0x20;
// Send the character bitmap.
#ifdef FONT_IS_PROPORTIONAL
@ -122,13 +119,12 @@ void display_text_P(PGM_P message) {
}
// Send space between characters.
for (i = 0; i < FONT_SYMBOL_SPACE; i++) {
displaybus_write(0x00, 0);
// TODO: we finalise a I2C (or other) bus message after each character
// here because we have no idea on how many more are following. This
// is highly inefficient and makes the displaybus buffer almost
// pointless.
displaybus_write(0x00, (i == FONT_SYMBOL_SPACE - 1));
}
message++;
}
// Send another space for transmission end.
displaybus_write(0x00, 1);
}
#endif /* TEACUP_C_INCLUDE && DISPLAY_TYPE_SSD1306 */

View File

@ -25,7 +25,7 @@ static void i2c_test(void) {
128 columns, so we offset by 32 columns to get it to the center.
*/
display_set_cursor(1, 32);
display_text_P(PSTR("Welcome to Teacup"));
display_writestr_P(PSTR("Welcome to Teacup"));
}
#endif /* I2C_TEST */