summaryrefslogtreecommitdiff
path: root/shared-module/sharpdisplay
diff options
context:
space:
mode:
authorfoamyguy <foamyguy@gmail.com>2020-11-08 18:32:15 -0600
committerGitHub <noreply@github.com>2020-11-08 18:32:15 -0600
commitcf21c4da601e00a614efd8ade774a0c8e5444c64 (patch)
tree118a157edbc1884f502de8e9e26f79d178ed8c9a /shared-module/sharpdisplay
parent7611e71a1bc49bcb426e0854519d5143eb262a17 (diff)
parenteec9821fdc19ca81c2d0811a6b6c5909a54b8c81 (diff)
Merge pull request #1 from adafruit/main
merge from adafruit
Diffstat (limited to 'shared-module/sharpdisplay')
-rw-r--r--shared-module/sharpdisplay/SharpMemoryFramebuffer.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/shared-module/sharpdisplay/SharpMemoryFramebuffer.c b/shared-module/sharpdisplay/SharpMemoryFramebuffer.c
index 71e00d7f0..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) {
@@ -90,10 +91,6 @@ bool common_hal_sharpdisplay_framebuffer_get_pixels_in_byte_share_row(sharpdispl
}
void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *self) {
- if (!allocation_from_ptr(self->bufinfo.buf)) {
- self->bufinfo.buf = NULL;
- }
-
if (self->bus != &self->inline_bus
#if BOARD_SPI
&& self->bus != common_hal_board_get_spi()
@@ -105,7 +102,9 @@ void common_hal_sharpdisplay_framebuffer_reset(sharpdisplay_framebuffer_obj_t *s
}
void common_hal_sharpdisplay_framebuffer_reconstruct(sharpdisplay_framebuffer_obj_t *self) {
-
+ if (!allocation_from_ptr(self->bufinfo.buf)) {
+ self->bufinfo.buf = NULL;
+ }
}
void common_hal_sharpdisplay_framebuffer_get_bufinfo(sharpdisplay_framebuffer_obj_t *self, mp_buffer_info_t *bufinfo) {
@@ -157,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;