You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@mynewt.apache.org by "kasjer (via GitHub)" <gi...@apache.org> on 2025/09/25 12:24:15 UTC
Re: [PR] tinyusb/da146xx/usb_monitor: Add usb monitor for da146xx [mynewt-core]
kasjer commented on code in PR #3496:
URL: https://github.com/apache/mynewt-core/pull/3496#discussion_r2378117116
##########
hw/usb/tinyusb/da146xx/include/tusb_hw.h:
##########
@@ -22,9 +22,28 @@
#define CFG_TUSB_MCU OPT_MCU_DA1469X
+#include <os/mynewt.h>
#include <syscfg/syscfg.h>
#include <stdbool.h>
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
+/**
+ * Set event queue for USB monitoring
+ */
+void tinyusb_da146xx_usb_monitor_evq_set(struct os_eventq *evq);
+
+/**
+ *
+ * Register callback for USB state monitor changes
+ */
+void tinyusb_da146xx_usb_monitor_register_cb(void (*cb)(bool connected));
+#endif
+
+/**
+ * Check if USB is connected (based on keep-alive and VBUS if used)
Review Comment:
What keep-alive means here?
It's not clear when this function should return true
##########
hw/usb/tinyusb/da146xx/src/da1469x.c:
##########
@@ -49,6 +52,27 @@ tinyusb_vbus_changed(bool present)
}
}
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
+static void
+da1469x_da146xx_usb_monitor_cb(bool connected)
+{
+ /* Trigger vbus change if not using VBUS detection
+ * or if using custom VBUS handling
+ */
+ if (MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, ignore) ||
+ MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, custom)) {
+ tinyusb_vbus_changed(connected);
+ }
+}
+#endif /* MYNEWT_VAL(DA146XX_USB_MONITOR) */
+
+static void
Review Comment:
There is no reason to move `USBD_IRQHandler()` function around
##########
hw/usb/tinyusb/da146xx/src/da1469x.c:
##########
@@ -66,9 +90,59 @@ tinyusb_hardware_init(void)
if (MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, auto)) {
/* If VBUS handling is set to 'auto' let da1469x_vbus module handle notification */
da1469x_vbus_add_handler(tinyusb_vbus_changed);
- }
- else if (MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, ignore)) {
+ } else if (MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, ignore) ||
+ MYNEWT_VAL_CHOICE(DA1469X_USB_VBUS_HANDLING, custom)) {
/* If VBUS handling is ignored notify TinyUSB that VBUS is on */
- tinyusb_vbus_changed(true);
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
+ /* With USB Monitor enabled, don't immediately notify VBUS on
+ * Wait for actual USB activity (Setup packet) to be detected
+ * by USB Monitor before notifying TinyUSB of VBUS presence.
Review Comment:
This comment looks strange.
VBUS notification is normally used to connect USB device to host by connection pull up resistor.
If application for some reason ignores VBUS (present of not) and makes call to tusb_connect(0) to start activity on USB, I don't see any reason to later notify USB about VBUS that will call tusb_connect again.
First call will start USB activity regardless of VBUS.
VBUS is not used for anything else apart from initiating connection and disconnecting when it's gone.
##########
hw/usb/tinyusb/da146xx/src/da1469x.c:
##########
@@ -24,21 +24,24 @@
#include <device/usbd.h>
-static bool vbus_present;
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
-static void
-USBD_IRQHandler(void)
-{
- tud_int_handler(0);
-}
+#ifdef MYNEWT_VAL_DA146XX_USB_MONITOR_EVQ
+struct os_eventq MYNEWT_VAL(DA146XX_USB_MONITOR_EVQ);
+#endif
+
+#include <da146xx_usb_monitor/da146xx_usb_monitor.h>
+#endif
+
+static bool g_vbus_present;
Review Comment:
changing variable name here is not necessary
##########
hw/usb/tinyusb/da146xx/src/da1469x.c:
##########
@@ -24,21 +24,24 @@
#include <device/usbd.h>
-static bool vbus_present;
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
-static void
-USBD_IRQHandler(void)
-{
- tud_int_handler(0);
-}
+#ifdef MYNEWT_VAL_DA146XX_USB_MONITOR_EVQ
+struct os_eventq MYNEWT_VAL(DA146XX_USB_MONITOR_EVQ);
Review Comment:
Having event queue specified in syscfg would make sense if code use existing specific queue that should be shared instead of default queue.
Variable name specified in syscfg is a bit strange, provided that no header exposes it anyway.
##########
hw/usb/tinyusb/da146xx/src/da1469x.c:
##########
@@ -24,21 +24,24 @@
#include <device/usbd.h>
-static bool vbus_present;
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
-static void
-USBD_IRQHandler(void)
-{
- tud_int_handler(0);
-}
+#ifdef MYNEWT_VAL_DA146XX_USB_MONITOR_EVQ
+struct os_eventq MYNEWT_VAL(DA146XX_USB_MONITOR_EVQ);
+#endif
+
+#include <da146xx_usb_monitor/da146xx_usb_monitor.h>
+#endif
+
+static bool g_vbus_present;
static void
tinyusb_vbus_changed(bool present)
{
- if (vbus_present == present) {
+ if (g_vbus_present == present) {
Review Comment:
Code change here due to unnecessary variable name change
##########
hw/usb/tinyusb/da146xx/include/tusb_hw.h:
##########
@@ -22,9 +22,28 @@
#define CFG_TUSB_MCU OPT_MCU_DA1469X
+#include <os/mynewt.h>
#include <syscfg/syscfg.h>
#include <stdbool.h>
+#if MYNEWT_VAL(DA146XX_USB_MONITOR)
+/**
+ * Set event queue for USB monitoring
+ */
+void tinyusb_da146xx_usb_monitor_evq_set(struct os_eventq *evq);
+
+/**
+ *
+ * Register callback for USB state monitor changes
+ */
+void tinyusb_da146xx_usb_monitor_register_cb(void (*cb)(bool connected));
+#endif
+
+/**
+ * Check if USB is connected (based on keep-alive and VBUS if used)
+ */
+bool tinyusb_da146xx_is_connected(void);
Review Comment:
Body of this function is not available when DA146XX_USB_MONITOR is not set
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@mynewt.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org