From 91c8741c8fc685a83d8eb7f660402acd3d738799 Mon Sep 17 00:00:00 2001 From: strahi-linux Date: Thu, 26 Dec 2024 08:21:08 +0100 Subject: [PATCH 1/6] LCD timeouts fixed --- .../controller/hd44780_lcd_controller.c | 30 +++---- middleware/lcd/lib/src/lcd.c | 33 ++++--- tests/lcd/src/main.c | 90 ++++++++++--------- 3 files changed, 72 insertions(+), 81 deletions(-) diff --git a/middleware/lcd/lib/src/drivers/controller/hd44780_lcd_controller.c b/middleware/lcd/lib/src/drivers/controller/hd44780_lcd_controller.c index 5fade2b36..6030f7b7e 100644 --- a/middleware/lcd/lib/src/drivers/controller/hd44780_lcd_controller.c +++ b/middleware/lcd/lib/src/drivers/controller/hd44780_lcd_controller.c @@ -43,9 +43,11 @@ #include "lcd.h" #include "assembly.h" +#include "delays.h" /** * @brief: Macro used for timeout between pulses. + * @note: If needed. */ #define timeout(_x) while(_x--) assembly(NOP); @@ -55,41 +57,31 @@ void hd44780_lcd_init( uint32_t lcd_handle ) { lcd_handle_t lcd_handle_local; memcpy(&lcd_handle_local, (void *)lcd_handle, sizeof(lcd_handle_t)); - uint16_t timeout_value = lcd_handle_local.config.waitBetweenWrites; - if ( LCD_MODE_BIT_4 == lcd_handle_local.config.mode ) { // 4-bit mode. lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET | LCD_CMD_MODE_4BIT, LCD_SELECT_CMD ); - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 5 ); lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET | LCD_CMD_MODE_4BIT, LCD_SELECT_CMD ); - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 5 ); lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET | LCD_CMD_MODE_4BIT, LCD_SELECT_CMD ); - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 1 ); } else { // 8-bit mode - default state. lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET, LCD_SELECT_CMD ); - timeout( timeout_value ); + Delay_ms( 5 ); lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET, LCD_SELECT_CMD ); - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 5 ); lcd_write( lcd_handle_local, LCD_CMD_FUNCTION_SET, LCD_SELECT_CMD ); - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 1 ); } // Standard LCD initialization. lcd_write( lcd_handle_local, LCD_CMD_CLEAR, LCD_SELECT_CMD ); // Clear LCD first. - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 2 ); lcd_write( lcd_handle_local, LCD_CMD_CURSOR_OFF, LCD_SELECT_CMD ); // Don't show cursor. - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 2 ); lcd_write( lcd_handle_local, LCD_ROW_1, LCD_SELECT_CMD ); // Set first row as active initially. - timeout_value = lcd_handle_local.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 2 ); } // ------------------------------------------------------------------------ END diff --git a/middleware/lcd/lib/src/lcd.c b/middleware/lcd/lib/src/lcd.c index cd6db52a8..fe6a0234d 100644 --- a/middleware/lcd/lib/src/lcd.c +++ b/middleware/lcd/lib/src/lcd.c @@ -44,6 +44,7 @@ #include "lcd.h" #include "board.h" #include "assembly.h" +#include "delays.h" /** * @brief: Macro used for timeout between pulses. @@ -106,7 +107,7 @@ void lcd_configure_default( lcd_config_t *config ) { config->mode = LCD_MODE_BIT_4; /** - * @brief Set 1000 by default. + * @brief Set 10000 by default. */ config->waitBetweenWrites = 10000; } @@ -115,7 +116,6 @@ void lcd_configure_default( lcd_config_t *config ) { lcd_err_t lcd_configure( lcd_handle_t *lcd_handle, lcd_config_t *config ) { lcd_err_t status = LCD_ERROR; uint8_t bit_data_err_cnt = 0; - uint16_t timeout_value = config->waitBetweenWrites; if ( lcd_handle ) { if ( config ) { @@ -127,16 +127,11 @@ lcd_err_t lcd_configure( lcd_handle_t *lcd_handle, lcd_config_t *config ) { else digital_out_low( &lcd_handle->cs_pin ); - timeout( timeout_value ); - if ( DIGITAL_OUT_SUCCESS != digital_out_init( &lcd_handle->rst_pin, lcd_handle->config.pin_rst ) ) return status; else digital_out_low( &lcd_handle->rst_pin ); - timeout_value = config->waitBetweenWrites; - timeout( timeout_value ); - // Backlight pin is optional. if ( HAL_PIN_NC != lcd_handle->config.pin_backlight ) { if ( DIGITAL_OUT_SUCCESS != digital_out_init( &lcd_handle->backlight_pin, lcd_handle->config.pin_backlight ) ) @@ -152,6 +147,13 @@ lcd_err_t lcd_configure( lcd_handle_t *lcd_handle, lcd_config_t *config ) { data_pin_iteration++; } + /** + * SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + * according to datasheet, we need at least 40 ms after power rises above 2.7 V + * before sending commands. + */ + Delay_ms( 50 ); + if ( ( LCD_MODE_BIT_4 == lcd_handle->config.mode ) && ( 4 == bit_data_err_cnt ) ) status = LCD_SUCCESS; @@ -167,11 +169,9 @@ lcd_err_t lcd_configure( lcd_handle_t *lcd_handle, lcd_config_t *config ) { } void lcd_init( lcd_handle_t lcd_handle, init_sequence_ptr init_sequence ) { - uint16_t timeout_value = lcd_handle.config.waitBetweenWrites; - if ( true == lcd_handle.init_state ) { clear_lines( lcd_handle ); - timeout( timeout_value ); + timeout( lcd_handle.config.waitBetweenWrites ); if (init_sequence) { (*init_sequence)((uint32_t)&lcd_handle); } @@ -317,8 +317,6 @@ void lcd_backlight_on( lcd_handle_t lcd_handle ) { /* --------------------------------------------- PRIVATE FUNCTIONS - IMPLEMENTATIONS ----------------------------------------*/ static inline void lcd_pulse( lcd_handle_t lcd_handle, lcd_select_t cmd_or_data ) { - uint16_t timeout_value = lcd_handle.config.waitBetweenWrites; - // Send LOW or HIGH pulse on RS/RST pin for selecting adequate register. if ( LCD_SELECT_CMD == cmd_or_data ) { digital_out_low( &lcd_handle.rst_pin ); @@ -327,19 +325,18 @@ static inline void lcd_pulse( lcd_handle_t lcd_handle, lcd_select_t cmd_or_data } // Generate a High-to-low pulse on EN/CS pin. - timeout( timeout_value ); + Delay_ms( 1 ); digital_out_high( &lcd_handle.cs_pin ); - timeout_value = lcd_handle.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 1 ); digital_out_low( &lcd_handle.cs_pin ); - timeout_value = lcd_handle.config.waitBetweenWrites; - timeout( timeout_value ); + Delay_ms( 10 ); } static inline void clear_lines( lcd_handle_t lcd_handle ) { // Write 0 to all data lines. lcd_write_bit_of_data( lcd_handle, 0x00 ); + Delay_ms( 2 ); } static inline void lcd_write_bit_of_data( lcd_handle_t lcd_handle, uint8_t value ) { @@ -348,7 +345,7 @@ static inline void lcd_write_bit_of_data( lcd_handle_t lcd_handle, uint8_t value for ( uint8_t i = 0; i < 8; i++ ) { if ( HAL_PIN_NC != *data_pin_iteration ) { - digital_out_write( &lcd_handle.data_pins[i], ( value >> cnt ) & 0x01 ); + digital_out_write( &lcd_handle.data_pins[i], (( value >> cnt ) & 0x01) ); cnt++; } data_pin_iteration++; diff --git a/tests/lcd/src/main.c b/tests/lcd/src/main.c index 6b718ed79..aa7d08d09 100644 --- a/tests/lcd/src/main.c +++ b/tests/lcd/src/main.c @@ -101,52 +101,54 @@ int main( void ) { preinit(); #endif - // Expected output is for display to be turned ON. - if (LCD_ERROR == test_1()) { - printf_me("LCD failed initialization!\r\n"); - while(1); + while(1) { + // Expected output is for display to be turned ON. + if (LCD_ERROR == test_1()) { + printf_me("LCD failed initialization!\r\n"); + while(1); + } + + // Expected output is the following text in row 1: + // CHAR:123+-/*@& + test_2(); + + // Expected output is the following text in row 1: + // Clear and write! + test_3(); + + // Expected output is the following text in row 1: + // Clear and write! + // And following output in row 2: + // MikroE LCD Test + test_4(); + + // Expected output is text being shifted to the left. + test_5(); + + // Expected output is text being shifted to the right. + test_6(); + + // Expected output is text disappearing and reappearing a couple of times. + test_7(); + + // Expected output is cursor disappearing and reappearing a couple of times + // at the last position. Next to last character in row 2. + test_8(); + + // Expected output is cursor moving to the left 3 times, + // then moving to first position and finally moving + // 3 times to the right. + test_9(); + + // Expected output is the LCD blinking. + test_10(); + + // Signal END on LCD. + lcd_clear(lcd); + lcd_cursor_off(lcd); + lcd_write_text(lcd, "TEST COMPLETED!", LCD_ROW_1); } - // Expected output is the following text in row 1: - // CHAR:123+-/*@& - test_2(); - - // Expected output is the following text in row 1: - // Clear and write! - test_3(); - - // Expected output is the following text in row 1: - // Clear and write! - // And following output in row 2: - // MikroE LCD Test - test_4(); - - // Expected output is text being shifted to the left. - test_5(); - - // Expected output is text being shifted to the right. - test_6(); - - // Expected output is text disappearing and reappearing a couple of times. - test_7(); - - // Expected output is cursor disappearing and reappearing a couple of times - // at the last position. Next to last character in row 2. - test_8(); - - // Expected output is cursor moving to the left 3 times, - // then moving to first position and finally moving - // 3 times to the right. - test_9(); - - // Expected output is the LCD blinking. - test_10(); - - // Signal END on LCD. - lcd_clear(lcd); - lcd_cursor_off(lcd); - lcd_write_text(lcd, "TEST COMPLETED!", LCD_ROW_1); - return 0; } From 2e98df70be3dfbb6297f35bacf611f62096b9f88 Mon Sep 17 00:00:00 2001 From: "ivan.ruzavin" Date: Thu, 26 Dec 2024 15:17:08 +0100 Subject: [PATCH 2/6] Updated lcd implementation --- middleware/lcd/lib/src/lcd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/middleware/lcd/lib/src/lcd.c b/middleware/lcd/lib/src/lcd.c index fe6a0234d..d15a2c68d 100644 --- a/middleware/lcd/lib/src/lcd.c +++ b/middleware/lcd/lib/src/lcd.c @@ -51,6 +51,11 @@ */ #define timeout(_x) while(_x--) assembly(NOP); +/** + * @brief: Variable used to store data before shifting. + */ +static uint8_t lcd_cmd_data_saved; + /* --------------------------------------------- PRIVATE FUNCTIONS - DECLARATIONS -------------------------------------------*/ /** @@ -179,6 +184,7 @@ void lcd_init( lcd_handle_t lcd_handle, init_sequence_ptr init_sequence ) { } void lcd_write( lcd_handle_t lcd_handle, char lcd_cmd_data, lcd_select_t cmd_or_data ) { + lcd_cmd_data_saved = lcd_cmd_data; if ( false == lcd_handle.init_state ) { return; } @@ -191,7 +197,7 @@ void lcd_write( lcd_handle_t lcd_handle, char lcd_cmd_data, lcd_select_t cmd_or_ } // 8-bit mode or lower nibble for 4-bit mode. - lcd_write_bit_of_data( lcd_handle, lcd_cmd_data ); + lcd_write_bit_of_data( lcd_handle, lcd_cmd_data_saved ); lcd_pulse( lcd_handle, cmd_or_data ); } From 6b134363c6b6f00ab0cdd62eaf15e39be00057fa Mon Sep 17 00:00:00 2001 From: "ivan.ruzavin" Date: Thu, 26 Dec 2024 15:22:12 +0100 Subject: [PATCH 3/6] Fixed bracket spaces --- middleware/lcd/lib/src/lcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middleware/lcd/lib/src/lcd.c b/middleware/lcd/lib/src/lcd.c index d15a2c68d..d756c807f 100644 --- a/middleware/lcd/lib/src/lcd.c +++ b/middleware/lcd/lib/src/lcd.c @@ -351,7 +351,7 @@ static inline void lcd_write_bit_of_data( lcd_handle_t lcd_handle, uint8_t value for ( uint8_t i = 0; i < 8; i++ ) { if ( HAL_PIN_NC != *data_pin_iteration ) { - digital_out_write( &lcd_handle.data_pins[i], (( value >> cnt ) & 0x01) ); + digital_out_write( &lcd_handle.data_pins[i], ( ( value >> cnt ) & 0x01 ) ); cnt++; } data_pin_iteration++; From a7d6e508f61190e06ad841bb3ddc2733428b11d5 Mon Sep 17 00:00:00 2001 From: "ivan.ruzavin" Date: Thu, 26 Dec 2024 15:29:24 +0100 Subject: [PATCH 4/6] Added changelog --- changelog.md | 1 + changelog/v2.13.1/changelog.md | 39 +++++++++++++++++++ .../include/mikrosdk_version.h | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 changelog/v2.13.1/changelog.md diff --git a/changelog.md b/changelog.md index ec864624b..bbcd54a8c 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ **VERSIONS:** ++ **[v2.13.1](./changelog/v2.13.1/changelog.md)** + **[v2.13.0](./changelog/v2.13.0/changelog.md)** + **[v2.12.2](./changelog/v2.12.2/changelog.md)** + **[v2.12.1](./changelog/v2.12.1/changelog.md)** diff --git a/changelog/v2.13.1/changelog.md b/changelog/v2.13.1/changelog.md new file mode 100644 index 000000000..c78767e47 --- /dev/null +++ b/changelog/v2.13.1/changelog.md @@ -0,0 +1,39 @@ +

+ MikroElektronika +

+ +--- + +**[BACK TO MAIN FILE](../../changelog.md)** + +--- + +# `v2.13.1` + ++ released: 2024-12-27 + +## Changes + ++ [`v2.13.1`](#v2131) + + [Changes](#changes) + + [Fixes](#fixes) + + +### Fixes + +#### mikroSDK + ++ Fixed LCD implementation for all architectures + +### NEW HARDWARE + +> NOTE: +>> If any new hardware was added to current version, it will be listed here. + +Support added for following hardware: + +--- + +**[BACK TO MAIN FILE](../../changelog.md)** + +--- diff --git a/platform/mikrosdk_version/include/mikrosdk_version.h b/platform/mikrosdk_version/include/mikrosdk_version.h index 1936cf577..0449a3c4a 100644 --- a/platform/mikrosdk_version/include/mikrosdk_version.h +++ b/platform/mikrosdk_version/include/mikrosdk_version.h @@ -67,7 +67,7 @@ extern "C"{ * @note changes in patch version indicate smaller updates, * bug fixes and improvements */ -#define mikroSDK_PATCH_VERSION 0 +#define mikroSDK_PATCH_VERSION 1 /** * @brief mikroSDK_GET_VERSION From a6a418878ee2598d11953b39a879390876b99c8e Mon Sep 17 00:00:00 2001 From: Strahinja Jacimovic Date: Thu, 26 Dec 2024 15:55:04 +0100 Subject: [PATCH 5/6] Update changelog/v2.13.1/changelog.md --- changelog/v2.13.1/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog/v2.13.1/changelog.md b/changelog/v2.13.1/changelog.md index c78767e47..787f12aba 100644 --- a/changelog/v2.13.1/changelog.md +++ b/changelog/v2.13.1/changelog.md @@ -24,6 +24,7 @@ #### mikroSDK + Fixed LCD implementation for all architectures + + Issue with timing after optimizing (speeding up) SDK ### NEW HARDWARE From 6c9280901a5f8a5e899bd82e11bab6a2d44b03bb Mon Sep 17 00:00:00 2001 From: Strahinja Jacimovic Date: Thu, 26 Dec 2024 15:55:12 +0100 Subject: [PATCH 6/6] Update changelog/v2.13.1/changelog.md --- changelog/v2.13.1/changelog.md | 1 - 1 file changed, 1 deletion(-) diff --git a/changelog/v2.13.1/changelog.md b/changelog/v2.13.1/changelog.md index 787f12aba..2c498472e 100644 --- a/changelog/v2.13.1/changelog.md +++ b/changelog/v2.13.1/changelog.md @@ -18,7 +18,6 @@ + [Changes](#changes) + [Fixes](#fixes) - ### Fixes #### mikroSDK