From c1c43b3c8351db111f484e3f4e40d137db3c78df Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 7 Aug 2018 13:33:44 +0700 Subject: [PATCH] nrfx power --- src/Makefile | 11 +++++++---- src/main.c | 10 +++------- src/usb/usb.c | 12 +++--------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Makefile b/src/Makefile index 1ceacf9..ae7bdd1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -113,6 +113,10 @@ endif C_SOURCE_FILES += $(SRC_PATH)/main.c C_SOURCE_FILES += $(SRC_PATH)/dfu_ble_svc.c +# nrfx + +C_SOURCE_FILES += $(NRFX_PATH)/drivers/src/nrfx_power.c + # SDK 11 files C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader.c C_SOURCE_FILES += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c @@ -189,15 +193,16 @@ endif #****************************************************************************** # src -IPATH += $(SRC_PATH)/ +IPATH += $(SRC_PATH) IPATH += $(SRC_PATH)/cmsis/include IPATH += $(SRC_PATH)/usb -IPATH += $(TUSB_PATH)/ +IPATH += $(TUSB_PATH) # nrfx IPATH += $(NRFX_PATH) IPATH += $(NRFX_PATH)/mdk IPATH += $(NRFX_PATH)/hal +IPATH += $(NRFX_PATH)/drivers/include IPATH += $(SDK11_PATH)/libraries/bootloader_dfu/hci_transport IPATH += $(SDK11_PATH)/libraries/bootloader_dfu @@ -221,8 +226,6 @@ IPATH += $(SDK_PATH)/libraries/hci IPATH += $(SDK_PATH)/drivers_nrf/delay #IPATH += $(SDK_PATH)/drivers_nrf/uart #IPATH += $(SDK_PATH)/drivers_nrf/power -#IPATH += $(SDK_PATH)/drivers_nrf/usbd -#IPATH += $(SDK_PATH)/device # Softdevice IPATH += $(SD_PATH)/headers diff --git a/src/main.c b/src/main.c index a50e279..6c9e5e1 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,8 @@ #include #include #include +#include "nrfx.h" +#include "nrfx_power.h" #include "nordic_common.h" #include "sdk_common.h" @@ -38,6 +40,7 @@ #include "bootloader.h" #include "bootloader_util.h" + #include "nrf.h" #include "nrf_soc.h" #include "nrf_nvic.h" @@ -69,13 +72,6 @@ void usb_teardown(void); * We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */ extern void tusb_hal_nrf_power_event(uint32_t event); -// TODO fully move to nrfx -enum { - NRFX_POWER_USB_EVT_DETECTED, /**< USB power detected on the connector (plugged in). */ - NRFX_POWER_USB_EVT_REMOVED, /**< USB power removed from the connector. */ - NRFX_POWER_USB_EVT_READY /**< USB power regulator ready. */ -}; - #else #define usb_init() diff --git a/src/usb/usb.c b/src/usb/usb.c index 974630d..16ec6a6 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -34,6 +34,9 @@ */ /**************************************************************************/ +#include "nrfx.h" +#include "nrfx_power.h" + #ifdef SOFTDEVICE_PRESENT #include "nrf_sdm.h" #include "nrf_soc.h" @@ -42,13 +45,6 @@ #include "nrf_usbd.h" #include "tusb.h" -// TODO fully move to nrfx -enum { - NRFX_POWER_USB_EVT_DETECTED, /**< USB power detected on the connector (plugged in). */ - NRFX_POWER_USB_EVT_REMOVED, /**< USB power removed from the connector. */ - NRFX_POWER_USB_EVT_READY /**< USB power regulator ready. */ -}; - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ @@ -78,7 +74,6 @@ void usb_init(void) }else #endif { -#if 0 // TODO enable // Power module init const nrfx_power_config_t pwr_cfg = { 0 }; nrfx_power_init(&pwr_cfg); @@ -90,7 +85,6 @@ void usb_init(void) nrfx_power_usbevt_enable(); usb_reg = NRF_POWER->USBREGSTATUS; -#endif } if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) {