Skip to content

Commit

Permalink
Initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
dsabala committed Mar 4, 2023
1 parent 30a1534 commit a37096e
Show file tree
Hide file tree
Showing 45 changed files with 45,418 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
10 changes: 10 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"configurations": [
{
"name": "CMake config",
"intelliSenseMode": "${default}",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
6 changes: 6 additions & 0 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"name": "gcc-arm",
"toolchainFile": "cmake/toolchains/gcc-arm.cmake"
}
]
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug STM32407VG",
"type": "cortex-debug",
"request": "launch",
"servertype": "jlink",
"cwd": "${workspaceRoot}",
"executable": "./build/hd44780-example",
"serverpath": "JLinkGDBServerCLExe",
"device": "STM32F407VG",
"interface": "swd",
"svdFile": "${workspaceFolder}/STM32F407.svd",
"runToEntryPoint": "main"
}
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# v0.1.0 - 04.03.2023
- initial release
99 changes: 99 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
cmake_minimum_required(VERSION 3.16)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(hd44780 C)

option(BUILD_EXAMPLE "Build library example" ON)

################################################################################
# HD44780 library
################################################################################

add_library(hd44780)
add_library(dsabala::hd44780 ALIAS hd44780)

target_sources(hd44780
PRIVATE
src/hd44780.c
PUBLIC
src/hd44780.h
)

target_include_directories(hd44780
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)

################################################################################
# HD44780 library example
################################################################################

if(BUILD_EXAMPLE)
enable_language(ASM)

add_executable(hd44780-example)

set(CPU_OPTIONS
-mthumb
-mcpu=cortex-m4
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
)

target_compile_options(hd44780
PRIVATE
${CPU_OPTIONS}
)

target_link_libraries(hd44780-example
PRIVATE
hd44780
)

target_compile_options(hd44780-example
PRIVATE
-Og
-Wall
-Wextra
-fdata-sections
-ffunction-sections
-Wno-unused-parameter
${CPU_OPTIONS}
)

target_compile_definitions(hd44780-example
PRIVATE
STM32F407xx
USE_HAL_DRIVER
HSE_VALUE=8000000U
)

target_include_directories(hd44780-example
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/example/src
${CMAKE_CURRENT_SOURCE_DIR}/example/stm32f4-drivers/include
)

target_sources(hd44780-example
PRIVATE
example/src/bsp_lcd.c
example/src/main.c
example/stm32f4-drivers/source/startup_stm32f407xx.s
example/stm32f4-drivers/source/stm32f4xx_hal.c
example/stm32f4-drivers/source/stm32f4xx_hal_cortex.c
example/stm32f4-drivers/source/stm32f4xx_hal_gpio.c
example/stm32f4-drivers/source/system_stm32f4xx.c
)

target_link_options(hd44780-example
PRIVATE
-T${CMAKE_CURRENT_SOURCE_DIR}/example/stm32f4-drivers/STM32F407VGTx_FLASH.ld
-specs=nosys.specs
-lnosys
-lc
-Wl,-Map=${PROJECT_NAME}.map,--gc-sections,--cref,--print-memory-usage
${CPU_OPTIONS}
)

endif()
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
# hd44780
Fully loaded, dependency free, fail-safe, HD44780 driver
# Dependency free, UTF-8 ready, HD44780 driver

<img src="https://raw.githubusercontent.com/dsabala/hd44780/master/hd44780.gif">

[![Github Issues](https://img.shields.io/github/issues/dsabala/hd44780?style=plastic)](http://github.com/dsabala/hd44780/issues)
[![Github Releases](https://img.shields.io/github/v/release/dsabala/hd44780?style=plastic)](https://github.com/dsabala/hd44780/releases)
[![GitHub license](https://img.shields.io/github/license/dsabala/hd44780?style=plastic)](https://raw.githubusercontent.com/dsabala/hd44780/master/LICENSE)

# Overview

Yet another HD44780 C driver. It might fit your needs if you are interested in one of its core features:
- **dependency free** - its free from any Arduino or STM HAL headers, only standard library headers are used
- **fail-safe** - it will handle hardware fails gently and return error code
- **UTF-8 string support** - minimalistic support for UTF-8 strings (8 custom characters can be mapped)
- **decoupled from underlying drivers** - by callback functions
- **multi-instantaneous** - more than one LCDs can be driven
- **support both communication modes** 4bit and 8bit interface with busy flag read
- **MIT license** - just fork this library and modify it to your needs
- **ready example** - for STM32F407G-DISC1 evalboard

Nothing comes without flaws, the disadvantages of this driver are:
- **arcane callbacks have to be implemented** - you might found it overcomplicated
- **binary size is not prority** - better choose other lib if your target platform lacks ROM memory
- **UTF-8 support might be too minimalistic** - its only 8 characters that can be mapped to CGRAM memory of HD44780
- **some features like shifting text are not implemented** - its still work in progrss

# Glimpse into features

Interface overview:
There are 8 poublic functions that covers 95% of HD44780 functionality
```c
hd44780_ret_e hd44780_init(const hd44780_ctx* const ctx);
hd44780_ret_e hd44780_clear(const hd44780_ctx* const ctx);
hd44780_ret_e hd44780_write_text(const hd44780_ctx* const ctx, const char* text);
hd44780_ret_e hd44780_set_pos(const hd44780_ctx* const ctx, uint8_t row, uint8_t column);
hd44780_ret_e hd44780_cursor_cfg(const hd44780_ctx* const ctx, hd44780_cursor cursor_cfg);
hd44780_ret_e hd44780_display_off(const hd44780_ctx* const ctx);
hd44780_ret_e hd44780_def_char(const hd44780_ctx* const ctx, uint8_t index, const uint8_t* const pattern);
hd44780_ret_e hd44780_disp_char(const hd44780_ctx* const ctx, uint8_t index);
```
Return codes:
```c
typedef enum {
HD44780_OK = 0, /**< Success */
HD44780_INV_ARG = 1, /**< Invalid argument */
HD44780_TIMEOUT = 2, /**< Timeout */
HD44780_CUSTOM_CHARS_INV = 3, /**< Custom character array invalid */
HD44780_CHAR_NOT_FOUND = 4, /**< Custom character not found */
} hd44780_ret_e;
```

Usage examples:
```c
/* Get driver context from library - application glue code */
const hd44780_ctx* const lcd_ctx = hd44780_instance_ctx_get();

/* Initialise display */
hd44780_init(lcd_ctx);

/* Set positon to first line and write text */
hd44780_set_pos(lcd_ctx, 0, 0);
hd44780_write_text(lcd_ctx, "Bonjour collègues 🍌"); /* UTF-8 is supported */
```
Example of UTF-8 custom characters map:
```c
static const character_mapping mappings[3] = {
{
.utf_8_code = U'è',
.character_bitmap = {0b01000, 0b00100, 0b01110, 0b10001, 0b11111, 0b10000, 0b01110, 0b00000},
},
{
.utf_8_code = U'🍌',
.character_bitmap = {0b01000, 0b00110, 0b00011, 0b00011, 0b00011, 0b00110, 0b01100, 0b10000},
}
};
```

Full description of callbacks that user of library have to implement is available
in header file.

# Status
This library is not finished, there are surely bugs and things that can be simplified
or features that can be added. It was tested only on 4x20 display of one manufacturer.
I decided to release it in this stage because
I have no experience with UTF-8 and open source libraries and have no idea if
this library can be useful for someone.
7 changes: 7 additions & 0 deletions cmake/toolchains/gcc-arm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SIZE_UTIL arm-none-eabi-size)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Loading

0 comments on commit a37096e

Please sign in to comment.