summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerzy Kasenberg <[email protected]>2021-09-17 11:48:38 +0200
committerJerzy Kasenberg <[email protected]>2021-09-17 12:20:57 +0200
commita71ac71d7f9fda4f72b02148a194987821864fa4 (patch)
tree9eef48a6f4cf4386c0121a4ab45a162c86319483
parent6d8677a78ab4973ff498ec2fe8ea40a1cde230a1 (diff)
da1469x_dk_xxx: Add VBUS handling
Two BSPs with DA146xx MCUs are now adopted to VBUS handling changed introduced to dcd_da146xx driver. da14695_dk_usb as bus-powered devices informs driver that VBUS is present at startup. da1469x-dk-pro has VBUS change interrupt handler that informs driver about VBUS changes.
-rw-r--r--hw/bsp/da14695_dk_usb/da14695_dk_usb.c9
-rw-r--r--hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c26
2 files changed, 33 insertions, 2 deletions
diff --git a/hw/bsp/da14695_dk_usb/da14695_dk_usb.c b/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
index e7c7ae364..bdb30e0e5 100644
--- a/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
+++ b/hw/bsp/da14695_dk_usb/da14695_dk_usb.c
@@ -53,6 +53,9 @@ void UnhandledIRQ(void)
while(1);
}
+// DA146xx driver function that must be called whenever VBUS changes.
+extern void tusb_vbus_changed(bool present);
+
void board_init(void)
{
// LED
@@ -70,7 +73,10 @@ void board_init(void)
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
- NVIC_SetPriority(USB_IRQn, 2);
+#if TUSB_OPT_DEVICE_ENABLED
+ // This board is USB powered there is no need to monitor
+ // VBUS line. Notify driver that VBUS is present.
+ tusb_vbus_changed(true);
/* Setup USB IRQ */
NVIC_SetPriority(USB_IRQn, 2);
@@ -81,6 +87,7 @@ void board_init(void)
mcu_gpio_set_pin_function(14, MCU_GPIO_MODE_INPUT, MCU_GPIO_FUNC_USB);
mcu_gpio_set_pin_function(15, MCU_GPIO_MODE_INPUT, MCU_GPIO_FUNC_USB);
+#endif
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c b/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
index 85fa17152..2b6931e4e 100644
--- a/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
+++ b/hw/bsp/da1469x_dk_pro/da1469x-dk-pro.c
@@ -36,6 +36,21 @@ void USB_IRQHandler(void)
tud_int_handler(0);
}
+#if TUSB_OPT_DEVICE_ENABLED
+// DA146xx driver function that must be called whenever VBUS changes
+extern void tusb_vbus_changed(bool present);
+
+// VBUS change interrupt handler
+void VBUS_IRQHandler(void)
+{
+ bool present = (CRG_TOP->ANA_STATUS_REG & CRG_TOP_ANA_STATUS_REG_VBUS_AVAILABLE_Msk) != 0;
+ // Clear VBUS interrupt
+ CRG_TOP->VBUS_IRQ_CLEAR_REG = 1;
+
+ tusb_vbus_changed(present);
+}
+#endif
+
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
@@ -70,7 +85,15 @@ void board_init(void)
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
- NVIC_SetPriority(USB_IRQn, 2);
+#if TUSB_OPT_DEVICE_ENABLED
+ // Setup interrupt for both connect and disconnect
+ CRG_TOP->VBUS_IRQ_MASK_REG = CRG_TOP_VBUS_IRQ_MASK_REG_VBUS_IRQ_EN_FALL_Msk |
+ CRG_TOP_VBUS_IRQ_MASK_REG_VBUS_IRQ_EN_RISE_Msk;
+ NVIC_SetPriority(VBUS_IRQn, 2);
+ // Trigger interrupt at the start to inform driver about VBUS state at start
+ // otherwise it could go unnoticed.
+ NVIC_SetPendingIRQ(VBUS_IRQn);
+ NVIC_EnableIRQ(VBUS_IRQn);
/* Setup USB IRQ */
NVIC_SetPriority(USB_IRQn, 2);
@@ -81,6 +104,7 @@ void board_init(void)
mcu_gpio_set_pin_function(14, MCU_GPIO_MODE_INPUT, MCU_GPIO_FUNC_USB);
mcu_gpio_set_pin_function(15, MCU_GPIO_MODE_INPUT, MCU_GPIO_FUNC_USB);
+#endif
}
//--------------------------------------------------------------------+