diff --git a/lcd_hd44780.c b/lcd_hd44780.c index d8226d5..cf608a7 100644 --- a/lcd_hd44780.c +++ b/lcd_hd44780.c @@ -2,9 +2,9 @@ #include void lcd_hd44780_writeToDisp(lcd_hd44780_t *inst){ - inst->setGetDataIO_event(inst->DataGpio,inst->port_data,LCD_HD44780_SET); + inst->setGetGpio_event(&(inst->gpio_data),LCD_HD44780_SET); } - +/* void lcd_hd44780_clearDisp(lcd_hd44780_t *inst){ return; @@ -15,35 +15,67 @@ void lcd_hd44780_printf(lcd_hd44780_t *inst, char *string){ return; +}*/ + +static void lcd_writeCmd_disp(lcd_hd44780_t *inst, hd44780_cmd_t cmd, hd44780_setGet_t getSet){ + + inst->gpio_data.data_bus = cmd; + + + inst->gpio_data.rw_pin = getSet; + + // We want to write an instruction. + inst->gpio_data.rs_pin = LCD_HD44780_INSTRUCTION; + + // E pin is sopposed to be zero when data is ready on port. + inst->gpio_data.e_pin = 0; + + inst->setGetGpio_event(&(inst->gpio_data),getSet); + + // Then Clock data in with E pin: + inst->gpio_data.e_pin = 1; + + inst->setGetGpio_event(&(inst->gpio_data),getSet); + + // Then Clock data in with E pin: + inst->gpio_data.e_pin = 0; + + inst->setGetGpio_event(&(inst->gpio_data),getSet); + + } -void lcd_hd44780_regDataEvt(lcd_hd44780_t *inst ,void *inst_Data, setGet_DataGpio_Event_fpt getDataEvt_fpt){ +void lcd_hd44780_regGpioEvt(lcd_hd44780_t *inst, setGet_Gpio_Event_fpt getGpioEvt_fpt){ - if(inst == NULL)return; - if(inst_Data == NULL)return; - - - inst->DataGpio = inst_Data; - inst->setGetDataIO_event = getDataEvt_fpt; + //if(inst == NULL)return; + + inst->setGetGpio_event = getGpioEvt_fpt; } -void lcd_hd44780_regConfigEvt(lcd_hd44780_t *inst ,void *inst_Config, setGet_ConfigGpio_Event_fpt getConfigEvt_fpt){ - - if(inst == NULL)return; - if(inst_Config == NULL)return; - - - inst->SettingsGpio = inst_Config; - inst->setGetConfigIO_event = getConfigEvt_fpt; - - return; +void lcd_hd44780_regWaitEvt(lcd_hd44780_t *inst, wait_ms_Event_fpt waitEvt_fpt){ + + //if(inst == NULL)return; + + inst->wait_event = waitEvt_fpt; } + void lcd_hd44780_init(lcd_hd44780_t *inst, lcd_hd44780_bitmode bit_mode){ - inst->port_data = 0x00; + //inst->gpio_data = 0x00; inst->bit_mode = bit_mode; + inst->gpio_data.data_bus = 0x0; + inst->gpio_data.e_pin = 0x0; + inst->gpio_data.rs_pin = 0x1; + inst->gpio_data.rw_pin = 0x0; + + inst->setGetGpio_event(&(inst->gpio_data), 1); + + + lcd_writeCmd_disp(inst,LCD_HD44780_CLEAR_DISP,LCD_HD44780_SET); + //lcd_writeCmd_disp(inst,LCD_HD44780_DISP_ONOFF_CTL,LCD_HD44780_SET); + return; } diff --git a/lcd_hd44780.h b/lcd_hd44780.h index 82efdb5..3a19461 100644 --- a/lcd_hd44780.h +++ b/lcd_hd44780.h @@ -17,7 +17,7 @@ typedef enum { }lcd_hd44780_bitmode; -enum { +typedef enum { LCD_HD44780_CLEAR_DISP = 0x1, LCD_HD44780_RETURN_HOME = 0x2, @@ -25,34 +25,47 @@ enum { LCD_HD44780_DISP_ONOFF_CTL = 0x4, LCD_HD44780_CURSOR_SHIFT = 0x6, -}; +}hd44780_cmd_t; -enum{ +typedef enum{ LCD_HD44780_GET = 0, LCD_HD44780_SET = 1, -}; +}hd44780_setGet_t; -typedef int (*setGet_DataGpio_Event_fpt)(void*, uint8_t data_input, uint8_t set_get )reentrant; -typedef int (*setGet_ConfigGpio_Event_fpt)(void*, uint8_t data_input, uint8_t set_get )reentrant; +typedef enum{ + LCD_HD44780_INSTRUCTION = 0, + LCD_HD44780_DATA = 1, + +}hd44780_InstData_t; + +typedef struct { + + uint8_t data_bus : 8; + 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_DataGpio_Event_fpt setGetDataIO_event; - setGet_ConfigGpio_Event_fpt setGetConfigIO_event; + setGet_Gpio_Event_fpt setGetGpio_event; + wait_ms_Event_fpt wait_event; lcd_hd44780_bitmode bit_mode; - uint8_t port_data; - uint8_t port_settings; + hd44780_gpioset_t gpio_data; }lcd_hd44780_t; void lcd_hd44780_init(lcd_hd44780_t *inst,lcd_hd44780_bitmode bit_mode); -void lcd_hd44780_regConfigEvt(lcd_hd44780_t *inst , void *inst_Config, setGet_ConfigGpio_Event_fpt getConfigEvt_fpt); -void lcd_hd44780_regDataEvt(lcd_hd44780_t *inst , void *inst_Data, setGet_DataGpio_Event_fpt getDataEvt_fpt); +void lcd_hd44780_regGpioEvt(lcd_hd44780_t *inst, setGet_Gpio_Event_fpt getGpioEvt_fpt); +void lcd_hd44780_regWaitEvt(lcd_hd44780_t *inst, wait_ms_Event_fpt waitEvt_fpt); #endif /*LCD_HD44780_H_*/ -