clean up and rename usb file
This commit is contained in:
1 parent
868432f6fd
commit
318dbc3cc6
6 files changed
+64
-98
No files matched your search
@@ -1,9 +1,10 @@
|
||||
# Arduino Core for Adafruit Bluefruit nRF52 Boards
|
||||
|
||||
This repository contains the Arduino BSP for Adafruit nRF52 series:
|
||||
This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
|
||||
|
||||
- [Bluefruit Feather nRF52832](https://www.adafruit.com/product/3406)
|
||||
- [Bluefruit Feather nRF52840](https://www.adafruit.com/product/4062)
|
||||
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
|
||||
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
|
||||
- Adafruit Metro nRF52840 Express
|
||||
|
||||
Following boards are also included but are not officially supported:
|
||||
|
||||
|
||||
+31
-40
@@ -25,14 +25,9 @@
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrfx_power.h"
|
||||
#include "nrf_sdm.h"
|
||||
#include "nrf_soc.h"
|
||||
|
||||
#include "nrf_usbd.h"
|
||||
#include "tusb.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include "rtos.h"
|
||||
#include "Arduino.h"
|
||||
#include "Adafruit_TinyUSB_core.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
@@ -43,7 +38,35 @@
|
||||
// Serial is 64-bit DeviceID -> 16 chars len
|
||||
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
|
||||
|
||||
static void usb_device_task(void* param);
|
||||
/* tinyusb function that handles power event (detected, ready, removed)
|
||||
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
|
||||
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
void usb_init(void);
|
||||
|
||||
void Adafruit_TinyUSB_core_init(void)
|
||||
{
|
||||
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
|
||||
USBDevice.setID(USB_VID, USB_PID);
|
||||
USBDevice.begin();
|
||||
|
||||
usb_init();
|
||||
}
|
||||
|
||||
|
||||
// USB Device Driver task
|
||||
// This top level thread process all usb events and invoke callbacks
|
||||
static void usb_device_task(void* param)
|
||||
{
|
||||
(void) param;
|
||||
|
||||
// RTOS forever loop
|
||||
while (1)
|
||||
{
|
||||
// tinyusb device task
|
||||
tud_task();
|
||||
}
|
||||
}
|
||||
|
||||
// Init usb when starting up. Softdevice is not enabled yet
|
||||
void usb_init(void)
|
||||
@@ -85,36 +108,4 @@ void usb_init(void)
|
||||
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL);
|
||||
}
|
||||
|
||||
// Must be called before sd_softdevice_enable()
|
||||
// NRF_POWER is restricted prph used by Softdevice, must be release before enable SD
|
||||
void usb_softdevice_pre_enable(void)
|
||||
{
|
||||
nrfx_power_usbevt_disable();
|
||||
nrfx_power_usbevt_uninit();
|
||||
nrfx_power_uninit();
|
||||
}
|
||||
|
||||
// Must be called after sd_softdevice_enable()
|
||||
// To re-enable USB
|
||||
void usb_softdevice_post_enable(void)
|
||||
{
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
}
|
||||
|
||||
// USB Device Driver task
|
||||
// This top level thread process all usb events and invoke callbacks
|
||||
static void usb_device_task(void* param)
|
||||
{
|
||||
(void) param;
|
||||
|
||||
// RTOS forever loop
|
||||
while (1)
|
||||
{
|
||||
// tinyusb device task
|
||||
tud_task();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -32,4 +32,6 @@
|
||||
#include "Adafruit_USBD_CDC.h"
|
||||
#endif
|
||||
|
||||
void Adafruit_TinyUSB_core_init(void);
|
||||
|
||||
#endif /* ADAFRUIT_TINYUSB_CORE_H_ */
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018, hathach for Adafruit
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef USB_H_
|
||||
#define USB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void usb_init(void);
|
||||
void usb_softdevice_pre_enable(void);
|
||||
void usb_softdevice_post_enable(void);
|
||||
|
||||
/* tinyusb function that handles power event (detected, ready, removed)
|
||||
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
|
||||
void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USB_H_ */
|
||||
+1
-6
@@ -16,8 +16,6 @@
|
||||
#define ARDUINO_MAIN
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "usb.h"
|
||||
|
||||
// DEBUG Level 1
|
||||
#if CFG_DEBUG
|
||||
// weak function to avoid compilation error with
|
||||
@@ -75,10 +73,7 @@ int main( void )
|
||||
initVariant();
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
|
||||
USBDevice.setID(USB_VID, USB_PID);
|
||||
USBDevice.begin();
|
||||
usb_init();
|
||||
Adafruit_TinyUSB_core_init();
|
||||
#endif
|
||||
|
||||
#if CFG_DEBUG >= 3
|
||||
|
||||
@@ -37,11 +37,6 @@
|
||||
#include "bluefruit.h"
|
||||
#include "utility/bonding.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#include "nrfx_power.h"
|
||||
#include "usb/usb.h"
|
||||
#endif
|
||||
|
||||
#ifndef CFG_BLE_TX_POWER_LEVEL
|
||||
#define CFG_BLE_TX_POWER_LEVEL 0
|
||||
#endif
|
||||
@@ -59,6 +54,32 @@
|
||||
#define CFG_SOC_TASK_STACKSIZE (200)
|
||||
#endif
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#include "nrfx_power.h"
|
||||
|
||||
/* tinyusb function that handles power event (detected, ready, removed)
|
||||
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
|
||||
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
// Must be called before sd_softdevice_enable()
|
||||
// NRF_POWER is restricted prph used by Softdevice, must be release before enable SD
|
||||
void usb_softdevice_pre_enable(void)
|
||||
{
|
||||
nrfx_power_usbevt_disable();
|
||||
nrfx_power_usbevt_uninit();
|
||||
nrfx_power_uninit();
|
||||
}
|
||||
|
||||
// Must be called after sd_softdevice_enable()
|
||||
// To re-enable USB
|
||||
void usb_softdevice_post_enable(void)
|
||||
{
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
AdafruitBluefruit Bluefruit;
|
||||
|
||||
|
||||
Reference in new issue
Block a user