Skip to content

Commit 318dbc3

Browse files
committed
clean up and rename usb file
1 parent 868432f commit 318dbc3

File tree

6 files changed

+64
-98
lines changed

6 files changed

+64
-98
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Arduino Core for Adafruit Bluefruit nRF52 Boards
22

3-
This repository contains the Arduino BSP for Adafruit nRF52 series:
3+
This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
44

5-
- [Bluefruit Feather nRF52832](https://www.adafruit.com/product/3406)
6-
- [Bluefruit Feather nRF52840](https://www.adafruit.com/product/4062)
5+
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
6+
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
7+
- Adafruit Metro nRF52840 Express
78

89
Following boards are also included but are not officially supported:
910

cores/nRF5/Adafruit_TinyUSB_core/usb.c renamed to cores/nRF5/Adafruit_TinyUSB_core/Adafruit_TinyUSB_core.cpp

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525

2626
#include "nrfx.h"
2727
#include "nrfx_power.h"
28-
#include "nrf_sdm.h"
29-
#include "nrf_soc.h"
3028

31-
#include "nrf_usbd.h"
32-
#include "tusb.h"
33-
#include "usb.h"
34-
35-
#include "rtos.h"
29+
#include "Arduino.h"
30+
#include "Adafruit_TinyUSB_core.h"
3631

3732
//--------------------------------------------------------------------+
3833
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@@ -43,7 +38,35 @@
4338
// Serial is 64-bit DeviceID -> 16 chars len
4439
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
4540

46-
static void usb_device_task(void* param);
41+
/* tinyusb function that handles power event (detected, ready, removed)
42+
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
43+
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
44+
45+
void usb_init(void);
46+
47+
void Adafruit_TinyUSB_core_init(void)
48+
{
49+
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
50+
USBDevice.setID(USB_VID, USB_PID);
51+
USBDevice.begin();
52+
53+
usb_init();
54+
}
55+
56+
57+
// USB Device Driver task
58+
// This top level thread process all usb events and invoke callbacks
59+
static void usb_device_task(void* param)
60+
{
61+
(void) param;
62+
63+
// RTOS forever loop
64+
while (1)
65+
{
66+
// tinyusb device task
67+
tud_task();
68+
}
69+
}
4770

4871
// Init usb when starting up. Softdevice is not enabled yet
4972
void usb_init(void)
@@ -85,36 +108,4 @@ void usb_init(void)
85108
xTaskCreate( usb_device_task, "usbd", USBD_STACK_SZ, NULL, TASK_PRIO_HIGH, NULL);
86109
}
87110

88-
// Must be called before sd_softdevice_enable()
89-
// NRF_POWER is restricted prph used by Softdevice, must be release before enable SD
90-
void usb_softdevice_pre_enable(void)
91-
{
92-
nrfx_power_usbevt_disable();
93-
nrfx_power_usbevt_uninit();
94-
nrfx_power_uninit();
95-
}
96-
97-
// Must be called after sd_softdevice_enable()
98-
// To re-enable USB
99-
void usb_softdevice_post_enable(void)
100-
{
101-
sd_power_usbdetected_enable(true);
102-
sd_power_usbpwrrdy_enable(true);
103-
sd_power_usbremoved_enable(true);
104-
}
105-
106-
// USB Device Driver task
107-
// This top level thread process all usb events and invoke callbacks
108-
static void usb_device_task(void* param)
109-
{
110-
(void) param;
111-
112-
// RTOS forever loop
113-
while (1)
114-
{
115-
// tinyusb device task
116-
tud_task();
117-
}
118-
}
119-
120111
#endif

cores/nRF5/Adafruit_TinyUSB_core/Adafruit_TinyUSB_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@
3232
#include "Adafruit_USBD_CDC.h"
3333
#endif
3434

35+
void Adafruit_TinyUSB_core_init(void);
36+
3537
#endif /* ADAFRUIT_TINYUSB_CORE_H_ */

cores/nRF5/Adafruit_TinyUSB_core/usb.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

cores/nRF5/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#define ARDUINO_MAIN
1717
#include "Arduino.h"
1818

19-
#include "usb.h"
20-
2119
// DEBUG Level 1
2220
#if CFG_DEBUG
2321
// weak function to avoid compilation error with
@@ -75,10 +73,7 @@ int main( void )
7573
initVariant();
7674

7775
#ifdef NRF52840_XXAA
78-
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
79-
USBDevice.setID(USB_VID, USB_PID);
80-
USBDevice.begin();
81-
usb_init();
76+
Adafruit_TinyUSB_core_init();
8277
#endif
8378

8479
#if CFG_DEBUG >= 3

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
#include "bluefruit.h"
3838
#include "utility/bonding.h"
3939

40-
#ifdef NRF52840_XXAA
41-
#include "nrfx_power.h"
42-
#include "usb/usb.h"
43-
#endif
44-
4540
#ifndef CFG_BLE_TX_POWER_LEVEL
4641
#define CFG_BLE_TX_POWER_LEVEL 0
4742
#endif
@@ -59,6 +54,32 @@
5954
#define CFG_SOC_TASK_STACKSIZE (200)
6055
#endif
6156

57+
#ifdef NRF52840_XXAA
58+
#include "nrfx_power.h"
59+
60+
/* tinyusb function that handles power event (detected, ready, removed)
61+
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
62+
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
63+
64+
// Must be called before sd_softdevice_enable()
65+
// NRF_POWER is restricted prph used by Softdevice, must be release before enable SD
66+
void usb_softdevice_pre_enable(void)
67+
{
68+
nrfx_power_usbevt_disable();
69+
nrfx_power_usbevt_uninit();
70+
nrfx_power_uninit();
71+
}
72+
73+
// Must be called after sd_softdevice_enable()
74+
// To re-enable USB
75+
void usb_softdevice_post_enable(void)
76+
{
77+
sd_power_usbdetected_enable(true);
78+
sd_power_usbpwrrdy_enable(true);
79+
sd_power_usbremoved_enable(true);
80+
}
81+
82+
#endif
6283

6384
AdafruitBluefruit Bluefruit;
6485

0 commit comments

Comments
 (0)