refactor: FLASH size optimisations for B&W (#4827)

This commit is contained in:
philmoz
2024-04-01 09:43:50 +10:00
committed by GitHub
parent 46f484e6e5
commit 6c5eada23a
36 changed files with 608 additions and 655 deletions
+11 -32
View File
@@ -19,6 +19,8 @@
* GNU General Public License for more details.
*/
#include <cinttypes>
#include <stdio.h>
#include "yaml_bits.h"
#include "yaml_parser.h"
@@ -192,53 +194,31 @@ uint32_t yaml_hex2uint(const char* val, uint8_t val_len)
return i_val;
}
static char int2str_buffer[MAX_STR] = {0};
static const char _int2str_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9' };
constexpr int INT2STR_LEN = 16;
static char int2str_buffer[INT2STR_LEN] = {0};
char* yaml_unsigned2str(uint32_t i)
{
char* c = &(int2str_buffer[MAX_STR-2]);
do {
*(c--) = _int2str_lookup[i % 10];
i = i / 10;
} while((c > int2str_buffer) && i);
return (c + 1);
snprintf(int2str_buffer, INT2STR_LEN, "%" PRIu32, i);
return int2str_buffer;
}
char* yaml_signed2str(int32_t i)
{
if (i < 0) {
char* c = yaml_unsigned2str(-i);
*(--c) = '-';
return c;
}
return yaml_unsigned2str((uint32_t)i);
snprintf(int2str_buffer, INT2STR_LEN, "%" PRId32, i);
return int2str_buffer;
}
static const char _int2hex_lookup[] = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};
char* yaml_unsigned2hex(uint32_t i)
{
char* c = int2str_buffer;
for (int n = sizeof(uint32_t) * 2; n > 0; n--) {
*(c++) = _int2hex_lookup[(i >> ((n - 1) * 4)) & 0xF];
}
*c = '\0';
snprintf(int2str_buffer, INT2STR_LEN, "%08" PRIX32, i);
return int2str_buffer;
}
char* yaml_rgb2hex(uint32_t i)
{
char* c = int2str_buffer;
for (int n = 3 * 2; n > 0; n--) {
*(c++) = _int2hex_lookup[(i >> ((n - 1) * 4)) & 0xF];
}
*c = '\0';
snprintf(int2str_buffer, INT2STR_LEN, "%06" PRIX32, i);
return int2str_buffer;
}
@@ -250,4 +230,3 @@ int32_t yaml_to_signed(uint32_t i, uint32_t bits)
return i;
}