More hacking:
* initial Wii Motion+ support * initial timer support
This commit is contained in:
36
i2c.c
36
i2c.c
@@ -29,8 +29,13 @@ void init_i2c(void)
|
||||
IWREG(I2SCLL) = (25 * 100);
|
||||
IWREG(I2SCLH) = (12 * 100);
|
||||
#else
|
||||
# if 0
|
||||
IWREG(I2SCLL) = 1475; /* ~5kHz */
|
||||
IWREG(I2SCLH) = 1475;
|
||||
# else
|
||||
IWREG(I2SCLL) = 73; /* ~100kHz */
|
||||
IWREG(I2SCLH) = 73;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -45,11 +50,6 @@ int i2c_wait(void)
|
||||
return stat;
|
||||
}
|
||||
|
||||
void i2c_go(void)
|
||||
{
|
||||
IREG(I2CONCLR) = SIFLAG;
|
||||
}
|
||||
|
||||
int i2c_conreg(void)
|
||||
{
|
||||
return IREG(I2CONSET);
|
||||
@@ -64,14 +64,12 @@ bool i2c_send_start(void)
|
||||
{
|
||||
IREG(I2CONCLR) = STOFLAG | STAFLAG;
|
||||
IREG(I2CONSET) = STAFLAG;
|
||||
/* i2c_go(); */
|
||||
switch (i2c_wait()) {
|
||||
case 0x08:
|
||||
case 0x10:
|
||||
/* IREG(I2CONCLR) = STAFLAG; */
|
||||
return TRUE;
|
||||
default:
|
||||
/* IREG(I2CONCLR) = STAFLAG; */
|
||||
i2c_send_stop();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -84,12 +82,30 @@ bool i2c_send_address(int addr, bool write)
|
||||
bool i2c_send_data(int data)
|
||||
{
|
||||
IREG(I2DAT) = data;
|
||||
IREG(I2CONCLR) = STAFLAG | SIFLAG;
|
||||
IREG(I2CONCLR) = STAFLAG | STOFLAG | SIFLAG;
|
||||
switch (i2c_wait()) {
|
||||
case 0x18:
|
||||
case 0x28:
|
||||
case 0x40:
|
||||
return TRUE;
|
||||
default:
|
||||
i2c_send_stop();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
bool i2c_receive_data(int *data, bool last)
|
||||
{
|
||||
if (!last)
|
||||
IREG(I2CONSET) = AAFLAG;
|
||||
IREG(I2CONCLR) = STAFLAG | STOFLAG | SIFLAG | (last?AAFLAG:0);
|
||||
switch (i2c_wait()) {
|
||||
case 0x50:
|
||||
case 0x58:
|
||||
*data = IREG(I2DAT);
|
||||
return TRUE;
|
||||
default:
|
||||
i2c_send_stop();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +114,7 @@ void i2c_send_stop(void)
|
||||
{
|
||||
IREG(I2CONCLR) = STAFLAG | AAFLAG;
|
||||
IREG(I2CONSET) = STOFLAG;
|
||||
i2c_go();
|
||||
IREG(I2CONCLR) = SIFLAG;
|
||||
/* Don't think we need to wait here. Could be wrong. */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user