1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 17:25:20 +03:00

Work-in-progress.

This commit is contained in:
Dominic Clifton 2014-09-05 20:47:19 +01:00
parent 0c77e27f33
commit 9ce6dde1e7
5 changed files with 289 additions and 5 deletions

View file

@ -119,8 +119,9 @@ bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
if (!(I2Cx->CR2 & I2C_IT_EVT)) { // if we are restarting the driver
if (!(I2Cx->CR1 & 0x0100)) { // ensure sending a start
while (I2Cx->CR1 & 0x0200 && --timeout > 0) { ; } // wait for any stop to finish sending
if (timeout == 0)
if (timeout == 0) {
return i2cHandleHardwareFailure();
}
I2C_GenerateSTART(I2Cx, ENABLE); // send the start for the new job
}
I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, ENABLE); // allow the interrupts to fire off again
@ -128,8 +129,9 @@ bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
timeout = I2C_DEFAULT_TIMEOUT;
while (busy && --timeout > 0) { ; }
if (timeout == 0)
if (timeout == 0) {
return i2cHandleHardwareFailure();
}
return !error;
}
@ -173,11 +175,12 @@ bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
static void i2c_er_handler(void)
{
// Read the I2C1 status register
// Read the I2Cx status register
volatile uint32_t SR1Register = I2Cx->SR1;
if (SR1Register & 0x0F00) // an error
if (SR1Register & 0x0F00) { // an error
error = true;
}
// If AF, BERR or ARLO, abandon the current job and commence new if there are jobs
if (SR1Register & 0x0700) {