Bye bye Wii Motion Plus, hello MPU6050. Also, increase control loop

to 200Hz, add SD card logging, and a number of other changes.
This commit is contained in:
2014-05-06 21:03:48 +00:00
parent b482b85ffd
commit e8adff93c1
25 changed files with 1725 additions and 581 deletions

10
i2c.c
View File

@@ -33,8 +33,12 @@ void init_i2c(void)
IREG(I2CONSET) = 0x40; /* Enable I2C ready for Master Tx */
/* Set up for just under 400kHz */
#ifdef I2C_FAST
#if 0
IWREG(I2SCLL) = (25 * 100);
IWREG(I2SCLH) = (12 * 100);
#endif
IWREG(I2SCLL) = 25 * 4; /* ~400kHz */
IWREG(I2SCLH) = 12 * 4;
#else
IWREG(I2SCLL) = 73; /* ~100kHz */
IWREG(I2SCLH) = 73;
@@ -106,10 +110,10 @@ void __attribute__((interrupt("IRQ"))) i2c_interrupt_handler(void)
IREG(I2CONSET) = STAFLAG;
IREG(I2CONCLR) = STOFLAG | AAFLAG | SIFLAG;
} else {
event_set(i2c_transaction->event);
i2c_transaction = NULL;
IREG(I2CONSET) = STOFLAG;
IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG;
event_set(EVENT_I2C_COMPLETE);
}
}
break;
@@ -137,10 +141,10 @@ void __attribute__((interrupt("IRQ"))) i2c_interrupt_handler(void)
IREG(I2CONSET) = STAFLAG;
IREG(I2CONCLR) = STOFLAG | AAFLAG | SIFLAG;
} else {
event_set(i2c_transaction->event);
i2c_transaction = NULL;
IREG(I2CONSET) = STOFLAG;
IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG;
event_set(EVENT_I2C_COMPLETE);
}
break;
@@ -150,10 +154,10 @@ void __attribute__((interrupt("IRQ"))) i2c_interrupt_handler(void)
case 0x38: /* arbitration lost during SA+W or data */
case 0x00: /* bus error */
*(i2c_transaction->result) = I2C_FAIL;
event_set(i2c_transaction->event);
i2c_transaction = NULL;
IREG(I2CONSET) = STOFLAG;
IREG(I2CONCLR) = STAFLAG | AAFLAG | SIFLAG;
event_set(EVENT_I2C_COMPLETE);
break;
/* We don't handle slave mode */