From 3c83b59b53bf783a626c4185f61ea6f70706e330 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 6 Feb 2022 13:14:53 +1100 Subject: [PATCH] Expose Vbus --- source/Core/Drivers/USBPD.cpp | 11 +++++++++++ source/Core/Drivers/USBPD.h | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/Core/Drivers/USBPD.cpp b/source/Core/Drivers/USBPD.cpp index c2d7abef..d992763b 100644 --- a/source/Core/Drivers/USBPD.cpp +++ b/source/Core/Drivers/USBPD.cpp @@ -67,6 +67,17 @@ bool USBPowerDelivery::fusbPresent() { return detectionState == 1; } +bool USBPowerDelivery::isVBUSConnected() { + // Check the status reg + + FUSB302::fusb_status status; + if (fusb.fusb_get_status(&status)) { + return status.status0 & 0x80; + } + // As we are using this to detect the mod fail safe + return true; +} + bool pdbs_dpm_evaluate_capability(const pd_msg *capabilities, pd_msg *request) { /* Get the number of PDOs */ diff --git a/source/Core/Drivers/USBPD.h b/source/Core/Drivers/USBPD.h index bd41297b..7e27dbea 100644 --- a/source/Core/Drivers/USBPD.h +++ b/source/Core/Drivers/USBPD.h @@ -16,9 +16,9 @@ public: static void PPSTimerCallback(); // PPS Timer static void IRQOccured(); // Thread callback that an irq occured static void step(); // Iterate the step machine - static bool negotiationHasWorked(); // - static uint8_t getStateNumber(); // - + static bool negotiationHasWorked(); // Has PD negotiation worked (are we in a PD contract) + static uint8_t getStateNumber(); // Debugging - Get the internal state number + static bool isVBUSConnected(); // Is the VBus pin connected on the FUSB302 private: // static int detectionState;