Don't spam the MCU with reads (in hid.c)

This commit is contained in:
d0k3 2017-08-01 16:55:52 +02:00
parent cb694689aa
commit 90a7705d21

View File

@ -7,7 +7,8 @@ u32 InputWait() {
u32 pad_state_old = HID_STATE;
u32 cart_state_old = CART_STATE;
u32 sd_state_old = SD_STATE;
u64 timer = timer_start();
u64 timer_dpad = timer_start();
u64 timer_mcu = timer_dpad;
delay = (delay) ? 72 : 128;
while (true) {
u32 pad_state = HID_STATE;
@ -19,11 +20,12 @@ u32 InputWait() {
if (sd_state != sd_state_old)
return sd_state ? SD_INSERT : SD_EJECT;
u8 special_key;
if (I2C_readRegBuf(I2C_DEV_MCU, 0x10, &special_key, 1)) {
if ((timer_msec(timer_mcu) >= 64) && (I2C_readRegBuf(I2C_DEV_MCU, 0x10, &special_key, 1))) {
if (special_key == 0x01)
return pad_state | BUTTON_POWER;
else if (special_key == 0x04)
return pad_state | BUTTON_HOME;
timer_mcu = timer_start();
}
pad_state_old = pad_state;
delay = 0;
@ -31,7 +33,7 @@ u32 InputWait() {
}
if ((pad_state == pad_state_old) &&
(!(pad_state & BUTTON_ARROW) ||
(delay && (timer_msec(timer) < delay))))
(delay && (timer_msec(timer_dpad) < delay))))
continue;
// make sure the key is pressed
u32 t_pressed = 0;