mirror of
https://xff.cz/git/pinephone-keyboard/
synced 2024-11-09 22:15:42 +01:00
firmware: Implement USB enabled/disable control via I2C
This commit is contained in:
parent
134b4b6a8b
commit
176a2da7e2
1 changed files with 21 additions and 9 deletions
|
@ -1811,10 +1811,19 @@ void main(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get current system config
|
||||||
|
uint8_t cfg = REG_SYS(CONFIG);
|
||||||
|
__bit usb_enabled = !!(cfg & REG_SYS_CONFIG_USB_DEBUG_EN);
|
||||||
// if we were asked to jump to USB IAP, do it
|
// if we were asked to jump to USB IAP, do it
|
||||||
if (jump_to_usb_bootloader)
|
if (jump_to_usb_bootloader)
|
||||||
__asm__ ("ljmp _usb_bootloader_jump");
|
__asm__ ("ljmp _usb_bootloader_jump");
|
||||||
|
|
||||||
|
if (usb_initialized && !usb_enabled) {
|
||||||
|
usb_initialized = 0;
|
||||||
|
ticks = 0;
|
||||||
|
usb_disable();
|
||||||
|
}
|
||||||
|
|
||||||
// if the 20ms timer did not expire yet, check if we can
|
// if the 20ms timer did not expire yet, check if we can
|
||||||
// powerdown, otherwise busyloop
|
// powerdown, otherwise busyloop
|
||||||
if (!run_timed_tasks) {
|
if (!run_timed_tasks) {
|
||||||
|
@ -1830,7 +1839,7 @@ void main(void)
|
||||||
if (i2c_idle && !scan_active
|
if (i2c_idle && !scan_active
|
||||||
&& !p6_changed
|
&& !p6_changed
|
||||||
#if CONFIG_USB_STACK
|
#if CONFIG_USB_STACK
|
||||||
&& usb_initialized && usb_suspended
|
&& (usb_initialized || !usb_enabled) && usb_suspended
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_STOCK_FW
|
#if CONFIG_STOCK_FW
|
||||||
&& user_app_checked
|
&& user_app_checked
|
||||||
|
@ -1888,7 +1897,7 @@ void main(void)
|
||||||
|
|
||||||
#if CONFIG_USB_STACK
|
#if CONFIG_USB_STACK
|
||||||
// after 500ms, init usb
|
// after 500ms, init usb
|
||||||
if (!usb_initialized && ticks > 500 / 20) {
|
if (!usb_initialized && usb_enabled && ticks > 500 / 20) {
|
||||||
usb_init();
|
usb_init();
|
||||||
usb_initialized = 1;
|
usb_initialized = 1;
|
||||||
}
|
}
|
||||||
|
@ -1918,14 +1927,17 @@ void main(void)
|
||||||
ext_int_assert();
|
ext_int_assert();
|
||||||
delay_us(100);
|
delay_us(100);
|
||||||
ext_int_deassert();
|
ext_int_deassert();
|
||||||
#if CONFIG_USB_STACK
|
|
||||||
usb_key_change = 1;
|
|
||||||
|
|
||||||
// USB wakeup
|
#if CONFIG_USB_STACK
|
||||||
PAGESW = 1;
|
if (usb_enabled) {
|
||||||
if (P1_UDCCTRL & BIT(2)) {
|
usb_key_change = 1;
|
||||||
P1_UDCCTRL |= BIT(5);
|
|
||||||
P1_UDCCTRL &= ~BIT(5);
|
// USB wakeup
|
||||||
|
PAGESW = 1;
|
||||||
|
if (P1_UDCCTRL & BIT(2)) {
|
||||||
|
P1_UDCCTRL |= BIT(5);
|
||||||
|
P1_UDCCTRL &= ~BIT(5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue