scl_low(i2c); sda_high(i2c); return b; // return received byte } // Send the stop static void stop(const I2C_ABSTRACT_BUS* bus){ const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus; sda_low(i2c); halfDelay(); scl_high(i2c); halfDelay(); sda_high(i2c); halfDelay(); } static void init(I2C_ABSTRACT_BUS* bus){ const I2C_SOFTWARE_BUS* i2c = (I2C_SOFTWARE_BUS*)bus; // Make both pins high sda_high(i2c); scl_high(i2c); } // Expose this implementation to the linker I2C_CLASS const c_sw_i2c = MAKE_I2C_CLASS(&init, &start,&stop, &getByte, &putByte, null);
outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)|BV(TWSTA)); i2cWaitForComplete(); // Send the device addr and direction // uint8_t addr = device->addr; if(writeMode==FALSE){ addr |= 1; }else{ addr &= 0xfe; } outb(TWDR, addr); // begin send outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)); i2cWaitForComplete(); uint8_t got = inb(TWSR) & TWSR_STATUS_MASK; // get the status return( (got == expect) ? TRUE : FALSE ); } static void stop(const I2C_ABSTRACT_BUS* bus){ // transmit stop condition // leave with TWEA on for slave receiving outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA)|BV(TWSTO)); i2cState = I2C_IDLE; } // Expose this implementation to the linker const I2C_CLASS PROGMEM c_hw_i2c = MAKE_I2C_CLASS(&init, &start,&stop, &getByte, &putByte, &speed);