summaryrefslogtreecommitdiff
path: root/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-10-22 15:15:48 -0700
committerGitHub <noreply@github.com>2020-10-22 15:15:48 -0700
commit64c6d6d7e948eda2b320f9480093fe1104e9db47 (patch)
tree5372a17af99ee3684e8bbd7d391ed978b8a96e31 /shared-module/sharpdisplay/SharpMemoryFramebuffer.c
parentc8808f41a5e45a516d3a9060b15e6a1702fc4ffb (diff)
parentb520498c733356afdc418bd5a9841c7496a3926e (diff)
Merge pull request #3498 from jepler/sharpdisplay-reuse-supervisor-heap
Sharpdisplay: reuse supervisor heap
Diffstat (limited to 'shared-module/sharpdisplay/SharpMemoryFramebuffer.c')
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
index c23446828..b199e98d6 100644
--- a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
+++ b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
@@ -34,21 +34,22 @@
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
#include "supervisor/memory.h"
+#include "supervisor/shared/safe_mode.h"
#define SHARPMEM_BIT_WRITECMD_LSB (0x80)
#define SHARPMEM_BIT_VCOM_LSB (0x40)
-static inline void *hybrid_alloc(size_t sz) {
- if (gc_alloc_possible()) {
- return m_malloc(sz + sizeof(void*), true);
- } else {
- supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
- if (!allocation) {
- return NULL;
- }
+static void *hybrid_alloc(size_t sz) {
+ supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
+ if (allocation) {
memset(allocation->ptr, 0, sz);
return allocation->ptr;
}
+ if (gc_alloc_possible()) {
+ return m_malloc(sz, true);
+ }
+ reset_into_safe_mode(MEM_MANAGE);
+ return NULL; // unreached
}
static inline void hybrid_free(void *ptr_in) {
@@ -155,7 +156,8 @@ void common_hal_sharpdisplay_framebuffer_construct(sharpdisplay_framebuffer_obj_
int row_stride = common_hal_sharpdisplay_framebuffer_get_row_stride(self);
self->bufinfo.len = row_stride * height + 2;
- self->bufinfo.buf = gc_alloc(self->bufinfo.len, false, true);
+ // re-use a supervisor allocation if possible
+ self->bufinfo.buf = hybrid_alloc(self->bufinfo.len);
uint8_t *data = self->bufinfo.buf;
*data++ = SHARPMEM_BIT_WRITECMD_LSB;