Skip to content

Commit 7f88ba3

Browse files
committed
Revert "Allow main.py to be interrupted by ctrl-C" (adafruit#381)
* Revert "Read serial input as a background task so we can check for the interrupt character." This reverts commit 046092e. * Revert "Check INTERNAL_LIBM make flag in a safer way." This reverts commit 2b80add.
1 parent 2487226 commit 7f88ba3

6 files changed

Lines changed: 13 additions & 28 deletions

File tree

main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ bool start_mp(safe_mode_t safe_mode) {
127127

128128
pyexec_result_t result;
129129
bool found_main = false;
130-
131130
if (safe_mode != NO_SAFE_MODE) {
132131
serial_write(MSG_SAFE_MODE_NO_MAIN);
133132
} else {

ports/atmel-samd/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ SRC_C = \
238238
# Choose which flash filesystem impl to use.
239239
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
240240
# But that might not be true in the future.)
241-
ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
241+
ifdef INTERNAL_FLASH_FILESYSTEM
242242
SRC_C += internal_flash.c
243243
endif
244-
ifeq ($(SPI_FLASH_FILESYSTEM),1)
244+
ifdef SPI_FLASH_FILESYSTEM
245245
SRC_C += spi_flash.c
246246
endif
247247

@@ -278,7 +278,7 @@ SRC_COMMON_HAL = \
278278
usb_hid/__init__.c \
279279
usb_hid/Device.c
280280

281-
ifeq ($(INTERNAL_LIBM),1)
281+
ifdef INTERNAL_LIBM
282282
SRC_LIBM = $(addprefix lib/,\
283283
libm/math.c \
284284
libm/fmodf.c \
@@ -338,7 +338,7 @@ OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
338338
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
339339
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
340340
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
341-
ifeq ($(INTERNAL_LIBM),1)
341+
ifdef INTERNAL_LIBM
342342
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
343343
endif
344344

ports/atmel-samd/background.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
#include "background.h"
2727

2828
// #include "common-hal/audioio/AudioOut.h"
29-
#include "usb.h"
3029
#include "usb_mass_storage.h"
3130

3231
void run_background_tasks(void) {
3332
// audioout_background();
3433
usb_msc_background();
35-
usb_cdc_background();
3634
}

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h.
44
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none
55

6-
INTERNAL_LIBM = 1
6+
INTERNAL_LIBM = (1)
77

ports/atmel-samd/usb.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
static uint8_t usb_rx_buf[USB_RX_BUF_SIZE];
5757

5858
// Receive buffer head
59-
static volatile uint8_t usb_rx_buf_head = 0;
59+
static volatile uint8_t usb_rx_buf_head;
6060

6161
// Receive buffer tail
62-
static volatile uint8_t usb_rx_buf_tail = 0;
62+
static volatile uint8_t usb_rx_buf_tail;
6363

6464
// Number of bytes in receive buffer
65-
volatile uint8_t usb_rx_count = 0;
65+
volatile uint8_t usb_rx_count;
6666

6767
volatile bool mp_cdc_enabled = false;
6868
volatile bool usb_transmitting = false;
@@ -133,11 +133,8 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
133133
uint8_t c = cdc_packet_buffer[i];
134134
if (c == mp_interrupt_char) {
135135
mp_keyboard_interrupt();
136-
// If interrupted, flush all the input.
137-
usb_rx_count = 0;
138-
usb_rx_buf_head = 0;
139-
usb_rx_buf_tail = 0;
140-
break;
136+
// Don't put the interrupt into the buffer, just continue.
137+
continue;
141138
} else {
142139
// The count of characters present in receive buffer is
143140
// incremented.
@@ -147,7 +144,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
147144
if (usb_rx_buf_tail == USB_RX_BUF_SIZE) {
148145
// Reached the end of buffer, revert back to beginning of
149146
// buffer.
150-
usb_rx_buf_tail = 0;
147+
usb_rx_buf_tail = 0x00;
151148
}
152149
}
153150
}
@@ -222,7 +219,8 @@ void init_usb(void) {
222219
mscdf_register_callback(MSCDF_CB_TEST_DISK_READY, (FUNC_PTR)usb_msc_disk_is_ready);
223220
mscdf_register_callback(MSCDF_CB_XFER_BLOCKS_DONE, (FUNC_PTR)usb_msc_xfer_done);
224221

225-
usbdc_start(&multi_desc);
222+
int32_t result = usbdc_start(&multi_desc);
223+
while (result != ERR_NONE) {}
226224
usbdc_attach();
227225
}
228226

@@ -317,12 +315,3 @@ void usb_write(const char* buffer, uint32_t len) {
317315
bool usb_connected(void) {
318316
return cdc_enabled();
319317
}
320-
321-
// Poll for input if keyboard interrupts are enabled,
322-
// so that we can check for the interrupt char. read_complete() does the checking.
323-
void usb_cdc_background() {
324-
//
325-
if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read) {
326-
start_read();
327-
}
328-
}

ports/atmel-samd/usb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,5 @@ int usb_read(void);
3737
void usb_write(const char* buffer, uint32_t len);
3838
bool usb_bytes_available(void);
3939
bool usb_connected(void);
40-
void usb_cdc_background(void);
4140

4241
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_USB_H__

0 commit comments

Comments
 (0)