update tinyusb, work better with sd

This commit is contained in:
hathach 2019-01-29 20:47:01 +07:00
parent 765d877dfa
commit d1fb384a4a
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581
5 changed files with 26 additions and 6 deletions

@ -1 +1 @@
Subproject commit 5804e56e3c2ab4480bf72d94d997f769a645af47 Subproject commit 29b49199beb8e9b5fead83e5cd36105f8746f1d7

View File

@ -32,6 +32,8 @@
#include "ble_drv.h" #include "ble_drv.h"
#include "nrf_nvic.h" #include "nrf_nvic.h"
#include "nrf_sdm.h" #include "nrf_sdm.h"
#include "nrf_soc.h"
#include "nrfx_power.h"
#include "py/misc.h" #include "py/misc.h"
nrf_nvic_state_t nrf_nvic_state = { 0 }; nrf_nvic_state_t nrf_nvic_state = { 0 };
@ -89,6 +91,23 @@ void SD_EVT_IRQHandler(void) {
uint32_t evt_id; uint32_t evt_id;
while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) { while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) {
// sd_evt_handler(evt_id); // sd_evt_handler(evt_id);
switch (evt_id) {
// usb power event
case NRF_EVT_POWER_USB_DETECTED:
case NRF_EVT_POWER_USB_POWER_READY:
case NRF_EVT_POWER_USB_REMOVED: {
int32_t usbevt = (evt_id == NRF_EVT_POWER_USB_DETECTED ) ? NRFX_POWER_USB_EVT_DETECTED:
(evt_id == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY :
(evt_id == NRF_EVT_POWER_USB_REMOVED ) ? NRFX_POWER_USB_EVT_REMOVED : -1;
extern void tusb_hal_nrf_power_event (uint32_t event);
tusb_hal_nrf_power_event(usbevt);
}
break;
default: break;
}
} }
while (1) { while (1) {

View File

@ -6,6 +6,7 @@ $(error Incorrect softdevice set flag)
endif endif
CFLAGS += -DBLUETOOTH_SD_DEBUG=1 CFLAGS += -DBLUETOOTH_SD_DEBUG=1
CFLAGS += -DSOFTDEVICE_PRESENT
INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include
INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT) INC += -Ibluetooth/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)/$(SD)_$(MCU_VARIANT)_$(SOFTDEV_VERSION)_API/include/$(MCU_VARIANT)

View File

@ -43,6 +43,9 @@ extern void tusb_hal_nrf_power_event(uint32_t event);
void init_usb_hardware(void) { void init_usb_hardware(void) {
// 2 is max priority (0, 1 are reserved for SD)
NVIC_SetPriority(USBD_IRQn, 2);
// USB power may already be ready at this time -> no event generated // USB power may already be ready at this time -> no event generated
// We need to invoke the handler based on the status initially // We need to invoke the handler based on the status initially
uint32_t usb_reg; uint32_t usb_reg;

View File

@ -54,10 +54,8 @@ void load_serial_number(void) {
} }
} }
bool _usb_enabled = false;
bool usb_enabled(void) { bool usb_enabled(void) {
return _usb_enabled; return tusb_inited();
} }
void usb_init(void) { void usb_init(void) {
@ -65,7 +63,6 @@ void usb_init(void) {
load_serial_number(); load_serial_number();
tusb_init(); tusb_init();
_usb_enabled = true;
#if MICROPY_KBD_EXCEPTION #if MICROPY_KBD_EXCEPTION
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received
@ -77,7 +74,7 @@ void usb_init(void) {
} }
void usb_background(void) { void usb_background(void) {
if (usb_enabled()) { if (tusb_inited()) {
tud_task(); tud_task();
tud_cdc_write_flush(); tud_cdc_write_flush();
} }