Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions common/i2ckbd/i2ckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "i2ckbd.h"
#include "debug.h"

#if ENABLE_USB
#include "tusb.h"
#endif

static uint8_t i2c_inited = 0;

void init_i2c_kbd() {
Expand Down Expand Up @@ -30,7 +34,15 @@ int read_i2c_kbd() {
return -1;
}

#if ENABLE_USB
// Wait 16ms but service USB during the wait
for (int i = 0; i < 32; i++) {
sleep_us(500);
tud_task();
}
#else
sleep_ms(16);
#endif
retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) &buff, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
DEBUG_PRINT("I2C read err\n");
Expand Down Expand Up @@ -70,7 +82,15 @@ int read_battery() {
DEBUG_PRINT("Batt I2C write err\n");
return -1;
}
#if ENABLE_USB
// Wait 16ms but service USB during the wait
for (int i = 0; i < 32; i++) {
sleep_us(500);
tud_task();
}
#else
sleep_ms(16);
#endif
retval = i2c_read_timeout_us(I2C_KBD_MOD, I2C_KBD_ADDR, (unsigned char *) &buff, 2, false, 500000);
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
DEBUG_PRINT("Batt I2C read err\n");
Expand Down