Browse Source

kimera: Change procedure when i2c timeout

kimera
Kai Ryu 9 years ago
parent
commit
34de691cde
1 changed files with 15 additions and 11 deletions
  1. 15
    11
      keyboard/kimera/kimera.c

+ 15
- 11
keyboard/kimera/kimera.c View File

@@ -28,7 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kimera.h"
#include "debug.h"

#define SCL_CLOCK 400000L
#define SCL_CLOCK 400000L
#define SCL_DURATION (1000000L/SCL_CLOCK)/2
extern uint8_t i2c_force_stop;

uint8_t row_mapping[PX_COUNT] = {
@@ -296,19 +297,22 @@ ISR(WDT_vect)
{
dprintf("i2c timeout\n");

/* send stop condition */
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
TWCR = 0;

/* let slave to release SDA */
DDRD |= (1<<PD0);
for (uint8_t i = 0; i < 9; i++) {
PORTD &= ~(1<<PD0);
_delay_us((F_CPU / SCL_CLOCK - 16) / 2);
PORTD |= (1<<PD0);
_delay_us((F_CPU / SCL_CLOCK - 16) / 2);
TWCR = 0;
DDRD |= (1<<PD0);
DDRD &= ~(1<<PD1);
if (!(PIND & (1<<PD1))) {
for (uint8_t i = 0; i < 9; i++) {
PORTD &= ~(1<<PD0);
_delay_us(SCL_DURATION);
PORTD |= (1<<PD0);
_delay_us(SCL_DURATION);
}
}

/* send stop condition */
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);

/* escape from loop */
i2c_force_stop = 1;
}