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:
parent
bb8d6e0ad2
commit
6577578051
16
display.c
16
display.c
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -99,36 +99,32 @@ 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
|
||||
for (i = 0; i < pgm_read_byte(&font[index].columns); i++) {
|
||||
#else
|
||||
for (i = 0; i < FONT_COLUMNS; i++) {
|
||||
#endif
|
||||
displaybus_write(pgm_read_byte(&font[index].data[i]), 0);
|
||||
}
|
||||
// Send space between characters.
|
||||
for (i = 0; i < FONT_SYMBOL_SPACE; i++) {
|
||||
displaybus_write(0x00, 0);
|
||||
}
|
||||
|
||||
message++;
|
||||
// Send the character bitmap.
|
||||
#ifdef FONT_IS_PROPORTIONAL
|
||||
for (i = 0; i < pgm_read_byte(&font[index].columns); i++) {
|
||||
#else
|
||||
for (i = 0; i < FONT_COLUMNS; i++) {
|
||||
#endif
|
||||
displaybus_write(pgm_read_byte(&font[index].data[i]), 0);
|
||||
}
|
||||
// Send space between characters.
|
||||
for (i = 0; i < FONT_SYMBOL_SPACE; i++) {
|
||||
// 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));
|
||||
}
|
||||
// Send another space for transmission end.
|
||||
displaybus_write(0x00, 1);
|
||||
}
|
||||
|
||||
#endif /* TEACUP_C_INCLUDE && DISPLAY_TYPE_SSD1306 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue