1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NRFS_USB_H 8 #define NRFS_USB_H 9 10 #include <internal/services/nrfs_usb.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** @brief USB VBUS detector service event types. */ 17 typedef enum __NRFS_PACKED { 18 NRFS_USB_EVT_VBUS_STATUS_CHANGE, /** VBUS voltage detection status has changed. */ 19 NRFS_USB_EVT_REJECT, /** Request rejected. */ 20 } nrfs_usb_evt_type_t; 21 22 /** @brief USB VBUS detector service event. */ 23 typedef struct { 24 nrfs_usb_evt_type_t type; /** Event type. */ 25 bool vbus_detected; /** True if USB VBUS voltage is detected. */ 26 bool vregusb_ok; /** True if VREG is running OK. */ 27 bool usbhspll_ok; /** True if PLL is running OK. */ 28 } nrfs_usb_evt_t; 29 30 /** @brief USB VBUS detector service event handler type. */ 31 typedef void (*nrfs_usb_evt_handler_t)(nrfs_usb_evt_t const * p_evt, void * context); 32 33 /** 34 * @brief Function for initializing the USB VBUS detector service. 35 * 36 * @param[in] handler Function called as a response to the request. 37 * 38 * @retval NRFS_SUCCESS Service initialized successfully. 39 * @retval NRFS_ERR_INVALID_STATE Service was already initialized. 40 */ 41 nrfs_err_t nrfs_usb_init(nrfs_usb_evt_handler_t handler); 42 43 /** 44 * @brief Function for uninitializing the USB VBUS detector service. 45 * 46 * @warning Notifications from previous requests are dropped after service uninitialization. 47 */ 48 void nrfs_usb_uninit(void); 49 50 /** 51 * @brief Function for requesting USBHSPLL and VREGUSB to be enabled and configured in USB VBUS detector service. 52 * 53 * @param[in] p_context Opaque user data that will be passed to registered callback. 54 * 55 * @retval NRFS_SUCCESS Request sent successfully. 56 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 57 * @retval NRFS_ERR_IPC Backend returned error during request sending. 58 */ 59 nrfs_err_t nrfs_usb_enable_request(void * p_context); 60 61 /** 62 * @brief Function for requesting USBHSPLL and VREGUSB to be disabled in USB VBUS detector service. 63 * 64 * @param[in] p_context Opaque user data that will be passed to registered callback. 65 * 66 * @retval NRFS_SUCCESS Request sent successfully. 67 * @retval NRFS_ERR_INVALID_STATE Service is uninitialized. 68 * @retval NRFS_ERR_IPC Backend returned error during request sending. 69 */ 70 nrfs_err_t nrfs_usb_disable_request(void * p_context); 71 72 #ifdef __cplusplus 73 } 74 #endif 75 76 #endif /* NRFS_USB_H */ 77