|
34 | 34 | #include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h" |
35 | 35 |
|
36 | 36 | #include "supervisor/memory.h" |
| 37 | +#include "supervisor/shared/safe_mode.h" |
37 | 38 |
|
38 | 39 | #define SHARPMEM_BIT_WRITECMD_LSB (0x80) |
39 | 40 | #define SHARPMEM_BIT_VCOM_LSB (0x40) |
40 | 41 |
|
41 | | -static inline void *hybrid_alloc(size_t sz) { |
42 | | - if (gc_alloc_possible()) { |
43 | | - return m_malloc(sz + sizeof(void*), true); |
44 | | - } else { |
45 | | - supervisor_allocation *allocation = allocate_memory(align32_size(sz), false); |
46 | | - if (!allocation) { |
47 | | - return NULL; |
48 | | - } |
| 42 | +static void *hybrid_alloc(size_t sz) { |
| 43 | + supervisor_allocation *allocation = allocate_memory(align32_size(sz), false); |
| 44 | + if (allocation) { |
49 | 45 | memset(allocation->ptr, 0, sz); |
50 | 46 | return allocation->ptr; |
51 | 47 | } |
| 48 | + if (gc_alloc_possible()) { |
| 49 | + return m_malloc(sz, true); |
| 50 | + } |
| 51 | + reset_into_safe_mode(MEM_MANAGE); |
| 52 | + return NULL; // unreached |
52 | 53 | } |
53 | 54 |
|
54 | 55 | static inline void hybrid_free(void *ptr_in) { |
@@ -155,7 +156,8 @@ void common_hal_sharpdisplay_framebuffer_construct(sharpdisplay_framebuffer_obj_ |
155 | 156 |
|
156 | 157 | int row_stride = common_hal_sharpdisplay_framebuffer_get_row_stride(self); |
157 | 158 | self->bufinfo.len = row_stride * height + 2; |
158 | | - self->bufinfo.buf = gc_alloc(self->bufinfo.len, false, true); |
| 159 | + // re-use a supervisor allocation if possible |
| 160 | + self->bufinfo.buf = hybrid_alloc(self->bufinfo.len); |
159 | 161 |
|
160 | 162 | uint8_t *data = self->bufinfo.buf; |
161 | 163 | *data++ = SHARPMEM_BIT_WRITECMD_LSB; |
|
0 commit comments