Skip to content

Commit

Permalink
Feature/hw examples (#14)
Browse files Browse the repository at this point in the history
Examples of library implementation on various hardware configurations have been added.

1. ATMEGA328P_ARDUINO_UNO_R3
2. STM32G071RB_NUCLEO_BARE_METAL
3. STM32G071RB_NUCLEO_BARE_METAL
  • Loading branch information
niwciu authored Jan 14, 2024
1 parent 5576e1a commit c06125f
Show file tree
Hide file tree
Showing 143 changed files with 74,729 additions and 21,526 deletions.
18 changes: 9 additions & 9 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ LCD_HD44780
### 2. lcd_hd44780_def_char.h
Header file for defining user special characters and user special characters banks. Each bank can contain up to 8 characters that are user-defined combinations of characters from defined user-special characters. This allows to creation of different combinations of special characters that can be loaded depending on current code needs.
### 3. lcd_hd44780_interface.h
Header file with library interface declaration that needs to be implemented on the drivers' side. Please look at the code examples in the"hw" folder and search for the "LCD_IO_driver.c" file for more details.
Header file with library interface declaration that needs to be implemented on the drivers' side. Please look at the code examples in the "examples" folder and search for the "LCD_IO_driver.c" file for more details.
### 4. lcd_hd44780.c
Library main C file
### 5. lcd_hd44780.h
Expand All @@ -108,9 +108,9 @@ Library main header file with available library api.
```bash
git clone https://github.com/niwciu/LCD_HD44780.git
```
3. Enter to LCD_HD44780/hw/STM32G071RB/
3. Enter to LCD_HD44780/examples/STM32G071RB/
```bash
cd ./LCD_HD44780/hw/STM32G071RB
cd ./LCD_HD44780/examples/STM32G071RB
```
4. For make type:
```bash
Expand Down Expand Up @@ -155,9 +155,9 @@ Library main header file with available library api.
```bash
git clone https://github.com/niwciu/LCD_HD44780.git
```
3. Enter to LCD_HD44780/hw/STM32G474RB/
3. Enter to LCD_HD44780/examples/STM32G474RB/
```bash
cd ./LCD_HD44780/hw/STM32G474RB
cd ./LCD_HD44780/examples/STM32G474RB
```
4. For make type:
```bash
Expand Down Expand Up @@ -203,9 +203,9 @@ Library main header file with available library api.
```bash
git clone https://github.com/niwciu/LCD_HD44780.git
```
3. Enter to LCD_HD44780/hw/ATMEGA328P_ARDUINO_UNO_R3 folder
3. Enter to LCD_HD44780/examples/ATMEGA328P_ARDUINO_UNO_R3 folder
```bash
cd ./LCD_HD44780/hw/ATMEGA328P_ARDUINO_UNO_R3
cd ./LCD_HD44780/examples/ATMEGA328P_ARDUINO_UNO_R3
```
4. For make type:
```bash
Expand Down Expand Up @@ -423,7 +423,7 @@ LCD_HD44780
├───.github
├───.vscode
├───doc
├───hw
├───examples
│ ├───ATMEGA328P_ARDUINO_UNO_R3
│ ├───config
│ ├───STM32F030R8
Expand All @@ -445,7 +445,7 @@ Folder description:
- .github -> Folder with githubactions .yml scripts
- .vscode -> folder with vscode example settings for luch.json and tasks.json
- doc -> folder for any documentations needes or created in the project
- hw -> folder with example hardware implementations contain ready to compile examples for different uC
- hxamples -> folder with example hardware implementations contain ready to compile examples for different uC
- test -> folder where all tests are written. Folder contain fallowing subfolders:
- hw_test -> folder with configurations/setups for specyfic ucontrollers to make integration tests
- lcd_hd44780 -> folder where all unit tests for lcd_hd44780 module are keept
Expand Down
596 changes: 0 additions & 596 deletions cppcheck_report.txt

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
#
# usage: Edit MCPU-Variable to suit STM32 project requirements.
# For debug build using Unix Makefiles:
# cmake -S ./ -B Debug -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
# make -C Debug all (optional with VERBOSE=1 and -jxx ->xx numnber of cores)
# cmake -S ./ -B Build -G"Unix Makefiles"
# make -C Build all (optional with VERBOSE=1 and -jxx ->xx numnber of cores)
# For debug build using Ninja:
# cmake -S ./ -B Debug -G"Ninja" -DCMAKE_BUILD_TYPE=Debug
# ninja -C Debug (optional with -V and -jxx ->xx numnber of cores)
#
# For release build Unix Makefiles:
# cmake -S ./ -B Release -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
# make all -C Release VERBOSE=1 -j12 (optional with VERBOSE=1 and -jxx ->xx numnber of cores)
# For Release build using Ninja:
# cmake -S ./ -B Release -G"Ninja" -DCMAKE_BUILD_TYPE=Release
# ninja -C Release (optional -V and -jxx ->xx numnber of cores)
# cmake -S ./ -B Build -G"Ninja" -DCMAKE_BUILD_TYPE=Debug
# ninja -C Build (optional with -V and -jxx ->xx numnber of cores)
# additional custom targets for this project:
# Erase Atmega chip:
# 1. make erase / ninja erase
# Read Fuse Bits:
# 1. make write_fuses / ninja write_fuses
# Write Fuse Bits:
# 1. make write_fuses / ninja write_fuses
# Read Flash:
# 1. make read_flash / ninja read_flash
# Write Flash:
# 1. make flash / ninja flash
#############################################################################################################################
cmake_minimum_required(VERSION 3.10)

Expand Down Expand Up @@ -47,12 +51,17 @@ set(L_FUSE 0xfd)
set(LOCK_BIT 0xff)

set(INCLUDE_DIRS
./inc
./inc
../../src
)

set(C_SRCS
./src/main.c
./src/debug.c
./src/LCD_IO_driver.c

../../src/lcd_hd44780.c

)

set(ASM_SRCS
Expand All @@ -61,6 +70,7 @@ set(ASM_SRCS

set(GLOBAL_DEFINES
-DF_CPU=${F_CPU}
-DAVR
# -DBAUD=${BAUD}
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define ON 1
#define OFF 0

#define DEBUG_CONSOLE ON
#define DEBUG_CONSOLE OFF

#ifdef __cplusplus
}
Expand Down
181 changes: 181 additions & 0 deletions examples/ATMEGA328P_ARDUINO_UNO_R3/src/LCD_IO_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* @Author: lukasz.niewelt
* @Date: 2023-12-04 20:13:23
* @Last Modified by: lukasz.niewelt
* @Last Modified time: 2023-12-08 10:49:44
*/

// #include "lcd_hd44780_config.h"
#include "lcd_hd44780_interface.h"
#include "lcd_hd44780_config.h"
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>

#define LCD_DATA_PORT PORTD
#define LCD_DATA_PORT_DIR DDRD
#define LCD_DATA_INPUT PIND

#define LCD_SIG_PORT PORTB
#define LCD_SIG_PORT_DIR DDRB

#define LCD_BCKL_PORT PORTB
#define LCD_BCKL_PORT_DIR DDRB

#define LCD_PIN_D7 (1 << PIND7)
#define LCD_PIN_D6 (1 << PIND6)
#define LCD_PIN_D5 (1 << PIND5)
#define LCD_PIN_D4 (1 << PIND4)
#define LCD_PIN_RS (1 << PINB0)
#define LCD_PIN_RW (1 << PINC1)
#define LCD_PIN_E (1 << PINB1)
#define LCD_BCKL_PIN (1 << PINB5)

#define LCD_D4_MASK 0x01
#define LCD_D5_MASK 0x02
#define LCD_D6_MASK 0x04
#define LCD_D7_MASK 0x08

static void init_LCD_data_and_SIG_pins(void);
static void init_LCD_DATA_PINS_as_outputs(void);
static void init_LCD_DATA_PINS_as_inputs(void);
static void set_LCD_DATA_PINS_state(uint8_t data);
static uint8_t get_LCD_DATA_PINS_state(void);
static void init_LCD_SIGNAL_PINS_as_outputs(void);
static void LCD_set_SIG(enum lcd_sig LCD_SIG);
static void LCD_reset_SIG(enum lcd_sig LCD_SIG);
static void wraper_delay_us(uint32_t delay_us);

/************LCD_IO_driver_interface implementation START**************/
static const struct LCD_IO_driver_interface_struct LCD_IO_driver = {
init_LCD_data_and_SIG_pins,
init_LCD_DATA_PINS_as_outputs,
init_LCD_DATA_PINS_as_inputs,
set_LCD_DATA_PINS_state,
get_LCD_DATA_PINS_state,
init_LCD_SIGNAL_PINS_as_outputs,
LCD_set_SIG,
LCD_reset_SIG,
wraper_delay_us,
};
const struct LCD_IO_driver_interface_struct *LCD_IO_driver_interface_get(void)
{
return &LCD_IO_driver;
}

/*************LCD_IO_driver_interface implementation END***************/

static void init_LCD_data_and_SIG_pins(void)
{
//set BCKL PIN as output
LCD_BCKL_PORT_DIR |= LCD_BCKL_PIN;
//enable Backlight of the LCD
LCD_BCKL_PORT |= LCD_BCKL_PIN;
init_LCD_DATA_PINS_as_outputs();
init_LCD_SIGNAL_PINS_as_outputs();
}
static void init_LCD_DATA_PINS_as_outputs(void)
{
//set pins as output
LCD_DATA_PORT_DIR |= (LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7);
}
static void init_LCD_DATA_PINS_as_inputs(void)
{

//set pins as inputs
LCD_DATA_PORT_DIR &= ~(LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7);
// enable pull-up on input pins
LCD_DATA_PORT |= (LCD_PIN_D4 | LCD_PIN_D5 | LCD_PIN_D6 | LCD_PIN_D7);
}

static void set_LCD_DATA_PINS_state(uint8_t data)
{
if ((data & LCD_D4_MASK))
LCD_DATA_PORT |= LCD_PIN_D4;
else
LCD_DATA_PORT &= ~LCD_PIN_D4;

if ((data & LCD_D5_MASK))
LCD_DATA_PORT |= LCD_PIN_D5;
else
LCD_DATA_PORT &= ~LCD_PIN_D5;

if ((data & LCD_D6_MASK))
LCD_DATA_PORT |= LCD_PIN_D6;
else
LCD_DATA_PORT &= ~LCD_PIN_D6;

if ((data & LCD_D7_MASK))
LCD_DATA_PORT |= LCD_PIN_D7;
else
LCD_DATA_PORT &= ~LCD_PIN_D7;
}

static uint8_t get_LCD_DATA_PINS_state(void)
{
uint8_t data = 0;
if (LCD_DATA_INPUT & LCD_PIN_D4)
data = LCD_D4_MASK;
if (LCD_DATA_INPUT & LCD_PIN_D5)
data |= LCD_D5_MASK;
if (LCD_DATA_INPUT & LCD_PIN_D6)
data |= LCD_D6_MASK;
if (LCD_DATA_INPUT & LCD_PIN_D7)
data |= LCD_D7_MASK;
return data;
}

static void init_LCD_SIGNAL_PINS_as_outputs(void)
{
#if USE_RW_PIN == ON
LCD_SIG_PORT_DIR |= (LCD_PIN_RS | LCD_PIN_RW | LCD_PIN_E);

#else
LCD_SIG_PORT_DIR |= (LCD_PIN_RS | LCD_PIN_E);
#endif
}

static void LCD_set_SIG(enum lcd_sig LCD_SIG)
{
switch (LCD_SIG)
{
case LCD_RS:
LCD_SIG_PORT |= LCD_PIN_RS;
break;
case LCD_E:
LCD_SIG_PORT |= LCD_PIN_E;
break;
#if USE_RW_PIN == ON
case LCD_RW:
LCD_SIG_PORT |= LCD_PIN_RW;
break;
#endif
default:
break;
}
}

static void LCD_reset_SIG(enum lcd_sig LCD_SIG)
{
switch (LCD_SIG)
{
case LCD_RS:
LCD_SIG_PORT &= ~LCD_PIN_RS;
break;
case LCD_E:
LCD_SIG_PORT &= ~LCD_PIN_E;
break;
#if USE_RW_PIN == ON
case LCD_RW:
LCD_SIG_PORT &= ~LCD_PIN_RW;
break;
#endif
default:
break;
}
}

void wraper_delay_us(uint32_t delay_us)
{
_delay_us((double)(delay_us));
}
File renamed without changes.
78 changes: 78 additions & 0 deletions examples/ATMEGA328P_ARDUINO_UNO_R3/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include "project_config.h"
#if DEBUG_CONSOLE == ON
#include "debug.h"
#endif
#include "lcd_hd44780.h"

#define SHIFT_DELAY 400

const char *demo_tekst = {"Congratulation, you have just run LCD demo example."};
const char *demo_title = {"LCD HD44780 Demo"};

static void lcd_buf_slide_str_in(const char *str, enum LCD_LINES lcd_line, uint16_t speed);
static void lcd_buf_slide_str_out(const char *str, enum LCD_LINES lcd_line, uint16_t speed);

uint8_t j = 0;
uint8_t i = 0;

int main(void)
{

#if DEBUG_CONSOLE == ON
// Init the debug UART allowing us to use `printf`
debug_console_init();
#endif
lcd_init();
lcd_buf_str(demo_title);
lcd_update();
while (1)
{
lcd_buf_slide_str_in(demo_tekst, LINE_2, SHIFT_DELAY);
lcd_buf_slide_str_out(demo_tekst, LINE_2, SHIFT_DELAY);
}
return 0;
}

void lcd_buf_slide_str_out(const char *str, enum LCD_LINES lcd_line, uint16_t speed)
{
uint8_t str_end_flag = 0;
for (j = 0; j <= strlen(str); j++)
{
_delay_ms(speed);
lcd_buf_locate(lcd_line, C1);
for (i = 0; i < LCD_X; i++)
{
if ((str[j + i] != '\0') && (str_end_flag == 0))
{
lcd_buf_char(str[j + i]);
}
else
{
str_end_flag = 0xFF;
lcd_buf_char(' ');
}
}
str_end_flag = 0;
lcd_update();
}
}

void lcd_buf_slide_str_in(const char *str, enum LCD_LINES lcd_line, uint16_t speed)
{
for (i = LCD_X - 1; i > C1; i--)
{
_delay_ms(speed);
lcd_buf_locate(lcd_line, i);
for (uint8_t j = 0; j < (LCD_X - i); j++)
{
lcd_buf_char(str[j]);
}
lcd_update();
}
}
Loading

0 comments on commit c06125f

Please sign in to comment.