Files
hd44780u_driver/lcd_hd44780.h

97 lines
2.1 KiB
C

#ifndef LCD_HD44780_H_
#define LCD_HD44780_H_
#include <stdint.h>
// bit definetions
#define LCD_HD44780_RS 0
#define LCD_HD44780_RW 1
#define LCD_HD44780_E 2
#define LCD_HD44780_WRITE 0
#define LCD_HD44780_READ 1
typedef enum {
LCD_HD44780_BITMODE_8BIT,
LCD_HD44780_BITMODE_4BIT,
}lcd_hd44780_bitmode;
typedef enum {
LCD_HD44780_CLEAR_DISP = 0x1,
LCD_HD44780_RETURN_HOME = 0x2,
LCD_HD44780_ENTRY_MODE = 0x6,
LCD_HD44780_DISP_ONOFF_CTL = 0xE,
LCD_HD44780_DISPLAY_ON_CURSOR_ON_BLINK_ON = 0x0F,
LCD_HD44780_CURSOR_SHIFT = 0x6,
LCD_HD44780_FUNCTION_SET = 0x30,
}hd44780_cmd_t;
typedef enum{
LCD_HD44780_SET = 0,
LCD_HD44780_GET = 1,
}hd44780_setGet_t;
typedef enum{
LCD_HD44780_INSTRUCTION = 0,
LCD_HD44780_DATA = 1,
}hd44780_InstData_t;
typedef struct{
uint8_t DB0 : 1;
uint8_t DB1 : 1;
uint8_t DB2 : 1;
uint8_t DB3 : 1;
uint8_t DB4 : 1;
uint8_t DB5 : 1;
uint8_t DB6 : 1;
uint8_t DB7 : 1;
}hd44780_data_bits_t;
typedef struct {
union{
uint8_t data_bus : 8;
hd44780_data_bits_t data_bits;
};
hd44780_setGet_t rw_pin : 1;
uint8_t e_pin : 1;
hd44780_InstData_t rs_pin :1 ;
}hd44780_gpioset_t;
typedef int (*setGet_Gpio_Event_fpt)(hd44780_gpioset_t *data_input, uint8_t set_get);//reentrant;
typedef int (*wait_ms_Event_fpt)(uint32_t delay_ms);//reentrant;
typedef struct{
void *DataGpio;
void *SettingsGpio;
setGet_Gpio_Event_fpt setGetGpio_event;
wait_ms_Event_fpt wait_event;
lcd_hd44780_bitmode bit_mode;
hd44780_gpioset_t gpio_data;
// Flag for showing that init has been done.. After init im using polling Busy Flag instead of delay..
uint8_t isInit;
}cm_lcd_hd44780_t;
void lcd_hd44780_init(cm_lcd_hd44780_t *inst,lcd_hd44780_bitmode bit_mode);
void lcd_hd44780_regGpioEvt(cm_lcd_hd44780_t *inst, setGet_Gpio_Event_fpt getGpioEvt_fpt);
void lcd_hd44780_regWaitEvt(cm_lcd_hd44780_t *inst, wait_ms_Event_fpt waitEvt_fpt);
void lcd_hd44780_cursorHome(cm_lcd_hd44780_t *inst);
void lcd_hd44780_printf(cm_lcd_hd44780_t *inst, char *string);
void lcd_hd44780_clearDisp(cm_lcd_hd44780_t *inst);
void lcd_hd44780_print_xy(cm_lcd_hd44780_t *inst, uint8_t x, uint8_t y, const char *str);
#endif /*LCD_HD44780_H_*/