Skip to content

Commit 4eafaa4

Browse files
meijemaccarlescufi
authored andcommitted
nrfs: usb vbus enable/disable: expand usb service
Add request to enable/disable D+ pull-up. Signed-off-by: Maciej Meijer <[email protected]>
1 parent 243c670 commit 4eafaa4

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

nrfs/include/internal/requests/nrfs_usb_reqs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern "C" {
1616
enum {
1717
NRFS_USB_REQ_ENABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x01),
1818
NRFS_USB_REQ_DISABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x02),
19+
NRFS_USB_REQ_DPLUS_PULLUP_ENABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x03),
20+
NRFS_USB_REQ_DPLUS_PULLUP_DISABLE = NRFS_REQUEST_ID_DEF(NRFS_SERVICE_ID_USB, 0x04),
1921
};
2022

2123
#ifdef __cplusplus

nrfs/include/internal/services/nrfs_usb.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ typedef struct __NRFS_PACKED {
3232
nrfs_ctx_t ctx; /**< Context of the message. */
3333
} nrfs_usb_disable_req_t;
3434

35+
/** @brief USB D+ pull-up enable request structure. */
36+
typedef struct __NRFS_PACKED {
37+
nrfs_hdr_t hdr; /**< Header of the message. */
38+
nrfs_ctx_t ctx; /**< Context of the message. */
39+
} nrfs_usb_ld_dplus_pullup_enable_req_t;
40+
41+
/** @brief USB D+ pull-up disable request structure. */
42+
typedef struct __NRFS_PACKED {
43+
nrfs_hdr_t hdr; /**< Header of the message. */
44+
nrfs_ctx_t ctx; /**< Context of the message. */
45+
} nrfs_usb_ld_dplus_pullup_disable_req_t;
46+
47+
3548
/** @brief USB VBUS detector service notification structure for enable request. */
3649
typedef struct __NRFS_PACKED {
3750
nrfs_hdr_t hdr; /**< Header of the message. */

nrfs/include/services/nrfs_usb.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ nrfs_err_t nrfs_usb_enable_request(void * p_context);
6969
*/
7070
nrfs_err_t nrfs_usb_disable_request(void * p_context);
7171

72+
/**
73+
* @brief Function for requesting to enable dplus pullup within the USB Service.
74+
*
75+
* @param[in] p_context Opaque user data that will be passed to registered callback.
76+
*
77+
* @retval NRFS_SUCCESS Request sent successfully.
78+
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
79+
* @retval NRFS_ERR_IPC Backend returned error during request sending.
80+
*/
81+
nrfs_err_t nrfs_usb_dplus_pullup_enable(void* p_context);
82+
83+
/**
84+
* @brief Function for requesting to disable dplus pullup within the USB Service.
85+
*
86+
* @param[in] p_context Opaque user data that will be passed to registered callback.
87+
*
88+
* @retval NRFS_SUCCESS Request sent successfully.
89+
* @retval NRFS_ERR_INVALID_STATE Service is uninitialized.
90+
* @retval NRFS_ERR_IPC Backend returned error during request sending.
91+
*/
92+
nrfs_err_t nrfs_usb_dplus_pullup_disable(void * p_context);
93+
94+
7295
#ifdef __cplusplus
7396
}
7497
#endif

nrfs/src/services/nrfs_usb.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,34 @@ nrfs_err_t nrfs_usb_disable_request(void *p_context)
8686

8787
return nrfs_backend_send(&req, sizeof(req));
8888
}
89+
90+
nrfs_err_t nrfs_usb_dplus_pullup_enable(void *p_context)
91+
{
92+
if (!m_cb.is_initialized) {
93+
return NRFS_ERR_INVALID_STATE;
94+
}
95+
96+
nrfs_usb_ld_dplus_pullup_enable_req_t req;
97+
98+
NRFS_SERVICE_HDR_FILL(&req, NRFS_USB_REQ_DPLUS_PULLUP_ENABLE);
99+
NRFS_HDR_NO_RSP_SET(&req.hdr);
100+
req.ctx.ctx = (uint32_t)p_context;
101+
102+
return nrfs_backend_send(&req, sizeof(req));
103+
}
104+
105+
nrfs_err_t nrfs_usb_dplus_pullup_disable(void *p_context)
106+
{
107+
if (!m_cb.is_initialized) {
108+
return NRFS_ERR_INVALID_STATE;
109+
}
110+
111+
nrfs_usb_ld_dplus_pullup_disable_req_t req;
112+
113+
NRFS_SERVICE_HDR_FILL(&req, NRFS_USB_REQ_DPLUS_PULLUP_DISABLE);
114+
NRFS_HDR_NO_RSP_SET(&req.hdr);
115+
req.ctx.ctx = (uint32_t)p_context;
116+
117+
return nrfs_backend_send(&req, sizeof(req));
118+
}
119+

0 commit comments

Comments
 (0)