arturo182 review
This commit is contained in:
parent
a0b9871ba9
commit
bb28faf39c
|
@ -1 +1 @@
|
|||
Subproject commit 6129670e4a23812d1926b15c191d76538f7a325a
|
||||
Subproject commit 421ae8fc82b884e087e99c8ab3fa25883a3dd623
|
|
@ -26,7 +26,10 @@
|
|||
|
||||
#include "py/obj.h"
|
||||
#include "py/mpstate.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#include "usb.h"
|
||||
#endif
|
||||
|
||||
#if MICROPY_KBD_EXCEPTION
|
||||
|
||||
|
|
|
@ -30,7 +30,10 @@
|
|||
#include "usb.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.h"
|
||||
#include "nrf_soc.h"
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// STRING DESCRIPTORS
|
||||
|
@ -71,26 +74,53 @@ tud_desc_set_t tud_desc_set =
|
|||
.hid_report = NULL
|
||||
};
|
||||
|
||||
|
||||
/* 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 void tusb_hal_nrf_power_event(uint32_t event);
|
||||
|
||||
void usb_init(void) {
|
||||
|
||||
// USB power may already be ready at this time -> no event generated
|
||||
// We need to invoke the handler based on the status initially
|
||||
uint32_t usb_reg;
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// TODO support Softdevice config
|
||||
uint8_t sd_en = false;
|
||||
(void) sd_softdevice_is_enabled(&sd_en);
|
||||
|
||||
if ( sd_en ) {
|
||||
sd_power_usbdetected_enable(true);
|
||||
sd_power_usbpwrrdy_enable(true);
|
||||
sd_power_usbremoved_enable(true);
|
||||
|
||||
sd_power_usbregstatus_get(&usb_reg);
|
||||
}else
|
||||
#else
|
||||
// Softdevice is not present, init power module and register tusb power event function
|
||||
// for vusb detect, ready, removed
|
||||
extern void tusb_hal_nrf_power_event(uint32_t event);
|
||||
{
|
||||
// Power module init
|
||||
const nrfx_power_config_t pwr_cfg = { 0 };
|
||||
nrfx_power_init(&pwr_cfg);
|
||||
|
||||
// Power module init
|
||||
const nrfx_power_config_t pwr_cfg = { 0 };
|
||||
nrfx_power_init(&pwr_cfg);
|
||||
// Register tusb function as USB power handler
|
||||
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
|
||||
nrfx_power_usbevt_init(&config);
|
||||
|
||||
// USB Power detection
|
||||
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
|
||||
nrfx_power_usbevt_init(&config);
|
||||
nrfx_power_usbevt_enable();
|
||||
|
||||
nrfx_power_usbevt_enable();
|
||||
usb_reg = NRF_POWER->USBREGSTATUS;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) {
|
||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
|
||||
}
|
||||
|
||||
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) {
|
||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
||||
}
|
||||
|
||||
tusb_init();
|
||||
}
|
||||
|
||||
|
@ -129,5 +159,3 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
|
|||
|
||||
#endif
|
||||
|
||||
#endif // NRF52840_XXAA
|
||||
|
||||
|
|
|
@ -27,16 +27,8 @@
|
|||
#ifndef MICROPY_INCLUDED_NRF_USB_H
|
||||
#define MICROPY_INCLUDED_NRF_USB_H
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
void usb_init(void);
|
||||
|
||||
#else
|
||||
|
||||
#define usb_init()
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_USB_H
|
||||
|
|
Loading…
Reference in New Issue