Change NRF_APM USB detection code (#3939)

This commit is contained in:
todd-herbert 2024-05-22 08:58:05 +12:00 committed by GitHub
parent 040b851615
commit cdf86f4166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -555,14 +555,24 @@ void Power::readPowerStatus()
#ifdef NRF_APM // Section of code detects USB power on the RAK4631 and updates the power states. Takes 20 seconds or so to detect #ifdef NRF_APM // Section of code detects USB power on the RAK4631 and updates the power states. Takes 20 seconds or so to detect
// changes. // changes.
static nrfx_power_usb_state_t prev_nrf_usb_state = (nrfx_power_usb_state_t)-1; // -1 so that state detected at boot
nrfx_power_usb_state_t nrf_usb_state = nrfx_power_usbstatus_get(); nrfx_power_usb_state_t nrf_usb_state = nrfx_power_usbstatus_get();
if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) { // If state changed
powerFSM.trigger(EVENT_POWER_DISCONNECTED); if (nrf_usb_state != prev_nrf_usb_state) {
NRF_USB = OptFalse; // If changed to DISCONNECTED
} else { if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) {
powerFSM.trigger(EVENT_POWER_CONNECTED); powerFSM.trigger(EVENT_POWER_DISCONNECTED);
NRF_USB = OptTrue; NRF_USB = OptFalse;
}
// If changed to CONNECTED / READY
else {
powerFSM.trigger(EVENT_POWER_CONNECTED);
NRF_USB = OptTrue;
}
// Cache the current state
prev_nrf_usb_state = nrf_usb_state;
} }
#endif #endif
// Notify any status instances that are observing us // Notify any status instances that are observing us