Shrink builds and handle 0-length writes

This commit is contained in:
Scott Shawcroft 2021-07-01 12:49:11 -07:00
parent f2ef586331
commit 3940878695
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
6 changed files with 33 additions and 8 deletions

View File

@ -27,6 +27,7 @@ CIRCUITPY_RE = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_SDCARDIO = 0
CIRCUITPY_ULAB = 0
CIRCUITPY_USB_MIDI = 0
MICROPY_PY_ASYNC_AWAIT = 0

View File

@ -43,3 +43,5 @@ CIRCUITPY_WATCHDOG = 1
# Override optimization to keep binary small
OPTIMIZATION_FLAGS = -Os
SUPEROPT_VM = 0
SUPEROPT_GC = 0

View File

@ -96,6 +96,8 @@ void check_sec_status(uint8_t sec_status) {
// Turn off BLE on a reset or reload.
void bleio_reset() {
// Set this explicitly to save data.
common_hal_bleio_adapter_obj.base.type = &bleio_adapter_type;
if (!common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) {
return;
}
@ -107,12 +109,8 @@ void bleio_reset() {
}
// The singleton _bleio.Adapter object, bound to _bleio.adapter
// It currently only has properties and no state
bleio_adapter_obj_t common_hal_bleio_adapter_obj = {
.base = {
.type = &bleio_adapter_type,
},
};
// It currently only has properties and no state. Inited by bleio_reset
bleio_adapter_obj_t common_hal_bleio_adapter_obj;
void common_hal_bleio_check_connected(uint16_t conn_handle) {
if (conn_handle == BLE_CONN_HANDLE_INVALID) {

View File

@ -51,7 +51,7 @@
#endif
// These are in order from highest available frequency to lowest (32MHz first, then 8MHz).
STATIC spim_peripheral_t spim_peripherals[] = {
STATIC const spim_peripheral_t spim_peripherals[] = {
#if NRFX_CHECK(NRFX_SPIM3_ENABLED)
// SPIM3 exists only on nRF52840 and supports 32MHz max. All other SPIM's are only 8MHz max.
// Allocate SPIM3 first.

View File

@ -38,7 +38,7 @@ typedef struct {
typedef struct {
mp_obj_base_t base;
spim_peripheral_t *spim_peripheral;
const spim_peripheral_t *spim_peripheral;
bool has_lock;
uint8_t clock_pin_number;
uint8_t MOSI_pin_number;

View File

@ -275,9 +275,26 @@ STATIC uint8_t _process_write(const uint8_t *raw_buf, size_t command_len) {
// Align the next chunk to a sector boundary.
uint32_t offset = command->offset;
size_t chunk_size = MIN(total_write_length - offset, 512 - (offset % 512));
// Special case when truncating the file. (Deleting stuff off the end.)
if (chunk_size == 0) {
f_lseek(&active_file, offset);
f_truncate(&active_file);
f_close(&active_file);
#if CIRCUITPY_USB_MSC
usb_msc_unlock();
#endif
}
response.offset = offset;
response.free_space = chunk_size;
common_hal_bleio_packet_buffer_write(&_transfer_packet_buffer, (const uint8_t *)&response, sizeof(struct write_pacing), NULL, 0);
if (chunk_size == 0) {
// Don't reload until everything is written out of the packet buffer.
common_hal_bleio_packet_buffer_flush(&_transfer_packet_buffer);
// Trigger an autoreload
autoreload_now();
return ANY_COMMAND;
}
return WRITE_DATA;
}
@ -474,7 +491,12 @@ STATIC uint8_t _process_listdir(uint8_t *raw_buf, size_t command_len) {
STATIC uint8_t current_command[COMMAND_SIZE] __attribute__ ((aligned(4)));
STATIC volatile size_t current_offset;
STATIC uint8_t next_command;
STATIC bool running = false;
void supervisor_bluetooth_file_transfer_background(void) {
if (running) {
return;
}
running = true;
mp_int_t size = 1;
while (size > 0) {
size = common_hal_bleio_packet_buffer_readinto(&_transfer_packet_buffer, current_command + current_offset, COMMAND_SIZE - current_offset);
@ -527,9 +549,11 @@ void supervisor_bluetooth_file_transfer_background(void) {
current_offset = 0;
}
}
running = false;
}
void supervisor_bluetooth_file_transfer_disconnected(void) {
next_command = ANY_COMMAND;
current_offset = 0;
f_close(&active_file);
}