static void lcd_strobe(int fd, uint8_t data) { i2c_write_cmd(fd, data | En | LCD_BACKLIGHT); mysleep(1); //.0005); i2c_write_cmd(fd, ((data & ~En) | LCD_BACKLIGHT)); mysleep(1); //.0001); }
/* This performs a fast write of one or more consecutive bytes to an * I2C device. Not all devices support consecutive writes of more * than one byte; for these devices use efx_i2c_write() instead. */ int efx_i2c_fast_write(struct efx_i2c_interface *i2c, u8 device_id, u8 offset, const u8 *data, unsigned int len) { int i; int rc; EFX_WARN_ON_PARANOID(getsda(i2c) != 1); EFX_WARN_ON_PARANOID(getscl(i2c) != 1); EFX_WARN_ON_PARANOID(len < 1); /* Select device and starting offset */ i2c_start(i2c); rc = i2c_send_byte(i2c, i2c_write_cmd(device_id)); if (rc) goto out; rc = i2c_send_byte(i2c, offset); if (rc) goto out; /* Write data to device */ for (i = 0; i < len; i++) { rc = i2c_send_byte(i2c, data[i]); if (rc) goto out; } out: i2c_stop(i2c); i2c_release(i2c); return rc; }
int efx_i2c_check_presence(struct efx_i2c_interface *i2c, u8 device_id) { int rc; /* If someone is driving the bus low we just give up. */ if (getsda(i2c) == 0 || getscl(i2c) == 0) { EFX_ERR(i2c->efx, "%s someone is holding the I2C bus low." " Giving up.\n", __func__); return -EFAULT; } /* Pretend to initiate a device write */ i2c_start(i2c); rc = i2c_send_byte(i2c, i2c_write_cmd(device_id)); if (rc) goto out; out: i2c_stop(i2c); i2c_release(i2c); return rc; }
/* This performs a fast read of one or more consecutive bytes from an * I2C device. Not all devices support consecutive reads of more than * one byte; for these devices use efx_i2c_read() instead. */ int efx_i2c_fast_read(struct efx_i2c_interface *i2c, u8 device_id, u8 offset, u8 *data, unsigned int len) { int i; int rc; EFX_WARN_ON_PARANOID(getsda(i2c) != 1); EFX_WARN_ON_PARANOID(getscl(i2c) != 1); EFX_WARN_ON_PARANOID(data == NULL); EFX_WARN_ON_PARANOID(len < 1); /* Select device and starting offset */ i2c_start(i2c); rc = i2c_send_byte(i2c, i2c_write_cmd(device_id)); if (rc) goto out; rc = i2c_send_byte(i2c, offset); if (rc) goto out; /* Read data from device */ i2c_start(i2c); rc = i2c_send_byte(i2c, i2c_read_cmd(device_id)); if (rc) goto out; for (i = 0; i < (len - 1); i++) /* Read and acknowledge all but the last byte */ data[i] = i2c_recv_byte(i2c, 1); /* Read last byte with no acknowledgement */ data[i] = i2c_recv_byte(i2c, 0); out: i2c_stop(i2c); i2c_release(i2c); return rc; }
static void lcd_write_four_bits(int fd, uint8_t data) { i2c_write_cmd(fd, data | LCD_BACKLIGHT); lcd_strobe(fd, data); }