diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-03-26 14:28:52 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-03-26 14:28:52 +0000 |
commit | 44578159320d9d9bf89e8ac3b4d21635e8a45f10 (patch) | |
tree | 83c1327b9b4b0956343130ea190b870ab8b1217d /os/hal/platforms/STM32/i2c_lld.c | |
parent | b2f4a22581819dfa9c7608d764d563f9146a4755 (diff) | |
download | ChibiOS-44578159320d9d9bf89e8ac3b4d21635e8a45f10.tar.gz ChibiOS-44578159320d9d9bf89e8ac3b4d21635e8a45f10.tar.bz2 ChibiOS-44578159320d9d9bf89e8ac3b4d21635e8a45f10.zip |
I2C. Some improvements.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2841 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/STM32/i2c_lld.c')
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index 154a735fa..cb75b6da2 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -195,8 +195,16 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) { if ((i2cp->id_state == I2C_MWAIT_TF) && (i2cp->id_i2c->SR1 & I2C_SR1_BTF)){ chSysLockFromIsr(); i2cp->id_i2c->CR2 &= (~I2C_CR2_ITEVTEN); // disable BTF interrupt - i2cp->id_slave_config->id_callback(i2cp, i2cp->id_slave_config); chSysUnlockFromIsr(); + /* now driver is ready to generate (re)start/stop condition. + * Callback function is good place to do that.*/ + i2cp->id_state = I2C_READY; + + if (i2cp->id_slave_config->id_callback != NULL) + i2cp->id_slave_config->id_callback(i2cp, i2cp->id_slave_config); + else /* If no callback function set - generate stop */ + i2c_lld_master_stop(i2cp); + return; } else{ // debugging trap @@ -455,7 +463,9 @@ void i2c_lld_master_start(I2CDriver *i2cp){ i2cp->id_i2c->CR1 |= I2C_CR1_START; while (i2cp->id_i2c->CR1 & I2C_CR1_START); - i2cp->id_i2c->CR2 |= I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN; // enable interrupts + /* enable interrupts from I2C hardware. They will disable in driver state + machine after the tranafer finish.*/ + i2cp->id_i2c->CR2 |= I2C_CR2_ITEVTEN | I2C_CR2_ITBUFEN; } void i2c_lld_master_stop(I2CDriver *i2cp){ |