M arch/atmega48p_i2c.h +9 -3
@@ 53,13 53,19 @@ static inline void i2c_init_master(uint3
mmregs->twcr = REG_TWCR_TWEN;
}
-/* wait for action to complete */
-static inline bool i2c_sync(uint8_t status)
+/* wait for action to complete - return status */
+static inline uint8_t i2c_sync_raw(void)
{
while (!(mmregs->twcr & REG_TWCR_TWINT))
;
- return (mmregs->twsr & REG_TWSR_STATUS_MASK) == status;
+ return mmregs->twsr & REG_TWSR_STATUS_MASK;
+}
+
+/* wait for action to complete - expect specified status */
+static inline bool i2c_sync(uint8_t status)
+{
+ return i2c_sync_raw() == status;
}
/* transmit a START condition */