drivers: usb_dc_nrfx: move to new logger
Move to new logger and apply style guidelines. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
86ad1bd03d
commit
80ced11209
1 changed files with 176 additions and 176 deletions
|
@ -25,9 +25,9 @@
|
|||
#include <nrfx_usbd.h>
|
||||
|
||||
|
||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_USB_DRIVER_LEVEL
|
||||
#define SYS_LOG_DOMAIN "usb/nrfx"
|
||||
#include <logging/sys_log.h>
|
||||
#define LOG_LEVEL CONFIG_USB_DRIVER_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(usb_nrfx);
|
||||
|
||||
#define USB_BMREQUEST_SETADDRESS 0x05
|
||||
#define USB_BMREQUESTTYPE_POS 7uL
|
||||
|
@ -35,17 +35,17 @@
|
|||
#define USB_BMREQUESTTYPE_HOSTTODEVICE_MASK 0uL
|
||||
#define USB_BMREQUESTTYPE_DEVICETOHOST_MASK (1uL << USB_BMREQUESTTYPE_POS)
|
||||
|
||||
#define MAX_EP_BUF_SZ 64UL
|
||||
#define MAX_ISO_EP_BUF_SZ 1024UL
|
||||
#define MAX_EP_BUF_SZ 64UL
|
||||
#define MAX_ISO_EP_BUF_SZ 1024UL
|
||||
|
||||
#define USBD_EPSTATUS_EPIN_MASK (0x1FF << USBD_EPSTATUS_EPIN0_Pos)
|
||||
#define USBD_EPSTATUS_EPOUT_MASK (0x1FF << USBD_EPSTATUS_EPOUT0_Pos)
|
||||
#define USBD_EPDATASTATUS_EPIN_MASK (0x7F << USBD_EPDATASTATUS_EPIN1_Pos)
|
||||
#define USBD_EPDATASTATUS_EPOUT_MASK (0x7F << USBD_EPDATASTATUS_EPOUT1_Pos)
|
||||
#define USBD_EPSTATUS_EPIN_MASK (0x1FF << USBD_EPSTATUS_EPIN0_Pos)
|
||||
#define USBD_EPSTATUS_EPOUT_MASK (0x1FF << USBD_EPSTATUS_EPOUT0_Pos)
|
||||
#define USBD_EPDATASTATUS_EPIN_MASK (0x7F << USBD_EPDATASTATUS_EPIN1_Pos)
|
||||
#define USBD_EPDATASTATUS_EPOUT_MASK (0x7F << USBD_EPDATASTATUS_EPOUT1_Pos)
|
||||
|
||||
/** USB Work flags */
|
||||
#define NRF_USB_STATE_CHANGE 0
|
||||
#define NRF_USB_STATUS_CHANGE 1
|
||||
#define NRF_USB_STATE_CHANGE 0
|
||||
#define NRF_USB_STATUS_CHANGE 1
|
||||
|
||||
/**
|
||||
* @brief nRF USBD peripheral states
|
||||
|
@ -147,10 +147,10 @@ struct usbd_ep_event {
|
|||
* be derived from the theoretical number of backlog events possible depending
|
||||
* on the number of endpoints configured.
|
||||
*/
|
||||
#define FIFO_ELEM_MIN_SZ sizeof(struct usbd_ep_event)
|
||||
#define FIFO_ELEM_MAX_SZ sizeof(struct usbd_ep_event)
|
||||
#define FIFO_ELEM_COUNT 32
|
||||
#define FIFO_ELEM_ALIGN sizeof(unsigned int)
|
||||
#define FIFO_ELEM_MIN_SZ sizeof(struct usbd_ep_event)
|
||||
#define FIFO_ELEM_MAX_SZ sizeof(struct usbd_ep_event)
|
||||
#define FIFO_ELEM_COUNT 32
|
||||
#define FIFO_ELEM_ALIGN sizeof(unsigned int)
|
||||
|
||||
K_MEM_POOL_DEFINE(fifo_elem_pool, FIFO_ELEM_MIN_SZ, FIFO_ELEM_MAX_SZ,
|
||||
FIFO_ELEM_COUNT, FIFO_ELEM_ALIGN);
|
||||
|
@ -194,8 +194,8 @@ K_MEM_POOL_DEFINE(fifo_elem_pool, FIFO_ELEM_MIN_SZ, FIFO_ELEM_MAX_SZ,
|
|||
CFG_EPOUT_CNT + CFG_EP_ISOOUT_CNT)
|
||||
|
||||
/** Total buffer size for all endpoints */
|
||||
#define EP_BUF_TOTAL ((CFG_EPIN_CNT * MAX_EP_BUF_SZ) + \
|
||||
(CFG_EPOUT_CNT * MAX_EP_BUF_SZ) + \
|
||||
#define EP_BUF_TOTAL ((CFG_EPIN_CNT * MAX_EP_BUF_SZ) + \
|
||||
(CFG_EPOUT_CNT * MAX_EP_BUF_SZ) + \
|
||||
(CFG_EP_ISOIN_CNT * MAX_ISO_EP_BUF_SZ) + \
|
||||
(CFG_EP_ISOOUT_CNT * MAX_ISO_EP_BUF_SZ))
|
||||
|
||||
|
@ -372,7 +372,7 @@ static inline struct usbd_ep_event *usbd_evt_alloc(void)
|
|||
sizeof(struct usbd_ep_event),
|
||||
K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
SYS_LOG_DBG("USBD event alloc failed!");
|
||||
LOG_DBG("USBD event alloc failed!");
|
||||
__ASSERT_NO_MSG(0);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ void usb_dc_nrfx_power_event_callback(nrf_power_event_t event)
|
|||
ctx->state = USBD_DETACHED;
|
||||
break;
|
||||
default:
|
||||
SYS_LOG_DBG("Unknown USB power event");
|
||||
LOG_DBG("Unknown USB power event");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -470,7 +470,7 @@ static int hf_clock_enable(bool on, bool blocking)
|
|||
|
||||
clock = device_get_binding(CONFIG_CLOCK_CONTROL_NRF5_M16SRC_DRV_NAME);
|
||||
if (!clock) {
|
||||
SYS_LOG_ERR("NRF HF Clock device not found!");
|
||||
LOG_ERR("NRF HF Clock device not found!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -481,12 +481,12 @@ static int hf_clock_enable(bool on, bool blocking)
|
|||
}
|
||||
|
||||
if (ret && (blocking || (ret != -EINPROGRESS))) {
|
||||
SYS_LOG_ERR("HF clock %s fail: %d",
|
||||
on ? "start" : "stop", ret);
|
||||
LOG_ERR("HF clock %s fail: %d",
|
||||
on ? "start" : "stop", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SYS_LOG_DBG("HF clock %s success (%d)", on ? "start" : "stop", ret);
|
||||
LOG_DBG("HF clock %s success (%d)", on ? "start" : "stop", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -519,12 +519,12 @@ static void usbd_handle_state_change(struct nrf_usbd_ctx *ctx)
|
|||
{
|
||||
switch (ctx->state) {
|
||||
case USBD_ATTACHED:
|
||||
SYS_LOG_DBG("USB detected");
|
||||
LOG_DBG("USB detected");
|
||||
nrfx_usbd_enable();
|
||||
break;
|
||||
|
||||
case USBD_POWERED:
|
||||
SYS_LOG_DBG("USB Powered");
|
||||
LOG_DBG("USB Powered");
|
||||
ctx->status_code = USB_DC_CONNECTED;
|
||||
ctx->flags |= BIT(NRF_USB_STATUS_CHANGE);
|
||||
usbd_enable_endpoints(ctx);
|
||||
|
@ -533,7 +533,7 @@ static void usbd_handle_state_change(struct nrf_usbd_ctx *ctx)
|
|||
break;
|
||||
|
||||
case USBD_DETACHED:
|
||||
SYS_LOG_DBG("USB Removed");
|
||||
LOG_DBG("USB Removed");
|
||||
ctx->ready = false;
|
||||
nrfx_usbd_disable();
|
||||
ctx->status_code = USB_DC_DISCONNECTED;
|
||||
|
@ -571,18 +571,18 @@ static inline void usbd_work_process_setup(struct nrf_usbd_ep_ctx *ep_ctx)
|
|||
usbd_setup = (struct usb_setup_packet *)ep_ctx->buf.data;
|
||||
memset(usbd_setup, 0, sizeof(struct usb_setup_packet));
|
||||
usbd_setup->bmRequestType = nrf_usbd_setup_bmrequesttype_get();
|
||||
usbd_setup->bRequest = nrf_usbd_setup_brequest_get();
|
||||
usbd_setup->wValue = nrf_usbd_setup_wvalue_get();
|
||||
usbd_setup->wIndex = nrf_usbd_setup_windex_get();
|
||||
usbd_setup->wLength = nrf_usbd_setup_wlength_get();
|
||||
usbd_setup->bRequest = nrf_usbd_setup_brequest_get();
|
||||
usbd_setup->wValue = nrf_usbd_setup_wvalue_get();
|
||||
usbd_setup->wIndex = nrf_usbd_setup_windex_get();
|
||||
usbd_setup->wLength = nrf_usbd_setup_wlength_get();
|
||||
ep_ctx->buf.len = sizeof(struct usb_setup_packet);
|
||||
|
||||
SYS_LOG_DBG("SETUP: r:%d rt:%d v:%d i:%d l:%d",
|
||||
(u32_t)usbd_setup->bRequest,
|
||||
(u32_t)usbd_setup->bmRequestType,
|
||||
(u32_t)usbd_setup->wValue,
|
||||
(u32_t)usbd_setup->wIndex,
|
||||
(u32_t)usbd_setup->wLength);
|
||||
LOG_DBG("SETUP: r:%d rt:%d v:%d i:%d l:%d",
|
||||
(u32_t)usbd_setup->bRequest,
|
||||
(u32_t)usbd_setup->bmRequestType,
|
||||
(u32_t)usbd_setup->wValue,
|
||||
(u32_t)usbd_setup->wIndex,
|
||||
(u32_t)usbd_setup->wLength);
|
||||
|
||||
/* Inform the stack. */
|
||||
ep_ctx->cfg.cb(ep_ctx->cfg.addr, USB_DC_EP_SETUP);
|
||||
|
@ -613,7 +613,7 @@ static inline void usbd_work_process_recvreq(struct nrf_usbd_ctx *ctx,
|
|||
nrfx_err_t err = nrfx_usbd_ep_transfer(
|
||||
ep_addr_to_nrfx(ep_ctx->cfg.addr), &transfer);
|
||||
if (err != NRFX_SUCCESS) {
|
||||
SYS_LOG_ERR("nRF USBD transfer error (OUT): %d.", err);
|
||||
LOG_ERR("nRF USBD transfer error (OUT): %d.", err);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
}
|
||||
|
@ -640,8 +640,8 @@ static void usbd_work_handler(struct k_work *item)
|
|||
|
||||
while ((ev = usbd_evt_get()) != NULL) {
|
||||
if (!ctx->attached) {
|
||||
SYS_LOG_ERR("USBD event dropped (not attached): %d.", \
|
||||
(uint32_t)ev->evt);
|
||||
LOG_ERR("USBD event dropped (not attached): %d.",
|
||||
(uint32_t)ev->evt);
|
||||
} else {
|
||||
struct nrf_usbd_ep_ctx *ep_ctx = ev->ep;
|
||||
|
||||
|
@ -699,7 +699,7 @@ static void endpoint_ctx_init(void)
|
|||
ret = k_mem_pool_alloc(&ep_buf_pool, &ep_ctx->buf.block,
|
||||
MAX_EP_BUF_SZ, K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
SYS_LOG_ERR("EP buffer alloc failed for EPIN%d", i);
|
||||
LOG_ERR("EP buffer alloc failed for EPIN%d", i);
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
|
||||
|
@ -717,7 +717,7 @@ static void endpoint_ctx_init(void)
|
|||
ret = k_mem_pool_alloc(&ep_buf_pool, &ep_ctx->buf.block,
|
||||
MAX_EP_BUF_SZ, K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
SYS_LOG_ERR("EP buffer alloc failed for EPOUT%d", i);
|
||||
LOG_ERR("EP buffer alloc failed for EPOUT%d", i);
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
|
||||
|
@ -735,7 +735,7 @@ static void endpoint_ctx_init(void)
|
|||
ret = k_mem_pool_alloc(&ep_buf_pool, &ep_ctx->buf.block,
|
||||
MAX_ISO_EP_BUF_SZ, K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
SYS_LOG_ERR("EP buffer alloc failed for ISOIN");
|
||||
LOG_ERR("EP buffer alloc failed for ISOIN");
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
|
||||
|
@ -753,7 +753,7 @@ static void endpoint_ctx_init(void)
|
|||
ret = k_mem_pool_alloc(&ep_buf_pool, &ep_ctx->buf.block,
|
||||
MAX_ISO_EP_BUF_SZ, K_NO_WAIT);
|
||||
if (ret < 0) {
|
||||
SYS_LOG_ERR("EP buffer alloc failed for ISOOUT");
|
||||
LOG_ERR("EP buffer alloc failed for ISOOUT");
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
|
||||
|
@ -799,7 +799,7 @@ static void endpoint_ctx_deinit(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const * const p_event)
|
||||
static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const *const p_event)
|
||||
{
|
||||
struct nrf_usbd_ep_ctx *ep_ctx =
|
||||
endpoint_ctx(p_event->data.eptransfer.ep);
|
||||
|
@ -807,79 +807,79 @@ static void usbd_event_transfer_ctrl(nrfx_usbd_evt_t const * const p_event)
|
|||
|
||||
if (NRF_USBD_EPIN_CHECK(p_event->data.eptransfer.ep)) {
|
||||
switch (p_event->data.eptransfer.status) {
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_WRITE_COMPLETE;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_WRITE_COMPLETE;
|
||||
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
SYS_LOG_DBG("ctrl write complete");
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
LOG_DBG("ctrl write complete");
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
SYS_LOG_ERR(
|
||||
"Unexpected event (nrfx_usbd): %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
LOG_ERR(
|
||||
"Unexpected event (nrfx_usbd): %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (p_event->data.eptransfer.status) {
|
||||
case NRFX_USBD_EP_WAITING: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
case NRFX_USBD_EP_WAITING: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
|
||||
SYS_LOG_DBG("ctrl read request");
|
||||
LOG_DBG("ctrl read request");
|
||||
|
||||
ep_ctx->read_pending = true;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_REQ;
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
ep_ctx->read_pending = true;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_REQ;
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
nrfx_err_t err_code;
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_COMPLETE;
|
||||
|
||||
err_code = nrfx_usbd_ep_status_get(
|
||||
p_event->data.eptransfer.ep, &ep_ctx->buf.len);
|
||||
|
||||
if ((err_code != NRFX_SUCCESS) &&
|
||||
(err_code != (nrfx_err_t)NRFX_USBD_EP_OK)) {
|
||||
LOG_ERR("_ep_status_get failed! Code: %d.",
|
||||
err_code);
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
break;
|
||||
LOG_DBG("ctrl read done: %d", ep_ctx->buf.len);
|
||||
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
nrfx_err_t err_code;
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_COMPLETE;
|
||||
|
||||
err_code = nrfx_usbd_ep_status_get(
|
||||
p_event->data.eptransfer.ep, &ep_ctx->buf.len);
|
||||
|
||||
if ((err_code != NRFX_SUCCESS) &&
|
||||
(err_code != (nrfx_err_t)NRFX_USBD_EP_OK)) {
|
||||
SYS_LOG_ERR("_ep_status_get failed! Code: %d.",
|
||||
err_code);
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
SYS_LOG_DBG("ctrl read done: %d", ep_ctx->buf.len);
|
||||
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
SYS_LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void usbd_event_transfer_data(nrfx_usbd_evt_t const * const p_event)
|
||||
static void usbd_event_transfer_data(nrfx_usbd_evt_t const *const p_event)
|
||||
{
|
||||
struct nrf_usbd_ctx *ctx = get_usbd_ctx();
|
||||
struct nrf_usbd_ep_ctx *ep_ctx =
|
||||
|
@ -887,71 +887,71 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const * const p_event)
|
|||
|
||||
if (NRF_USBD_EPIN_CHECK(p_event->data.eptransfer.ep)) {
|
||||
switch (p_event->data.eptransfer.status) {
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_WRITE_COMPLETE;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_WRITE_COMPLETE;
|
||||
|
||||
SYS_LOG_DBG("write complete, ep %d",
|
||||
(u32_t)p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
LOG_DBG("write complete, ep %d",
|
||||
(u32_t)p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
SYS_LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (p_event->data.eptransfer.status) {
|
||||
case NRFX_USBD_EP_WAITING: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
case NRFX_USBD_EP_WAITING: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
|
||||
SYS_LOG_DBG("read request, ep %d",
|
||||
(u32_t)p_event->data.eptransfer.ep);
|
||||
LOG_DBG("read request, ep %d",
|
||||
(u32_t)p_event->data.eptransfer.ep);
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_REQ;
|
||||
usbd_evt_put(ev);
|
||||
ep_ctx->read_pending = true;
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_REQ;
|
||||
usbd_evt_put(ev);
|
||||
ep_ctx->read_pending = true;
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
case NRFX_USBD_EP_OK: {
|
||||
struct usbd_ep_event *ev = usbd_evt_alloc();
|
||||
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_COMPLETE;
|
||||
ev->ep = ep_ctx;
|
||||
ev->evt = EP_EVT_RECV_COMPLETE;
|
||||
|
||||
ep_ctx->buf.len = nrf_usbd_ep_amount_get(
|
||||
p_event->data.eptransfer.ep);
|
||||
ep_ctx->buf.len = nrf_usbd_ep_amount_get(
|
||||
p_event->data.eptransfer.ep);
|
||||
|
||||
SYS_LOG_DBG("read complete, ep %d, len %d",
|
||||
(u32_t)p_event->data.eptransfer.ep,
|
||||
ep_ctx->buf.len);
|
||||
LOG_DBG("read complete, ep %d, len %d",
|
||||
(u32_t)p_event->data.eptransfer.ep,
|
||||
ep_ctx->buf.len);
|
||||
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
usbd_evt_put(ev);
|
||||
usbd_work_schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
SYS_LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
default: {
|
||||
LOG_ERR("Unexpected event from nrfx_usbd: %d, ep %d",
|
||||
p_event->data.eptransfer.status,
|
||||
p_event->data.eptransfer.ep);
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -959,23 +959,23 @@ static void usbd_event_transfer_data(nrfx_usbd_evt_t const * const p_event)
|
|||
/**
|
||||
* @brief nRFx USBD driver event handler function.
|
||||
*/
|
||||
static void usbd_event_handler(nrfx_usbd_evt_t const * const p_event)
|
||||
static void usbd_event_handler(nrfx_usbd_evt_t const *const p_event)
|
||||
{
|
||||
struct nrf_usbd_ep_ctx *ep_ctx;
|
||||
struct usbd_ep_event *ev;
|
||||
|
||||
switch (p_event->type) {
|
||||
case NRFX_USBD_EVT_SUSPEND:
|
||||
SYS_LOG_DBG("SUSPEND state detected.");
|
||||
LOG_DBG("SUSPEND state detected.");
|
||||
break;
|
||||
case NRFX_USBD_EVT_RESUME:
|
||||
SYS_LOG_DBG("RESUMING from suspend.");
|
||||
LOG_DBG("RESUMING from suspend.");
|
||||
break;
|
||||
case NRFX_USBD_EVT_WUREQ:
|
||||
SYS_LOG_DBG("RemoteWU initiated.");
|
||||
LOG_DBG("RemoteWU initiated.");
|
||||
break;
|
||||
case NRFX_USBD_EVT_RESET:
|
||||
SYS_LOG_DBG("USBD Reset.");
|
||||
LOG_DBG("USBD Reset.");
|
||||
usbd_status_code_update(USB_DC_RESET);
|
||||
break;
|
||||
case NRFX_USBD_EVT_SOF:
|
||||
|
@ -1053,8 +1053,8 @@ int usb_dc_attach(void)
|
|||
err = nrfx_usbd_init(usbd_event_handler);
|
||||
|
||||
if (err != NRFX_SUCCESS) {
|
||||
SYS_LOG_DBG("nRF USBD driver init failed. Code: %d.",
|
||||
(u32_t)err);
|
||||
LOG_DBG("nRF USBD driver init failed. Code: %d.",
|
||||
(u32_t)err);
|
||||
return -EIO;
|
||||
}
|
||||
nrf5_power_usb_power_int_enable(true);
|
||||
|
@ -1101,7 +1101,7 @@ int usb_dc_reset(void)
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
SYS_LOG_DBG("USBD Reset.");
|
||||
LOG_DBG("USBD Reset.");
|
||||
|
||||
ret = usb_dc_detach();
|
||||
if (ret) {
|
||||
|
@ -1133,39 +1133,39 @@ int usb_dc_set_address(const u8_t addr)
|
|||
ctx = get_usbd_ctx();
|
||||
ctx->state = USBD_ADDRESS_SET;
|
||||
|
||||
SYS_LOG_DBG("Address set to: %d.", addr);
|
||||
LOG_DBG("Address set to: %d.", addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data * const ep_cfg)
|
||||
int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data *const ep_cfg)
|
||||
{
|
||||
u8_t ep_idx = NRF_USBD_EP_NR_GET(ep_cfg->ep_addr);
|
||||
|
||||
SYS_LOG_DBG("ep %x, mps %d, type %d", ep_cfg->ep_addr, ep_cfg->ep_mps,
|
||||
LOG_DBG("ep %x, mps %d, type %d", ep_cfg->ep_addr, ep_cfg->ep_mps,
|
||||
ep_cfg->ep_type);
|
||||
|
||||
if ((ep_cfg->ep_type == USB_DC_EP_CONTROL) && ep_idx) {
|
||||
SYS_LOG_ERR("invalid endpoint configuration");
|
||||
LOG_ERR("invalid endpoint configuration");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!NRF_USBD_EP_VALIDATE(ep_cfg->ep_addr)) {
|
||||
SYS_LOG_ERR("invalid endpoint index/address");
|
||||
LOG_ERR("invalid endpoint index/address");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((ep_cfg->ep_type == USB_DC_EP_ISOCHRONOUS) &&
|
||||
(!NRF_USBD_EPISO_CHECK(ep_cfg->ep_addr))) {
|
||||
SYS_LOG_WRN("invalid endpoint type");
|
||||
(!NRF_USBD_EPISO_CHECK(ep_cfg->ep_addr))) {
|
||||
LOG_WRN("invalid endpoint type");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const ep_cfg)
|
||||
int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const ep_cfg)
|
||||
{
|
||||
struct nrf_usbd_ep_ctx *ep_ctx;
|
||||
|
||||
|
@ -1217,14 +1217,14 @@ int usb_dc_ep_set_stall(const u8_t ep)
|
|||
nrfx_usbd_ep_stall(ep_addr_to_nrfx(ep));
|
||||
break;
|
||||
case USB_DC_EP_ISOCHRONOUS:
|
||||
SYS_LOG_ERR("STALL unsupported on ISO endpoint.s");
|
||||
LOG_ERR("STALL unsupported on ISO endpoint.s");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ep_ctx->buf.len = 0;
|
||||
ep_ctx->buf.curr = ep_ctx->buf.data;
|
||||
|
||||
SYS_LOG_DBG("STALL on EP %d.", ep);
|
||||
LOG_DBG("STALL on EP %d.", ep);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1244,7 +1244,7 @@ int usb_dc_ep_clear_stall(const u8_t ep)
|
|||
}
|
||||
|
||||
nrfx_usbd_ep_stall_clear(ep_addr_to_nrfx(ep));
|
||||
SYS_LOG_DBG("Unstall on EP %d", ep);
|
||||
LOG_DBG("Unstall on EP %d", ep);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1289,7 +1289,7 @@ int usb_dc_ep_enable(const u8_t ep)
|
|||
return -EALREADY;
|
||||
}
|
||||
|
||||
SYS_LOG_DBG("EP enable: %d.", ep);
|
||||
LOG_DBG("EP enable: %d.", ep);
|
||||
|
||||
ep_ctx->cfg.en = true;
|
||||
|
||||
|
@ -1318,7 +1318,7 @@ int usb_dc_ep_disable(const u8_t ep)
|
|||
return -EALREADY;
|
||||
}
|
||||
|
||||
SYS_LOG_DBG("EP disable: %d.", ep);
|
||||
LOG_DBG("EP disable: %d.", ep);
|
||||
|
||||
nrfx_usbd_ep_disable(ep_addr_to_nrfx(ep));
|
||||
ep_ctx->cfg.en = false;
|
||||
|
@ -1348,9 +1348,9 @@ int usb_dc_ep_flush(const u8_t ep)
|
|||
}
|
||||
|
||||
int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
|
||||
const u32_t data_len, u32_t * const ret_bytes)
|
||||
const u32_t data_len, u32_t *const ret_bytes)
|
||||
{
|
||||
SYS_LOG_DBG("ep_write: ep %d, len %d", ep, data_len);
|
||||
LOG_DBG("ep_write: ep %d, len %d", ep, data_len);
|
||||
struct nrf_usbd_ctx *ctx = get_usbd_ctx();
|
||||
struct nrf_usbd_ep_ctx *ep_ctx;
|
||||
u32_t bytes_to_copy;
|
||||
|
@ -1395,7 +1395,7 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
|
|||
* and perform appropriate action.
|
||||
*/
|
||||
if ((ep_ctx->cfg.type == USB_DC_EP_CONTROL)
|
||||
&& (nrfx_usbd_last_setup_dir_get() != ep)) {
|
||||
&& (nrfx_usbd_last_setup_dir_get() != ep)) {
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
nrfx_usbd_setup_clear();
|
||||
return 0;
|
||||
|
@ -1405,7 +1405,7 @@ int usb_dc_ep_write(const u8_t ep, const u8_t *const data,
|
|||
|
||||
if (err != NRFX_SUCCESS) {
|
||||
k_sem_give(&ctx->dma_in_use);
|
||||
SYS_LOG_ERR("nRF USBD write error: %d.", (u32_t)err);
|
||||
LOG_ERR("nRF USBD write error: %d.", (u32_t)err);
|
||||
__ASSERT_NO_MSG(0);
|
||||
}
|
||||
|
||||
|
@ -1498,9 +1498,9 @@ int usb_dc_ep_read_continue(u8_t ep)
|
|||
}
|
||||
|
||||
int usb_dc_ep_read(const u8_t ep, u8_t *const data,
|
||||
const u32_t max_data_len, u32_t * const read_bytes)
|
||||
const u32_t max_data_len, u32_t *const read_bytes)
|
||||
{
|
||||
SYS_LOG_DBG("ep_read: ep %d, maxlen %d", ep, max_data_len);
|
||||
LOG_DBG("ep_read: ep %d, maxlen %d", ep, max_data_len);
|
||||
int ret;
|
||||
|
||||
ret = usb_dc_ep_read_wait(ep, data, max_data_len, read_bytes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue