diff options
Diffstat (limited to 'firmware/src/screen.c')
-rw-r--r-- | firmware/src/screen.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/firmware/src/screen.c b/firmware/src/screen.c new file mode 100644 index 0000000..06f038c --- /dev/null +++ b/firmware/src/screen.c @@ -0,0 +1,38 @@ +#include "screen.h" +#include <stddef.h> +#include <stdlib.h> + +Screen* newScreen(unsigned short rows, unsigned short columns, void (*update)(Screen)) { + unsigned short i; + + Screen* screen = calloc(1, sizeof(Screen)); + if (screen == NULL) + return NULL; + + screen->data = (unsigned char**) calloc(rows, sizeof(unsigned char*)); + if (screen->data == NULL) + return NULL; + for (i = 0; i < rows; i++) { + screen->data[i] = (unsigned char*) calloc(columns + 1, sizeof(unsigned char)); + if (screen->data[i] == NULL) { + for (; i >= 0; i--) + free(screen->data[i]); + free(screen->data); + return NULL; + } + } + + screen->rows = rows; + screen->columns = columns; + screen->first_visible_row = screen->first_visible_column = NULL; + screen->cursor_x = screen->cursor_y = NULL; + screen->update = update; + return screen; +} + +inline void freeScreen(Screen* screen) { + unsigned short i; + for (i = 0; i < screen->rows; i++) + free(screen->data[i]); + free(screen->data); +} |