Skip to content

Commit a0b9871

Browse files
committed
use seperate interrupt_char.c for nrf
move usb descriptors into usb.c
1 parent d4e84a9 commit a0b9871

File tree

5 files changed

+99
-92
lines changed

5 files changed

+99
-92
lines changed

ports/nrf/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ SRC_C += \
102102
tick.c \
103103
background.c \
104104
internal_flash.c \
105+
interrupt_char.c \
105106
drivers/bluetooth/ble_drv.c \
106107
drivers/bluetooth/ble_uart.c \
107108
boards/$(BOARD)/board.c \
@@ -113,7 +114,6 @@ SRC_C += \
113114
lib/timeutils/timeutils.c \
114115
lib/utils/buffer_helper.c \
115116
lib/utils/context_manager_helpers.c \
116-
lib/utils/interrupt_char.c \
117117
lib/utils/pyexec.c \
118118
lib/utils/stdout_helpers.c \
119119
lib/libc/string0.c \
@@ -123,7 +123,6 @@ ifeq ($(MCU_SUB_VARIANT),nrf52840)
123123

124124
SRC_C += \
125125
usb/usb.c \
126-
usb/tusb_descriptors.c \
127126
usb/usb_msc_flash.c \
128127
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
129128
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \

ports/nrf/interrupt_char.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "py/obj.h"
28+
#include "py/mpstate.h"
29+
#include "usb.h"
30+
31+
#if MICROPY_KBD_EXCEPTION
32+
33+
int mp_interrupt_char;
34+
35+
void mp_hal_set_interrupt_char(int c) {
36+
if (c != -1) {
37+
mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
38+
}
39+
mp_interrupt_char = c;
40+
41+
#ifdef NRF52840_XXAA
42+
tud_cdc_set_wanted_char(c);
43+
#endif
44+
}
45+
46+
void mp_keyboard_interrupt(void) {
47+
MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
48+
#if MICROPY_ENABLE_SCHEDULER
49+
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
50+
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
51+
}
52+
#endif
53+
}
54+
55+
#endif

ports/nrf/usb/tusb_descriptors.c

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

ports/nrf/usb/usb.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,49 @@
2828
#include "nrfx_power.h"
2929
#include "tick.h"
3030
#include "usb.h"
31-
32-
#include "lib/mp-readline/readline.h"
3331
#include "lib/utils/interrupt_char.h"
3432

3533
#ifdef NRF52840_XXAA
3634

35+
//--------------------------------------------------------------------+
36+
// STRING DESCRIPTORS
37+
//--------------------------------------------------------------------+
38+
39+
// array of pointer to string descriptors
40+
uint16_t const * const string_desc_arr [] =
41+
{
42+
// 0 index is supported language = English
43+
TUD_DESC_STRCONV(0x0409),
44+
45+
// Manufacturer
46+
TUD_DESC_STRCONV('A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s'),
47+
48+
// Product
49+
TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','Y',' ','n','R','F','5','2'),
50+
51+
// Serials TODO use chip ID
52+
TUD_DESC_STRCONV('1', '2', '3', '4', '5'),
53+
54+
// CDC Interface
55+
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l'),
56+
57+
// MSC Interface
58+
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','t','o','r','a','g','e'),
59+
60+
// Custom Interface
61+
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','C','u','s','t','o','m')
62+
};
63+
64+
// tud_desc_set is required by tinyusb stack
65+
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
66+
tud_desc_set_t tud_desc_set =
67+
{
68+
.device = NULL,
69+
.config = NULL,
70+
.string_arr = (uint8_t const **) string_desc_arr,
71+
.hid_report = NULL
72+
};
73+
3774
void usb_init(void) {
3875

3976
#ifdef SOFTDEVICE_PRESENT
@@ -55,12 +92,6 @@ void usb_init(void) {
5592
#endif
5693

5794
tusb_init();
58-
59-
#if MICROPY_KBD_EXCEPTION
60-
// set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() fired when Ctrl+C is received
61-
// TODO should be called in mp_hal_set_interrupt_char()
62-
tud_cdc_set_wanted_char(CHAR_CTRL_C);
63-
#endif
6495
}
6596

6697
//--------------------------------------------------------------------+
@@ -91,12 +122,12 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
91122
(void) itf; // not used
92123

93124
if (mp_interrupt_char == wanted_char) {
94-
tud_cdc_read_flush(); // flush read fifo
125+
tud_cdc_read_flush(); // flush read fifo
95126
mp_keyboard_interrupt();
96127
}
97128
}
98129

99130
#endif
100131

101-
#endif
132+
#endif // NRF52840_XXAA
102133

ports/nrf/usb/usb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#ifndef MICROPY_INCLUDED_NRF_USB_H
2828
#define MICROPY_INCLUDED_NRF_USB_H
2929

30-
#include "tusb.h"
31-
3230
#ifdef NRF52840_XXAA
3331

32+
#include "tusb.h"
33+
3434
void usb_init(void);
3535

3636
#else

0 commit comments

Comments
 (0)