From bb8d6e0ad2709096d8d56f5a314b0abe0e57fa25 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 25 Apr 2016 00:28:51 +0200 Subject: [PATCH] Display: create and use display_set_cursor(). Having this in a seperate function will be helpful later. --- display.h | 4 +++- display_ssd1306.c | 22 +++++++++++++++++++--- i2c_test.c | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/display.h b/display.h index 786ea2d..7215c34 100644 --- a/display.h +++ b/display.h @@ -34,6 +34,8 @@ void display_init(void); void display_clear(void); -void display_text_P(uint8_t line, uint8_t column, PGM_P message_P); + +void display_set_cursor(uint8_t line, uint8_t column); +void display_text_P(PGM_P message_P); #endif /* _DISPLAY_H */ diff --git a/display_ssd1306.c b/display_ssd1306.c index e52e1b0..fd5b029 100644 --- a/display_ssd1306.c +++ b/display_ssd1306.c @@ -78,10 +78,16 @@ void display_clear(void) { } /** - Prints the text at a given position. + Sets the cursor to the given position. + + \param line The vertical cursor position to set, in lines. First line is + zero. Line height is character height, which is currently + fixed to 8 pixels. + + \param column The horizontal cursor position to set, in pixels. First + column is zero. */ -void display_text_P(uint8_t line, uint8_t column, PGM_P message) { - uint8_t i, index; +void display_set_cursor(uint8_t line, uint8_t column) { // Enter command mode. displaybus_write(0x00, 0); @@ -90,6 +96,16 @@ void display_text_P(uint8_t line, uint8_t column, PGM_P message) { // Set column. displaybus_write(0x00 | (column & 0x0F), 0); displaybus_write(0x10 | ((column >> 4) & 0x0F), 1); +} + +/** + Prints the text at the current cursor position. + + \param message Zero terminated string of the text to be displayed, stored + in program memory. +*/ +void display_text_P(PGM_P message) { + uint8_t i, index; // Render text to bitmap to display. displaybus_write(0x40, 0); diff --git a/i2c_test.c b/i2c_test.c index 48527e3..7d74f75 100644 --- a/i2c_test.c +++ b/i2c_test.c @@ -24,7 +24,8 @@ static void i2c_test(void) { "Welcome to Teacup" is 64 pixel columns wide, entire display is 128 columns, so we offset by 32 columns to get it to the center. */ - display_text_P(1, 32, PSTR("Welcome to Teacup")); + display_set_cursor(1, 32); + display_text_P(PSTR("Welcome to Teacup")); } #endif /* I2C_TEST */