Example #1
0
static int i2c_stop(void)
{
	u32 ctl;

	ctl = readl(&i2c_base->ctl) & 0xc0;
	ctl |= TWI_CTL_STP;

	writel(ctl, &i2c_base->ctl);

	/* dummy to delay one I/O operation to make sure it's started */
	(void)readl(&i2c_base->ctl);

	if (i2c_wait_ctl(TWI_CTL_STP, 0) != 0)
		return -1;
	if (i2c_wait_status(TWI_STAT_IDLE))
		return -1;
	if (i2c_wait_bus_idle() != 0)
		return -1;

	return 0;
}
Example #2
0
// Wait until the slave address has been acknowledged
static inline void i2c_wait_addr_rx(i2c_t *obj) {
    uint32_t sr1_mask = I2C_SR1_ADDR;
    uint32_t sr2_mask = I2C_SR2_MSL | I2C_SR2_BUSY;
    i2c_wait_status(obj, sr1_mask, sr2_mask);
}
Example #3
0
// Wait until a byte has been received
static inline void i2c_wait_receive(i2c_t *obj) {
    uint32_t sr1_mask = I2C_SR1_RXNE;
    uint32_t sr2_mask = I2C_SR2_MSL | I2C_SR2_BUSY;
    i2c_wait_status(obj, sr1_mask, sr2_mask);
}
Example #4
0
// Wait until the start condition has been accepted
static inline void i2c_wait_start(i2c_t *obj) {
    uint32_t sr1_mask = I2C_SR1_SB;
    uint32_t sr2_mask = I2C_SR2_MSL | I2C_SR2_BUSY;
    i2c_wait_status(obj, sr1_mask, sr2_mask);
}
Example #5
0
// Wait until a byte has been sent
static inline void i2c_wait_send(i2c_t *obj) {
    uint32_t sr1_mask = I2C_SR1_BTF | I2C_SR1_TXE;
    uint32_t sr2_mask = I2C_SR2_MSL | I2C_SR2_BUSY | I2C_SR2_TRA;
    i2c_wait_status(obj, sr1_mask, sr2_mask);
}