From 04a28c3cc24aa19938cf3e2b0bd9472a975d6d91 Mon Sep 17 00:00:00 2001 From: neithanmo Date: Mon, 16 Sep 2024 16:55:57 -0600 Subject: [PATCH 1/2] Refactor: Change buffer sizes from uint16_t to size_t for larger capacity --- include/buffering.h | 10 +++++----- src/buffering.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/buffering.h b/include/buffering.h index ec6e80c..121ba27 100644 --- a/include/buffering.h +++ b/include/buffering.h @@ -26,8 +26,8 @@ extern "C" { typedef struct { uint8_t *data; - uint16_t size; - uint16_t pos; + size_t size; + size_t pos; uint8_t in_use: 1; } buffer_state_t; @@ -37,9 +37,9 @@ typedef struct { /// \param flash_buffer /// \param flash_buffer_size void buffering_init(uint8_t *ram_buffer, - uint16_t ram_buffer_size, + size_t ram_buffer_size, uint8_t *flash_buffer, - uint16_t flash_buffer_size); + size_t flash_buffer_size); /// Reset buffer void buffering_reset(); @@ -48,7 +48,7 @@ void buffering_reset(); /// \param data /// \param length /// \return the number of appended bytes -int buffering_append(uint8_t *data, int length); +int buffering_append(uint8_t *data, size_t length); /// buffering_get_ram_buffer /// \return diff --git a/src/buffering.c b/src/buffering.c index e956782..01602ad 100644 --- a/src/buffering.c +++ b/src/buffering.c @@ -25,9 +25,9 @@ buffer_state_t ram; // Ram buffer_state_t flash; // Flash void buffering_init(uint8_t *ram_buffer, - uint16_t ram_buffer_size, + size_t ram_buffer_size, uint8_t *flash_buffer, - uint16_t flash_buffer_size) { + size_t flash_buffer_size) { ram.data = ram_buffer; ram.size = ram_buffer_size; ram.pos = 0; @@ -46,11 +46,11 @@ void buffering_reset() { flash.in_use = 0; } -int buffering_append(uint8_t *data, int length) { +int buffering_append(uint8_t *data, size_t length) { if (ram.in_use) { if (ram.size - ram.pos >= length) { // RAM in use, append to ram if there is enough space - MEMCPY(ram.data + ram.pos, data, (size_t) length); + MEMCPY(ram.data + ram.pos, data, length); ram.pos += length; } else { // If RAM is not big enough copy memory to flash @@ -66,7 +66,7 @@ int buffering_append(uint8_t *data, int length) { } else { // Flash in use, append to flash if (flash.size - flash.pos >= length) { - MEMCPY_NV(flash.data + flash.pos, data, (size_t) length); + MEMCPY_NV(flash.data + flash.pos, data, length); flash.pos += length; } else { return 0; From 9629aa24af2d738747034b85a6dba7f2cf0ab8f4 Mon Sep 17 00:00:00 2001 From: neithanmo Date: Mon, 16 Sep 2024 17:51:36 -0600 Subject: [PATCH 2/2] Bump lib version --- include/zxversion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zxversion.h b/include/zxversion.h index c95c5a9..186967b 100644 --- a/include/zxversion.h +++ b/include/zxversion.h @@ -17,4 +17,4 @@ #define ZXLIB_MAJOR 28 #define ZXLIB_MINOR 0 -#define ZXLIB_PATCH 6 +#define ZXLIB_PATCH 7