fix I2C shit? I think

This commit is contained in:
Arisotura
2019-06-15 17:23:48 +02:00
parent 58e3ff61ac
commit 93330d2670
2 changed files with 51 additions and 35 deletions

View File

@ -59,6 +59,10 @@ u32 NWRAMMask[2][3];
void Reset() void Reset()
{ {
//NDS::ARM9->CP15Write(0x910, 0x0D00000A);
//NDS::ARM9->CP15Write(0x911, 0x00000020);
//NDS::ARM9->CP15Write(0x100, NDS::ARM9->CP15Read(0x100) | 0x00050000);
NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM9->JumpTo(BootAddr[0]);
NDS::ARM7->JumpTo(BootAddr[1]); NDS::ARM7->JumpTo(BootAddr[1]);

View File

@ -103,6 +103,8 @@ namespace DSi_I2C
{ {
u8 Cnt; u8 Cnt;
u8 Data;
u32 Device; u32 Device;
bool Init() bool Init()
@ -119,6 +121,9 @@ void DeInit()
void Reset() void Reset()
{ {
Cnt = 0;
Data = 0;
Device = -1; Device = -1;
DSi_BPTWL::Reset(); DSi_BPTWL::Reset();
@ -126,60 +131,67 @@ void Reset()
void WriteCnt(u8 val) void WriteCnt(u8 val)
{ {
printf("I2C: write CNT %02X\n", val);
val &= 0xF7; val &= 0xF7;
// TODO: check ACK flag // TODO: check ACK flag
// TODO: transfer delay // TODO: transfer delay
// TODO: IRQ
// TODO: check read/write direction
if (val & (1<<7)) if (val & (1<<7))
{ {
if (val & (1<<2)) bool islast = Cnt & (1<<0);
if (val & (1<<5))
{ {
Device = -1; // read
printf("I2C: start\n"); printf("I2C read, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast);
switch (Device)
{
case 0x4A: Data = DSi_BPTWL::Read(islast); break;
default: Data = 0; break;
} }
} }
else
{
// write
printf("I2C write, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast);
if (val & (1<<1))
{
Device = Data;
printf("I2C: start, device=%02X\n", Device);
switch (Device)
{
case 0x4A: DSi_BPTWL::Start(); return;
}
}
else
{
switch (Device)
{
case 0x4A: DSi_BPTWL::Write(Data, islast); break;
}
}
}
val &= 0x7F;
}
Cnt = val; Cnt = val;
} }
u8 ReadData() u8 ReadData()
{ {
switch (Device) return Data;
{
case 0x4A: return DSi_BPTWL::Read(Cnt & (1<<0));
default:
printf("I2C: read from unknown device %02X\n", Device);
break;
}
return 0;
} }
void WriteData(u8 val) void WriteData(u8 val)
{ {
if (Device == -1) Data = val;
{
Device = val;
switch (Device)
{
case 0x4A: DSi_BPTWL::Start(); return;
default:
printf("I2C: start on unknown device %02X\n", Device);
break;
}
return;
}
switch (Device)
{
case 0x4A: DSi_BPTWL::Write(val, Cnt & (1<<0)); return;
default:
printf("I2C: write to unknown device %02X\n", Device);
break;
}
} }
} }