should fix #1021
- update tinyusb for wanted char - move usb code into usb.c
This commit is contained in:
parent
bfe14ff824
commit
3525d65af3
|
@ -1 +1 @@
|
|||
Subproject commit a0849fee9f4b268ccc9798c70c654a835f8e20c8
|
||||
Subproject commit 6129670e4a23812d1926b15c191d76538f7a325a
|
|
@ -122,6 +122,7 @@ SRC_C += \
|
|||
ifeq ($(MCU_SUB_VARIANT),nrf52840)
|
||||
|
||||
SRC_C += \
|
||||
usb/usb.c \
|
||||
usb/tusb_descriptors.c \
|
||||
usb/usb_msc_flash.c \
|
||||
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
|
||||
|
|
|
@ -51,15 +51,10 @@ Prerequisite steps for building the nrf port:
|
|||
git submodule update --init
|
||||
make -C mpy-cross
|
||||
|
||||
By default, the feather52832 is used as compile target. To build and flash issue the following command inside the ports/nrf/ folder:
|
||||
To build and flash issue the following command inside the ports/nrf/ folder:
|
||||
|
||||
make
|
||||
make flash
|
||||
|
||||
Alternatively the target board could be defined:
|
||||
|
||||
make BOARD=pca10056
|
||||
make flash
|
||||
make BOARD=pca10056
|
||||
make BOARD=pca10056 flash
|
||||
|
||||
## Compile and Flash with Bluetooth Stack
|
||||
|
||||
|
|
|
@ -29,6 +29,6 @@
|
|||
void run_background_tasks(void) {
|
||||
#ifdef NRF52840_XXAA
|
||||
tusb_task();
|
||||
tud_cdc_flush();
|
||||
tud_cdc_write_flush();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,13 +26,9 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrfx_power.h"
|
||||
#include "boards/board.h"
|
||||
|
||||
#include "tick.h"
|
||||
#include "tusb.h"
|
||||
#include "nrfx.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
|
||||
|
@ -40,27 +36,7 @@ void board_init(void) {
|
|||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
// Init USB
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// TODO support Softdevice config
|
||||
#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);
|
||||
|
||||
// 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();
|
||||
#endif
|
||||
|
||||
tusb_init();
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
|
@ -72,21 +48,6 @@ void reset_board(void) {
|
|||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tud_mount_cb(uint8_t rhport) {
|
||||
(void) rhport;
|
||||
}
|
||||
|
||||
void tud_umount_cb(uint8_t rhport) {
|
||||
(void) rhport;
|
||||
}
|
||||
|
||||
uint32_t tusb_hal_millis(void) {
|
||||
uint64_t ms;
|
||||
uint32_t us;
|
||||
current_tick(&ms, &us);
|
||||
return (uint32_t) ms;
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ extern const struct _mp_obj_module_t mp_module_ubluepy;
|
|||
// We need to provide a declaration/definition of alloca()
|
||||
#include <alloca.h>
|
||||
|
||||
extern void run_background_tasks(void);
|
||||
void run_background_tasks(void);
|
||||
#define MICROPY_VM_HOOK_LOOP run_background_tasks();
|
||||
#define MICROPY_VM_HOOK_RETURN run_background_tasks();
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 hathach for Adafruit Industries
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrfx_power.h"
|
||||
#include "tick.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include "lib/mp-readline/readline.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
void usb_init(void) {
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
// TODO support Softdevice config
|
||||
#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);
|
||||
|
||||
// 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();
|
||||
#endif
|
||||
|
||||
tusb_init();
|
||||
|
||||
#if MICROPY_KBD_EXCEPTION
|
||||
// set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() fired when Ctrl+C is received
|
||||
// TODO should be called in mp_hal_set_interrupt_char()
|
||||
tud_cdc_set_wanted_char(CHAR_CTRL_C);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tud_mount_cb(void) {
|
||||
}
|
||||
|
||||
void tud_umount_cb(void) {
|
||||
}
|
||||
|
||||
uint32_t tusb_hal_millis(void) {
|
||||
uint64_t ms;
|
||||
uint32_t us;
|
||||
current_tick(&ms, &us);
|
||||
return (uint32_t) ms;
|
||||
}
|
||||
|
||||
#if MICROPY_KBD_EXCEPTION
|
||||
|
||||
/**
|
||||
* Callback invoked when received an "wanted" char.
|
||||
* @param itf Interface index (for multiple cdc interfaces)
|
||||
* @param wanted_char The wanted char (set previously)
|
||||
*/
|
||||
void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
|
||||
{
|
||||
(void) itf; // not used
|
||||
|
||||
if (mp_interrupt_char == wanted_char) {
|
||||
tud_cdc_read_flush(); // flush read fifo
|
||||
mp_keyboard_interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 hathach for Adafruit Industries
|
||||
*
|
||||
* 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 MICROPY_INCLUDED_NRF_USB_H
|
||||
#define MICROPY_INCLUDED_NRF_USB_H
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef NRF52840_XXAA
|
||||
|
||||
void usb_init(void);
|
||||
|
||||
#else
|
||||
|
||||
#define usb_init()
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_USB_H
|
Loading…
Reference in New Issue