Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool start_mp(safe_mode_t safe_mode) {

pyexec_result_t result;
bool found_main = false;

if (safe_mode != NO_SAFE_MODE) {
serial_write(MSG_SAFE_MODE_NO_MAIN);
} else {
Expand Down
8 changes: 4 additions & 4 deletions ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ SRC_C = \
# Choose which flash filesystem impl to use.
# (Right now INTERNAL_FLASH_FILESYSTEM and SPI_FLASH_FILESYSTEM are mutually exclusive.
# But that might not be true in the future.)
ifdef INTERNAL_FLASH_FILESYSTEM
ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
SRC_C += internal_flash.c
endif
ifdef SPI_FLASH_FILESYSTEM
ifeq ($(SPI_FLASH_FILESYSTEM),1)
SRC_C += spi_flash.c
endif

Expand Down Expand Up @@ -278,7 +278,7 @@ SRC_COMMON_HAL = \
usb_hid/__init__.c \
usb_hid/Device.c

ifdef INTERNAL_LIBM
ifeq ($(INTERNAL_LIBM),1)
SRC_LIBM = $(addprefix lib/,\
libm/math.c \
libm/fmodf.c \
Expand Down Expand Up @@ -338,7 +338,7 @@ OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
ifdef INTERNAL_LIBM
ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif

Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/asf4
2 changes: 2 additions & 0 deletions ports/atmel-samd/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
#include "background.h"

// #include "common-hal/audioio/AudioOut.h"
#include "usb.h"
#include "usb_mass_storage.h"

void run_background_tasks(void) {
// audioout_background();
usb_msc_background();
usb_cdc_background();
}
2 changes: 1 addition & 1 deletion ports/atmel-samd/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h.
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=none

INTERNAL_LIBM = (1)
INTERNAL_LIBM = 1

27 changes: 19 additions & 8 deletions ports/atmel-samd/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
static uint8_t usb_rx_buf[USB_RX_BUF_SIZE];

// Receive buffer head
static volatile uint8_t usb_rx_buf_head;
static volatile uint8_t usb_rx_buf_head = 0;

// Receive buffer tail
static volatile uint8_t usb_rx_buf_tail;
static volatile uint8_t usb_rx_buf_tail = 0;

// Number of bytes in receive buffer
volatile uint8_t usb_rx_count;
volatile uint8_t usb_rx_count = 0;

volatile bool mp_cdc_enabled = false;
volatile bool usb_transmitting = false;
Expand Down Expand Up @@ -133,8 +133,11 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
uint8_t c = cdc_packet_buffer[i];
if (c == mp_interrupt_char) {
mp_keyboard_interrupt();
// Don't put the interrupt into the buffer, just continue.
continue;
// If interrupted, flush all the input.
usb_rx_count = 0;
usb_rx_buf_head = 0;
usb_rx_buf_tail = 0;
break;
} else {
// The count of characters present in receive buffer is
// incremented.
Expand All @@ -144,7 +147,7 @@ static bool read_complete(const uint8_t ep, const enum usb_xfer_code rc, const u
if (usb_rx_buf_tail == USB_RX_BUF_SIZE) {
// Reached the end of buffer, revert back to beginning of
// buffer.
usb_rx_buf_tail = 0x00;
usb_rx_buf_tail = 0;
}
}
}
Expand Down Expand Up @@ -219,8 +222,7 @@ void init_usb(void) {
mscdf_register_callback(MSCDF_CB_TEST_DISK_READY, (FUNC_PTR)usb_msc_disk_is_ready);
mscdf_register_callback(MSCDF_CB_XFER_BLOCKS_DONE, (FUNC_PTR)usb_msc_xfer_done);

int32_t result = usbdc_start(&multi_desc);
while (result != ERR_NONE) {}
usbdc_start(&multi_desc);
usbdc_attach();
}

Expand Down Expand Up @@ -315,3 +317,12 @@ void usb_write(const char* buffer, uint32_t len) {
bool usb_connected(void) {
return cdc_enabled();
}

// Poll for input if keyboard interrupts are enabled,
// so that we can check for the interrupt char. read_complete() does the checking.
void usb_cdc_background() {
//
if (mp_interrupt_char != -1 && cdc_enabled() && !pending_read) {
start_read();
}
}
1 change: 1 addition & 0 deletions ports/atmel-samd/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ int usb_read(void);
void usb_write(const char* buffer, uint32_t len);
bool usb_bytes_available(void);
bool usb_connected(void);
void usb_cdc_background(void);

#endif // __MICROPY_INCLUDED_ATMEL_SAMD_USB_H__