From 2f340ca5fd2f3ae55849737b1a9bd5faf477a0c0 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski <q3k@q3k.org> Date: Sun, 28 Jul 2019 22:02:19 +0200 Subject: [PATCH] epicardiumy: fix epicardium_disp_framebuffer API --- epicardium/epicardium.h | 18 +++++++++++++----- epicardium/modules/display.c | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 6b8e98aa..b6097f7d 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -283,12 +283,13 @@ struct disp_framebuffer { * * .. code-block:: cpp * - * struct disp_framebuffer *fb = epic_disp_framebuffer(); + * struct disp_framebuffer **fb; + * epic_disp_framebuffer(fb); * uint16_t red = 0b1111100000000000; * for (int y = 0; y < DISP_HEIGHT; y++) { * for (int x = 0; x < DISP_WIDTH; x++) { - * fb->fb[y][x][0] = red >> 8; - * fb->fb[y][x][1] = red & 0xFF; + * (*fb)->fb[y][x][0] = red >> 8; + * (*fb)->fb[y][x][1] = red & 0xFF; * } * } * epic_disp_update(); @@ -318,6 +319,10 @@ API(API_DISP_CLOSE, int epic_disp_close()); /** * Causes the changes that have been written to the framebuffer * to be shown on the display + * :return: ``0`` on success or a negative value in case of an error: + * + * - ``-EBUSY``: Display was already locked from another task. + * - ``-EAGAIN``: Display is currently being updated. */ API(API_DISP_UPDATE, int epic_disp_update()); /** @@ -445,9 +450,12 @@ API(API_DISP_CIRC, * Returns the back framebuffer (the display buffer that's currently inactive * that will be shown after the next call to ``epic_disp_update``. * - * :returns: pointer to a framebuffer + * :param fb: output: current framebuffer + * :return: ``0`` on success or negative value in case of an error: + * + * - ``-EBUSY``: Display was already locked from another task. */ -API(API_DISP_FRAMEBUFFER, struct disp_framebuffer *epic_disp_framebuffer()); +API(API_DISP_FRAMEBUFFER, int epic_disp_framebuffer(struct disp_framebuffer **fb)); /** diff --git a/epicardium/modules/display.c b/epicardium/modules/display.c index 1f521553..f5cca2b8 100644 --- a/epicardium/modules/display.c +++ b/epicardium/modules/display.c @@ -119,15 +119,23 @@ int epic_disp_update() int cl = check_lock(); if (cl < 0) { return cl; - } else { - LCD_Update(); - return 0; } + + if (LCD_Update()) { + return -EAGAIN; + } + return 0; } -struct disp_framebuffer *epic_disp_framebuffer() +int epic_disp_framebuffer(struct disp_framebuffer **fb) { - return (struct disp_framebuffer *)LCD_Framebuffer(); + int cl = check_lock(); + if (cl < 0) { + return cl; + } + + *fb = (struct disp_framebuffer *)LCD_Framebuffer(); + return 0; } int epic_disp_open() -- GitLab