diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 6b8e98aa81cd04531e7919f40095828fffb1c214..b6097f7d7e2ec9095add077a3f0a3d5bec5ebe36 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 1f521553256afbb1d30e80a9c7a3e9cbbc0b68c7..f5cca2b8cf363c7e55d79cec35740c658e65749b 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()