From d4c5a034e315d021d2f85a3d75caafcadd7c3faf Mon Sep 17 00:00:00 2001 From: batt Date: Fri, 28 May 2010 15:03:48 +0000 Subject: [PATCH] Add configurable options for HD44780 LCD display columns and rows. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3877 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/cfg_lcd_hd44.h | 14 ++++++++++++++ bertos/drv/lcd_hd44.c | 24 ++++++++++++------------ bertos/drv/lcd_hd44.h | 22 +++++++++++++++++----- bertos/drv/lcd_text.c | 20 ++++++++++---------- bertos/drv/lcd_text.h | 12 ++++++------ bertos/drv/lcd_text_hwtest.c | 2 +- bertos/mware/blanker.c | 10 +++++----- 7 files changed, 65 insertions(+), 39 deletions(-) diff --git a/bertos/cfg/cfg_lcd_hd44.h b/bertos/cfg/cfg_lcd_hd44.h index 78f1f20b..7bea4376 100644 --- a/bertos/cfg/cfg_lcd_hd44.h +++ b/bertos/cfg/cfg_lcd_hd44.h @@ -51,5 +51,19 @@ */ #define CONFIG_LCD_ADDRESS_FAST 1 +/** + * Number of columns in LCD display. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "lcd_hd44_cols" + */ +#define CONFIG_LCD_COLS LCD_HD44_COLS_16 + +/** + * Number of rows in LCD display. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "lcd_hd44_rows" + */ +#define CONFIG_LCD_ROWS LCD_HD44_ROWS_2 + #endif /* CFG_LCD_H */ diff --git a/bertos/drv/lcd_hd44.c b/bertos/drv/lcd_hd44.c index 959878fd..78df78d5 100644 --- a/bertos/drv/lcd_hd44.c +++ b/bertos/drv/lcd_hd44.c @@ -70,7 +70,7 @@ static const uint8_t lcd_address[] = 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, -#if LCD_COLS > 16 +#if CONFIG_LCD_COLS > 16 0x90, 0x91, 0x92, 0x93, #endif @@ -79,17 +79,17 @@ static const uint8_t lcd_address[] = 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, -#if LCD_COLS > 16 +#if CONFIG_LCD_COLS > 16 0xD0, 0xD1, 0xD2, 0xD3, #endif -#if LCD_ROWS > 2 +#if CONFIG_LCD_ROWS > 2 /* row 2 */ 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, -#if LCD_COLS > 16 +#if CONFIG_LCD_COLS > 16 0xA4, 0xA5, 0xA6, 0xA7, #endif @@ -98,32 +98,32 @@ static const uint8_t lcd_address[] = 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, -#if LCD_COLS > 16 +#if CONFIG_LCD_COLS > 16 0xE4, 0xE5, 0xE6, 0xE7, #endif -#endif /* LCD_ROWS > 2 */ +#endif /* CONFIG_LCD_ROWS > 2 */ }; -STATIC_ASSERT(countof(lcd_address) == LCD_ROWS * LCD_COLS); +STATIC_ASSERT(countof(lcd_address) == CONFIG_LCD_ROWS * CONFIG_LCD_COLS); #else /* CONFIG_LCD_ADDRESS_FAST == 0 */ static const uint8_t col_address[] = { 0x80, 0xC0, -#if LCD_ROWS > 2 +#if CONFIG_LCD_ROWS > 2 0x94, 0xD4 #endif }; -STATIC_ASSERT(countof(col_address) == LCD_ROWS); +STATIC_ASSERT(countof(col_address) == CONFIG_LCD_ROWS); /** * Addresses of LCD display character positions, calculated runtime to save RAM */ static uint8_t lcd_address(uint8_t addr) { - return col_address[addr / LCD_COLS] + addr % LCD_COLS; + return col_address[addr / CONFIG_LCD_COLS] + addr % CONFIG_LCD_COLS; } #endif /* CONFIG_LCD_ADDRESS_FAST */ @@ -345,11 +345,11 @@ void lcd_putc(uint8_t addr, uint8_t c) lcd_current_addr = addr + 1; /* If we are at end of display wrap the address to 0 */ - if (lcd_current_addr == LCD_COLS * LCD_ROWS) + if (lcd_current_addr == CONFIG_LCD_COLS * CONFIG_LCD_ROWS) lcd_current_addr = 0; /* If we are at the end of a row put the cursor at the beginning of the next */ - if (!(lcd_current_addr % LCD_COLS)) + if (!(lcd_current_addr % CONFIG_LCD_COLS)) lcd_setReg(lcd_address(lcd_current_addr)); } diff --git a/bertos/drv/lcd_hd44.h b/bertos/drv/lcd_hd44.h index de7f122b..0616d31c 100644 --- a/bertos/drv/lcd_hd44.h +++ b/bertos/drv/lcd_hd44.h @@ -48,12 +48,24 @@ #include /* For stdint types */ /** - * \name Display dimensions (in chars) - * \{ + * \name Values for CONFIG_LCD_ROWS. + * + * Select the number of rows which are available + * on the HD44780 Display. + * $WIZ$ lcd_hd44_rows = "LCD_HD44_ROWS_2", "LCD_HD44_ROWS_4" + */ +#define LCD_HD44_ROWS_2 2 +#define LCD_HD44_ROWS_4 4 + +/** + * \name Values for CONFIG_LCD_COLS. + * + * Select the number of columns which are available + * on the HD44780 Display. + * $WIZ$ lcd_hd44_cols = "LCD_HD44_COLS_16", "LCD_HD44_COLS_20" */ -#define LCD_ROWS 2 -#define LCD_COLS 16 -/* \} */ +#define LCD_HD44_COLS_16 16 +#define LCD_HD44_COLS_20 20 /** * \name Hitachi HD44 commands. diff --git a/bertos/drv/lcd_text.c b/bertos/drv/lcd_text.c index 94b46b77..ff480776 100644 --- a/bertos/drv/lcd_text.c +++ b/bertos/drv/lcd_text.c @@ -85,8 +85,8 @@ static lcdpos_t lcd_CursorAddr; void lcd_setAddr(Layer *layer, lcdpos_t addr) { /* Sanity check: wrap around to display limits */ - while (addr >= LCD_ROWS * LCD_COLS) - addr -= LCD_ROWS * LCD_COLS; + while (addr >= CONFIG_LCD_ROWS * CONFIG_LCD_COLS) + addr -= CONFIG_LCD_ROWS * CONFIG_LCD_COLS; layer->addr = addr; } @@ -124,7 +124,7 @@ static void lcd_putCharUnlocked(char c, Layer *layer) layer->buf[addr] = c; /* Move to next character */ - if (++layer->addr >= LCD_COLS * LCD_ROWS) + if (++layer->addr >= CONFIG_LCD_COLS * CONFIG_LCD_ROWS) layer->addr = 0; /* Do not write on LCD if layer is hidden. */ @@ -166,7 +166,7 @@ void lcd_layerSet(Layer *layer, char c) LOCK_LCD; lcd_setAddr(layer, 0); - for (i = 0; i < LCD_COLS * LCD_ROWS; i++) + for (i = 0; i < CONFIG_LCD_COLS * CONFIG_LCD_ROWS; i++) lcd_putCharUnlocked(c, layer); UNLOCK_LCD; } @@ -184,7 +184,7 @@ void lcd_clearLine(Layer *layer, int y) LOCK_LCD; lcd_setAddr(layer, LCD_POS(0, y)); - for (i = 0; i < LCD_COLS; i++) + for (i = 0; i < CONFIG_LCD_COLS; i++) lcd_putCharUnlocked(0, layer); UNLOCK_LCD; } @@ -242,7 +242,7 @@ int lcd_vprintf(Layer *layer, lcdpos_t addr, uint8_t mode, const char *format, v * NOTE: calculating the string lenght BEFORE it gets * printf()-formatted. Real lenght may differ. */ - pad = (LCD_COLS - strlen(format)) / 2; + pad = (CONFIG_LCD_COLS - strlen(format)) / 2; while (pad--) lcd_putCharUnlocked(' ', layer); } @@ -250,7 +250,7 @@ int lcd_vprintf(Layer *layer, lcdpos_t addr, uint8_t mode, const char *format, v len = _formatted_write(format, (void (*)(char, void *))lcd_putCharUnlocked, layer, ap); if (mode & (LCD_FILL | LCD_CENTER)) - while (layer->addr % LCD_COLS) + while (layer->addr % CONFIG_LCD_COLS) lcd_putCharUnlocked(' ', layer); /* @@ -321,7 +321,7 @@ Layer *lcd_newLayer(char pri) layer = (Layer *)LIST_HEAD(&lcd_FreeLayers); layer->addr = 0; - memset(layer->buf, 0, LCD_ROWS * LCD_COLS); + memset(layer->buf, 0, CONFIG_LCD_ROWS * CONFIG_LCD_COLS); lcd_enqueueLayer(layer, pri); @@ -339,7 +339,7 @@ static void lcd_refresh(void) lcdpos_t addr; Layer *l; - for (addr = 0; addr < LCD_ROWS * LCD_COLS; ++addr) + for (addr = 0; addr < CONFIG_LCD_ROWS * CONFIG_LCD_COLS; ++addr) { FOREACH_NODE(l, &lcd_Layers) { @@ -389,7 +389,7 @@ void lcd_deleteLayer(Layer *layer) lcdpos_t addr; /* Repair damage on underlaying layers */ - for (addr = 0; addr < LCD_ROWS * LCD_COLS; ++addr) + for (addr = 0; addr < CONFIG_LCD_ROWS * CONFIG_LCD_COLS; ++addr) { /* If location was covered by us */ if (layer->buf[addr]) diff --git a/bertos/drv/lcd_text.h b/bertos/drv/lcd_text.h index 4f9be32a..09a1c70e 100644 --- a/bertos/drv/lcd_text.h +++ b/bertos/drv/lcd_text.h @@ -61,11 +61,11 @@ #define LAYER_HIDDEN -127 /* Compute LCD address from x/y coordinates */ -#define LCD_POS(x,y) ((lcdpos_t)((uint8_t)(x) + (uint8_t)(y) * (uint8_t)LCD_COLS)) -#define LCD_ROW0 (LCD_COLS * 0) -#define LCD_ROW1 (LCD_COLS * 1) -#define LCD_ROW2 (LCD_COLS * 2) -#define LCD_ROW3 (LCD_COLS * 3) +#define LCD_POS(x,y) ((lcdpos_t)((uint8_t)(x) + (uint8_t)(y) * (uint8_t)CONFIG_LCD_COLS)) +#define LCD_ROW0 (CONFIG_LCD_COLS * 0) +#define LCD_ROW1 (CONFIG_LCD_COLS * 1) +#define LCD_ROW2 (CONFIG_LCD_COLS * 2) +#define LCD_ROW3 (CONFIG_LCD_COLS * 3) /** * Overwrapping layer context. @@ -91,7 +91,7 @@ typedef struct _Layer * Characters cells with value 0 are transparent with respect * to other layers in the background. */ - char buf[LCD_COLS * LCD_ROWS]; + char buf[CONFIG_LCD_COLS * CONFIG_LCD_ROWS]; } Layer; diff --git a/bertos/drv/lcd_text_hwtest.c b/bertos/drv/lcd_text_hwtest.c index fedde87e..028b8327 100644 --- a/bertos/drv/lcd_text_hwtest.c +++ b/bertos/drv/lcd_text_hwtest.c @@ -45,7 +45,7 @@ void lcd_test(void) { int i; - for (i = 0; i < LCD_ROWS * LCD_COLS; ++i) + for (i = 0; i < CONFIG_LCD_ROWS * CONFIG_LCD_COLS; ++i) { lcd_putCharUnlocked('0' + (i % 10), lcd_DefLayer); timer_delay(100); diff --git a/bertos/mware/blanker.c b/bertos/mware/blanker.c index 7e64bfa5..4168504c 100644 --- a/bertos/mware/blanker.c +++ b/bertos/mware/blanker.c @@ -95,25 +95,25 @@ void blk_retrigger(void) */ static void blk_hack(void) { - static signed char blk_colstart[LCD_COLS]; + static signed char blk_colstart[CONFIG_LCD_COLS]; UBYTE row, col; if (rand()%3 == 0) { /* Modify one column */ - col = rand() % LCD_COLS; + col = rand() % CONFIG_LCD_COLS; blk_colstart[col] += rand() % 12 - 5; } - for (col = 0; col < LCD_COLS; ++col) + for (col = 0; col < CONFIG_LCD_COLS; ++col) { if (blk_colstart[col] > 0) { --blk_colstart[col]; /* Scroll down */ - for(row = LCD_ROWS-1; row; --row) + for(row = CONFIG_LCD_ROWS-1; row; --row) { lcd_SetAddr(blk_layer, LCD_POS(col,row)); lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer); @@ -128,7 +128,7 @@ static void blk_hack(void) ++blk_colstart[col]; /* Clear tail */ - for(row = 0; row < LCD_ROWS; ++row) + for(row = 0; row < CONFIG_LCD_ROWS; ++row) { if (blk_layer->Buf[LCD_POS(col,row)] != ' ') { -- 2.25.1