diff --git a/server/drivers/hd44780-ftdi.c b/server/drivers/hd44780-ftdi.c index ca77b7a..cb4169b 100644 --- a/server/drivers/hd44780-ftdi.c +++ b/server/drivers/hd44780-ftdi.c @@ -1,8 +1,21 @@ /** \file server/drivers/hd44780-ftdi.c * \c ftdi connection type of \c hd44780 driver for Hitachi HD44780 based LCD displays. + * +\verbatim + info for 4bit mode (ftdi_mode == 4): + wiring example: + FTDI chip: D0 D1 D2 D3 D4 D5 D6 D7 + | | | | | | | | + HD44780: D4 D5 D6 D7 EN RS RW n/c + + in LCDd.conf we then need to define + ftdi_line_RS=0x40 + ftdi_line_RW=0x20 + ftdi_line_EN=0x10 +\endverbatim */ -/* +/*- * FTDI/USB driver module for Hitachi HD44780 based LCD displays * connected to a FT2232C/D chip in 8 bit mode. * @@ -16,23 +29,6 @@ * */ -/* info for 4bit mote (ftdi_mode == 4): - wiring example: - FTDI chip: D0 D1 D2 D3 D4 D5 D6 D7 - | | | | | | | | - HD44780: D4 D5 D6 D7 EN RS RW n/c - - in LCDd.conf we then need to define - ftdi_line_RS=0x40 - ftdi_line_RW=0x20 - ftdi_line_EN=0x10 -*/ - -#include "hd44780-ftdi.h" -#include "hd44780-low.h" - -#include "report.h" - #include #include #include @@ -47,8 +43,11 @@ # include "config.h" #endif +#include "hd44780-ftdi.h" +#include "hd44780-low.h" +#include "report.h" -// connection type specific functions to be exposed using pointers in init() +/* connection type specific functions to be exposed using pointers in init() */ void ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch); void ftdi_HD44780_backlight(PrivateData *p, unsigned char state); void ftdi_HD44780_close(PrivateData *p); @@ -66,30 +65,30 @@ hd_init_ftdi(Driver *drvthis) int vendor_id, product_id; int f; - PrivateData *p = (PrivateData*) drvthis->private_data; + PrivateData *p = (PrivateData *)drvthis->private_data; p->hd44780_functions->senddata = ftdi_HD44780_senddata; p->hd44780_functions->backlight = ftdi_HD44780_backlight; p->hd44780_functions->close = ftdi_HD44780_close; - // Load config + /* Load config */ vendor_id = drvthis->config_get_int(drvthis->name, "VendorID", 0, 0x0403); product_id = drvthis->config_get_int(drvthis->name, "ProductID", 0, 0x6001); - // these config settings are not documented intentionally + /* these config settings are not documented intentionally */ p->ftdi_mode = drvthis->config_get_int(drvthis->name, "ftdi_mode", 0, 8); p->ftdi_line_RS = drvthis->config_get_int(drvthis->name, "ftdi_line_RS", 0, 0x01); p->ftdi_line_RW = drvthis->config_get_int(drvthis->name, "ftdi_line_RW", 0, 0x02); p->ftdi_line_EN = drvthis->config_get_int(drvthis->name, "ftdi_line_EN", 0, 0x04); p->ftdi_line_backlight = drvthis->config_get_int(drvthis->name, "ftdi_line_backlight", 0, 0x08); - //some foolproof check + /* some foolproof check */ if (p->ftdi_mode != 4 && p->ftdi_mode != 8) { report(RPT_ERR, "invalid ftdi_mode: %d", p->ftdi_mode); return -1; } - // Init 1. channel: data + /* Init 1. channel: data */ ftdi_init(&p->ftdic); ftdi_set_interface(&p->ftdic, INTERFACE_A); f = ftdi_usb_open(&p->ftdic, vendor_id, product_id); @@ -102,7 +101,7 @@ hd_init_ftdi(Driver *drvthis) debug(RPT_DEBUG, "enabling bitbang mode(channel 1)\n"); if (p->ftdi_mode == 4) { - //set fast baudrate for 4 bit wiring to eliminate garbage on lcd + /* set fast baudrate for 4 bit wiring to eliminate garbage on lcd */ f = ftdi_set_baudrate(&p->ftdic, 921600); if (f < 0) { report(RPT_ERR, "unable to open ftdi device: %d (%s)", f, ftdi_get_error_string(&p->ftdic)); @@ -110,10 +109,10 @@ hd_init_ftdi(Driver *drvthis) } } - ftdi_enable_bitbang(&p->ftdic, 0xFF); + ftdi_set_bitmode(&p->ftdic, 0xFF, BITMODE_BITBANG); if (p->ftdi_mode == 8) { - // Init 2. channel: control + /* Init 2. channel: control */ ftdi_init(&p->ftdic2); ftdi_set_interface(&p->ftdic2, INTERFACE_B); f = ftdi_usb_open(&p->ftdic2, vendor_id, product_id); @@ -124,18 +123,21 @@ hd_init_ftdi(Driver *drvthis) debug(RPT_DEBUG, "ftdi open succeeded(channel 2): %d", f); debug(RPT_DEBUG, "enabling bitbang mode (channel 2)"); - ftdi_enable_bitbang(&p->ftdic2, 0xFF); + ftdi_set_bitmode(&p->ftdic2, 0xFF, BITMODE_BITBANG); - // FTDI bug: Sometimes first write gets lost on kernel 2.6, needs investigation. - ftdi_HD44780_senddata (p, 0, RS_INSTR, FUNCSET | IF_8BIT); - usleep (4100); + /* + * FTDI bug: Sometimes first write gets lost on kernel 2.6, needs + * investigation. + */ + ftdi_HD44780_senddata(p, 0, RS_INSTR, FUNCSET | IF_8BIT); + usleep(4100); common_init(p, IF_8BIT); } else if (p->ftdi_mode == 4) { - ftdi_HD44780_senddata (p, 0, RS_INSTR, FUNCSET | IF_4BIT ); - ftdi_HD44780_senddata (p, 0, RS_INSTR, FUNCSET | IF_4BIT ); - ftdi_HD44780_senddata (p, 0, RS_INSTR, FUNCSET | IF_4BIT ); + ftdi_HD44780_senddata(p, 0, RS_INSTR, FUNCSET | IF_4BIT); + ftdi_HD44780_senddata(p, 0, RS_INSTR, FUNCSET | IF_4BIT); + ftdi_HD44780_senddata(p, 0, RS_INSTR, FUNCSET | IF_4BIT); common_init(p, IF_4BIT); } @@ -156,15 +158,15 @@ void ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch) { if (p->ftdi_mode == 8) { - // Output data on first channel + /* Output data on first channel */ int f = ftdi_write_data(&p->ftdic, &ch, 1); if (f < 0) { p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", - f, ftdi_get_error_string(&p->ftdic)); - exit (-1); + f, ftdi_get_error_string(&p->ftdic)); + exit(-1); } - // Setup RS and R/W and EN + /* Setup RS and R/W and EN */ ch = p->ftdi_line_EN | p->backlight_bit; if (flags == RS_DATA) { ch |= p->ftdi_line_RS; @@ -172,11 +174,11 @@ ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char fla f = ftdi_write_data(&p->ftdic2, &ch, 1); if (f < 0) { p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", - f, ftdi_get_error_string(&p->ftdic2)); + f, ftdi_get_error_string(&p->ftdic2)); exit(-1); } - // Disable E + /* Disable E */ ch = 0x00 | p->backlight_bit; if (flags == RS_DATA) { ch |= p->ftdi_line_RS; @@ -184,7 +186,7 @@ ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char fla f = ftdi_write_data(&p->ftdic2, &ch, 1); if (f < 0) { p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", - f, ftdi_get_error_string(&p->ftdic2)); + f, ftdi_get_error_string(&p->ftdic2)); exit(-1); } } @@ -196,20 +198,20 @@ ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char fla portControl = p->ftdi_line_RS; } - buf[0] = ((ch>>4) & 0x0F) | portControl | p->ftdi_line_EN; - buf[1] = ((ch>>4) & 0x0F) | portControl; + buf[0] = ((ch >> 4) & 0x0F) | portControl | p->ftdi_line_EN; + buf[1] = ((ch >> 4) & 0x0F) | portControl; buf[2] = (ch & 0x0F) | portControl | p->ftdi_line_EN; buf[3] = (ch & 0x0F) | portControl; int f = ftdi_write_data(&p->ftdic, buf, 4); if (f < 0) { - p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", - f, ftdi_get_error_string(&p->ftdic)); - exit(-1); + p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", + f, ftdi_get_error_string(&p->ftdic)); + exit(-1); } if (flags == RS_INSTR) { - usleep (4100); + usleep(4100); } } } @@ -231,7 +233,7 @@ ftdi_HD44780_backlight(PrivateData *p, unsigned char state) f = ftdi_write_data(&p->ftdic2, &state, 1); if (f < 0) { p->hd44780_functions->drv_report(RPT_ERR, "failed to write: %d (%s). Exiting", - f, ftdi_get_error_string(&p->ftdic2)); + f, ftdi_get_error_string(&p->ftdic2)); exit(-1); } }