/* * This function reads one byte from the slave device * * Parameters: * ack - Flag to indicate either to send the acknowledge * message to the slave device or not * * Return Value: * One byte data read from the Slave device */ static unsigned char sw_i2c_read_byte(unsigned char ack) { int i; unsigned char data = 0; for (i = 7; i >= 0; i--) { /* Set the SCL to Low and SDA to High (Input) */ sw_i2c_scl(0); sw_i2c_sda(1); sw_i2c_wait(); /* Set the SCL High */ sw_i2c_scl(1); sw_i2c_wait(); /* Read data bits from SDA */ data |= (sw_i2c_read_sda() << i); } if (ack) sw_i2c_ack(); /* Set the SCL Low and SDA High */ sw_i2c_scl(0); sw_i2c_sda(1); return data; }
int sw_i2c_read(unsigned char chip, unsigned char location, unsigned char* buf, int count) { int i; #ifdef MROBE_100 /* does not use register addressing */ (void) location; #else sw_i2c_start(); sw_i2c_outb((chip & 0xfe) | SW_I2C_WRITE); if (!sw_i2c_getack()) { sw_i2c_stop(); return -1; } sw_i2c_outb(location); if (!sw_i2c_getack()) { sw_i2c_stop(); return -2; } #endif sw_i2c_start(); sw_i2c_outb((chip & 0xfe) | SW_I2C_READ); if (!sw_i2c_getack()) { sw_i2c_stop(); return -3; } for (i=0; i<count-1; i++) { buf[i] = sw_i2c_inb(); sw_i2c_ack(); } /* 1byte min */ buf[i] = sw_i2c_inb(); sw_i2c_nack(); sw_i2c_stop(); return 0; }