uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler) { if (events_handler == NULL) { return NRF_ERROR_NULL; } // Check if function was not called before. if (m_ser_phy_hci_slip_event_handler != NULL) { return NRF_ERROR_INVALID_STATE; } ret_code_t ret = app_usbd_class_append( app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm)); if (ret != NRF_SUCCESS) { return ret; } m_ser_phy_hci_slip_event_handler = events_handler; ser_phy_hci_slip_reset(); return NRF_SUCCESS; }
static ret_code_t cdc_acm_serial_state_notify(app_usbd_cdc_acm_t const * p_cdc_acm) { app_usbd_class_inst_t const * p_inst = app_usbd_cdc_acm_class_inst_get(p_cdc_acm); app_usbd_cdc_acm_ctx_t * p_cdc_acm_ctx = cdc_acm_ctx_get(p_cdc_acm); nrf_drv_usbd_ep_t ep = comm_ep_in_addr_get(p_inst); NRF_DRV_USBD_TRANSFER_OUT(transfer, &p_cdc_acm_ctx->request.payload, sizeof(app_usbd_cdc_acm_notify_t)); return app_usbd_ep_transfer(ep, &transfer); }
size_t app_usbd_cdc_acm_rx_size(app_usbd_cdc_acm_t const * p_cdc_acm) { app_usbd_class_inst_t const * p_inst = app_usbd_cdc_acm_class_inst_get(p_cdc_acm); nrf_drv_usbd_ep_t ep = data_ep_out_addr_get(p_inst); size_t size; ret_code_t ret = nrf_drv_usbd_ep_status_get(ep, &size); if (ret != NRF_SUCCESS) { return 0; } return size; }
void nrf5UartInit(void) { static const app_usbd_config_t usbdConfig = {.ev_state_proc = usbdUserEventHandler}; memset((void *)&sUsbState, 0, sizeof(sUsbState)); app_usbd_serial_num_generate(); ret_code_t ret = app_usbd_init(&usbdConfig); assert(ret == NRF_SUCCESS); app_usbd_class_inst_t const *cdcAcmInstance = app_usbd_cdc_acm_class_inst_get(&sAppCdcAcm); ret = app_usbd_class_append(cdcAcmInstance); assert(ret == NRF_SUCCESS); ret = app_usbd_power_events_enable(); assert(ret == NRF_SUCCESS); }
ret_code_t app_usbd_cdc_acm_write(app_usbd_cdc_acm_t const * p_cdc_acm, const void * p_buf, size_t length) { app_usbd_class_inst_t const * p_inst = app_usbd_cdc_acm_class_inst_get(p_cdc_acm); app_usbd_cdc_acm_ctx_t * p_cdc_acm_ctx = cdc_acm_ctx_get(p_cdc_acm); bool dtr_state = (p_cdc_acm_ctx->line_state & APP_USBD_CDC_ACM_LINE_STATE_DTR) ? true : false; if (!dtr_state) { /*Port is not opened*/ return NRF_ERROR_INVALID_STATE; } nrf_drv_usbd_ep_t ep = data_ep_in_addr_get(p_inst); NRF_DRV_USBD_TRANSFER_IN(transfer, p_buf, length); return app_usbd_ep_transfer(ep, &transfer); }