Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ralim/usb-pd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen V. Brown <Ralim@Ralimtek.com>2022-02-06 06:41:37 +0300
committerBen V. Brown <Ralim@Ralimtek.com>2022-02-06 06:41:37 +0300
commitb38598261df4f705bcbd37cdd5dcccfaa5ab7b4a (patch)
tree5982ea2bbc962d24d0d11dc114a28547c3431a1f
parent4c5a5625bab7191b77147e1ef1bd6e2705f9e640 (diff)
Add logic to test VBus connectivity
-rw-r--r--include/fusb302b.h3
-rw-r--r--src/fusb302b.cpp18
2 files changed, 21 insertions, 0 deletions
diff --git a/include/fusb302b.h b/include/fusb302b.h
index ce473c5..ad41366 100644
--- a/include/fusb302b.h
+++ b/include/fusb302b.h
@@ -82,6 +82,9 @@ public:
bool runCCLineSelection() const;
+ // Measure VBus with the MADC and check if its connected
+ bool isVBUSConnected() const;
+
private:
const uint8_t DeviceAddress; // I2C address for this device
// I2C bus access functions, should return true if command worked
diff --git a/src/fusb302b.cpp b/src/fusb302b.cpp
index 10b5153..c2792f8 100644
--- a/src/fusb302b.cpp
+++ b/src/fusb302b.cpp
@@ -189,6 +189,24 @@ bool FUSB302::runCCLineSelection() const {
}
return true;
}
+
+bool FUSB302::isVBUSConnected() const {
+ // So we want to set MEAS_VBUS to enable measuring the VBus signal
+ // Then check the status
+ uint8_t measureBackup = fusb_read_byte(FUSB_MEASURE);
+ uint8_t switchesBackup = fusb_read_byte(FUSB_SWITCHES0);
+ // clear MEAS_CCx bits
+ fusb_write_byte(FUSB_SWITCHES0, switchesBackup & 0b11110011);
+ osDelay(10);
+ fusb_write_byte(FUSB_MEASURE, 0b01000000);
+ osDelay(100);
+ uint8_t status = fusb_read_byte(FUSB_STATUS0);
+ // Write back original value
+ fusb_write_byte(FUSB_MEASURE, measureBackup);
+ fusb_write_byte(FUSB_SWITCHES0, switchesBackup);
+ return (status & (0b00100000)) != 0;
+}
+
bool FUSB302::fusb_get_status(fusb_status *status) const {
/* Read the interrupt and status flags into status */