diff --git a/.github/workflows/clang-format_check.yml b/.github/workflows/clang-format_check.yml index d19d503..7b2c58e 100644 --- a/.github/workflows/clang-format_check.yml +++ b/.github/workflows/clang-format_check.yml @@ -5,7 +5,6 @@ on: branches: [main, develop] pull_request: branches: [main, develop] -# on: workflow_dispatch jobs: formatting-check: name: Formatting Check diff --git a/.github/workflows/run_cppcheck.yml b/.github/workflows/run_cppcheck.yml index 499f5f4..926d65e 100644 --- a/.github/workflows/run_cppcheck.yml +++ b/.github/workflows/run_cppcheck.yml @@ -8,13 +8,13 @@ on: jobs: cppcheck-annotations_scr: - name: cppcheck-annotations + name: cppcheck-annotations /src runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4.1.1 - - name: Run cppcheck-annotation-action + - name: Run cppcheck-annotation-action for src uses: Konstantin343/cppcheck-annotation-action@v1.0 with: std: 'c99' @@ -24,15 +24,13 @@ jobs: annotation-failures: 'warning' # suppress: 'unusedFunction' # annotation-level-default: 'error' - - - name: Annotate lines with errors + - name: Annotate lines with errors src uses: yuzutech/annotations-action@v0.4.0 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" title: 'Results of CppCheck src files' input: 'annotations.json' - - - name: Run cppcheck-annotation-action + - name: Run cppcheck-annotation-action for tests uses: Konstantin343/cppcheck-annotation-action@v1.0 with: std: 'c99' @@ -42,10 +40,10 @@ jobs: annotation-failures: 'warning' # suppress: 'unusedFunction' # annotation-level-default: 'error' - - - name: Annotate lines with errors + - name: Annotate lines with errors test_src uses: yuzutech/annotations-action@v0.4.0 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" - title: 'Results of CppCheck test src files' - input: 'annotations.json' \ No newline at end of file + title: 'Results of CppCheck test lcd_hd44780 files' + input: 'annotations.json' + diff --git a/.gitignore b/.gitignore index a81b62c..9ef128b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ out_avr/ Release/ Debug/ Build/ -.vscode/settings.json +.vscode/ # HW test ingnored files .metadata/ .cproject @@ -13,3 +13,4 @@ Build/ + diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index feb4fa7..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "configurations": [ - { - "name": "windows-gcc-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "compilerPath": "C:/Qt_6_5/Tools/mingw1120_64/bin/gcc.exe", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "windows-gcc-x64" - }, - { - "name": "AVR-GCC ATMega328P", - "includePath": [ - "${workspaceFolder}/**", - "D:/19_EMBEDED_TOOLS/1_AVR_toolchain/avr/include/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE", - "__AVR_ATmega3250P__", - "AVR" - ], - "cppStandard": "gnu++17", - "compilerPath": "D:\\19_EMBEDED_TOOLS\\1_AVR_toolchain\\bin\\avr-gcc.exe", - "cStandard": "c99" - }, - { - "name": "ARM-GCC", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "cppStandard": "gnu++17", - "compilerPath": "C:\\ST\\STM32CubeCLT\\GNU-tools-for-STM32\\bin\\arm-none-eabi-gcc.exe", - "cStandard": "c99" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 109429f..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": true, - "cwd": "d:/0_Projekty/6_Biblioteki/LCD_HD44780/test/lcd_hd44780", - "program": "d:/0_Projekty/6_Biblioteki/LCD_HD44780/test/lcd_hd44780/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index ce240ef..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "build lcd_hd44780_test", - "type": "shell", - "command": "make", - "args": [ - "all", - "-j12", - "-o lcd_hd44780.o" - - ], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": { - "kind": "build", - "isDefault": true - }, - // "problemMatcher": [], - // "dependsOn":["run lizard test"], - }, - { - "label": "clean lcd_hd44780_test", - "type": "shell", - "command": "make clean", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "shell", - "label": "run lcd_hd44780_test", - "command": "./lcd_hd44780_test.exe", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": "test" - }, - { - "type": "shell", - "label": "UBUNTU run lcd_hd44780_test", - "command": "./lcd_hd44780_test", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": "test" - }, - { - "label": "run lizard test", - "type": "shell", - "command": "lizard src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -w -i 1", - "args": [], - "options": { - "cwd": "${workspaceFolder}" - }, - "group": "test", - - }, - { - "label": "run lizard test with report", - "type": "shell", - "command": "lizard src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -o reports/Cyclomatic_Complexity/Lizard_report.html", - "args": [], - "options": { - "cwd": "${workspaceFolder}" - }, - "group": "test", - - }, - { - "label": "run cppcheck for src", - "type": "shell", - "command": "cppcheck", - "args": [ - // ".", // option for whole project - "src/", - // "-itest/unity/", //suppress directory test/unity/ - // "-itest/template/", //suppress directory test/template/ - "--enable=all", - "--inconclusive", - "--force" , - "--inline-suppr", - // "--output-file=reports/cppcheck.out", // this will print out report instead of printing problems in terminal - "--platform=win64", - "--suppress=missingInclude", - "--suppress=missingIncludeSystem", - "--suppress=unusedFunction", - ], - "options": { - "cwd": "${workspaceFolder}" - }, - "group": "test", - }, - { - "label": "run cppcheck for test", - "type": "shell", - "command": "cppcheck", - "args": [ - // ".", // option for whole project - "test/lcd_hd44780", - "-itest/lcd_hd44780/out", - "-itest/lcd_hd44780/out_avr", - // "-itest/template/", //suppress directory test/template/ - "--enable=all", - "--inconclusive", - "--force" , - "--inline-suppr", - // "--output-file=reports/cppcheck.out", // this will print out report instead of printing problems in terminal - "--platform=win64", - "--suppress=missingInclude", - "--suppress=missingIncludeSystem", - // "--suppress=unusedFunction", - ], - "options": { - "cwd": "${workspaceFolder}" - }, - "group": "test", - }, - { // to use it replace "template" with specific module and provide whole"directory_to_your_project_folder" for exampel "D_/Projects/Project_a" D:/0_Projekty/6_Biblioteki/LCD_HD44780/ - "label": "UBUNTU lcd_hd44780 code coverage report generation", - "type": "shell", - "command": "python3 -m gcovr CMakeFiles/lcd_hd44780_test.dir/home/sandra/Pulpit/test/LCD_HD44780 -r ../../.. --html-details ../../../reports/Code_Coverage/lcd_hd44780_gcov_report.html", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": "test", - - }, - { // to use it replace "template" with specific module and provide whole"directory_to_your_project_folder" for exampel "D_/Projects/Project_a" D:/0_Projekty/6_Biblioteki/LCD_HD44780/ - "label": "lcd_hd44780 code coverage report generation", - "type": "shell", - "command": "python3 -m gcovr CMakeFiles/lcd_hd44780_test.dir/D_/0_Projekty/6_Biblioteki/LCD_HD44780/src -r ../../.. --html-details ../../../reports/Code_Coverage/lcd_hd44780_gcov_report.html", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out" - }, - "group": "test", - - } - { // to use it replace "template" with specific module and provide whole"directory_to_your_project_folder" for exampel "D_/Projects/Project_a" D:/0_Projekty/6_Biblioteki/LCD_HD44780/ - "label": "lcd_hd44780 AVR code coverage report generation", - "type": "shell", - "command": "python3 -m gcovr CMakeFiles/lcd_hd44780_test.dir/D_/0_Projekty/6_Biblioteki/LCD_HD44780/src -r ../../.. --html-details ../../../reports/Code_Coverage/lcd_hd44780_AVR_gcov_report.html", - "args": [], - "options": { - "cwd": "${workspaceFolder}/test/lcd_hd44780/out_avr" - }, - "group": "test", - - } - // { // to use it replace "template" with specific module and provide whole"directory_to_your_project_folder" for exampel "D_/Projects/Project_a" - // "label": "template module.c code coverage report generation", - // "type": "shell", - // "command": "python3 -m gcovr CMakeFiles/template_test.dir/directory_to_your_project_folder -r ../../.. --html-details ../../../reports/Code_Coverage/template_gcov_report.html", - // "args": [], - // "options": { - // "cwd": "${workspaceFolder}/test/template/out" - // }, - // "group": "test", - - // }, - ] -} \ No newline at end of file diff --git a/reports/Code_Coverage/info.txt b/reports/Code_Coverage/info.txt deleted file mode 100644 index 21cb249..0000000 --- a/reports/Code_Coverage/info.txt +++ /dev/null @@ -1,14 +0,0 @@ -This folder will contain output from GCov tool. Look at the template task shown below - - // { // to use it replace "template" with specific module and provide whole"directory_to_your_project_folder" for exampel "D_/Projects/Project_a" - // "label": "template module.c code coverage report generation", - // "type": "shell", - // "command": "python -m gcovr CMakeFiles/template_test.dir/directory_to_your_project_folder -r ../../.. --html-details ../../../reports/Code_Coverage/template_gcov_report.html", - // "args": [], - // "options": { - // "cwd": "${workspaceFolder}/test/template/out" - // }, - // "group": "test", - - // }, - Delete this file after generating first report. \ No newline at end of file diff --git a/reports/Code_Coverage/lcd_hd44780_gcov_report.functions.html b/reports/Code_Coverage/lcd_hd44780_gcov_report.functions.html index c087afc..e2c90da 100644 --- a/reports/Code_Coverage/lcd_hd44780_gcov_report.functions.html +++ b/reports/Code_Coverage/lcd_hd44780_gcov_report.functions.html @@ -23,7 +23,7 @@

GCC Code Coverage Report

Date: - 2023-12-08 00:43:02 + 2024-01-12 11:24:32 @@ -38,21 +38,21 @@

GCC Code Coverage Report

Lines: - 73 - 73 - 100.0% + 228 + 230 + 99.1% Functions: - 12 - 12 + 35 + 35 100.0% Branches: - 2 - 2 - 100.0% + 46 + 47 + 97.9% @@ -74,170 +74,492 @@

GCC Code Coverage Report

- lcd_char + check_lcd_buf_possition_ptr_overflow + + + src\lcd_hd44780.c + + + 438 + + + called 837 times + + + + + copy_lcd_buf_2_prev_lcd_buf + + + src\lcd_hd44780.c + + + 445 + + + called 469 times + + + + + fill_bin_value_buffer + + + src\lcd_hd44780.c + + + 403 + + + called 27 times + + + + + fill_zeros_buffer + + + src\lcd_hd44780.c + + + 423 + + + called 27 times + + + + + lcd_bin + + + src\lcd_hd44780.c + + + 671 + + + called 14 times + + + + + lcd_blinking_cursor_on + + + src\lcd_hd44780.c + + + 763 + + + called 7 times + + + + + lcd_buf_bin + + + src\lcd_hd44780.c + + + 881 + + + called 13 times + + + + + lcd_buf_char + + + src\lcd_hd44780.c + + + 780 + + + called 63 times + + + + + lcd_buf_cls + + + src\lcd_hd44780.c + + + 770 + + + called 382 times + + + + + lcd_buf_hex + + + src\lcd_hd44780.c + + + 856 + + + called 32 times + + + + + lcd_buf_int + + + src\lcd_hd44780.c + + + 829 + + + called 28 times + + + + + lcd_buf_locate + + + src\lcd_hd44780.c + + + 787 + + + called 87 times + + + + + lcd_buf_str + + + src\lcd_hd44780.c + + + 792 + + + called 160 times + + + + + lcd_char + + + src\lcd_hd44780.c + + + 587 + + + called 348 times + + + + + lcd_cls + + + src\lcd_hd44780.c + + + 540 + + + called 382 times + + + + + lcd_cursor_off + + + src\lcd_hd44780.c + + + 754 + + + called 7 times + + + + + lcd_cursor_on + + + src\lcd_hd44780.c + + + 744 + + + called 7 times + + + + + lcd_def_char + + + src\lcd_hd44780.c + + + 558 + + + called 63 times + + + + + lcd_hex + + + src\lcd_hd44780.c + + + 645 + + + called 28 times + + + + + lcd_home + + + src\lcd_hd44780.c + + + 731 + + + called 7 times + + + + + lcd_init + + + src\lcd_hd44780.c + + + 495 + + + called 375 times + + + + + lcd_int + + + src\lcd_hd44780.c + + + 617 + + + called 28 times + + + + + lcd_load_char_bank + + + src\lcd_hd44780.c + + + 568 + + + called 7 times + + + + + lcd_locate - src\lcd_hd44780.c + src\lcd_hd44780.c - 238 + 699 - called 2 times + called 439 times - lcd_cls + lcd_reset_all_SIG - src\lcd_hd44780.c + src\lcd_hd44780.c - 195 + 136 - called 16 times + called 375 times - lcd_def_char + lcd_set_all_SIG - src\lcd_hd44780.c + src\lcd_hd44780.c - 210 + 127 - called 18 times + called 375 times - lcd_init + lcd_str - src\lcd_hd44780.c + src\lcd_hd44780.c - 156 + 598 - called 14 times + called 77 times - lcd_load_char_bank + lcd_update - src\lcd_hd44780.c + src\lcd_hd44780.c - 220 + 802 - called 2 times + called 94 times - lcd_reset_all_SIG + lcd_write_4bit_data - src\lcd_hd44780.c + src\lcd_hd44780.c - 78 + 145 - called 14 times + called 8118 times - lcd_set_all_SIG + lcd_write_byte - src\lcd_hd44780.c + src\lcd_hd44780.c - 69 + 165 - called 14 times + called 3309 times - lcd_write_4bit_data + lcd_write_cmd - src\lcd_hd44780.c + src\lcd_hd44780.c - 87 + 153 - called 536 times + called 2100 times - lcd_write_byte + lcd_write_data - src\lcd_hd44780.c + src\lcd_hd44780.c - 107 + 159 - called 240 times + called 1209 times - lcd_write_cmd + register_LCD_IO_driver - src\lcd_hd44780.c + src\lcd_hd44780.c - 95 + 122 - called 94 times + called 375 times - lcd_write_data + update_lcd_curosr_possition - src\lcd_hd44780.c + src\lcd_hd44780.c - 101 + 455 - called 146 times + called 7520 times - register_LCD_IO_driver + write_lcd_buf_2_lcd - src\lcd_hd44780.c + src\lcd_hd44780.c - 64 + 471 - called 14 times + called 7520 times diff --git a/reports/Code_Coverage/lcd_hd44780_gcov_report.html b/reports/Code_Coverage/lcd_hd44780_gcov_report.html index d7dbd0b..ad43667 100644 --- a/reports/Code_Coverage/lcd_hd44780_gcov_report.html +++ b/reports/Code_Coverage/lcd_hd44780_gcov_report.html @@ -23,7 +23,7 @@

GCC Code Coverage Report

Date: - 2023-12-08 00:43:02 + 2024-01-12 11:24:32 Coverage: @@ -46,21 +46,21 @@

GCC Code Coverage Report

Lines: - 73 - 73 - 100.0% + 228 + 230 + 99.1% Functions: - 12 - 12 + 35 + 35 100.0% Branches: - 2 - 2 - 100.0% + 46 + 47 + 97.9% @@ -93,14 +93,14 @@

GCC Code Coverage Report

lcd_hd44780.c - 100.0 + 99.1 - 100.0% - 73 / 73 + 99.1% + 228 / 230 100.0% - 12 / 12 - 100.0% - 2 / 2 + 35 / 35 + 97.9% + 46 / 47 diff --git a/reports/Code_Coverage/lcd_hd44780_gcov_report.lcd_hd44780.c.9b5fec2915da14d10e466e7fb812c453.html b/reports/Code_Coverage/lcd_hd44780_gcov_report.lcd_hd44780.c.9b5fec2915da14d10e466e7fb812c453.html index 38f7778..fa04692 100644 --- a/reports/Code_Coverage/lcd_hd44780_gcov_report.lcd_hd44780.c.9b5fec2915da14d10e466e7fb812c453.html +++ b/reports/Code_Coverage/lcd_hd44780_gcov_report.lcd_hd44780.c.9b5fec2915da14d10e466e7fb812c453.html @@ -27,7 +27,7 @@

GCC Code Coverage Report

Date: - 2023-12-08 00:43:02 + 2024-01-12 11:24:32 @@ -41,21 +41,21 @@

GCC Code Coverage Report

Lines: - 73 - 73 - 100.0% + 228 + 230 + 99.1% Functions: - 12 - 12 + 35 + 35 100.0% Branches: - 2 - 2 - 100.0% + 46 + 47 + 97.9% @@ -75,134 +75,387 @@

GCC Code Coverage Report

- lcd_char + check_lcd_buf_possition_ptr_overflow + + + 438 + + + called 837 times + + + + + copy_lcd_buf_2_prev_lcd_buf + + + 445 + + + called 469 times + + + + + fill_bin_value_buffer + + + 403 + + + called 27 times + + + + + fill_zeros_buffer + + + 423 + + + called 27 times + + + + + lcd_bin + + + 671 + + + called 14 times + + + + + lcd_blinking_cursor_on + + + 763 + + + called 7 times + + + + + lcd_buf_bin + + + 881 + + + called 13 times + + + + + lcd_buf_char + + + 780 + + + called 63 times + + + + + lcd_buf_cls + + + 770 + + + called 382 times + + + + + lcd_buf_hex + + + 856 + + + called 32 times + + + + + lcd_buf_int + + + 829 + + + called 28 times + + + + + lcd_buf_locate + + + 787 + + + called 87 times + + + + + lcd_buf_str + + + 792 + + + called 160 times + + + + + lcd_char + + + 587 + + + called 348 times + + + + + lcd_cls + + + 540 + + + called 382 times + + + + + lcd_cursor_off + + + 754 + + + called 7 times + + + + + lcd_cursor_on + + + 744 + + + called 7 times + + + + + lcd_def_char + + + 558 + + + called 63 times + + + + + lcd_hex + + + 645 + + + called 28 times + + + + + lcd_home + + + 731 + + + called 7 times + + + + + lcd_init + + + 495 + + + called 375 times + + + + + lcd_int + + + 617 + + + called 28 times + + + + + lcd_load_char_bank + + + 568 + + + called 7 times + + + + + lcd_locate - 238 + 699 - called 2 times + called 439 times - lcd_cls + lcd_reset_all_SIG - 195 + 136 - called 16 times + called 375 times - lcd_def_char + lcd_set_all_SIG - 210 + 127 - called 18 times + called 375 times - lcd_init + lcd_str - 156 + 598 - called 14 times + called 77 times - lcd_load_char_bank + lcd_update - 220 + 802 - called 2 times + called 94 times - lcd_reset_all_SIG + lcd_write_4bit_data - 78 + 145 - called 14 times + called 8118 times - lcd_set_all_SIG + lcd_write_byte - 69 + 165 - called 14 times + called 3309 times - lcd_write_4bit_data + lcd_write_cmd - 87 + 153 - called 536 times + called 2100 times - lcd_write_byte + lcd_write_data - 107 + 159 - called 240 times + called 1209 times - lcd_write_cmd + register_LCD_IO_driver - 95 + 122 - called 94 times + called 375 times - lcd_write_data + update_lcd_curosr_possition - 101 + 455 - called 146 times + called 7520 times - register_LCD_IO_driver + write_lcd_buf_2_lcd - 64 + 471 - called 14 times + called 7520 times @@ -252,7 +505,7 @@

GCC Code Coverage Report

- * @Last Modified time: 2023-12-08 00:01:47 + * @Last Modified time: 2024-01-10 18:04:17 6 @@ -287,84 +540,84 @@

GCC Code Coverage Report

- + #include <stdio.h> 11 - #define BUSY_FLAG 1 << 7 + #include <stdlib.h> 12 - + #include <string.h> 13 - // LCD driver commands + 14 - // clang-format off + typedef char lcd_pos_t; 15 - #define LCDC_CLS 0x01 + // clang-format off 16 - #define LCDC_HOME 0x02 + #define BUSY_FLAG 1 << 7 17 - /********************************/ + #define VAL_PREFIX_LENGHT 2U 18 - #define LCDC_ENTRY_MODE 0x04 + 19 - #define LCDC_ENTRYR 0x02 + // LCD driver commands 20 - #define LCDC_ENTRYL 0x00 + #define LCDC_CLS 0x01 21 - #define LCDC_MOVE 0x01 + #define LCDC_HOME 0x02 22 @@ -378,70 +631,70 @@

GCC Code Coverage Report

- #define LCDC_ONOFF 0x08 + #define LCDC_ENTRY_MODE 0x04 24 - #define LCDC_DISPLAYON 0x04 + #define LCDC_ENTRYR 0x02 25 - #define LCDC_CURSORON 0x02 + #define LCDC_ENTRYL 0x00 26 - #define LCDC_CURSOROFF 0x00 + #define LCDC_MOVE 0x01 27 - #define LCDC_BLINKON 0x01 + /********************************/ 28 - /********************************/ + #define LCDC_ONOFF 0x08 29 - #define LCDC_SHIFT 0x10 + #define LCDC_DISPLAYON 0x04 30 - #define LCDC_SHIFTDISP 0x08 + #define LCDC_CURSORON 0x02 31 - #define LCDC_SHIFTR 0x04 + #define LCDC_CURSOROFF 0x00 32 - #define LCDC_SHIFTL 0x00 + #define LCDC_BLINKON 0x01 33 @@ -455,203 +708,203 @@

GCC Code Coverage Report

- #define LCDC_FUNC 0x20 + #define LCDC_SHIFT 0x10 35 - #define LCDC_FUNC8B 0x10 + #define LCDC_SHIFTDISP 0x08 36 - #define LCDC_FUNC4B 0x00 + #define LCDC_SHIFTR 0x04 37 - #define LCDC_FUNC2L 0x08 + #define LCDC_SHIFTL 0x00 38 - #define LCDC_FUNC1L 0x00 + /********************************/ 39 - #define LCDC_FUNC5x10 0x04 + #define LCDC_FUNC 0x20 40 - #define LCDC_FUNC5x7 0x00 + #define LCDC_FUNC8B 0x10 41 - /********************************/ + #define LCDC_FUNC4B 0x00 42 - #define LCDC_SET_CGRAM 0x40 + #define LCDC_FUNC2L 0x08 43 - #define LCDC_SET_DDRAM 0x80 + #define LCDC_FUNC1L 0x00 44 - // clang-format on + #define LCDC_FUNC5x10 0x04 45 - + #define LCDC_FUNC5x7 0x00 46 - + /********************************/ 47 - + #define LCDC_SET_CGRAM 0x40 48 - + #define LCDC_SET_DDRAM 0x80 49 - static const struct LCD_IO_driver_interface_struct *LCD = NULL; + 50 - // const struct char_bank_struct *char_bank = &char_bank_1; + #ifndef UNIT_TEST 51 - + #define PRIVATE static 52 - static void register_LCD_IO_driver(void); + #else 53 - static void lcd_set_all_SIG(void); + #define PRIVATE 54 - static void lcd_reset_all_SIG(void); + #endif 55 - static void lcd_write_4bit_data(uint8_t data); + 56 - static void lcd_write_cmd(uint8_t cmd); + #if LCD_BUFFERING == ON 57 - static void lcd_write_data(uint8_t data); + 58 - static void lcd_write_byte(uint8_t byte); + #define LAST_CHAR_IN_LCD_LINE (LCD_X-1) 59 - #if USE_RW_PIN == ON + #define LAST_LCD_LINE (LCD_Y-1) 60 - static uint8_t lcd_read_byte(void); + 61 - static uint8_t lcd_read_4bit_data(void); + PRIVATE char lcd_buffer[LCD_Y][LCD_X]; 62 - #endif + PRIVATE char prev_lcd_buffer[LCD_Y][LCD_X]; 63 @@ -664,92 +917,92 @@

GCC Code Coverage Report

64 - 14 - static void register_LCD_IO_driver(void) + + static lcd_pos_t *lcd_buf_position_ptr; 65 - { + #endif 66 - 14 - LCD = LCD_IO_driver_interface_get(); + + 67 - 14 - } + + static const struct LCD_IO_driver_interface_struct *LCD = NULL; 68 - + bool LCD_UPDATE_EVENT = false; 69 - 14 - static void lcd_set_all_SIG(void) + + 70 - { + static void register_LCD_IO_driver(void); 71 - 14 - LCD->set_SIG(LCD_E); + + static void lcd_set_all_SIG(void); 72 - 14 - LCD->set_SIG(LCD_RS); + + static void lcd_reset_all_SIG(void); 73 - #if USE_RW_PIN == ON + static void lcd_write_4bit_data(uint8_t data); 74 - LCD->set_SIG(LCD_RW); + static void lcd_write_cmd(uint8_t cmd); 75 - #endif + static void lcd_write_data(uint8_t data); 76 - 14 - } + + static void lcd_write_byte(uint8_t byte); 77 @@ -762,932 +1015,932 @@

GCC Code Coverage Report

78 - 14 - static void lcd_reset_all_SIG(void) + + #if USE_RW_PIN == ON 79 - { + static uint8_t lcd_read_byte(void); 80 - #if USE_RW_PIN == ON + static uint8_t lcd_read_4bit_data(void); 81 - LCD->reset_SIG(LCD_RW); + #endif 82 - #endif + #ifdef AVR 83 - 14 - LCD->reset_SIG(LCD_RS); + + #if ((USE_LCD_INT == ON) || (USE_LCD_HEX == ON)) 84 - 14 - LCD->reset_SIG(LCD_E); + + static void lcd_put_spaces(uint8_t empty_spaces); 85 - 14 - } + + #endif 86 - + #if USE_LCD_INT == ON 87 - 536 - void lcd_write_4bit_data(uint8_t data) + + static void lcd_int_AVR(int val, uint8_t width, enum alignment alignment); 88 - { + #endif 89 - 536 - LCD->set_SIG(LCD_E); + + #if USE_LCD_HEX == ON 90 - 536 - data &= 0x0F; + + static void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment); 91 - 536 - LCD->write_data(data); + + #endif 92 - 536 - LCD->reset_SIG(LCD_E); + + #if USE_LCD_BIN == ON 93 - 536 - } + + static void lcd_bin_AVR(int val, uint8_t width); 94 - + #endif 95 - 94 - static void lcd_write_cmd(uint8_t cmd) + + #if LCD_BUFFERING == ON 96 - { + #if ((USE_LCD_BUF_INT == ON) || (USE_LCD_BUF_HEX == ON)) 97 - 94 - LCD->reset_SIG(LCD_RS); + + static void lcd_buf_put_spaces(uint8_t empty_spaces); 98 - 94 - lcd_write_byte(cmd); + + #endif 99 - 94 - } + + #if USE_LCD_BUF_INT == ON 100 - + static void lcd_buf_int_AVR(int val, uint8_t width, enum alignment alignment); 101 - 146 - void lcd_write_data(uint8_t data) + + #endif 102 - { + #if USE_LCD_BUF_HEX == ON 103 - 146 - LCD->set_SIG(LCD_RS); + + static void lcd_buf_hex_AVR(int val, uint8_t width, enum alignment alignment); 104 - 146 - lcd_write_byte(data); + + #endif 105 - 146 - } + + #if USE_LCD_BUF_BIN == ON 106 - + static void lcd_buf_bin_AVR(int val, uint8_t width); 107 - 240 - void lcd_write_byte(uint8_t byte) + + #endif 108 - { + #endif 109 - #if USE_RW_PIN == ON + #else 110 - LCD->reset_SIG(LCD_RW); + #if (USE_LCD_BIN == ON || ((LCD_BUFFERING == ON) && (LCD_USE_BUF_BIN == ON))) 111 - #endif + static void fill_bin_value_buffer(int val, char *bin_val_buffer); 112 - 240 - lcd_write_4bit_data((byte) >> 4); + + static void fill_zeros_buffer(const char *buffer, uint8_t width, char *zeros_buf); 113 - 240 - lcd_write_4bit_data((byte)&0x0F); + + #endif 114 - #if USE_RW_PIN == ON + #endif 115 - //check_BUSSY_FALG + #if LCD_BUFFERING==ON 116 - LCD->set_data_pins_as_inputs(); + static void check_lcd_buf_possition_ptr_overflow(void); 117 - LCD->reset_SIG(LCD_RS); + static void copy_lcd_buf_2_prev_lcd_buf(void); 118 - LCD->set_SIG(LCD_RW); + static void update_lcd_curosr_possition(uint8_t *lcd_cursor_position,uint8_t *lcd_line, uint8_t *missed_char_counter_in_LCD_line); 119 - while (lcd_read_byte() & BUSY_FLAG) + static void write_lcd_buf_2_lcd(const uint8_t *lcd_cursor_position,const uint8_t *lcd_line,uint8_t * missed_char_counter_in_LCD_line, const lcd_pos_t *prev_lcd_buff_pos_ptr); 120 - { + #endif 121 - } + 122 - - LCD->reset_SIG(LCD_RW); + 375 + static void register_LCD_IO_driver(void) 123 - LCD->set_data_pins_as_outputs(); + { 124 - - + 375 + LCD = LCD_IO_driver_interface_get(); 125 - - #else + 375 + } 126 - 240 - LCD->delay_us(120); + + 127 - - #endif + 375 + static void lcd_set_all_SIG(void) 128 - 240 - } + + { 129 - - + 375 + LCD->set_SIG(LCD_E); 130 - - #if USE_RW_PIN == ON + 375 + LCD->set_SIG(LCD_RS); 131 - uint8_t lcd_read_byte(void) + #if USE_RW_PIN == ON 132 - { + LCD->set_SIG(LCD_RW); 133 - uint8_t data; + #endif 134 - - //read 4 MSB + 375 + } 135 - data = (lcd_read_4bit_data() << 4); + 136 - - //read 4 LSB + 375 + static void lcd_reset_all_SIG(void) 137 - data |= (lcd_read_4bit_data() & 0x0F); + { 138 - return data; + #if USE_RW_PIN == ON 139 - } + LCD->reset_SIG(LCD_RW); 140 - + #endif 141 - - uint8_t lcd_read_4bit_data(void) + 375 + LCD->reset_SIG(LCD_RS); 142 - - { + 375 + LCD->reset_SIG(LCD_E); 143 - - uint8_t data; + 375 + } 144 - LCD->set_SIG(LCD_E); + 145 - - data = LCD->read_data(); + 8118 + void lcd_write_4bit_data(uint8_t data) 146 - LCD->reset_SIG(LCD_E); + { 147 - - return data; + 8118 + LCD->set_SIG(LCD_E); 148 - - } + 8118 + data &= 0x0F; 149 - - #endif + 8118 + LCD->write_data(data); 150 - - + 8118 + LCD->reset_SIG(LCD_E); 151 - - /** + 8118 + } 152 - * @brief Function that initialize LCD in 4-bit mode with or without LCD R/W Pin handling. + 153 - - * @attention LCD R/W handling should be configured in lcd_hd44780_config.h by setting USE_RW_PIN to 1 (Enable R/W Pin + 2100 + static void lcd_write_cmd(uint8_t cmd) 154 - * handling) or 0 (disable R/W Pin handling). + { 155 - - */ + 2100 + LCD->reset_SIG(LCD_RS); 156 - 14 - void lcd_init(void) + 2100 + lcd_write_byte(cmd); 157 - - { + 2100 + } 158 - 14 - register_LCD_IO_driver(); + + 159 - 14 - LCD->init_LCD_pins(); + 1209 + void lcd_write_data(uint8_t data) 160 - /**************************BASIC LCD INIT - basing on DS init procedure***************************************/ + { 161 - - // set all LCD signals to High for more than 15ms ->bit different then in DS base on other implementation from internet + 1209 + LCD->set_SIG(LCD_RS); 162 - 14 - lcd_set_all_SIG(); + 1209 + lcd_write_byte(data); 163 - 14 - LCD->delay_us(15000); + 1209 + } 164 - 14 - lcd_reset_all_SIG(); + + 165 - - // send 0x03 & wait more then 4,1ms + 3309 + void lcd_write_byte(uint8_t byte) 166 - 14 - lcd_write_4bit_data(0x03); + + { 167 - 14 - LCD->delay_us(4500); + + #if USE_RW_PIN == ON 168 - // send 0x03 & wait more then 100us + LCD->reset_SIG(LCD_RW); 169 - 14 - lcd_write_4bit_data(0x03); + + #endif 170 - 14 - LCD->delay_us(110); + 3309 + lcd_write_4bit_data((byte) >> 4); 171 - - // send 0x03 & wait more then 100us + 3309 + lcd_write_4bit_data((byte) & 0x0F); 172 - 14 - lcd_write_4bit_data(0x03); + + #if USE_RW_PIN == ON 173 - 14 - LCD->delay_us(110); + + // check_BUSSY_FALG 174 - // send 0x02 & wait more then 100us + LCD->set_data_pins_as_inputs(); 175 - 14 - lcd_write_4bit_data(0x02); + + LCD->reset_SIG(LCD_RS); 176 - 14 - LCD->delay_us(110); + + LCD->set_SIG(LCD_RW); 177 - // FUNCTION SET ->send cmd -> LCD in 4-bit mode, 2 rows, char size 5x7 + while (lcd_read_byte() & BUSY_FLAG) 178 - 14 - lcd_write_cmd(LCDC_FUNC | LCDC_FUNC4B | LCDC_FUNC2L | LCDC_FUNC5x7); + + { 179 - // DISPLAY_ON_OFF send cmd -> enable lcd + } 180 - 14 - lcd_write_cmd(LCDC_ONOFF | LCDC_CURSOROFF | LCDC_DISPLAYON); + + LCD->reset_SIG(LCD_RW); 181 - // LCD clear screen + LCD->set_data_pins_as_outputs(); 182 - 14 - lcd_cls(); + + 183 - // ENTRY MODe SET do not shift LCD shift cursor right after placing a char + #else 184 - 14 - lcd_write_cmd(LCDC_ENTRY_MODE | LCDC_ENTRYR); + 3309 + LCD->delay_us(120); 185 - /*********************************END of BASIC LCD INIT***************************************/ + #endif 186 - - + 3309 + } 187 - // ToDo define sepcial characters in LCD CGRAM + 188 - + #if USE_RW_PIN == ON 189 - 14 - } + + uint8_t lcd_read_byte(void) 190 - + { 191 - /** + uint8_t data; 192 - * @brief Function that clear the LCD screen and set the cursor on the position of first character in first line of LCD + // read 4 MSB 193 - * screen. + data = (lcd_read_4bit_data() << 4); 194 - */ + // read 4 LSB 195 - 16 - void lcd_cls(void) + + data |= (lcd_read_4bit_data() & 0x0F); 196 - { + return data; 197 - 16 - lcd_write_cmd (LCDC_CLS); + + } 198 - 16 - LCD->delay_us(4900); + + 199 - 16 - } + + uint8_t lcd_read_4bit_data(void) 200 - + { 201 - /** + uint8_t data; 202 - * @brief Function for defining custom user characters in CGRAM of the LCD. + LCD->set_SIG(LCD_E); 203 - * @param CGRAM_char_index Position/addres of the character in CGRAM of the LCD where defined char should be written. + data = LCD->read_data(); 204 - * For the predefined example of special characters, taken values are defined in the type enum LCD_CGRAM that is defined + LCD->reset_SIG(LCD_E); 205 - * in lcd-hd44780.h + return data; 206 - * @param def_char Pointer to the predefined special character. + } 207 - * @note CGRAM_char_index - This Parameter can take values from 0 to 7. For the predefined example of special + #endif 208 - * characters, taken values are defined in the type enum LCD_CGRAM that is defined in lcd-hd44780.h + #ifdef AVR 209 - */ + #if ((USE_LCD_INT == ON) || (USE_LCD_HEX == ON)) 210 - 18 - void lcd_def_char(enum LCD_CGRAM CGRAM_char_index, const uint8_t *def_char) + + static void lcd_put_spaces(uint8_t empty_spaces) 211 @@ -1700,231 +1953,5015 @@

GCC Code Coverage Report

212 - 18 - lcd_write_cmd(LCDC_SET_CGRAM | ((DEF_CHAR_ADR_MASK & CGRAM_char_index) * LCD_CGRAM_BYTES_PER_CHAR)); + + for (uint8_t i = 0; i < empty_spaces; i++) 213 -
- 2/2 -
-
✓ Branch 0 taken 144 times.
-
✓ Branch 1 taken 18 times.
-
-
- 162 - for (uint8_t j = 0; j < LCD_CGRAM_BYTES_PER_CHAR; j++) + + { 214 - { + lcd_char(' '); 215 - 144 - lcd_write_data(def_char[j]); + + } 216 - } + } 217 - 18 - lcd_write_cmd(LCDC_SET_DDRAM); + + #endif 218 - 18 - } + + #if USE_LCD_INT == ON 219 - + static void lcd_int_AVR(int val, uint8_t width, enum alignment alignment) 220 - 2 - void lcd_load_char_bank(const struct char_bank_struct *char_bank) + + { 221 - { + uint8_t buf_lenght = 0; 222 - 2 - lcd_def_char(0,char_bank->char_0); + + char buffer[20]; // 19chars for 64 bit int + end char '\0' 223 - 2 - lcd_def_char(1,char_bank->char_1); + + buffer[0] = '\0'; 224 - 2 - lcd_def_char(2,char_bank->char_2); + + itoa(val, buffer, 10); 225 - 2 - lcd_def_char(3,char_bank->char_3); + + buf_lenght = strlen(buffer); 226 - 2 - lcd_def_char(4,char_bank->char_4); + + if (buf_lenght >= (width)) 227 - 2 - lcd_def_char(5,char_bank->char_5); + + { 228 - 2 - lcd_def_char(6,char_bank->char_6); + + lcd_str(buffer); 229 - 2 - lcd_def_char(7,char_bank->char_7); + + } 230 - 2 - } + + else 231 - + { 232 - /** + uint8_t empty_spaces_qty = width - buf_lenght; 233 - * @brief Function for print the char on the LCD screen under current position of the LCD cursor. + if (alignment == right) 234 - * @param C char (for example '1') or it's ASCI code (0x31). + { 235 - * @note For user defined char, place CGRAM_char_index (Position/addres of the character in CGRAM of the LCD where + lcd_put_spaces(empty_spaces_qty); 236 - * defined char was written). + lcd_str(buffer); 237 - */ + } 238 - 2 - void lcd_char(char C) + + else 239 - { + { 240 - 2 - uint8_t data = (uint8_t)(C); + + lcd_str(buffer); 241 - 2 - lcd_write_data(data); + + lcd_put_spaces(empty_spaces_qty); 242 - 2 - } + + } 243 + } + + + 244 + + + + } + + + 245 + + + + #endif + + + 246 + + + + #if USE_LCD_HEX == ON + + + 247 + + + + static void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment) + + + 248 + + + + { + + + 249 + + + + char buffer[17]; + + + 250 + + + + buffer[0] = '\0'; + + + 251 + + + + itoa(val, buffer, 16); + + + 252 + + + + static const char *prefix = {"0x"}; + + + 253 + + + + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + + + 254 + + + + { + + + 255 + + + + lcd_str(prefix); + + + 256 + + + + lcd_str(buffer); + + + 257 + + + + } + + + 258 + + + + else + + + 259 + + + + { + + + 260 + + + + uint8_t empty_spaces_qty = width - (VAL_PREFIX_LENGHT + strlen(buffer)); + + + 261 + + + + + + + 262 + + + + if (alignment == right) + + + 263 + + + + { + + + 264 + + + + lcd_put_spaces(empty_spaces_qty); + + + 265 + + + + lcd_str(prefix); + + + 266 + + + + lcd_str(buffer); + + + 267 + + + + } + + + 268 + + + + else + + + 269 + + + + { + + + 270 + + + + lcd_str(prefix); + + + 271 + + + + lcd_str(buffer); + + + 272 + + + + lcd_put_spaces(empty_spaces_qty); + + + 273 + + + + } + + + 274 + + + + } + + + 275 + + + + } + + + 276 + + + + #endif + + + 277 + + + + #if USE_LCD_BIN == ON + + + 278 + + + + static void lcd_bin_AVR(int val, uint8_t width) + + + 279 + + + + { + + + 280 + + + + char buffer[35]; // 0b 0000 0000 0000 0000 0000 0000 0000 0000 + + + 281 + + + + static const char *prefix = {"0b"}; + + + 282 + + + + buffer[0] = '\0'; + + + 283 + + + + + + + 284 + + + + itoa(val, buffer, 2); + + + 285 + + + + // if (buf_lenght < (width - VAL_PREFIX_LENGHT)) + + + 286 + + + + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + + + 287 + + + + { + + + 288 + + + + lcd_str(prefix); + + + 289 + + + + lcd_str(buffer); + + + 290 + + + + } + + + 291 + + + + else + + + 292 + + + + { + + + 293 + + + + uint8_t zeros_qty = (width - (VAL_PREFIX_LENGHT + strlen(buffer))); + + + 294 + + + + lcd_str(prefix); + + + 295 + + + + for (uint8_t i = 0; i < zeros_qty; i++) + + + 296 + + + + { + + + 297 + + + + lcd_char('0'); + + + 298 + + + + } + + + 299 + + + + lcd_str(buffer); + + + 300 + + + + } + + + 301 + + + + } + + + 302 + + + + #endif + + + 303 + + + + + + + 304 + + + + #if LCD_BUFFERING== ON + + + 305 + + + + #if ((USE_LCD_BUF_INT == ON) || (USE_LCD_BUF_HEX == ON)) + + + 306 + + + + static void lcd_buf_put_spaces(uint8_t empty_spaces) + + + 307 + + + + { + + + 308 + + + + for (uint8_t i = 0; i < empty_spaces; i++) + + + 309 + + + + { + + + 310 + + + + lcd_buf_char(' '); + + + 311 + + + + } + + + 312 + + + + } + + + 313 + + + + #endif + + + 314 + + + + #if USE_LCD_BUF_INT == ON + + + 315 + + + + static void lcd_buf_int_AVR(int val, uint8_t width, enum alignment alignment) + + + 316 + + + + { + + + 317 + + + + uint8_t buf_lenght = 0; + + + 318 + + + + char buffer[20]; // 19chars for 64 bit int + end char '\0' + + + 319 + + + + buffer[0] = '\0'; + + + 320 + + + + itoa(val, buffer, 10); + + + 321 + + + + buf_lenght = strlen(buffer); + + + 322 + + + + if (buf_lenght >= (width)) + + + 323 + + + + { + + + 324 + + + + lcd_buf_str(buffer); + + + 325 + + + + } + + + 326 + + + + else + + + 327 + + + + { + + + 328 + + + + uint8_t empty_spaces_qty = width - buf_lenght; + + + 329 + + + + if (alignment == right) + + + 330 + + + + { + + + 331 + + + + lcd_buf_put_spaces(empty_spaces_qty); + + + 332 + + + + lcd_buf_str(buffer); + + + 333 + + + + } + + + 334 + + + + else + + + 335 + + + + { + + + 336 + + + + lcd_buf_str(buffer); + + + 337 + + + + lcd_buf_put_spaces(empty_spaces_qty); + + + 338 + + + + } + + + 339 + + + + } + + + 340 + + + + } + + + 341 + + + + #endif + + + 342 + + + + + + + 343 + + + + #if USE_LCD_BUF_HEX == ON + + + 344 + + + + void lcd_buf_hex_AVR(int val, uint8_t width, enum alignment alignment) + + + 345 + + + + { + + + 346 + + + + char buffer[17]; + + + 347 + + + + buffer[0] = '\0'; + + + 348 + + + + itoa(val, buffer, 16); + + + 349 + + + + static const char *prefix = {"0x"}; + + + 350 + + + + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + + + 351 + + + + { + + + 352 + + + + lcd_buf_str(prefix); + + + 353 + + + + lcd_buf_str(buffer); + + + 354 + + + + } + + + 355 + + + + else + + + 356 + + + + { + + + 357 + + + + uint8_t empty_spaces_qty = width - (VAL_PREFIX_LENGHT + strlen(buffer)); + + + 358 + + + + + + + 359 + + + + if (alignment == right) + + + 360 + + + + { + + + 361 + + + + lcd_buf_put_spaces(empty_spaces_qty); + + + 362 + + + + lcd_buf_str(prefix); + + + 363 + + + + lcd_buf_str(buffer); + + + 364 + + + + } + + + 365 + + + + else + + + 366 + + + + { + + + 367 + + + + lcd_buf_str(prefix); + + + 368 + + + + lcd_buf_str(buffer); + + + 369 + + + + lcd_buf_put_spaces(empty_spaces_qty); + + + 370 + + + + } + + + 371 + + + + } + + + 372 + + + + } + + + 373 + + + + #endif + + + 374 + + + + #if USE_LCD_BUF_BIN == ON + + + 375 + + + + static void lcd_buf_bin_AVR(int val, uint8_t width) + + + 376 + + + + { + + + 377 + + + + char buffer[35]; // 0b 0000 0000 0000 0000 0000 0000 0000 0000 + + + 378 + + + + static const char *prefix = {"0b"}; + + + 379 + + + + buffer[0] = '\0'; + + + 380 + + + + + + + 381 + + + + itoa(val, buffer, 2); + + + 382 + + + + // if (buf_lenght < (width - VAL_PREFIX_LENGHT)) + + + 383 + + + + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + + + 384 + + + + { + + + 385 + + + + lcd_buf_str(prefix); + + + 386 + + + + lcd_buf_str(buffer); + + + 387 + + + + } + + + 388 + + + + else + + + 389 + + + + { + + + 390 + + + + uint8_t zeros_qty = (width - (VAL_PREFIX_LENGHT + strlen(buffer))); + + + 391 + + + + lcd_buf_str(prefix); + + + 392 + + + + for (uint8_t i = 0; i < zeros_qty; i++) + + + 393 + + + + { + + + 394 + + + + lcd_buf_char('0'); + + + 395 + + + + } + + + 396 + + + + lcd_buf_str(buffer); + + + 397 + + + + } + + + 398 + + + + } + + + 399 + + + + #endif + + + 400 + + + + #endif + + + 401 + + + + #else + + + 402 + + + + #if USE_LCD_BIN == ON + + + 403 + + + 27 + static void fill_bin_value_buffer(int val, char *bin_val_buffer) + + + 404 + + + + { + + + 405 + + + 27 + uint32_t bit_mask = 0x80000000; + + + 406 + +
+ 2/2 +
+
✓ Branch 0 taken 864 times.
+
✓ Branch 1 taken 27 times.
+
+
+ + 891 + while (bit_mask != 0) + + + 407 + + + + { + + + 408 + +
+ 2/2 +
+
✓ Branch 0 taken 54 times.
+
✓ Branch 1 taken 810 times.
+
+
+ + 864 + if ((bit_mask & val) != 0) + + + 409 + + + + { + + + 410 + + + 54 + strcat(bin_val_buffer, "1"); + + + 411 + + + + } + + + 412 + + + + else + + + 413 + + + + { + + + 414 + +
+ 2/2 +
+
✓ Branch 0 taken 27 times.
+
✓ Branch 1 taken 783 times.
+
+
+ + 810 + if (strlen(bin_val_buffer) != 0) + + + 415 + + + + { + + + 416 + + + 27 + strcat(bin_val_buffer, "0"); + + + 417 + + + + } + + + 418 + + + + } + + + 419 + + + 864 + bit_mask = bit_mask >> 1; + + + 420 + + + + } + + + 421 + + + 27 + } + + + 422 + + + + + + + 423 + + + 27 + static void fill_zeros_buffer(const char *buffer, uint8_t width, char *zeros_buf) + + + 424 + + + + { + + + 425 + +
+ 2/2 +
+
✓ Branch 0 taken 15 times.
+
✓ Branch 1 taken 12 times.
+
+
+ + 27 + if (strlen(buffer) < (width + VAL_PREFIX_LENGHT)) + + + 426 + + + + { + + + 427 + + + 15 + uint8_t zeros_qty = width - ((strlen(buffer) + VAL_PREFIX_LENGHT)); + + + 428 + +
+ 2/2 +
+
✓ Branch 0 taken 15 times.
+
✓ Branch 1 taken 15 times.
+
+
+ + 30 + for (uint8_t t = 0; t < zeros_qty; t++) + + + 429 + + + + { + + + 430 + + + 15 + strcat(zeros_buf, "0"); + + + 431 + + + + } + + + 432 + + + + } + + + 433 + + + 27 + } + + + 434 + + + + #endif + + + 435 + + + + #endif + + + 436 + + + + + + + 437 + + + + #if LCD_BUFFERING==ON + + + 438 + + + 837 + static void check_lcd_buf_possition_ptr_overflow(void) + + + 439 + + + + { + + + 440 + +
+ 2/2 +
+
✓ Branch 0 taken 21 times.
+
✓ Branch 1 taken 816 times.
+
+
+ + 837 + if(++lcd_buf_position_ptr>&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]) + + + 441 + + + + { + + + 442 + + + 21 + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + + + 443 + + + + } + + + 444 + + + 837 + } + + + 445 + + + 469 + static void copy_lcd_buf_2_prev_lcd_buf(void) + + + 446 + + + + { + + + 447 + +
+ 2/2 +
+
✓ Branch 0 taken 1876 times.
+
✓ Branch 1 taken 469 times.
+
+
+ + 2345 + for(uint8_t y=0;y<LCD_Y;y++) + + + 448 + + + + { + + + 449 + +
+ 2/2 +
+
✓ Branch 0 taken 37520 times.
+
✓ Branch 1 taken 1876 times.
+
+
+ + 39396 + for(uint8_t x=0;x<LCD_X;x++) + + + 450 + + + + { + + + 451 + + + 37520 + prev_lcd_buffer[y][x]=lcd_buffer[y][x]; + + + 452 + + + + } + + + 453 + + + + } + + + 454 + + + 469 + } + + + 455 + + + 7520 + static void update_lcd_curosr_possition(uint8_t *lcd_cursor_position,uint8_t *lcd_line, uint8_t *missed_char_counter_in_LCD_line) + + + 456 + + + + { + + + 457 + +
+ 2/2 +
+
✓ Branch 0 taken 376 times.
+
✓ Branch 1 taken 7144 times.
+
+
+ + 7520 + if((++(*lcd_cursor_position))>=LCD_X) + + + 458 + + + + { + + + 459 + + + 376 + *lcd_cursor_position=0; + + + 460 + + + 376 + (*lcd_line)++; + + + 461 + + + 376 + *missed_char_counter_in_LCD_line=0; + + + 462 + +
+ 2/2 +
+
✓ Branch 0 taken 94 times.
+
✓ Branch 1 taken 282 times.
+
+
+ + 376 + if(*lcd_line==LCD_Y) + + + 463 + + + + { + + + 464 + + + 94 + *lcd_line=LINE_1; + + + 465 + + + + } + + + 466 + + + 376 + lcd_locate(*lcd_line,*lcd_cursor_position); + + + 467 + + + + + + + 468 + + + + } + + + 469 + + + 7520 + } + + + 470 + + + + + + + 471 + + + 7520 + void write_lcd_buf_2_lcd(const uint8_t * lcd_cursor_position, const uint8_t *lcd_line, uint8_t * missed_char_counter_in_LCD_line, const lcd_pos_t *prev_lcd_buff_pos_ptr) + + + 472 + + + + { + + + 473 + +
+ 2/2 +
+
✓ Branch 0 taken 341 times.
+
✓ Branch 1 taken 7179 times.
+
+
+ + 7520 + if(*lcd_buf_position_ptr!=*prev_lcd_buff_pos_ptr) + + + 474 + + + + { + + + 475 + +
+ 2/2 +
+
✓ Branch 0 taken 28 times.
+
✓ Branch 1 taken 313 times.
+
+
+ + 341 + if (*missed_char_counter_in_LCD_line!=0) + + + 476 + + + + { + + + 477 + + + 28 + lcd_locate(*lcd_line,*lcd_cursor_position); + + + 478 + + + 28 + *missed_char_counter_in_LCD_line=0; + + + 479 + + + + } + + + 480 + + + 341 + lcd_char(*lcd_buf_position_ptr); + + + 481 + + + + } + + + 482 + + + + else + + + 483 + + + + { + + + 484 + + + 7179 + (*missed_char_counter_in_LCD_line)++; + + + 485 + + + + } + + + 486 + + + 7520 + } + + + 487 + + + + + + + 488 + + + + #endif + + + 489 + + + + + + + 490 + + + + /** + + + 491 + + + + * @brief Function that initialize LCD in 4-bit mode with or without LCD R/W Pin handling. + + + 492 + + + + * @attention LCD R/W handling should be configured in lcd_hd44780_config.h by setting USE_RW_PIN to 1 (Enable R/W Pin + + + 493 + + + + * handling) or 0 (disable R/W Pin handling). + + + 494 + + + + */ + + + 495 + + + 375 + void lcd_init(void) + + + 496 + + + + { + + + 497 + + + 375 + register_LCD_IO_driver(); + + + 498 + + + 375 + LCD->init_LCD_pins(); + + + 499 + + + + /**************************BASIC LCD INIT - basing on DS init procedure***************************************/ + + + 500 + + + + // set all LCD signals to High for more than 15ms ->bit different then in DS base on other implementation from internet + + + 501 + + + 375 + lcd_set_all_SIG(); + + + 502 + + + 375 + LCD->delay_us(15000); + + + 503 + + + 375 + lcd_reset_all_SIG(); + + + 504 + + + + // send 0x03 & wait more then 4,1ms + + + 505 + + + 375 + lcd_write_4bit_data(0x03); + + + 506 + + + 375 + LCD->delay_us(4500); + + + 507 + + + + // send 0x03 & wait more then 100us + + + 508 + + + 375 + lcd_write_4bit_data(0x03); + + + 509 + + + 375 + LCD->delay_us(110); + + + 510 + + + + // send 0x03 & wait more then 100us + + + 511 + + + 375 + lcd_write_4bit_data(0x03); + + + 512 + + + 375 + LCD->delay_us(110); + + + 513 + + + + // send 0x02 & wait more then 100us + + + 514 + + + 375 + lcd_write_4bit_data(0x02); + + + 515 + + + 375 + LCD->delay_us(110); + + + 516 + + + + // FUNCTION SET ->send cmd -> LCD in 4-bit mode, 2 rows, char size 5x7 + + + 517 + + + 375 + lcd_write_cmd(LCDC_FUNC | LCDC_FUNC4B | LCDC_FUNC2L | LCDC_FUNC5x7); + + + 518 + + + + // DISPLAY_ON_OFF send cmd -> enable lcd + + + 519 + + + 375 + lcd_write_cmd(LCDC_ONOFF | LCDC_CURSOROFF | LCDC_DISPLAYON); + + + 520 + + + + // LCD clear screen + + + 521 + + + 375 + lcd_cls(); + + + 522 + + + + // ENTRY MODe SET do not shift LCD shift cursor right after placing a char + + + 523 + + + 375 + lcd_write_cmd(LCDC_ENTRY_MODE | LCDC_ENTRYR); + + + 524 + + + + /*********************************END of BASIC LCD INIT***************************************/ + + + 525 + + + + #if LCD_BUFFERING == ON + + + 526 + + + + //clear lcd_buffer by putting spaces inside of the buffer + + + 527 + + + 375 + lcd_buf_cls(); + + + 528 + + + + //copy lcd_buffer with spaces to prev_lcd_buffer + + + 529 + + + 375 + copy_lcd_buf_2_prev_lcd_buf(); + + + 530 + + + + // clear flag due to init procedure that reset lcd screan and buffers + + + 531 + + + 375 + LCD_UPDATE_EVENT=false; + + + 532 + + + + #endif + + + 533 + + + + + + + 534 + + + 375 + } + + + 535 + + + + + + + 536 + + + + /** + + + 537 + + + + * @brief Function that clear the LCD screen and set the cursor on the position of first character in first line of LCD + + + 538 + + + + * screen. + + + 539 + + + + */ + + + 540 + + + 382 + void lcd_cls(void) + + + 541 + + + + { + + + 542 + + + 382 + lcd_write_cmd(LCDC_CLS); + + + 543 + + + + #if USE_RW_PIN == OFF + + + 544 + + + 382 + LCD->delay_us(4900); + + + 545 + + + + #endif + + + 546 + + + 382 + } + + + 547 + + + + + + + 548 + + + + #if USE_DEF_CHAR_FUNCTION == ON + + + 549 + + + + /** + + + 550 + + + + * @brief Function for defining custom user characters in CGRAM of the LCD. + + + 551 + + + + * @param CGRAM_char_index Position/addres of the character in CGRAM of the LCD where defined char should be written. + + + 552 + + + + * For the predefined example of special characters, taken values are defined in the type enum LCD_CGRAM that is defined + + + 553 + + + + * in lcd-hd44780.h + + + 554 + + + + * @param def_char Pointer to the predefined special character. + + + 555 + + + + * @note CGRAM_char_index - This Parameter can take values from 0 to 7. For the predefined example of special + + + 556 + + + + * characters, taken values are defined in the type enum LCD_CGRAM that is defined in lcd-hd44780.h + + + 557 + + + + */ + + + 558 + + + 63 + void lcd_def_char(const uint8_t CGRAM_bank_x_char_adr, const uint8_t *def_char) + + + 559 + + + + { + + + 560 + + + 63 + lcd_write_cmd(LCDC_SET_CGRAM | ((DEF_CHAR_ADR_MASK & CGRAM_bank_x_char_adr) * LCD_CGRAM_BYTES_PER_CHAR)); + + + 561 + +
+ 2/2 +
+
✓ Branch 0 taken 504 times.
+
✓ Branch 1 taken 63 times.
+
+
+ + 567 + for (uint8_t j = 0; j < LCD_CGRAM_BYTES_PER_CHAR; j++) + + + 562 + + + + { + + + 563 + + + 504 + lcd_write_data(def_char[j]); + + + 564 + + + + } + + + 565 + + + 63 + lcd_write_cmd(LCDC_SET_DDRAM); + + + 566 + + + 63 + } + + + 567 + + + + + + + 568 + + + 7 + void lcd_load_char_bank(const struct char_bank_struct *char_bank) + + + 569 + + + + { + + + 570 + + + 7 + lcd_def_char(0, char_bank->char_0); + + + 571 + + + 7 + lcd_def_char(1, char_bank->char_1); + + + 572 + + + 7 + lcd_def_char(2, char_bank->char_2); + + + 573 + + + 7 + lcd_def_char(3, char_bank->char_3); + + + 574 + + + 7 + lcd_def_char(4, char_bank->char_4); + + + 575 + + + 7 + lcd_def_char(5, char_bank->char_5); + + + 576 + + + 7 + lcd_def_char(6, char_bank->char_6); + + + 577 + + + 7 + lcd_def_char(7, char_bank->char_7); + + + 578 + + + 7 + } + + + 579 + + + + #endif + + + 580 + + + + + + + 581 + + + + /** + + + 582 + + + + * @brief Function for print the char on the LCD screen under current position of the LCD cursor. + + + 583 + + + + * @param C char (for example '1') or it's ASCI code (0x31). + + + 584 + + + + * @note For user defined char, place CGRAM_char_index (Position/addres of the character in CGRAM of the LCD where + + + 585 + + + + * defined char was written). + + + 586 + + + + */ + + + 587 + + + 348 + void lcd_char(const char C) + + + 588 + + + + { + + + 589 + + + 348 + uint8_t data = (uint8_t)(C); + + + 590 + + + 348 + lcd_write_data(data); + + + 591 + + + 348 + } + + + 592 + + + + + + + 593 + + + + /** + + + 594 + + + + * @brief Function for printing/writing string on LCD screen. Writing the string on LCD screen start from current LCD + + + 595 + + + + * cursor position. + + + 596 + + + + * @param str string that should be printed/written on the LCD screen + + + 597 + + + + */ + + + 598 + + + 77 + void lcd_str(const char *str) + + + 599 + + + + { + + + 600 + + + + register char znak; + + + 601 + +
+ 2/2 +
+
✓ Branch 0 taken 357 times.
+
✓ Branch 1 taken 77 times.
+
+
+ + 434 + while ((znak = *(str++))) + + + 602 + + + + { + + + 603 + + + 357 + lcd_write_data((uint8_t)(znak)); + + + 604 + + + + } + + + 605 + + + 77 + } + + + 606 + + + + + + + 607 + + + + #if USE_LCD_INT == ON + + + 608 + + + + /** + + + 609 + + + + * @brief Function for print the integer value on the LCD screen under current position of the LCD cursor. + + + 610 + + + + * @param val int type value to print on LCD screen + + + 611 + + + + * @param width Minimum number of characters to be printed. If the value to be printed is shorter than this number, the + + + 612 + + + + * result is padded with blank spaces. The value is not truncated even if the result is larger. + + + 613 + + + + * @param alignment If the value to be printed is shorter than width, this parmaeter will specify aligment of the + + + 614 + + + + * printed tekst value. This parameter can be set to "left" or "right" + + + 615 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 616 + + + + */ + + + 617 + + + 28 + void lcd_int(int val, uint8_t width, enum alignment alignment) + + + 618 + + + + { + + + 619 + + + + #ifdef AVR + + + 620 + + + + lcd_int_AVR(val, width, alignment); + + + 621 + + + + #else + + + 622 + + + + char buffer[20]; // 19chars for 64 bit int + end char '\0' + + + 623 + + + 28 + buffer[0] = '\0'; + + + 624 + +
+ 2/2 +
+
✓ Branch 0 taken 21 times.
+
✓ Branch 1 taken 7 times.
+
+
+ + 28 + if (alignment == right) + + + 625 + + + 21 + sprintf(buffer, "%*i", width, val); + + + 626 + + + + else + + + 627 + + + 7 + sprintf(buffer, "%-*i", width, val); + + + 628 + + + 28 + lcd_str(buffer); + + + 629 + + + + #endif + + + 630 + + + 28 + } + + + 631 + + + + #endif + + + 632 + + + + + + + 633 + + + + #if USE_LCD_HEX == ON + + + 634 + + + + /** + + + 635 + + + + * @brief Function for print the integer value in hexadecimal format on the LCD screen under current position of the LCD + + + 636 + + + + * cursor. + + + 637 + + + + * @param val int type value to print on LCD screen in hexadecimal format + + + 638 + + + + * @param width Minimum number of characters to be printed. If the value to be printed is shorter than this number, the + + + 639 + + + + * result is padded with blank spaces. The value is not truncated even if the result is larger. Width should contain + + + 640 + + + + * additional 2 characters for '0x' at the begining of the printed value. + + + 641 + + + + * @param alignment If the value to be printed is shorter than width, this parmaeter will specify aligment of the + + + 642 + + + + * printed tekst value. This parameter can be set to "left" or "right" + + + 643 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 644 + + + + */ + + + 645 + + + 28 + void lcd_hex(int val, uint8_t width, enum alignment alignment) + + + 646 + + + + { + + + 647 + + + + #ifdef AVR + + + 648 + + + + lcd_hex_AVR(val, width, alignment); + + + 649 + + + + #else + + + 650 + + + + char buffer[17]; + + + 651 + + + 28 + buffer[0] = '\0'; + + + 652 + +
+ 2/2 +
+
✓ Branch 0 taken 21 times.
+
✓ Branch 1 taken 7 times.
+
+
+ + 28 + if (alignment == right) + + + 653 + + + 21 + sprintf(buffer, "%#*x", width, val); + + + 654 + + + + else + + + 655 + + + 7 + sprintf(buffer, "%-#*x", width, val); + + + 656 + + + 28 + lcd_str(buffer); + + + 657 + + + + #endif + + + 658 + + + 28 + } + + + 659 + + + + #endif + + + 660 + + + + + + + 661 + + + + #if USE_LCD_BIN == ON + + + 662 + + + + /** + + + 663 + + + + * @brief Function for print the integer value in hexadecimal format on the LCD screen under current position of the LCD + + + 664 + + + + * cursor. + + + 665 + + + + * @param val int type value to print on LCD screen in hexadecimal format + + + 666 + + + + * @param width Minimum number of characters to be printed. If the value to be printed is shorter than this number, the + + + 667 + + + + * result is padded with blank spaces. The value is not truncated even if the result is larger. Width should contain + + + 668 + + + + * additional 2 characters for '0x' at the begining of the printed value. + + + 669 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 670 + + + + */ + + + 671 + + + 14 + void lcd_bin(int val, uint8_t width) + + + 672 + + + + { + + + 673 + + + + #ifdef AVR + + + 674 + + + + lcd_bin_AVR(val, width); + + + 675 + + + + #else + + + 676 + + + + char buffer[35]; + + + 677 + + + + char bin_val_buffer[35]; + + + 678 + + + + char zeros_buf[35]; + + + 679 + + + 14 + buffer[0] = '\0'; + + + 680 + + + 14 + bin_val_buffer[0] = '\0'; + + + 681 + + + 14 + zeros_buf[0] = '\0'; + + + 682 + + + + + + + 683 + + + 14 + fill_bin_value_buffer(val, bin_val_buffer); + + + 684 + + + 14 + fill_zeros_buffer(bin_val_buffer, width, zeros_buf); + + + 685 + + + 14 + strcat(buffer, "0b"); + + + 686 + + + 14 + strcat(buffer, zeros_buf); + + + 687 + + + 14 + strcat(buffer, bin_val_buffer); + + + 688 + + + 14 + lcd_str(buffer); + + + 689 + + + + #endif + + + 690 + + + 14 + } + + + 691 + + + + + + + 692 + + + + #endif + + + 693 + + + + + + + 694 + + + + /** + + + 695 + + + + * @brief Function that move LCD cursor to specific posiotion located under x and y coordinate + + + 696 + + + + * @param y LCD row/line number. Defined enum value LINE_1, LINE_2,... etc. + + + 697 + + + + * @param x LCD column number. Defined enum value C1, C2, C3,... etc. + + + 698 + + + + */ + + + 699 + + + 439 + void lcd_locate(enum LCD_LINES y, enum LCD_COLUMNS x) + + + 700 + + + + { + + + 701 + +
+ 4/5 +
+
✓ Branch 0 taken 122 times.
+
✓ Branch 1 taken 108 times.
+
✓ Branch 2 taken 101 times.
+
✓ Branch 3 taken 108 times.
+
✗ Branch 4 not taken.
+
+
+ + 439 + switch (y) + + + 702 + + + + { + + + 703 + + + 122 + case 0: + + + 704 + + + 122 + y = LCD_LINE1_ADR; + + + 705 + + + 122 + break; + + + 706 + + + + + + + 707 + + + + #if (LCD_Y > 1) + + + 708 + + + 108 + case 1: + + + 709 + + + 108 + y = LCD_LINE2_ADR; + + + 710 + + + 108 + break; + + + 711 + + + + #endif + + + 712 + + + + #if (LCD_Y > 2) + + + 713 + + + 101 + case 2: + + + 714 + + + 101 + y = LCD_LINE3_ADR; + + + 715 + + + 101 + break; + + + 716 + + + + #endif + + + 717 + + + + #if (LCD_Y > 3) + + + 718 + + + 108 + case 3: + + + 719 + + + 108 + y = LCD_LINE4_ADR; + + + 720 + + + 108 + break; + + + 721 + + + + #endif + + + 722 + + + ✗ + default: + + + 723 + + + ✗ + break; + + + 724 + + + + } + + + 725 + + + 439 + lcd_write_cmd((uint8_t)(LCDC_SET_DDRAM + y + x)); + + + 726 + + + 439 + } + + + 727 + + + + #if USE_LCD_CURSOR_HOME == ON + + + 728 + + + + /** + + + 729 + + + + * @brief Function that move lcd cursor to the first posision at first row of LCD screen + + + 730 + + + + */ + + + 731 + + + 7 + void lcd_home(void) + + + 732 + + + + { + + + 733 + + + 7 + lcd_write_cmd(LCDC_CLS | LCDC_HOME); + + + 734 + + + + #if USE_RW_PIN == OFF + + + 735 + + + 7 + LCD->delay_us(4900); + + + 736 + + + + #endif + + + 737 + + + 7 + } + + + 738 + + + + #endif + + + 739 + + + + + + + 740 + + + + #if USE_LCD_CURSOR_ON == ON + + + 741 + + + + /** + + + 742 + + + + * @brief Function that activates the visibility of the LCD cursor. + + + 743 + + + + */ + + + 744 + + + 7 + void lcd_cursor_on(void) + + + 745 + + + + { + + + 746 + + + 7 + lcd_write_cmd(LCDC_ONOFF | LCDC_DISPLAYON | LCDC_CURSORON); + + + 747 + + + 7 + } + + + 748 + + + + #endif + + + 749 + + + + + + + 750 + + + + #if USE_LCD_CURSOR_OFF == ON + + + 751 + + + + /** + + + 752 + + + + * @brief Function that deactivates the visibility and blinking of the LCD cursor. + + + 753 + + + + */ + + + 754 + + + 7 + void lcd_cursor_off(void) + + + 755 + + + + { + + + 756 + + + 7 + lcd_write_cmd(LCDC_ONOFF | LCDC_DISPLAYON); + + + 757 + + + 7 + } + + + 758 + + + + #endif + + + 759 + + + + #if USE_LCD_BLINKING_CURSOR_ON == ON + + + 760 + + + + /** + + + 761 + + + + * @brief Function that activates the visibility and blinking of the LCD cursor. + + + 762 + + + + */ + + + 763 + + + 7 + void lcd_blinking_cursor_on(void) + + + 764 + + + + { + + + 765 + + + 7 + lcd_write_cmd(LCDC_ONOFF | LCDC_DISPLAYON | LCDC_CURSORON | LCDC_BLINKON); + + + 766 + + + 7 + } + + + 767 + + + + #endif + + + 768 + + + + + + + 769 + + + + #if LCD_BUFFERING == ON + + + 770 + + + 382 + void lcd_buf_cls(void) + + + 771 + + + + { + + + 772 + +
+ 2/2 +
+
✓ Branch 0 taken 30560 times.
+
✓ Branch 1 taken 382 times.
+
+
+ + 30942 + for(lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; lcd_buf_position_ptr<=&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]; lcd_buf_position_ptr++) + + + 773 + + + + { + + + 774 + + + 30560 + *lcd_buf_position_ptr=' '; + + + 775 + + + + } + + + 776 + + + 382 + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + + + 777 + + + 382 + LCD_UPDATE_EVENT=true; + + + 778 + + + 382 + } + + + 779 + + + + + + + 780 + + + 63 + void lcd_buf_char(const char c) + + + 781 + + + + { + + + 782 + + + 63 + *lcd_buf_position_ptr=c; + + + 783 + + + 63 + check_lcd_buf_possition_ptr_overflow(); + + + 784 + + + 63 + LCD_UPDATE_EVENT=true; + + + 785 + + + 63 + } + + + 786 + + + + + + + 787 + + + 87 + void lcd_buf_locate(enum LCD_LINES y, enum LCD_COLUMNS x) + + + 788 + + + + { + + + 789 + + + 87 + lcd_buf_position_ptr=&lcd_buffer[y][x]; + + + 790 + + + 87 + } + + + 791 + + + + + + + 792 + + + 160 + void lcd_buf_str(const char *str) + + + 793 + + + + { + + + 794 + +
+ 2/2 +
+
✓ Branch 0 taken 774 times.
+
✓ Branch 1 taken 160 times.
+
+
+ + 934 + while (*str) + + + 795 + + + + { + + + 796 + + + 774 + *(lcd_buf_position_ptr)=*(str++); + + + 797 + + + 774 + check_lcd_buf_possition_ptr_overflow(); + + + 798 + + + + } + + + 799 + + + 160 + LCD_UPDATE_EVENT=true; + + + 800 + + + 160 + } + + + 801 + + + + + + + 802 + + + 94 + void lcd_update(void) + + + 803 + + + + { + + + 804 + + + + static uint8_t lcd_cursor_position=0; + + + 805 + + + + static uint8_t lcd_line=0; + + + 806 + + + + static uint8_t missed_char_counter_in_LCD_line=0; + + + 807 + + + + // static const lcd_pos_t *prev_lcd_buff_pos_ptr=&prev_lcd_buffer[LINE_1][C1]; + + + 808 + + + + + + + 809 + +
+ 2/2 +
+
✓ Branch 0 taken 7520 times.
+
✓ Branch 1 taken 94 times.
+
+
+ + 7614 + for(lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; lcd_buf_position_ptr<=&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]; lcd_buf_position_ptr++) + + + 810 + + + + { + + + 811 + + + 7520 + write_lcd_buf_2_lcd(&lcd_cursor_position,&lcd_line,&missed_char_counter_in_LCD_line,&prev_lcd_buffer[LINE_1][C1]); + + + 812 + + + 7520 + update_lcd_curosr_possition(&lcd_cursor_position,&lcd_line,&missed_char_counter_in_LCD_line); + + + 813 + + + + } + + + 814 + + + 94 + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + + + 815 + + + 94 + copy_lcd_buf_2_prev_lcd_buf(); + + + 816 + + + 94 + LCD_UPDATE_EVENT=false; + + + 817 + + + 94 + } + + + 818 + + + + + + + 819 + + + + #if USE_LCD_BUF_INT == ON + + + 820 + + + + /** + + + 821 + + + + * @brief Function for adding intiger value as string to the LCD buffer under current position of the LCD buffer pointer. + + + 822 + + + + * @param val int type value to add to LCD buffer + + + 823 + + + + * @param width Minimum number of characters to be added to LCD buffer. If the value to be added to the LCD buffer is shorter than width, the + + + 824 + + + + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght is larger then width value. + + + 825 + + + + * @param alignment If the value to be added to LCD buffer as string is shorter than width, this parameter will specify alignment of the + + + 826 + + + + * tekst represented the value. This parameter can be set to "left" or "right" + + + 827 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 828 + + + + */ + + + 829 + + + 28 + void lcd_buf_int(int val, uint8_t width, enum alignment alignment) + + + 830 + + + + { + + + 831 + + + + #ifdef AVR + + + 832 + + + + lcd_buf_int_AVR(val, width, alignment); + + + 833 + + + + #else + + + 834 + + + + char buffer[20]; // 19chars for 64 bit int + end char '\0' + + + 835 + + + 28 + buffer[0] = '\0'; + + + 836 + +
+ 2/2 +
+
✓ Branch 0 taken 21 times.
+
✓ Branch 1 taken 7 times.
+
+
+ + 28 + if (alignment == right) + + + 837 + + + 21 + sprintf(buffer, "%*i", width, val); + + + 838 + + + + else + + + 839 + + + 7 + sprintf(buffer, "%-*i", width, val); + + + 840 + + + 28 + lcd_buf_str(buffer); + + + 841 + + + + #endif + + + 842 + + + 28 + } + + + 843 + + + + #endif + + + 844 + + + + + + + 845 + + + + #if USE_LCD_BUF_HEX == ON + + + 846 + + + + /** + + + 847 + + + + * @brief Function for adding intiger value in hexadecimal format as string to the LCD buffer under current position of the LCD buffer pointer. + + + 848 + + + + * @param val int type value to add to LCD buffer as string in hexadecimal format + + + 849 + + + + * @param width Minimum number of characters to be added to lcd buffer. If the value to be added to buffer is shorter than width, the + + + 850 + + + + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght is larger then width value. Width should contain + + + 851 + + + + * additional 2 characters for "0x" at the begining of the value represented as string. example: 0x01-> width=4 + + + 852 + + + + * @param alignment If the value to be added to LCD buffer as string is shorter than width, this parameter will specify alignment of the + + + 853 + + + + * tekst represented the value. This parameter can be set to "left" or "right" + + + 854 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 855 + + + + */ + + + 856 + + + 32 + void lcd_buf_hex(int val, uint8_t width, enum alignment alignment) + + + 857 + + + + { + + + 858 + + + + #ifdef AVR + + + 859 + + + + lcd_buf_hex_AVR(val, width, alignment); + + + 860 + + + + #else + + + 861 + + + + char buffer[17]; + + + 862 + + + 32 + buffer[0] = '\0'; + + + 863 + +
+ 2/2 +
+
✓ Branch 0 taken 21 times.
+
✓ Branch 1 taken 11 times.
+
+
+ + 32 + if (alignment == right) + + + 864 + + + 21 + sprintf(buffer, "%#*x", width, val); + + + 865 + + + + else + + + 866 + + + 11 + sprintf(buffer, "%-#*x", width, val); + + + 867 + + + 32 + lcd_buf_str(buffer); + + + 868 + + + + #endif + + + 869 + + + 32 + } + + + 870 + + + + #endif + + + 871 + + + + + + + 872 + + + + #if USE_LCD_BUF_BIN == ON + + + 873 + + + + /** + + + 874 + + + + * @brief Function for adding to the LCD buffer the integer value in binary format as string under current position of the LCD buffer pointer + + + 875 + + + + * @param val int type value to be added to the LCD buffer as string in hexadecimal format + + + 876 + + + + * @param width Minimum number of characters to be added to LCD buffer. If the value to be added to buffer as string lenght is shorter than width, the + + + 877 + + + + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght represented the value i binary format lenght + + + 878 + + + + * is larger then width value. Width should contain additional 2 characters for "0b" at the begining of the value represented as string. example: 0b01-> width=4 + + + 879 + + + + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + + + 880 + + + + */ + + + 881 + + + 13 + void lcd_buf_bin(int val, uint8_t width) + + + 882 + + + + { + + + 883 + + + + #ifdef AVR + + + 884 + + + + lcd_buf_bin_AVR(val, width); + + + 885 + + + + #else + + + 886 + + + + char buffer[35]; + + + 887 + + + + char bin_val_buffer[35]; + + + 888 + + + + char zeros_buf[35]; + + + 889 + + + 13 + buffer[0] = '\0'; + + + 890 + + + 13 + bin_val_buffer[0] = '\0'; + + + 891 + + + 13 + zeros_buf[0] = '\0'; + + + 892 + + + + + + + 893 + + + 13 + fill_bin_value_buffer(val, bin_val_buffer); + + + 894 + + + 13 + fill_zeros_buffer(bin_val_buffer, width, zeros_buf); + + + 895 + + + 13 + strcat(buffer, "0b"); + + + 896 + + + 13 + strcat(buffer, zeros_buf); + + + 897 + + + 13 + strcat(buffer, bin_val_buffer); + + + 898 + + + 13 + lcd_buf_str(buffer); + + + 899 + + + + #endif + + + 900 + + + 13 + } + + + 901 + + + + + + + 902 + + + + #endif + + + 903 + + + + #endif + + + 904 + + + + + + + 905 + + + diff --git a/reports/Cyclomatic_Complexity/Lizard_report.html b/reports/Cyclomatic_Complexity/Lizard_report.html index 7f71479..fd3b96d 100644 --- a/reports/Cyclomatic_Complexity/Lizard_report.html +++ b/reports/Cyclomatic_Complexity/Lizard_report.html @@ -55,12 +55,12 @@

Code Complexity Report

+ Source file: ../../../src/lcd_hd44780.c - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -268,11 +348,211 @@

Code Complexity Report

- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -339,7 +619,27 @@

Code Complexity Report

- + + + + + + + + + + + + + + + + + + + + + @@ -347,19 +647,344 @@

Code Complexity Report

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Source file: ../../../src/lcd_hd44780_config.h + Source file: ../../../src/lcd_hd44780_def_char.h + Source file: ../../../src/lcd_hd44780_interface.h @@ -369,7 +994,7 @@

Code Complexity Report


- Source file: src/lcd_hd44780.c
Function name Cyclomatic complexity (12) -LOC (21) +LOC (30) Token count @@ -248,18 +248,98 @@

Code Complexity Report

lcd_initlcd_put_spaces 27281
lcd_int_AVR3261043
lcd_hex_AVR3281293
lcd_bin_AVR3221172
lcd_buf_put_spaces220711028
lcd_clslcd_buf_int_AVR3261043
lcd_buf_hex_AVR3281293
lcd_buf_bin_AVR3221172
fill_bin_value_buffer419712
fill_zeros_buffer311703
check_lcd_buf_possition_ptr_overflow27331
copy_lcd_buf_2_prev_lcd_buf310541
update_lcd_curosr_possition314693
write_lcd_buf_2_lcd316714
lcd_init 2231221
lcd_cls2522231
lcd_str2837
lcd_int311703
lcd_hex311703
lcd_bin216982
lcd_locate821722
lcd_home25201
lcd_cursor_on14151
lcd_cursor_off14131
lcd_blinking_cursor_on14171
lcd_buf_cls29551
lcd_buf_char16211
lcd_buf_locate14232
lcd_buf_str29351
lcd_update2141051
lcd_buf_int311703
lcd_buf_hex311703
lcd_buf_bin216982
+ Source file: ../../../src/lcd_hd44780.h
- Source file: src/lcd_hd44780.h
- Source file: src/lcd_hd44780_config.h
- Source file: src/lcd_hd44780_interface.h
diff --git a/reports/cppcheck_report.txt b/reports/cppcheck_report.txt deleted file mode 100644 index 96f2199..0000000 --- a/reports/cppcheck_report.txt +++ /dev/null @@ -1,122 +0,0 @@ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:273:0: information: Skipping configuration 'HSE_VALUE' since the value of 'HSE_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSE_VALUE; -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:285:0: information: Skipping configuration 'HSE_VALUE' since the value of 'HSE_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull; -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:270:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSI_VALUE; -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:303:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:310:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSI_VALUE; -^ -hw/STM32F091RB/Core/Src/system_stm32f0xx.c:273:0: information: Skipping configuration 'HSE_VALUE' since the value of 'HSE_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSE_VALUE; -^ -hw/STM32F091RB/Core/Src/system_stm32f0xx.c:285:0: information: Skipping configuration 'HSE_VALUE' since the value of 'HSE_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = (HSE_VALUE/predivfactor) * pllmull; -^ -hw/STM32F091RB/Core/Src/system_stm32f0xx.c:270:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSI_VALUE; -^ -hw/STM32F091RB/Core/Src/system_stm32f0xx.c:303:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = (HSI_VALUE >> 1) * pllmull; -^ -hw/STM32F091RB/Core/Src/system_stm32f0xx.c:310:0: information: Skipping configuration 'HSI_VALUE' since the value of 'HSI_VALUE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly. [ConfigurationNotChecked] - SystemCoreClock = HSI_VALUE; -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:260:0: style: The function 'SystemCoreClockUpdate' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/system_stm32f0xx.c:163:0: style: The function 'SystemInit' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:92:0: style: The function '_close' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:169:0: style: The function '_execve' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:61:0: style: The function '_exit' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:163:0: style: The function '_fork' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:99:0: style: The function '_fstat' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:48:0: style: The function '_getpid' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:106:0: style: The function '_isatty' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:155:0: style: The function '_link' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:112:0: style: The function '_lseek' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:120:0: style: The function '_open' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:67:0: style: The function '_read' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/sysmem.c:54:0: style: The function '_sbrk' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:148:0: style: The function '_stat' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:142:0: style: The function '_times' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:135:0: style: The function '_unlink' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:128:0: style: The function '_wait' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:80:0: style: The function '_write' is never used. [unusedFunction] - -^ -hw/STM32F030R8/Core/Src/syscalls.c:44:0: style: The function 'initialise_monitor_handles' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:486:0: style: The function 'lcd_bin' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:578:0: style: The function 'lcd_blinking_cursor_on' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:569:0: style: The function 'lcd_cursor_off' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:559:0: style: The function 'lcd_cursor_on' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:460:0: style: The function 'lcd_hex' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:546:0: style: The function 'lcd_home' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:317:0: style: The function 'lcd_init' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:432:0: style: The function 'lcd_int' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:383:0: style: The function 'lcd_load_char_bank' is never used. [unusedFunction] - -^ -src/lcd_hd44780.c:514:0: style: The function 'lcd_locate' is never used. [unusedFunction] - -^ -nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude] - diff --git a/src/lcd_hd44780.c b/src/lcd_hd44780.c index a5b03b8..0644886 100644 --- a/src/lcd_hd44780.c +++ b/src/lcd_hd44780.c @@ -2,15 +2,16 @@ * @Author: lukasz.niewelt * @Date: 2023-12-06 21:39:30 * @Last Modified by: lukasz.niewelt - * @Last Modified time: 2023-12-13 13:18:13 + * @Last Modified time: 2024-01-10 18:04:17 */ #include "lcd_hd44780.h" #include -#include "stdio.h" -#include "stdlib.h" -#include "string.h" +#include +#include +#include +typedef char lcd_pos_t; // clang-format off #define BUSY_FLAG 1 << 7 #define VAL_PREFIX_LENGHT 2U @@ -46,39 +47,25 @@ #define LCDC_SET_CGRAM 0x40 #define LCDC_SET_DDRAM 0x80 +#ifndef UNIT_TEST +#define PRIVATE static +#else +#define PRIVATE +#endif -/******************** definitions of Line addres for different lcd screens ****************/ -//https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_addressing/lcd_addressing_index.html +#if LCD_BUFFERING == ON -#if LCD_TYPE ==1604 -#define LCD_Y 4 -#define LCD_X 16 -#define LCD_LINE1_ADR 0x00 -#define LCD_LINE2_ADR 0x40 -#define LCD_LINE3_ADR 0x10 -#define LCD_LINE4_ADR 0x50 -#endif +#define LAST_CHAR_IN_LCD_LINE (LCD_X-1) +#define LAST_LCD_LINE (LCD_Y-1) -#if LCD_TYPE==2004 -#define LCD_Y 4 -#define LCD_X 20 -#define LCD_LINE1_ADR 0x00 -#define LCD_LINE2_ADR 0x40 -#define LCD_LINE3_ADR 0x14 -#define LCD_LINE4_ADR 0x54 -#endif +PRIVATE char lcd_buffer[LCD_Y][LCD_X]; +PRIVATE char prev_lcd_buffer[LCD_Y][LCD_X]; -#if LCD_TYPE==1602 -#define LCD_Y 2 -#define LCD_X 16 -#define LCD_LINE1_ADR 0x00 -#define LCD_LINE2_ADR 0x40 +static lcd_pos_t *lcd_buf_position_ptr; #endif -// clang-format on - static const struct LCD_IO_driver_interface_struct *LCD = NULL; -// const struct char_bank_struct *char_bank = &char_bank_1; +bool LCD_UPDATE_EVENT = false; static void register_LCD_IO_driver(void); static void lcd_set_all_SIG(void); @@ -93,14 +80,44 @@ static uint8_t lcd_read_byte(void); static uint8_t lcd_read_4bit_data(void); #endif #ifdef AVR +#if ((USE_LCD_INT == ON) || (USE_LCD_HEX == ON)) static void lcd_put_spaces(uint8_t empty_spaces); +#endif +#if USE_LCD_INT == ON static void lcd_int_AVR(int val, uint8_t width, enum alignment alignment); +#endif +#if USE_LCD_HEX == ON static void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment); +#endif +#if USE_LCD_BIN == ON static void lcd_bin_AVR(int val, uint8_t width); +#endif +#if LCD_BUFFERING == ON +#if ((USE_LCD_BUF_INT == ON) || (USE_LCD_BUF_HEX == ON)) +static void lcd_buf_put_spaces(uint8_t empty_spaces); +#endif +#if USE_LCD_BUF_INT == ON +static void lcd_buf_int_AVR(int val, uint8_t width, enum alignment alignment); +#endif +#if USE_LCD_BUF_HEX == ON +static void lcd_buf_hex_AVR(int val, uint8_t width, enum alignment alignment); +#endif +#if USE_LCD_BUF_BIN == ON +static void lcd_buf_bin_AVR(int val, uint8_t width); +#endif +#endif #else +#if (USE_LCD_BIN == ON || ((LCD_BUFFERING == ON) && (LCD_USE_BUF_BIN == ON))) static void fill_bin_value_buffer(int val, char *bin_val_buffer); static void fill_zeros_buffer(const char *buffer, uint8_t width, char *zeros_buf); #endif +#endif +#if LCD_BUFFERING==ON +static void check_lcd_buf_possition_ptr_overflow(void); +static void copy_lcd_buf_2_prev_lcd_buf(void); +static void update_lcd_curosr_possition(uint8_t *lcd_cursor_position,uint8_t *lcd_line, uint8_t *missed_char_counter_in_LCD_line); +static void write_lcd_buf_2_lcd(const uint8_t *lcd_cursor_position,const uint8_t *lcd_line,uint8_t * missed_char_counter_in_LCD_line, const lcd_pos_t *prev_lcd_buff_pos_ptr); +#endif static void register_LCD_IO_driver(void) { @@ -189,6 +206,7 @@ uint8_t lcd_read_4bit_data(void) } #endif #ifdef AVR +#if ((USE_LCD_INT == ON) || (USE_LCD_HEX == ON)) static void lcd_put_spaces(uint8_t empty_spaces) { for (uint8_t i = 0; i < empty_spaces; i++) @@ -196,7 +214,9 @@ static void lcd_put_spaces(uint8_t empty_spaces) lcd_char(' '); } } -void lcd_int_AVR(int val, uint8_t width, enum alignment alignment) +#endif +#if USE_LCD_INT == ON +static void lcd_int_AVR(int val, uint8_t width, enum alignment alignment) { uint8_t buf_lenght = 0; char buffer[20]; // 19chars for 64 bit int + end char '\0' @@ -222,7 +242,9 @@ void lcd_int_AVR(int val, uint8_t width, enum alignment alignment) } } } -void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment) +#endif +#if USE_LCD_HEX == ON +static void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment) { char buffer[17]; buffer[0] = '\0'; @@ -251,7 +273,9 @@ void lcd_hex_AVR(int val, uint8_t width, enum alignment alignment) } } } -void lcd_bin_AVR(int val, uint8_t width) +#endif +#if USE_LCD_BIN == ON +static void lcd_bin_AVR(int val, uint8_t width) { char buffer[35]; // 0b 0000 0000 0000 0000 0000 0000 0000 0000 static const char *prefix = {"0b"}; @@ -275,7 +299,107 @@ void lcd_bin_AVR(int val, uint8_t width) lcd_str(buffer); } } +#endif + +#if LCD_BUFFERING== ON +#if ((USE_LCD_BUF_INT == ON) || (USE_LCD_BUF_HEX == ON)) +static void lcd_buf_put_spaces(uint8_t empty_spaces) +{ + for (uint8_t i = 0; i < empty_spaces; i++) + { + lcd_buf_char(' '); + } +} +#endif +#if USE_LCD_BUF_INT == ON +static void lcd_buf_int_AVR(int val, uint8_t width, enum alignment alignment) +{ + uint8_t buf_lenght = 0; + char buffer[20]; // 19chars for 64 bit int + end char '\0' + buffer[0] = '\0'; + itoa(val, buffer, 10); + buf_lenght = strlen(buffer); + if (buf_lenght >= (width)) + { + lcd_buf_str(buffer); + } + else + { + uint8_t empty_spaces_qty = width - buf_lenght; + if (alignment == right) + { + lcd_buf_put_spaces(empty_spaces_qty); + lcd_buf_str(buffer); + } + else + { + lcd_buf_str(buffer); + lcd_buf_put_spaces(empty_spaces_qty); + } + } +} +#endif + +#if USE_LCD_BUF_HEX == ON +void lcd_buf_hex_AVR(int val, uint8_t width, enum alignment alignment) +{ + char buffer[17]; + buffer[0] = '\0'; + itoa(val, buffer, 16); + static const char *prefix = {"0x"}; + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + { + lcd_buf_str(prefix); + lcd_buf_str(buffer); + } + else + { + uint8_t empty_spaces_qty = width - (VAL_PREFIX_LENGHT + strlen(buffer)); + + if (alignment == right) + { + lcd_buf_put_spaces(empty_spaces_qty); + lcd_buf_str(prefix); + lcd_buf_str(buffer); + } + else + { + lcd_buf_str(prefix); + lcd_buf_str(buffer); + lcd_buf_put_spaces(empty_spaces_qty); + } + } +} +#endif +#if USE_LCD_BUF_BIN == ON +static void lcd_buf_bin_AVR(int val, uint8_t width) +{ + char buffer[35]; // 0b 0000 0000 0000 0000 0000 0000 0000 0000 + static const char *prefix = {"0b"}; + buffer[0] = '\0'; + + itoa(val, buffer, 2); + // if (buf_lenght < (width - VAL_PREFIX_LENGHT)) + if (width <= (strlen(buffer) + VAL_PREFIX_LENGHT)) + { + lcd_buf_str(prefix); + lcd_buf_str(buffer); + } + else + { + uint8_t zeros_qty = (width - (VAL_PREFIX_LENGHT + strlen(buffer))); + lcd_buf_str(prefix); + for (uint8_t i = 0; i < zeros_qty; i++) + { + lcd_buf_char('0'); + } + lcd_buf_str(buffer); + } +} +#endif +#endif #else +#if USE_LCD_BIN == ON static void fill_bin_value_buffer(int val, char *bin_val_buffer) { uint32_t bit_mask = 0x80000000; @@ -295,6 +419,7 @@ static void fill_bin_value_buffer(int val, char *bin_val_buffer) bit_mask = bit_mask >> 1; } } + static void fill_zeros_buffer(const char *buffer, uint8_t width, char *zeros_buf) { if (strlen(buffer) < (width + VAL_PREFIX_LENGHT)) @@ -306,6 +431,59 @@ static void fill_zeros_buffer(const char *buffer, uint8_t width, char *zeros_buf } } } +#endif +#endif + +#if LCD_BUFFERING==ON +static void check_lcd_buf_possition_ptr_overflow(void) +{ + if(++lcd_buf_position_ptr>&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]) + { + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + } +} +static void copy_lcd_buf_2_prev_lcd_buf(void) +{ + for(uint8_t y=0;y=LCD_X) + { + *lcd_cursor_position=0; + (*lcd_line)++; + *missed_char_counter_in_LCD_line=0; + if(*lcd_line==LCD_Y) + { + *lcd_line=LINE_1; + } + lcd_locate(*lcd_line,*lcd_cursor_position); + + } +} + +void write_lcd_buf_2_lcd(const uint8_t * lcd_cursor_position, const uint8_t *lcd_line, uint8_t * missed_char_counter_in_LCD_line, const lcd_pos_t *prev_lcd_buff_pos_ptr) +{ + if(*lcd_buf_position_ptr!=*prev_lcd_buff_pos_ptr) + { + if (*missed_char_counter_in_LCD_line!=0) + { + lcd_locate(*lcd_line,*lcd_cursor_position); + *missed_char_counter_in_LCD_line=0; + } + lcd_char(*lcd_buf_position_ptr); + } + else + { + (*missed_char_counter_in_LCD_line)++; + } +} #endif @@ -344,8 +522,15 @@ void lcd_init(void) // ENTRY MODe SET do not shift LCD shift cursor right after placing a char lcd_write_cmd(LCDC_ENTRY_MODE | LCDC_ENTRYR); /*********************************END of BASIC LCD INIT***************************************/ - - // ToDo define sepcial characters in LCD CGRAM +#if LCD_BUFFERING == ON + //clear lcd_buffer by putting spaces inside of the buffer + lcd_buf_cls(); + //copy lcd_buffer with spaces to prev_lcd_buffer + copy_lcd_buf_2_prev_lcd_buf(); + // clear flag due to init procedure that reset lcd screan and buffers + LCD_UPDATE_EVENT=false; +#endif + } /** @@ -579,4 +764,141 @@ void lcd_blinking_cursor_on(void) { lcd_write_cmd(LCDC_ONOFF | LCDC_DISPLAYON | LCDC_CURSORON | LCDC_BLINKON); } -#endif \ No newline at end of file +#endif + +#if LCD_BUFFERING == ON +void lcd_buf_cls(void) +{ + for(lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; lcd_buf_position_ptr<=&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]; lcd_buf_position_ptr++) + { + *lcd_buf_position_ptr=' '; + } + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + LCD_UPDATE_EVENT=true; +} + +void lcd_buf_char(const char c) +{ + *lcd_buf_position_ptr=c; + check_lcd_buf_possition_ptr_overflow(); + LCD_UPDATE_EVENT=true; +} + +void lcd_buf_locate(enum LCD_LINES y, enum LCD_COLUMNS x) +{ + lcd_buf_position_ptr=&lcd_buffer[y][x]; +} + +void lcd_buf_str(const char *str) +{ + while (*str) + { + *(lcd_buf_position_ptr)=*(str++); + check_lcd_buf_possition_ptr_overflow(); + } + LCD_UPDATE_EVENT=true; +} + +void lcd_update(void) +{ + static uint8_t lcd_cursor_position=0; + static uint8_t lcd_line=0; + static uint8_t missed_char_counter_in_LCD_line=0; + // static const lcd_pos_t *prev_lcd_buff_pos_ptr=&prev_lcd_buffer[LINE_1][C1]; + + for(lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; lcd_buf_position_ptr<=&lcd_buffer[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE]; lcd_buf_position_ptr++) + { + write_lcd_buf_2_lcd(&lcd_cursor_position,&lcd_line,&missed_char_counter_in_LCD_line,&prev_lcd_buffer[LINE_1][C1]); + update_lcd_curosr_possition(&lcd_cursor_position,&lcd_line,&missed_char_counter_in_LCD_line); + } + lcd_buf_position_ptr=&lcd_buffer[LINE_1][C1]; + copy_lcd_buf_2_prev_lcd_buf(); + LCD_UPDATE_EVENT=false; +} + +#if USE_LCD_BUF_INT == ON +/** + * @brief Function for adding intiger value as string to the LCD buffer under current position of the LCD buffer pointer. + * @param val int type value to add to LCD buffer + * @param width Minimum number of characters to be added to LCD buffer. If the value to be added to the LCD buffer is shorter than width, the + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght is larger then width value. + * @param alignment If the value to be added to LCD buffer as string is shorter than width, this parameter will specify alignment of the + * tekst represented the value. This parameter can be set to "left" or "right" + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + */ +void lcd_buf_int(int val, uint8_t width, enum alignment alignment) +{ +#ifdef AVR + lcd_buf_int_AVR(val, width, alignment); +#else + char buffer[20]; // 19chars for 64 bit int + end char '\0' + buffer[0] = '\0'; + if (alignment == right) + sprintf(buffer, "%*i", width, val); + else + sprintf(buffer, "%-*i", width, val); + lcd_buf_str(buffer); +#endif +} +#endif + +#if USE_LCD_BUF_HEX == ON +/** + * @brief Function for adding intiger value in hexadecimal format as string to the LCD buffer under current position of the LCD buffer pointer. + * @param val int type value to add to LCD buffer as string in hexadecimal format + * @param width Minimum number of characters to be added to lcd buffer. If the value to be added to buffer is shorter than width, the + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght is larger then width value. Width should contain + * additional 2 characters for "0x" at the begining of the value represented as string. example: 0x01-> width=4 + * @param alignment If the value to be added to LCD buffer as string is shorter than width, this parameter will specify alignment of the +* tekst represented the value. This parameter can be set to "left" or "right" + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + */ +void lcd_buf_hex(int val, uint8_t width, enum alignment alignment) +{ +#ifdef AVR + lcd_buf_hex_AVR(val, width, alignment); +#else + char buffer[17]; + buffer[0] = '\0'; + if (alignment == right) + sprintf(buffer, "%#*x", width, val); + else + sprintf(buffer, "%-#*x", width, val); + lcd_buf_str(buffer); +#endif +} +#endif + +#if USE_LCD_BUF_BIN == ON +/** + * @brief Function for adding to the LCD buffer the integer value in binary format as string under current position of the LCD buffer pointer + * @param val int type value to be added to the LCD buffer as string in hexadecimal format + * @param width Minimum number of characters to be added to LCD buffer. If the value to be added to buffer as string lenght is shorter than width, the + * result is padded with blank spaces. The value to be added to buffer as string is not truncated if the string lenght represented the value i binary format lenght + * is larger then width value. Width should contain additional 2 characters for "0b" at the begining of the value represented as string. example: 0b01-> width=4 + * @attention to compile for AVR ucontrollers definition of flag AVR is required. + */ +void lcd_buf_bin(int val, uint8_t width) +{ +#ifdef AVR + lcd_buf_bin_AVR(val, width); +#else + char buffer[35]; + char bin_val_buffer[35]; + char zeros_buf[35]; + buffer[0] = '\0'; + bin_val_buffer[0] = '\0'; + zeros_buf[0] = '\0'; + + fill_bin_value_buffer(val, bin_val_buffer); + fill_zeros_buffer(bin_val_buffer, width, zeros_buf); + strcat(buffer, "0b"); + strcat(buffer, zeros_buf); + strcat(buffer, bin_val_buffer); + lcd_buf_str(buffer); +#endif +} + +#endif +#endif + diff --git a/src/lcd_hd44780.h b/src/lcd_hd44780.h index 2bd9ecf..a9f2b40 100644 --- a/src/lcd_hd44780.h +++ b/src/lcd_hd44780.h @@ -2,7 +2,7 @@ * @Author: lukasz.niewelt * @Date: 2023-12-06 21:40:29 * @Last Modified by: lukasz.niewelt - * @Last Modified time: 2023-12-12 18:03:17 + * @Last Modified time: 2024-01-10 14:00:22 */ #ifndef _LCD_HD_44780_H_ @@ -12,11 +12,10 @@ extern "C" { #endif /* __cplusplus */ +#include #include "lcd_hd44780_config.h" #include "lcd_hd44780_interface.h" -#if USE_DEF_CHAR_FUNCTION == ON #include "lcd_hd44780_def_char.h" -#endif enum alignment { @@ -24,6 +23,8 @@ extern "C" right }; + extern bool LCD_UPDATE_EVENT; + void lcd_init(void); void lcd_cls(void); @@ -43,6 +44,16 @@ extern "C" void lcd_cursor_off(void); void lcd_blinking_cursor_on(void); + void lcd_buf_cls(void); + void lcd_buf_char(const char c); + void lcd_buf_locate(enum LCD_LINES y, enum LCD_COLUMNS x); + void lcd_buf_str(const char *str); + void lcd_update(void); + + void lcd_buf_int(int val, uint8_t width, enum alignment alignment); + void lcd_buf_hex(int val, uint8_t width, enum alignment alignment); + void lcd_buf_bin(int val, uint8_t width); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/lcd_hd44780_config.h b/src/lcd_hd44780_config.h index 379a53d..29450e0 100644 --- a/src/lcd_hd44780_config.h +++ b/src/lcd_hd44780_config.h @@ -2,7 +2,7 @@ * @Author: lukasz.niewelt * @Date: 2023-12-06 21:38:27 * @Last Modified by: lukasz.niewelt - * @Last Modified time: 2023-12-08 16:57:42 + * @Last Modified time: 2024-01-09 21:20:52 */ #ifndef _LCD_HD44780_CONFIG_H_ @@ -26,9 +26,11 @@ extern "C" * ON - when RW pin is connected * OFF - when RW pin is not connected ********************************************************************************************/ -#define LCD_TYPE 2004 +#define LCD_TYPE 1602 #define USE_RW_PIN OFF +#define LCD_BUFFERING ON + //definitions of Line and collumn labels for lcd_locate enum LCD_LINES { @@ -61,7 +63,42 @@ enum LCD_COLUMNS{ #define USE_LCD_CURSOR_OFF ON #define USE_LCD_BLINKING_CURSOR_ON ON +#if LCD_BUFFERING == ON +#define USE_LCD_BUF_INT ON +#define USE_LCD_BUF_HEX ON +#define USE_LCD_BUF_BIN ON +#endif + + +/******************** definitions of Line addres for different lcd screens ****************/ +//https://web.alfredstate.edu/faculty/weimandn/lcd/lcd_addressing/lcd_addressing_index.html + +#if LCD_TYPE ==1604 +#define LCD_Y 4 +#define LCD_X 16 +#define LCD_LINE1_ADR 0x00 +#define LCD_LINE2_ADR 0x40 +#define LCD_LINE3_ADR 0x10 +#define LCD_LINE4_ADR 0x50 +#endif + +#if LCD_TYPE==2004 +#define LCD_Y 4 +#define LCD_X 20 +#define LCD_LINE1_ADR 0x00 +#define LCD_LINE2_ADR 0x40 +#define LCD_LINE3_ADR 0x14 +#define LCD_LINE4_ADR 0x54 +#endif + +#if LCD_TYPE==1602 +#define LCD_Y 2 +#define LCD_X 16 +#define LCD_LINE1_ADR 0x00 +#define LCD_LINE2_ADR 0x40 +#endif + // clang-format on #ifdef __cplusplus } diff --git a/src/lcd_hd44780_def_char.h b/src/lcd_hd44780_def_char.h index 121e42f..6156113 100644 --- a/src/lcd_hd44780_def_char.h +++ b/src/lcd_hd44780_def_char.h @@ -12,6 +12,19 @@ extern "C" { #endif /* __cplusplus */ + + struct char_bank_struct + { + const uint8_t *char_0; + const uint8_t *char_1; + const uint8_t *char_2; + const uint8_t *char_3; + const uint8_t *char_4; + const uint8_t *char_5; + const uint8_t *char_6; + const uint8_t *char_7; + }; + #if USE_DEF_CHAR_FUNCTION == ON #define LCD_CGRAM_BYTES_PER_CHAR 8 #define DEF_CHAR_ADR_MASK 7 @@ -28,17 +41,6 @@ extern "C" // here add "definition" of new chars /**********************USER CHAR DEFINITIONS END********************************/ - struct char_bank_struct - { - const uint8_t *char_0; - const uint8_t *char_1; - const uint8_t *char_2; - const uint8_t *char_3; - const uint8_t *char_4; - const uint8_t *char_5; - const uint8_t *char_6; - const uint8_t *char_7; - }; /**********************USER CHAR CGRAM BANKS DEFINITIONS START*******************/ static const struct char_bank_struct lcd_cgram_bank_1 = { Pol_e, diff --git a/test/hw_test/hw_test_main.c b/test/hw_test/hw_test_main.c index 03112ff..cc1e6ef 100644 --- a/test/hw_test/hw_test_main.c +++ b/test/hw_test/hw_test_main.c @@ -7,7 +7,29 @@ #include "tim_delay.h" #endif +#define BASIC_FUNCTIONS_TESTS OFF +#define BUFFERING_FUNCTION_TESTS ON + +#if BASIC_FUNCTIONS_TESTS == ON +static void basic_func_tests(void); +#endif +#if BUFFERING_FUNCTION_TESTS == ON +static void buffering_func_tests(void); +#endif + void main_hw_test(void) +{ + #if BASIC_FUNCTIONS_TESTS == ON + basic_func_tests(); + #endif + #if BUFFERING_FUNCTION_TESTS == ON + buffering_func_tests(); + #endif + while (1); +} + +#if BASIC_FUNCTIONS_TESTS == ON +void basic_func_tests(void) { lcd_init(); lcd_char('G'); @@ -19,7 +41,6 @@ void main_hw_test(void) lcd_char(pol_o); lcd_char(zn_wody); lcd_char('l'); - _delay_ms(1000); lcd_cls(); lcd_cursor_on(); @@ -43,6 +64,55 @@ void main_hw_test(void) lcd_bin(5, 1); lcd_locate(LINE_2, C8); lcd_bin(5, 8); - while (1) - ; -} \ No newline at end of file + _delay_ms(1000); +} +#endif +#if BUFFERING_FUNCTION_TESTS == ON +void buffering_func_tests(void) +{ + lcd_init(); + lcd_buf_char('G'); + lcd_buf_locate(0,2); + lcd_buf_str("Test"); + lcd_update(); + _delay_ms(1000); + lcd_locate(0,0); + lcd_buf_char('a'); + lcd_update(); + _delay_ms(1000); + lcd_buf_cls(); + lcd_load_char_bank(&lcd_cgram_bank_1); + lcd_buf_char(pol_e); + lcd_buf_char(pol_o); + lcd_buf_char(zn_wody); + lcd_update(); + _delay_ms(1000); + lcd_buf_cls(); + #if LCD_TYPE==1602 + lcd_buf_locate(LINE_1,C16); + lcd_buf_str("test1"); + lcd_buf_locate(LINE_2,C16); + lcd_buf_str("test2"); + #elif LCD_TYPE==2004 + lcd_buf_locate(LINE_1,C20); + lcd_buf_str("test1"); + lcd_buf_locate(LINE_2,C20); + lcd_buf_str("test2"); + lcd_buf_locate(LINE_3,C20); + lcd_buf_str("test3"); + lcd_buf_locate(LINE_4,C20); + lcd_buf_str("test4"); + #else + #endif + lcd_update(); + lcd_buf_cls(); + lcd_buf_hex(24, 6, right); + lcd_buf_int(24, 6, right); + lcd_buf_locate(LINE_2, C1); + lcd_buf_bin(5, 1); + lcd_buf_locate(LINE_2, C8); + lcd_buf_bin(5, 8); + _delay_ms(1000); + lcd_update(); +} +#endif diff --git a/test/lcd_hd44780/CMakeLists.txt b/test/lcd_hd44780/CMakeLists.txt index c3f6525..1ccf0c9 100644 --- a/test/lcd_hd44780/CMakeLists.txt +++ b/test/lcd_hd44780/CMakeLists.txt @@ -12,16 +12,16 @@ # 2. enter the "out" folder # 3. ninja -C out -o lcd_hd44780.o (optional with -V and -jxx ->xx numnber of cores) # additional custom targets for this project: -# Running unit tests when you are in out folder: -# 1. make run +# Running unit tests when you are in "out" folder: +# 1. make run / ninja run # If lizard is installed and you are in the out folder: -# 1. make ccm -> code complexity metrix print in console -# 2. make ccmr -> code complexity metrics report generation +# 1. make ccm / ninja ccm-> code complexity metrix print in console +# 2. make ccmr / ninja ccmr-> code complexity metrics report generation # If cppcheck is installed and you are in the out folder -# 1. make cppcheck_src -> static analize for src folder printed in console +# 1. make/ninja cppcheck_src -> static analize for src folder printed in console # 2. make cppcheck_test-> static analize for src folder printed in console # If gcovr is installed and you are in the out folder -# 1. make ccr -> code coverage report generation +# 1. make ccr / ninja ccr -> code coverage report generation # ############################################################################################################################# cmake_minimum_required(VERSION 3.10) @@ -59,10 +59,12 @@ set(TEST_SRCS mock_LCD_IO_driver.c lcd_hd44780_test_basic_func.c lcd_hd44780_test_common.c + lcd_hd44780_test_buffering.c #mock_module.c ) set(GLOBAL_DEFINES + -DUNIT_TEST # -DAVR ) diff --git a/test/lcd_hd44780/avr_code_test/CMakeLists.txt b/test/lcd_hd44780/avr_code_test/CMakeLists.txt index 983f1fa..7ff3fe5 100644 --- a/test/lcd_hd44780/avr_code_test/CMakeLists.txt +++ b/test/lcd_hd44780/avr_code_test/CMakeLists.txt @@ -1,9 +1,37 @@ +############################################################################################################################# +# file: CMakeLists.txt +# brief: Template "CMakeLists.txt" for building Unit test modules. +# +# usage: +# For build using Unix Makefiles: +# 1.cmake -S./ -B ../out_avr -G"Unix Makefiles" +# 2.enter the "out_avr" folder +# 3.make all -o lcd_hd44780.o (-jXX additionaly to speed up) +# For build using Ninja: +# 1. cmake -S./ -B ../out_avr -G"Ninja" +# 2. enter the "out_avr" folder +# 3. ninja -C out -o lcd_hd44780.o (optional with -V and -jxx ->xx numnber of cores) +# additional custom targets for this project: +# Running unit tests when you are in "out_avr" folder: +# 1. make run /ninja run +# If lizard is installed and you are in the out folder: +# 1. make ccm / ninja ccm -> code complexity metrix print in console +# 2. make ccmr / ninja ccmr-> code complexity metrics report generation +# If cppcheck is installed and you are in the out folder +# 1. make/ninja cppcheck_src -> static analize for src folder printed in console +# 2. make/ninja cppcheck_test-> static analize for src folder printed in console +# If gcovr is installed and you are in the out folder +# 1. make ccr/ ninja ccr-> code coverage report generation +# +############################################################################################################################# cmake_minimum_required(VERSION 3.10) project(lcd_hd44780_test C) add_subdirectory(../../unity unity) +set(CUSTOM_TARGETS_FILE_DIR ../custom_targets.cmake) + set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") set(INCLUDE_DIRS @@ -26,13 +54,17 @@ set(TEST_SRCS ../mock_LCD_IO_driver.c ../lcd_hd44780_test_basic_func.c ../lcd_hd44780_test_common.c + ../lcd_hd44780_test_buffering.c #mock_module.c ) set(GLOBAL_DEFINES -DAVR + -DUNIT_TEST ) +include(${CUSTOM_TARGETS_FILE_DIR}) + include_directories(${INCLUDE_DIRS} ${TEST_INCLUDE_DIRS}) add_definitions(${GLOBAL_DEFINES}) diff --git a/test/lcd_hd44780/custom_targets.cmake b/test/lcd_hd44780/custom_targets.cmake index e8cfdd5..b82f072 100644 --- a/test/lcd_hd44780/custom_targets.cmake +++ b/test/lcd_hd44780/custom_targets.cmake @@ -14,20 +14,20 @@ add_custom_target(run lcd_hd44780_test) # check if lizard software is available find_program(lizard_program lizard) if(lizard_program) - message(STATUS "Lizard was found, you can use predefined targets for src folder Code Complexity Metrics: \r\n\tccm,\r\n\ttccmr") + message(STATUS "Lizard was found, you can use predefined targets for src folder Code Complexity Metrics: \r\n\tccm,\r\n\tccmr,") else() message(STATUS "Lizard was not found. \r\n\tInstall Lizard to get predefined targets for src folder Code Complexity Metrics") endif() # Prints CCM for src folder in the console -add_custom_target(ccm lizard src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -i 1) +add_custom_target(ccm lizard ../../../src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -i 1) # Create CCM report in reports/Cylcomatic_Complexity/ -add_custom_target(ccmr lizard src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -o ../../../reports/Cyclomatic_Complexity/Lizard_report.html) +add_custom_target(ccmr lizard ../../../src/ --CCN 12 -Tnloc=30 -a 4 --languages cpp -V -o ../../../reports/Cyclomatic_Complexity/Lizard_report.html) # TARGET FOR MAKING STATIC ANALYSIS OF THE SOURCE CODE AND UNIT TEST CODE # check if cppchec software is available find_program(cppcheck_program cppcheck) if(cppcheck_program) - message(STATUS "CppCheck was found, you can use predefined targets for static analize : \r\n\tcppcheck_src,\r\n\tcppcheck_tests.") + message(STATUS "CppCheck was found, you can use predefined targets for static analize : \r\n\tcppcheck_src,\r\n\tcppcheck_tests,") else() message(STATUS "CppCheck was not found. \r\n\tInstall CppCheck to get predefined targets for static analize") endif() @@ -42,7 +42,7 @@ find_program(GCOVR gcovr) find_program(PYTHON3 python3) if(PYTHON3) if(GCOVR) - message(STATUS "python 3 and gcovr was found, you can use predefined targets for uint tests code coverage report generation : \r\n\tccr") + message(STATUS "python 3 and gcovr was found, you can use predefined targets for uint tests code coverage report generation : \r\n\tccr,") else() message(STATUS "pyton 3 was found but gcovr was not found. \r\n\tInstall gcovr to get predefined targets for uint tests code coverage report generation") endif() diff --git a/test/lcd_hd44780/lcd_hd44780_test_basic_func.c b/test/lcd_hd44780/lcd_hd44780_test_basic_func.c index bc30698..e892fe0 100644 --- a/test/lcd_hd44780/lcd_hd44780_test_basic_func.c +++ b/test/lcd_hd44780/lcd_hd44780_test_basic_func.c @@ -1,3 +1,9 @@ +/* + * @Author: lukasz.niewelt + * @Date: 2023-12-03 16:59:56 + * @Last Modified by: lukasz.niewelt + * @Last Modified time: 2024-01-10 17:30:47 + */ #include "unity/fixture/unity_fixture.h" #include "lcd_hd44780.h" #include "lcd_hd44780_test_common.h" @@ -132,11 +138,10 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdBlinkingCursorOnThenSign #endif TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdLocateThenSignalSequenceIsCorrect) { - uint8_t line_no_2_adr = 0x40; #if USE_RW_PIN == ON - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + line_no_2_adr + C5), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C5), 0x00); #else - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + line_no_2_adr + C5), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C5), 0); #endif expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); @@ -146,56 +151,49 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdLocateThenSignalSequence TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdStrThenSignalSequenceIsCorrect) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("TEst"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("TEst", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_str("TEst"); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdLocateAndSetAllLinesLocationThenSignalSequenceIsCorrect) { - uint8_t line_no_1_adr = 0x00; - uint8_t line_no_2_adr = 0x40; -#if LCD_TYPE == 2004 - uint8_t line_no_3_adr = 0x14; - uint8_t line_no_4_adr = 0x54; -#elif LCD_TYTPE == 1604 - uint8_t line_no_3_adr = 0x10; - uint8_t line_no_4_adr = 0x50; -#endif #if USE_RW_PIN == ON - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + line_no_1_adr + C5), 0x00); - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_2_adr + C4), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE1_ADR + C5), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C4), 0x00); #if ((LCD_TYPE == 2004) || (LCD_TYTPE == 1604)) - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_3_adr + C3), 0x00); - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_4_adr + C6), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE3_ADR + C3), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + C6), 0x00); #endif #else - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + line_no_1_adr + C5), 0); - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_2_adr + C4), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(0, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE1_ADR + C5), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C4), 0); #if ((LCD_TYPE == 2004) || (LCD_TYTPE == 1604)) - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_3_adr + C3), 0); - next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + line_no_4_adr + C6), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE3_ADR + C3), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + C6), 0); #endif #endif expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_locate(LINE_1, C5); lcd_locate(LINE_2, C4); +#if ((LCD_TYPE == 1604) || (LCD_TYPE == 2004)) lcd_locate(LINE_3, C3); lcd_locate(LINE_4, C6); +#endif TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } - +#if USE_LCD_INT == ON TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_24_2_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("24"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("24", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_int(24, 2, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_2444_2_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("2444"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("2444", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_int(2444, 2, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -203,7 +201,7 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_2444_2_right_ThenSi TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_16_4_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString) { - next_log_no = define_expected_sequence_for_send_string_to_LCD(" 16"); + next_log_no = define_expected_sequence_for_send_string_to_LCD(" 16", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_int(16, 4, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -211,15 +209,16 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_16_4_right_ThenSign TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_61045_8_left_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("61045 "); + next_log_no = define_expected_sequence_for_send_string_to_LCD("61045 ", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_int(61045, 8, left); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } - +#endif +#if USE_LCD_HEX == ON TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_10_1_left_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("0xa"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("0xa", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_hex(10, 1, left); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -227,7 +226,7 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_10_1_left_ThenSign TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_255_6_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD(" 0xff"); + next_log_no = define_expected_sequence_for_send_string_to_LCD(" 0xff", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_hex(255, 6, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -235,7 +234,7 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_255_6_right_ThenSi TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_20_5_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD(" 0x14"); + next_log_no = define_expected_sequence_for_send_string_to_LCD(" 0x14", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_hex(20, 5, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -243,15 +242,16 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_20_5_right_ThenSig TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_20_1_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("0x14"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("0x14", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_hex(20, 1, right); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } - +#endif +#if USE_LCD_BIN == ON TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_bin_5_6_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("0b0101"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("0b0101", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_bin(5, 6); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); @@ -259,12 +259,12 @@ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_bin_5_6_ThenSignalSequ TEST(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_bin_5_1_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig) { - next_log_no = define_expected_sequence_for_send_string_to_LCD("0b101"); + next_log_no = define_expected_sequence_for_send_string_to_LCD("0b101", 0); expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); lcd_bin(5, 1); TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); } - +#endif // TEST(lcd_hd44780_basic_functions, ) // { // TEST_FAIL_MESSAGE("Implement your test!"); diff --git a/test/lcd_hd44780/lcd_hd44780_test_buffering.c b/test/lcd_hd44780/lcd_hd44780_test_buffering.c new file mode 100644 index 0000000..fb3fe0a --- /dev/null +++ b/test/lcd_hd44780/lcd_hd44780_test_buffering.c @@ -0,0 +1,406 @@ +/* + * @Author: lukasz.niewelt + * @Date: 2024-01-08 15:45:14 + * @Last Modified by: lukasz.niewelt + * @Last Modified time: 2024-01-10 18:06:19 + */ + +#include "unity/fixture/unity_fixture.h" +// #include "lcd_hd44780_config.h" +#include "lcd_hd44780.h" +#include "lcd_hd44780_test_common.h" +#include + +#if LCD_BUFFERING == ON + +#define LAST_CHAR_IN_LCD_LINE_POSITION (LCD_X - 1) +#define LAST_LCD_LINE (LCD_Y - 1) + +extern char lcd_buffer[LCD_Y][LCD_X]; +extern char prev_lcd_buffer[LCD_Y][LCD_X]; +char expected_lcd_buf[LCD_Y][LCD_X]; + +static void define_expected_buffer_value_for_cls(void); +static log_no_t define_expected_sequence_for_move_to_last_character_from_first_line_whne_nothing_to_print_on_lcd(log_no_t start_log_no); +static log_no_t define_expected_sequence_for_lcd_locate_0_0(log_no_t start_log_no); + +TEST_GROUP(lcd_hd44780_buffering); + +TEST_SETUP(lcd_hd44780_buffering) +{ + /* Init before every test */ + lcd_init(); + clear_expected_LCD_Port_delay_dump_data(); + mock_clear_LCD_Port_delay_dump_data(); + next_log_no = 0; + expected_buf_lenght = 0; +} + +TEST_TEAR_DOWN(lcd_hd44780_buffering) +{ + /* Cleanup after every test */ +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLcdBufferContainSpaces) +{ + define_expected_buffer_value_for_cls(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdBufCharThenBufferEqualToExpected) +{ + lcd_buf_char('a'); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = 'a'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdBufCharAandLcdBufCharBUsedThenBufferEqualToExpected) +{ + lcd_buf_char('A'); + lcd_buf_char('B'); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = 'A'; + expected_lcd_buf[LINE_1][C2] = 'B'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateFirstLineLastLetterAndLcdBufCharAThenBufferEqualToExpected) +{ + lcd_buf_locate(LINE_1, LAST_CHAR_IN_LCD_LINE_POSITION); + lcd_buf_char('A'); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][LAST_CHAR_IN_LCD_LINE_POSITION] = 'A'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateFirstLineLastLetterAndLcdBufCharAandLcdBufCharBThenBufferEqualToExpected) +{ + lcd_buf_locate(LINE_1, LAST_CHAR_IN_LCD_LINE_POSITION); + lcd_buf_char('A'); + lcd_buf_char('B'); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][LAST_CHAR_IN_LCD_LINE_POSITION] = 'A'; + expected_lcd_buf[LINE_2][C1] = 'B'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateLastLineLastLetterAndLcdBufCharAandLcdBufCharBThenBufferEqualToExpected) +{ + lcd_buf_locate(LAST_LCD_LINE, LAST_CHAR_IN_LCD_LINE_POSITION); + lcd_buf_char('A'); + lcd_buf_char('B'); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE_POSITION] = 'A'; + expected_lcd_buf[LINE_1][C1] = 'B'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrTestThenLcdBufferEqualToExpectedLcdBuffer) +{ + lcd_buf_str("Test"); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = 'T'; + expected_lcd_buf[LINE_1][C2] = 'e'; + expected_lcd_buf[LINE_1][C3] = 's'; + expected_lcd_buf[LINE_1][C4] = 't'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndSetLcdLocateLastLineLastCharacterWhenLcdBufStrTestThenLcdBufferEqualToExpectedLcdBuffer) +{ + lcd_buf_locate(LAST_LCD_LINE, LAST_CHAR_IN_LCD_LINE_POSITION); + lcd_buf_str("Test"); + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LAST_LCD_LINE][LAST_CHAR_IN_LCD_LINE_POSITION] = 'T'; + expected_lcd_buf[LINE_1][C1] = 'e'; + expected_lcd_buf[LINE_1][C2] = 's'; + expected_lcd_buf[LINE_1][C3] = 't'; + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLCD_UPDATE_EVENTflagIsFALSE) +{ + TEST_ASSERT_FALSE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLCD_UPDATE_EVENTflagIsTRUEWhenLcdInitThenLCD_UPDATE_EVENTflagIsFalse) +{ + LCD_UPDATE_EVENT = true; + lcd_init(); + TEST_ASSERT_FALSE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufCharThenLCD_UPDATE_EVENTflagIsTRUE) +{ + lcd_buf_char('a'); + TEST_ASSERT_TRUE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrThenLCD_UPDATE_EVENTflagIsTRUE) +{ + lcd_buf_str("TEST"); + TEST_ASSERT_TRUE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufClsThenLCD_UPDATE_EVENTflagIsTRUE) +{ + lcd_buf_cls(); + TEST_ASSERT_TRUE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLCD_UPDATE_EVENTflagIsTRUEWhenLcdUpdateThenLCD_UPDATE_EVENTflagIsFALSE) +{ + LCD_UPDATE_EVENT = true; + lcd_update(); + TEST_ASSERT_FALSE(LCD_UPDATE_EVENT); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLcdCurrentScreenBufferContainSpaces) +{ + define_expected_buffer_value_for_cls(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, prev_lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLcdBufStrWhenLcdUpdateThenLcdCurrentScreenBufferIsEqualToLcdBuffer) +{ + lcd_buf_str("TEST"); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(lcd_buffer, prev_lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrThenLcdCurrentScreenBufferStillContainSpaces) +{ + define_expected_buffer_value_for_cls(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, prev_lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndSetLcdLocateLastLineLastCharacterAndLcdBufStrTestWhenUpdateLcdScrThenSignalSequenceForUpdateLcdScrIsCorrect) +{ + // write "est" on LCD + next_log_no = define_expected_sequence_for_send_string_to_LCD("est", 0); + // move cursor to lasr line last character + next_log_no = define_expected_sequence_for_move_to_last_character_from_first_line_whne_nothing_to_print_on_lcd(next_log_no); + // wirte "T" on LCD + next_log_no = define_expected_sequence_for_send_string_to_LCD("T", next_log_no); + // move cursor to begining of LCD (0,0) + next_log_no = define_expected_sequence_for_lcd_locate_0_0(next_log_no); + expected_buf_lenght = (next_log_no) * (LOG_DATA_AMOUNT); + lcd_buf_locate(LAST_LCD_LINE, LAST_CHAR_IN_LCD_LINE_POSITION); + lcd_buf_str("Test"); + lcd_update(); + TEST_ASSERT_EQUAL_UINT16_ARRAY(expected_LCD_Port_delay_dump_data, mock_LCD_Port_delay_dump_data, expected_buf_lenght); +} + +#if USE_LCD_BUF_INT == ON +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_24_2_right_ThenLcdBufferContainInt24AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '2'; + expected_lcd_buf[LINE_1][C2] = '4'; + lcd_buf_int(24, 2, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_2444_2_right_ThenLcdBufferContainInt2444AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '2'; + expected_lcd_buf[LINE_1][C2] = '4'; + expected_lcd_buf[LINE_1][C3] = '4'; + expected_lcd_buf[LINE_1][C4] = '4'; + lcd_buf_int(2444, 2, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_16_4_right_ThenLcdBufferContainInt__16AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = ' '; + expected_lcd_buf[LINE_1][C2] = ' '; + expected_lcd_buf[LINE_1][C3] = '1'; + expected_lcd_buf[LINE_1][C4] = '6'; + lcd_buf_str("1234"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_int(16, 4, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_61045_8_left_ThenLcdBufferContainInt61045___AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '6'; + expected_lcd_buf[LINE_1][C2] = '1'; + expected_lcd_buf[LINE_1][C3] = '0'; + expected_lcd_buf[LINE_1][C4] = '4'; + expected_lcd_buf[LINE_1][C5] = '5'; + expected_lcd_buf[LINE_1][C6] = ' '; + expected_lcd_buf[LINE_1][C7] = ' '; + expected_lcd_buf[LINE_1][C8] = ' '; + lcd_buf_str("99999999"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_int(61045, 8, left); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +#endif +#if USE_LCD_BUF_HEX == ON +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_10_1_left_ThenLcdBufferContain0xaAsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '0'; + expected_lcd_buf[LINE_1][C2] = 'x'; + expected_lcd_buf[LINE_1][C3] = 'a'; + lcd_buf_hex(10, 1, left); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_255_6_right_ThenLcdBufferContain__0xFFAsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = ' '; + expected_lcd_buf[LINE_1][C2] = ' '; + expected_lcd_buf[LINE_1][C3] = '0'; + expected_lcd_buf[LINE_1][C4] = 'x'; + expected_lcd_buf[LINE_1][C5] = 'f'; + expected_lcd_buf[LINE_1][C6] = 'f'; + lcd_buf_str("123456"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_hex(255, 6, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_5_right_ThenLcdBufferContainInt_0x14AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = ' '; + expected_lcd_buf[LINE_1][C2] = '0'; + expected_lcd_buf[LINE_1][C3] = 'x'; + expected_lcd_buf[LINE_1][C4] = '1'; + expected_lcd_buf[LINE_1][C5] = '4'; + lcd_buf_str("12345"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_hex(20, 5, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_1_right_ThenLcdBufferContainInt0x14AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '0'; + expected_lcd_buf[LINE_1][C2] = 'x'; + expected_lcd_buf[LINE_1][C3] = '1'; + expected_lcd_buf[LINE_1][C4] = '4'; + lcd_buf_str("1234"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_hex(20, 1, right); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_6_left_ThenLcdBufferContainInt_0x14AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '0'; + expected_lcd_buf[LINE_1][C2] = 'x'; + expected_lcd_buf[LINE_1][C3] = '1'; + expected_lcd_buf[LINE_1][C4] = '4'; + expected_lcd_buf[LINE_1][C5] = ' '; + expected_lcd_buf[LINE_1][C6] = ' '; + lcd_buf_str("123456"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_hex(20, 6, left); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +#endif +#if USE_LCD_BUF_BIN == ON +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_bin_5_6_ThenLcdBufferContainInt0b0101AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '0'; + expected_lcd_buf[LINE_1][C2] = 'b'; + expected_lcd_buf[LINE_1][C3] = '0'; + expected_lcd_buf[LINE_1][C4] = '1'; + expected_lcd_buf[LINE_1][C5] = '0'; + expected_lcd_buf[LINE_1][C6] = '1'; + lcd_buf_str("123456"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_bin(5, 6); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} + +TEST(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_bin_5_1_ThenLcdBufferContainInt0b101AsString) +{ + define_expected_buffer_value_for_cls(); + expected_lcd_buf[LINE_1][C1] = '0'; + expected_lcd_buf[LINE_1][C2] = 'b'; + expected_lcd_buf[LINE_1][C3] = '1'; + expected_lcd_buf[LINE_1][C4] = '0'; + expected_lcd_buf[LINE_1][C5] = '1'; + lcd_buf_str("12345"); + lcd_buf_locate(LINE_1, C1); + lcd_buf_bin(5, 1); + lcd_update(); + TEST_ASSERT_EQUAL_UINT8_ARRAY(expected_lcd_buf, lcd_buffer, (LCD_X * LCD_Y)); +} +#endif + +// TEST(lcd_hd44780_buffering, ) +// { +// TEST_FAIL_MESSAGE("Added test") +// } + +static void define_expected_buffer_value_for_cls(void) +{ + for (uint8_t line = 0; line < LCD_Y; line++) + { + for (uint8_t collumn = 0; collumn < LCD_X; collumn++) + { + expected_lcd_buf[line][collumn] = ' '; + } + } +} + +static log_no_t define_expected_sequence_for_move_to_last_character_from_first_line_whne_nothing_to_print_on_lcd(log_no_t start_log_no) +{ +#if ((LCD_TYPE == 2004) || (LCD_TYPE == 1604)) + +#if USE_RW_PIN == ON + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C1), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE3_ADR + C1), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + C1), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + LAST_CHAR_IN_LCD_LINE_POSITION), 0x00); +#else + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C1), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE3_ADR + C1), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + C1), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE4_ADR + LAST_CHAR_IN_LCD_LINE_POSITION), 0); +#endif +#elif LCD_TYPE == 1602 +#if USE_RW_PIN == ON + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C1), 0x00); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + LAST_CHAR_IN_LCD_LINE_POSITION), 0x00); +#else + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + C1), 0); + next_log_no = define_expected_sequence_for_send_cmd_to_LCD(next_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE2_ADR + LAST_CHAR_IN_LCD_LINE_POSITION), 0); +#endif +#else + ptrintf("\r\n\r\n\t define_expected_sequence_for_move_to_last_character_from_first_line_whne_nothing_to_print_on_lcd -> go to this function and specify your expected signal sequence for your LCD_TYPE"); +#endif + return next_log_no; +} + +log_no_t define_expected_sequence_for_lcd_locate_0_0(log_no_t start_log_no) +{ +#if USE_RW_PIN == ON + return define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE1_ADR + C1), 0x00); +#else + return define_expected_sequence_for_send_cmd_to_LCD(start_log_no, (uint8_t)(LCDC_SET_DDRAM + LCD_LINE1_ADR + C1), 0); +#endif +} +#endif \ No newline at end of file diff --git a/test/lcd_hd44780/lcd_hd44780_test_common.c b/test/lcd_hd44780/lcd_hd44780_test_common.c index 928cdcc..57696b8 100644 --- a/test/lcd_hd44780/lcd_hd44780_test_common.c +++ b/test/lcd_hd44780/lcd_hd44780_test_common.c @@ -2,7 +2,7 @@ * @Author: lukasz.niewelt * @Date: 2023-12-07 16:59:56 * @Last Modified by: lukasz.niewelt - * @Last Modified time: 2023-12-08 12:30:37 + * @Last Modified time: 2024-01-10 10:13:21 */ #include "lcd_hd44780_test_common.h" @@ -36,7 +36,7 @@ uint8_t read_prev_LCD_SIG_PORT_state(void) uint16_t define_expected_sequence_for_first_15_ms_delay(void) { - uint16_t log_no = 0; + log_no_t log_no = 0; // set E expected_LCD_Port_delay_dump_data[log_no][SIG_PORT] = mock_LCD_E; @@ -78,7 +78,7 @@ uint16_t define_expected_sequence_for_first_15_ms_delay(void) return log_no; } -uint16_t define_expected_sequence_for_read_write_4_bit_data(uint16_t log_no, uint8_t R_W_data, uint16_t delay) +uint16_t define_expected_sequence_for_read_write_4_bit_data(log_no_t log_no, uint8_t R_W_data, uint16_t delay) { // setE expected_LCD_Port_delay_dump_data[log_no][SIG_PORT] = expected_LCD_Port_delay_dump_data[log_no - 1][SIG_PORT] | mock_LCD_E; @@ -103,7 +103,7 @@ uint16_t define_expected_sequence_for_read_write_4_bit_data(uint16_t log_no, uin return log_no; } #if USE_RW_PIN == ON -uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t cmd, uint8_t expected_readed_data) +uint16_t define_expected_sequence_for_send_cmd_to_LCD(log_no_t log_no, uint8_t cmd, uint8_t expected_readed_data) { // reset RS @@ -152,7 +152,7 @@ uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t c return log_no; } #else -uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t cmd, uint16_t additional_cmd_delay) +uint16_t define_expected_sequence_for_send_cmd_to_LCD(log_no_t log_no, uint8_t cmd, uint16_t additional_cmd_delay) { // reset RS @@ -188,7 +188,7 @@ uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t c #endif #if USE_RW_PIN == ON -uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t data, uint8_t expected_readed_data, uint16_t additional_cmd_delay) +uint16_t define_expected_sequence_for_send_data_to_LCD(log_no_t log_no, uint8_t data, uint8_t expected_readed_data, uint16_t additional_cmd_delay) { // reset RS if (log_no != 0) @@ -243,7 +243,7 @@ uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t return log_no; } #else -uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t data, uint16_t additional_cmd_delay) +uint16_t define_expected_sequence_for_send_data_to_LCD(log_no_t log_no, uint8_t data, uint16_t additional_cmd_delay) { // reset RS if (log_no != 0) @@ -276,8 +276,8 @@ uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t return log_no; } #endif - -uint16_t define_expect_sequence_for_lcd_def_char(uint16_t log_no, const uint8_t CGRAM_bank_x_char_index, const uint8_t *def_char) +#if USE_DEF_CHAR_FUNCTION == ON +uint16_t define_expect_sequence_for_lcd_def_char(log_no_t log_no, const uint8_t CGRAM_bank_x_char_index, const uint8_t *def_char) { uint8_t CGRAM_start_adress = ((DEF_CHAR_ADR_MASK & CGRAM_bank_x_char_index) * LCD_CGRAM_BYTES_PER_CHAR); uint8_t cmd = (LCDC_SET_CGRAM | CGRAM_start_adress); @@ -303,10 +303,10 @@ uint16_t define_expect_sequence_for_lcd_def_char(uint16_t log_no, const uint8_t return log_no; } - -uint16_t define_expected_sequence_for_send_string_to_LCD(const char *string) +#endif +uint16_t define_expected_sequence_for_send_string_to_LCD(const char *string, uint16_t next_log) { - uint16_t next_log = 0; + // uint16_t next_log = 0; register char c; while ((c = *(string++))) { diff --git a/test/lcd_hd44780/lcd_hd44780_test_common.h b/test/lcd_hd44780/lcd_hd44780_test_common.h index e6340df..fce1c39 100644 --- a/test/lcd_hd44780/lcd_hd44780_test_common.h +++ b/test/lcd_hd44780/lcd_hd44780_test_common.h @@ -2,7 +2,7 @@ * @Author: lukasz.niewelt * @Date: 2023-12-07 16:59:53 * @Last Modified by: lukasz.niewelt - * @Last Modified time: 2023-12-08 12:30:50 + * @Last Modified time: 2024-01-10 13:10:56 */ #include #include "mock_LCD_IO_driver.h" @@ -12,22 +12,25 @@ #define DATA_PORT 1 #define DELAY 2 -extern uint16_t next_log_no; +typedef uint16_t log_no_t; +typedef uint16_t buf_len_t; + +extern log_no_t next_log_no; extern uint16_t expected_LCD_Port_delay_dump_data[BUF_SIZE][LOG_DATA_AMOUNT]; -extern uint16_t expected_buf_lenght; +extern buf_len_t expected_buf_lenght; void clear_expected_LCD_Port_delay_dump_data(void); uint8_t read_prev_LCD_DATA_PORT_state(void); uint8_t read_prev_LCD_SIG_PORT_state(void); uint16_t define_expected_sequence_for_first_15_ms_delay(void); -uint16_t define_expected_sequence_for_read_write_4_bit_data(uint16_t log_no, uint8_t R_W_data, uint16_t delay); +uint16_t define_expected_sequence_for_read_write_4_bit_data(log_no_t log_no, uint8_t R_W_data, uint16_t delay); #if USE_RW_PIN == ON -uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t cmd, uint8_t expected_readed_data); -uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t data, uint8_t expected_readed_data, uint16_t additional_cmd_delay); +uint16_t define_expected_sequence_for_send_cmd_to_LCD(log_no_t log_no, uint8_t cmd, uint8_t expected_readed_data); +uint16_t define_expected_sequence_for_send_data_to_LCD(log_no_t log_no, uint8_t data, uint8_t expected_readed_data, uint16_t additional_cmd_delay); #else -uint16_t define_expected_sequence_for_send_cmd_to_LCD(uint16_t log_no, uint8_t cmd, uint16_t additional_cmd_delay); -uint16_t define_expected_sequence_for_send_data_to_LCD(uint16_t log_no, uint8_t data, uint16_t additional_cmd_delay); +uint16_t define_expected_sequence_for_send_cmd_to_LCD(log_no_t log_no, uint8_t cmd, uint16_t additional_cmd_delay); +uint16_t define_expected_sequence_for_send_data_to_LCD(log_no_t log_no, uint8_t data, uint16_t additional_cmd_delay); #endif -uint16_t define_expect_sequence_for_lcd_def_char(uint16_t log_no, const uint8_t CGRAM_bank_x_char_index, const uint8_t *def_char); -uint16_t define_expected_sequence_for_send_string_to_LCD(const char *string); \ No newline at end of file +uint16_t define_expect_sequence_for_lcd_def_char(log_no_t log_no, const uint8_t CGRAM_bank_x_char_index, const uint8_t *def_char); +uint16_t define_expected_sequence_for_send_string_to_LCD(const char *string, uint16_t next_log); \ No newline at end of file diff --git a/test/lcd_hd44780/lcd_hd44780_test_main.c b/test/lcd_hd44780/lcd_hd44780_test_main.c index 37e9600..010f073 100644 --- a/test/lcd_hd44780/lcd_hd44780_test_main.c +++ b/test/lcd_hd44780/lcd_hd44780_test_main.c @@ -13,4 +13,5 @@ static void run_all_tests(void) { RUN_TEST_GROUP(lcd_hd44780_init); RUN_TEST_GROUP(lcd_hd44780_basic_functions); + RUN_TEST_GROUP(lcd_hd44780_buffering); } \ No newline at end of file diff --git a/test/lcd_hd44780/lcd_hd44780_test_runner.c b/test/lcd_hd44780/lcd_hd44780_test_runner.c index bffbc86..5736f41 100644 --- a/test/lcd_hd44780/lcd_hd44780_test_runner.c +++ b/test/lcd_hd44780/lcd_hd44780_test_runner.c @@ -7,7 +7,6 @@ TEST_GROUP_RUNNER(lcd_hd44780_init) RUN_TEST_CASE(lcd_hd44780_init, WhenLcdInitThenLcdDataPinsInit); RUN_TEST_CASE(lcd_hd44780_init, WhenLcdInitThenLcdDataPinsLowAtFirstLog); RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSetAllSignalsFor15msThenLcdPinStatIsCorrect); - RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSendFirstCmd0x03ThenLcdPinStateSequenceIsCorrect); RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSendSecondCmd0x03ThenLcdPinStateSequenceIsCorrect); RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSendThirdCmd0x03ThenLcdPinStateSequenceIsCorrect); @@ -17,7 +16,6 @@ TEST_GROUP_RUNNER(lcd_hd44780_init) RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSendDisplayClearScrCmdThenLcdPinStateSequenceIsCorrect); RUN_TEST_CASE(lcd_hd44780_init, GivenLcdInitWhenSendDisplayEntryModeCmdThenLcdPinStateSequenceIsCorrect); // RUN_TEST_CASE(lcd_hd44780_init, ) - // RUN_TEST_CASE(lcd_hd44780_init, ) } TEST_GROUP_RUNNER(lcd_hd44780_basic_functions) @@ -44,23 +42,63 @@ TEST_GROUP_RUNNER(lcd_hd44780_basic_functions) RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdLocateThenSignalSequenceIsCorrect); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdStrThenSignalSequenceIsCorrect); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUseLcdLocateAndSetAllLinesLocationThenSignalSequenceIsCorrect); +#if USE_LCD_INT == ON RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_24_2_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_2444_2_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_16_4_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_LcdInt_61045_8_left_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueAsString); +#endif +#if USE_LCD_HEX == ON RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_10_1_left_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_255_6_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_20_5_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_hex_20_1_right_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); +#endif +#if USE_LCD_BIN == ON RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_bin_5_6_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); RUN_TEST_CASE(lcd_hd44780_basic_functions, GivenLcdInitWhenUse_lcd_bin_5_1_ThenSignalSequenceForSendigIsEqualToLcdStrWithValueInHexAsStrig); - - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); - // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); +#endif // RUN_TEST_CASE(lcd_hd44780_basic_functions, ); } + +TEST_GROUP_RUNNER(lcd_hd44780_buffering) +{ + /* Test cases to run */ +#if LCD_BUFFERING == ON + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLcdBufferContainSpaces); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdBufCharThenBufferEqualToExpected); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdBufCharAandLcdBufCharBUsedThenBufferEqualToExpected); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateFirstLineLastLetterAndLcdBufCharAThenBufferEqualToExpected); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateFirstLineLastLetterAndLcdBufCharAandLcdBufCharBThenBufferEqualToExpected); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufLocateLastLineLastLetterAndLcdBufCharAandLcdBufCharBThenBufferEqualToExpected); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrTestThenLcdBufferEqualToExpectedLcdBuffer); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndSetLcdLocateLastLineLastCharacterWhenLcdBufStrTestThenLcdBufferEqualToExpectedLcdBuffer); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLCD_UPDATE_EVENTflagIsFALSE); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLCD_UPDATE_EVENTflagIsTRUEWhenLcdInitThenLCD_UPDATE_EVENTflagIsFalse); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufCharThenLCD_UPDATE_EVENTflagIsTRUE); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrThenLCD_UPDATE_EVENTflagIsTRUE); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufClsThenLCD_UPDATE_EVENTflagIsTRUE); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLCD_UPDATE_EVENTflagIsTRUEWhenLcdUpdateThenLCD_UPDATE_EVENTflagIsFALSE); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnWhenLcdInitThenLcdCurrentScreenBufferContainSpaces); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndLcdBufStrWhenLcdUpdateThenLcdCurrentScreenBufferIsEqualToLcdBuffer); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenLcdBufStrThenLcdCurrentScreenBufferStillContainSpaces); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitAndSetLcdLocateLastLineLastCharacterAndLcdBufStrTestWhenUpdateLcdScrThenSignalSequenceForUpdateLcdScrIsCorrect); +#if USE_LCD_BUF_INT == ON + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_24_2_right_ThenLcdBufferContainInt24AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_2444_2_right_ThenLcdBufferContainInt2444AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_16_4_right_ThenLcdBufferContainInt__16AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_LcdInt_61045_8_left_ThenLcdBufferContainInt61045___AsString); +#endif +#if USE_LCD_BUF_HEX == ON + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_10_1_left_ThenLcdBufferContain0xaAsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_255_6_right_ThenLcdBufferContain__0xFFAsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_5_right_ThenLcdBufferContainInt_0x14AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_1_right_ThenLcdBufferContainInt0x14AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_hex_20_6_left_ThenLcdBufferContainInt_0x14AsString); +#endif +#if USE_LCD_BUF_BIN == ON + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_bin_5_6_ThenLcdBufferContainInt0b0101AsString); + RUN_TEST_CASE(lcd_hd44780_buffering, GivenLcdBufferingOnAndLcdInitWhenUse_lcd_bin_5_1_ThenLcdBufferContainInt0b101AsString); +#endif +#endif +}