Skip to content

Commit 0dc2600

Browse files
authored
Merge pull request #1552 from tannewt/onsdbitmap
Fix displaying images off of SD cards.
2 parents 3e24b96 + b1e8c43 commit 0dc2600

File tree

7 files changed

+40
-31
lines changed

7 files changed

+40
-31
lines changed

extmod/vfs_fat_file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,15 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
186186
break;
187187
}
188188
}
189+
assert(vfs != NULL);
190+
if ((vfs->flags & FSUSER_USB_WRITABLE) != 0 && (mode & FA_WRITE) != 0) {
191+
mp_raise_OSError(MP_EROFS);
192+
}
189193

190194
pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t);
191195
o->base.type = type;
192196

193197
const char *fname = mp_obj_str_get_str(args[0].u_obj);
194-
assert(vfs != NULL);
195198
FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode);
196199
if (res != FR_OK) {
197200
m_del_obj(pyb_file_obj_t, o);

main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ void stop_mp(void) {
127127
#if CIRCUITPY_NETWORK
128128
network_module_deinit();
129129
#endif
130+
131+
#if MICROPY_VFS
132+
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
133+
134+
// Unmount all heap allocated vfs mounts.
135+
while (gc_nbytes(vfs) > 0) {
136+
vfs = vfs->next;
137+
}
138+
MP_STATE_VM(vfs_mount_table) = vfs;
139+
MP_STATE_VM(vfs_cur) = vfs;
140+
#endif
141+
142+
// Run any finalizers before we stop using the heap.
143+
gc_sweep_all();
130144
}
131145

132146
#define STRING_LIST(...) {__VA_ARGS__, ""}

ports/atmel-samd/boards/pyportal/board.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ uint8_t display_init_sequence[] = {
4848
0xc1, 1, 0x10, // Power control SAP[2:0];BT[3:0]
4949
0xc5, 2, 0x3e, 0x28, // VCM control
5050
0xc7, 1, 0x86, // VCM control2
51-
0x36, 1, 0x08, // Memory Access Control
51+
0x36, 1, 0xa8, // Memory Access Control
5252
0x37, 1, 0x00, // Vertical scroll zero
5353
0x3a, 1, 0x55, // COLMOD: Pixel Format Set
5454
0xb1, 2, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
@@ -82,7 +82,7 @@ void board_init(void) {
8282
240, // Height
8383
0, // column start
8484
0, // row start
85-
270, // rotation
85+
0, // rotation
8686
16, // Color depth
8787
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
8888
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command

py/circuitpy_mpconfig.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
#define MICROPY_FATFS_USE_LABEL (1)
124124
#define MICROPY_FATFS_RPATH (2)
125125
#define MICROPY_FATFS_MULTI_PARTITION (1)
126-
#define MICROPY_FATFS_NUM_PERSISTENT (1)
127126

128127
// Only enable this if you really need it. It allocates a byte cache of this size.
129128
// #define MICROPY_FATFS_MAX_SS (4096)

py/runtime.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,6 @@ void mp_init(void) {
131131
sizeof(MP_STATE_VM(fs_user_mount)) - MICROPY_FATFS_NUM_PERSISTENT);
132132
#endif
133133

134-
#if MICROPY_VFS
135-
#if MICROPY_FATFS_NUM_PERSISTENT > 0
136-
// We preserve the last MICROPY_FATFS_NUM_PERSISTENT mounts because newer
137-
// mounts are put at the front of the list.
138-
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
139-
// Count how many mounts we have.
140-
uint8_t count = 0;
141-
while (vfs != NULL) {
142-
vfs = vfs->next;
143-
count++;
144-
}
145-
// Find the vfs MICROPY_FATFS_NUM_PERSISTENT mounts from the end.
146-
vfs = MP_STATE_VM(vfs_mount_table);
147-
for (uint8_t j = 0; j < count - MICROPY_FATFS_NUM_PERSISTENT; j++) {
148-
vfs = vfs->next;
149-
}
150-
MP_STATE_VM(vfs_mount_table) = vfs;
151-
MP_STATE_VM(vfs_cur) = vfs;
152-
#else
153-
// initialise the VFS sub-system
154-
MP_STATE_VM(vfs_cur) = NULL;
155-
MP_STATE_VM(vfs_mount_table) = NULL;
156-
#endif
157-
#endif
158-
159134
#if MICROPY_PY_THREAD_GIL
160135
mp_thread_mutex_init(&MP_STATE_VM(gil_mutex));
161136
#endif

shared-module/displayio/__init__.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#include <string.h>
33
#include "shared-module/displayio/__init__.h"
44

5+
#include "py/reload.h"
56
#include "shared-bindings/displayio/Bitmap.h"
67
#include "shared-bindings/displayio/Display.h"
78
#include "shared-bindings/displayio/Group.h"
89
#include "shared-bindings/displayio/Palette.h"
10+
#include "supervisor/shared/autoreload.h"
911
#include "supervisor/shared/display.h"
1012
#include "supervisor/memory.h"
1113
#include "supervisor/usb.h"
@@ -18,7 +20,19 @@ static inline void swap(uint16_t* a, uint16_t* b) {
1820
*b = temp;
1921
}
2022

23+
bool refreshing_displays = false;
24+
2125
void displayio_refresh_displays(void) {
26+
// Somehow reloads from the sdcard are being lost. So, cheat and reraise.
27+
if (reload_requested) {
28+
mp_raise_reload_exception();
29+
return;
30+
}
31+
32+
if (refreshing_displays) {
33+
return;
34+
}
35+
refreshing_displays = true;
2236
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
2337
if (displays[i].display.base.type == NULL || displays[i].display.base.type == &mp_type_NoneType) {
2438
continue;
@@ -27,6 +41,7 @@ void displayio_refresh_displays(void) {
2741
displayio_display_update_backlight(display);
2842

2943
if (!displayio_display_frame_queued(display)) {
44+
refreshing_displays = false;
3045
return;
3146
}
3247
if (displayio_display_refresh_queued(display)) {
@@ -89,8 +104,9 @@ void displayio_refresh_displays(void) {
89104
index += 1;
90105
// The buffer is full, send it.
91106
if (index >= buffer_size) {
92-
if (!displayio_display_send_pixels(display, buffer, buffer_size / 2)) {
107+
if (!displayio_display_send_pixels(display, buffer, buffer_size / 2) || reload_requested) {
93108
displayio_display_finish_region_update(display);
109+
refreshing_displays = false;
94110
return;
95111
}
96112
// TODO(tannewt): Make refresh displays faster so we don't starve other
@@ -103,12 +119,14 @@ void displayio_refresh_displays(void) {
103119
// Send the remaining data.
104120
if (index && !displayio_display_send_pixels(display, buffer, index * 2)) {
105121
displayio_display_finish_region_update(display);
122+
refreshing_displays = false;
106123
return;
107124
}
108125
displayio_display_finish_region_update(display);
109126
}
110127
displayio_display_finish_refresh(display);
111128
}
129+
refreshing_displays = false;
112130
}
113131

114132
void common_hal_displayio_release_displays(void) {

supervisor/shared/filesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void filesystem_flush(void) {
9595
void filesystem_writable_by_python(bool writable) {
9696
fs_user_mount_t *vfs = &_internal_vfs;
9797

98-
if (writable) {
98+
if (!writable) {
9999
vfs->flags |= FSUSER_USB_WRITABLE;
100100
} else {
101101
vfs->flags &= ~FSUSER_USB_WRITABLE;

0 commit comments

Comments
 (0)