Skip to content

File syn_charlcd.c

FileList > display > syn_charlcd.c

Go to the source code of this file

Generic Character LCD Driver (HD44780, ST7066, KS0066 over I2C PCF8574 or 4-Bit Parallel GPIO).

  • #include "syn_charlcd.h"
  • #include "../util/syn_assert.h"
  • #include <string.h>

Public Functions

Type Name
void syn_charlcd_clear (SYN_CharLCD * lcd)
Clear LCD screen and reset cursor to home (0,0).
void syn_charlcd_create_char (SYN_CharLCD * lcd, uint8_t slot, const uint8_t charmap)
Load a custom 5x8 pixel character into CGRAM.
SYN_Status syn_charlcd_init_gpio (SYN_CharLCD * lcd, SYN_GPIO_Pin rs, SYN_GPIO_Pin en, SYN_GPIO_Pin d4, SYN_GPIO_Pin d5, SYN_GPIO_Pin d6, SYN_GPIO_Pin d7, uint8_t cols, uint8_t rows)
Initialize Character LCD in Direct 4-Bit Parallel GPIO mode.
SYN_Status syn_charlcd_init_i2c (SYN_CharLCD * lcd, SYN_GPIO_Pin scl, SYN_GPIO_Pin sda, uint8_t i2c_addr, uint8_t cols, uint8_t rows)
Initialize Character LCD in I2C PCF8574 Backpack mode.
void syn_charlcd_print (SYN_CharLCD * lcd, const char * str)
Print an ASCII string at current cursor position.
void syn_charlcd_set_backlight (SYN_CharLCD * lcd, bool enable)
Turn display backlight ON or OFF (I2C backpack mode).
void syn_charlcd_set_cursor (SYN_CharLCD * lcd, uint8_t col, uint8_t row)
Set cursor position.

Public Static Functions

Type Name
void send_gpio_byte (SYN_CharLCD * lcd, uint8_t val, bool is_data)
void send_gpio_nibble (SYN_CharLCD * lcd, uint8_t nibble)
void send_i2c_byte (SYN_CharLCD * lcd, uint8_t val, uint8_t mode)
void send_i2c_nibble (SYN_CharLCD * lcd, uint8_t nibble, uint8_t mode)
void write_command (SYN_CharLCD * lcd, uint8_t cmd)
void write_data (SYN_CharLCD * lcd, uint8_t data)
void write_i2c_byte (SYN_SoftI2C * i2c, uint8_t dev_addr, uint8_t byte)

Macros

Type Name
define PCF8574_BL 0x08
define PCF8574_EN 0x04
define PCF8574_RS 0x01
define PCF8574_RW 0x02

Public Functions Documentation

function syn_charlcd_clear

Clear LCD screen and reset cursor to home (0,0).

void syn_charlcd_clear (
    SYN_CharLCD * lcd
) 

Parameters:

  • lcd LCD context.

function syn_charlcd_create_char

Load a custom 5x8 pixel character into CGRAM.

void syn_charlcd_create_char (
    SYN_CharLCD * lcd,
    uint8_t slot,
    const uint8_t charmap
) 

Parameters:

  • lcd LCD context.
  • slot CGRAM slot (0 to 7).
  • charmap Array of 8 bytes (each byte represents a 5-bit pixel row).

function syn_charlcd_init_gpio

Initialize Character LCD in Direct 4-Bit Parallel GPIO mode.

SYN_Status syn_charlcd_init_gpio (
    SYN_CharLCD * lcd,
    SYN_GPIO_Pin rs,
    SYN_GPIO_Pin en,
    SYN_GPIO_Pin d4,
    SYN_GPIO_Pin d5,
    SYN_GPIO_Pin d6,
    SYN_GPIO_Pin d7,
    uint8_t cols,
    uint8_t rows
) 

Parameters:

  • lcd LCD context.
  • rs Register Select GPIO pin.
  • en Enable GPIO pin.
  • d4 Data Bit 4 GPIO pin.
  • d5 Data Bit 5 GPIO pin.
  • d6 Data Bit 6 GPIO pin.
  • d7 Data Bit 7 GPIO pin.
  • cols Columns (e.g. 16 or 20).
  • rows Rows (e.g. 2 or 4).

Returns:

SYN_OK on success.


function syn_charlcd_init_i2c

Initialize Character LCD in I2C PCF8574 Backpack mode.

SYN_Status syn_charlcd_init_i2c (
    SYN_CharLCD * lcd,
    SYN_GPIO_Pin scl,
    SYN_GPIO_Pin sda,
    uint8_t i2c_addr,
    uint8_t cols,
    uint8_t rows
) 

Parameters:

  • lcd LCD context.
  • scl I2C SCL GPIO pin.
  • sda I2C SDA GPIO pin.
  • i2c_addr PCF8574 I2C address (e.g. 0x27 or 0x3F).
  • cols Columns (e.g. 16 or 20).
  • rows Rows (e.g. 2 or 4).

Returns:

SYN_OK on success.


function syn_charlcd_print

Print an ASCII string at current cursor position.

void syn_charlcd_print (
    SYN_CharLCD * lcd,
    const char * str
) 

Parameters:

  • lcd LCD context.
  • str Null-terminated string.

function syn_charlcd_set_backlight

Turn display backlight ON or OFF (I2C backpack mode).

void syn_charlcd_set_backlight (
    SYN_CharLCD * lcd,
    bool enable
) 

Parameters:

  • lcd LCD context.
  • enable True for backlight ON.

function syn_charlcd_set_cursor

Set cursor position.

void syn_charlcd_set_cursor (
    SYN_CharLCD * lcd,
    uint8_t col,
    uint8_t row
) 

Parameters:

  • lcd LCD context.
  • col Column (0 to cols-1).
  • row Row (0 to rows-1).

Public Static Functions Documentation

function send_gpio_byte

static void send_gpio_byte (
    SYN_CharLCD * lcd,
    uint8_t val,
    bool is_data
) 

function send_gpio_nibble

static void send_gpio_nibble (
    SYN_CharLCD * lcd,
    uint8_t nibble
) 

function send_i2c_byte

static void send_i2c_byte (
    SYN_CharLCD * lcd,
    uint8_t val,
    uint8_t mode
) 

function send_i2c_nibble

static void send_i2c_nibble (
    SYN_CharLCD * lcd,
    uint8_t nibble,
    uint8_t mode
) 

function write_command

static void write_command (
    SYN_CharLCD * lcd,
    uint8_t cmd
) 

function write_data

static void write_data (
    SYN_CharLCD * lcd,
    uint8_t data
) 

function write_i2c_byte

static void write_i2c_byte (
    SYN_SoftI2C * i2c,
    uint8_t dev_addr,
    uint8_t byte
) 

Macro Definition Documentation

define PCF8574_BL

#define PCF8574_BL `0x08`

define PCF8574_EN

#define PCF8574_EN `0x04`

define PCF8574_RS

#define PCF8574_RS `0x01`

define PCF8574_RW

#define PCF8574_RW `0x02`


The documentation for this class was generated from the following file src/syntropic/display/syn_charlcd.c