Skip to content

Commit

Permalink
Merge pull request #11074 from bergzand/pr/usb/nrfusb
Browse files Browse the repository at this point in the history
nrf52: Add USB peripheral driver
  • Loading branch information
aabadie authored Jun 11, 2019
2 parents 4e5a320 + 98aa643 commit 761530c
Show file tree
Hide file tree
Showing 7 changed files with 757 additions and 5 deletions.
1 change: 1 addition & 0 deletions boards/common/particle-mesh/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_usbdev

# Various other features (if any)
FEATURES_PROVIDED += radio_nrf802154
Expand Down
3 changes: 2 additions & 1 deletion boards/nrf52840-mdk/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_usbdev

# Various other features (if any)
FEATURES_PROVIDED += radio_nrf802154
Expand Down
1 change: 1 addition & 0 deletions boards/nrf52840dk/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include $(RIOTBOARD)/common/nrf52xxxdk/Makefile.features
# Various other features (if any)
FEATURES_PROVIDED += radio_nrf802154
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_usbdev
1 change: 1 addition & 0 deletions boards/reel/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_usbdev

include $(RIOTBOARD)/common/nrf52/Makefile.features
78 changes: 78 additions & 0 deletions cpu/nrf52/include/nrfusb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2019 Koen Zandberg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup cpu_nrf52_nrfusb NRF usb peripheral implementation
* @ingroup cpu_nrf52
* @brief Minimal driver for the NRF52840 usb peripheral
*
* @{
*
* @file
* @brief USB interface functions for the nrf52840 class devices
*
* @author Koen Zandberg <koen@bergzand.net>
*/

#ifndef NRFUSB_H
#define NRFUSB_H

#include <stdint.h>
#include <stddef.h>
#include "periph/usbdev.h"
#include "cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* Number of USB peripherals on the MCU
*/
#define NRF_USB_NUM_PERIPH 1

/**
* USB endpoint buffer space
*/
#define NRF_USB_BUF_SPACE USBDEV_EP_BUF_SPACE

/**
* Number of USB IN and OUT endpoints
*/
#define NRF_USB_NUM_EP USBDEV_NUM_ENDPOINTS

/**
* @brief nrfusb setup packet state tracker for endpoint 0 handling
*/
typedef enum {
NRFUSB_SETUP_READY, /**< Ready for a new setup request */
NRFUSB_SETUP_READ, /**< Read request received */
NRFUSB_SETUP_WRITE, /**< Write request received */
NRFUSB_SETUP_ACKOUT, /**< Expecting an ACK on the out endpoint */
NRFUSB_SETUP_ACKIN, /**< Expecting an ACK on the in endpoint */
} nrfusb_setup_state_t;

/**
* @brief nrf usb peripheral device context
*/
typedef struct {
usbdev_t usbdev; /**< Inherited usbdev struct */
usbdev_ep_t ep_ins[NRF_USB_NUM_EP]; /**< IN type endpoints */
usbdev_ep_t ep_outs[ NRF_USB_NUM_EP]; /**< OUT type endpoints */
NRF_USBD_Type *device; /**< Ptr to the device registers */
size_t used; /**< Number of bytes from the
buffer that are used */
uint8_t buffer[NRF_USB_BUF_SPACE]; /**< Buffer space for endpoint data */
nrfusb_setup_state_t sstate; /**< Setup request state machine */
} nrfusb_t;

#ifdef __cplusplus
}
#endif
#endif /* NRFUSB_H */
/** @} */
Loading

0 comments on commit 761530c

Please sign in to comment.