summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/backlight/backlight_driver_common.c2
-rw-r--r--quantum/backlight/backlight_software.c2
-rw-r--r--quantum/dip_switch.c4
-rw-r--r--quantum/eeconfig.c13
-rw-r--r--quantum/encoder.c8
-rw-r--r--quantum/encoder.h8
-rw-r--r--quantum/keyboard.c15
-rw-r--r--quantum/keycode.h14
-rw-r--r--quantum/keycode_config.h1
-rw-r--r--quantum/keymap.h23
-rw-r--r--quantum/keymap_common.c2
-rw-r--r--quantum/painter/qp.h4
-rw-r--r--quantum/painter/qp_draw_image.c43
-rw-r--r--quantum/painter/qp_draw_text.c49
-rw-r--r--quantum/painter/qp_stream.c47
-rw-r--r--quantum/painter/qp_stream.h5
-rw-r--r--quantum/painter/rules.mk34
-rw-r--r--quantum/pointing_device/pointing_device.c8
-rw-r--r--quantum/pointing_device/pointing_device_drivers.c27
-rw-r--r--quantum/pointing_device_internal.h14
-rw-r--r--quantum/process_keycode/autocorrect_data_default.h85
-rw-r--r--quantum/process_keycode/process_autocorrect.c287
-rw-r--r--quantum/process_keycode/process_autocorrect.h17
-rw-r--r--quantum/process_keycode/process_leader.c2
-rw-r--r--quantum/process_keycode/process_ucis.c17
-rw-r--r--quantum/process_keycode/process_ucis.h6
-rw-r--r--quantum/process_keycode/process_unicode.c12
-rw-r--r--quantum/process_keycode/process_unicode.h5
-rw-r--r--quantum/process_keycode/process_unicode_common.c298
-rw-r--r--quantum/process_keycode/process_unicode_common.h184
-rw-r--r--quantum/process_keycode/process_unicodemap.c5
-rw-r--r--quantum/process_keycode/process_unicodemap.h6
-rw-r--r--quantum/quantum.c7
-rw-r--r--quantum/quantum.h5
-rw-r--r--quantum/quantum_keycodes.h8
-rw-r--r--quantum/quantum_keycodes_legacy.h4
-rw-r--r--quantum/rgb_matrix/rgb_matrix_drivers.c2
-rw-r--r--quantum/rgblight/rgblight.c4
-rw-r--r--quantum/secure.c3
-rw-r--r--quantum/split_common/split_util.c14
-rw-r--r--quantum/unicode/unicode.c383
-rw-r--r--quantum/unicode/unicode.h165
-rw-r--r--quantum/unicode/utf8.c (renamed from quantum/utf8.c)0
-rw-r--r--quantum/unicode/utf8.h (renamed from quantum/utf8.h)2
-rw-r--r--quantum/util.h52
-rw-r--r--quantum/via_ensure_keycode.h2
46 files changed, 1242 insertions, 656 deletions
diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c
index e4c2e90b5f..1eb8969084 100644
--- a/quantum/backlight/backlight_driver_common.c
+++ b/quantum/backlight/backlight_driver_common.c
@@ -9,7 +9,7 @@
#if defined(BACKLIGHT_PINS)
static const pin_t backlight_pins[] = BACKLIGHT_PINS;
# ifndef BACKLIGHT_LED_COUNT
-# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
+# define BACKLIGHT_LED_COUNT ARRAY_SIZE(backlight_pins)
# endif
# define FOR_EACH_LED(x) \
diff --git a/quantum/backlight/backlight_software.c b/quantum/backlight/backlight_software.c
index 3d412cab52..27ccbd2c9f 100644
--- a/quantum/backlight/backlight_software.c
+++ b/quantum/backlight/backlight_software.c
@@ -26,7 +26,7 @@ static const uint16_t backlight_duty_table[] = {
0b1110111011101110,
0b1111111111111111,
};
-#define backlight_duty_table_size (sizeof(backlight_duty_table) / sizeof(backlight_duty_table[0]))
+#define backlight_duty_table_size ARRAY_SIZE(backlight_duty_table)
// clang-format on
diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c
index eee29aaf91..e180cfccdf 100644
--- a/quantum/dip_switch.c
+++ b/quantum/dip_switch.c
@@ -33,7 +33,7 @@
#endif
#ifdef DIP_SWITCH_PINS
-# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t))
+# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad))
static pin_t dip_switch_pad[] = DIP_SWITCH_PINS;
#endif
@@ -43,7 +43,7 @@ typedef struct matrix_index_t {
uint8_t col;
} matrix_index_t;
-# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(matrix_index_t))
+# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad))
static matrix_index_t dip_switch_pad[] = DIP_SWITCH_MATRIX_GRID;
extern bool peek_matrix(uint8_t row_index, uint8_t col_index, bool read_raw);
static uint16_t scan_count;
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c
index 0ff9996ca4..27a0f6d48f 100644
--- a/quantum/eeconfig.c
+++ b/quantum/eeconfig.c
@@ -46,7 +46,8 @@ void eeconfig_init_quantum(void) {
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
default_layer_state = 0;
eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
- eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4);
+ // Enable oneshot and autocorrect by default: 0b0001 0100
+ eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x14);
eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
@@ -57,16 +58,6 @@ void eeconfig_init_quantum(void) {
eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0);
- // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
- // within the emulated eeprom via dfu-util or another tool
-#if defined INIT_EE_HANDS_LEFT
-# pragma message "Faking EE_HANDS for left hand"
- eeprom_update_byte(EECONFIG_HANDEDNESS, 1);
-#elif defined INIT_EE_HANDS_RIGHT
-# pragma message "Faking EE_HANDS for right hand"
- eeprom_update_byte(EECONFIG_HANDEDNESS, 0);
-#endif
-
#if defined(HAPTIC_ENABLE)
haptic_reset();
#else
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 5f8a7ce080..1393e34868 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -24,7 +24,8 @@
#include <string.h>
#ifndef ENCODER_MAP_KEY_DELAY
-# define ENCODER_MAP_KEY_DELAY 2
+# include "action.h"
+# define ENCODER_MAP_KEY_DELAY TAP_CODE_DELAY
#endif
#if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION)
@@ -143,9 +144,14 @@ void encoder_init(void) {
static void encoder_exec_mapping(uint8_t index, bool clockwise) {
// The delays below cater for Windows and its wonderful requirements.
action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true));
+# if ENCODER_MAP_KEY_DELAY > 0
wait_ms(ENCODER_MAP_KEY_DELAY);
+# endif // ENCODER_MAP_KEY_DELAY > 0
+
action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false));
+# if ENCODER_MAP_KEY_DELAY > 0
wait_ms(ENCODER_MAP_KEY_DELAY);
+# endif // ENCODER_MAP_KEY_DELAY > 0
}
#endif // ENCODER_MAP_ENABLE
diff --git a/quantum/encoder.h b/quantum/encoder.h
index 82f95b4931..4eb67fa25d 100644
--- a/quantum/encoder.h
+++ b/quantum/encoder.h
@@ -32,17 +32,17 @@ void encoder_state_raw(uint8_t* slave_state);
void encoder_update_raw(uint8_t* slave_state);
# if defined(ENCODERS_PAD_A_RIGHT)
-# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
-# define NUM_ENCODERS_RIGHT (sizeof(((pin_t[])ENCODERS_PAD_A_RIGHT)) / sizeof(pin_t))
+# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
+# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
# else
-# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
+# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
# endif
# define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT)
#else // SPLIT_KEYBOARD
-# define NUM_ENCODERS (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
+# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_LEFT NUM_ENCODERS
# define NUM_ENCODERS_RIGHT 0
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index 1c62a43d9d..3b5e9b0200 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -107,6 +107,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#ifdef BLUETOOTH_ENABLE
# include "outputselect.h"
+# ifdef BLUETOOTH_BLUEFRUIT_LE
+# include "bluefruit_le.h"
+# elif BLUETOOTH_RN42
+# include "rn42.h"
+# endif
#endif
#ifdef CAPS_WORD_ENABLE
# include "caps_word.h"
@@ -346,9 +351,6 @@ void quantum_init(void) {
#ifdef HAPTIC_ENABLE
haptic_init();
#endif
-#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE)
- set_output(OUTPUT_AUTO);
-#endif
}
/** \brief keyboard_init
@@ -410,6 +412,9 @@ void keyboard_init(void) {
// init after split init
pointing_device_init();
#endif
+#if defined(BLUETOOTH_RN42)
+ rn42_init();
+#endif
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
debug_enable = true;
@@ -670,5 +675,9 @@ void keyboard_task(void) {
programmable_button_send();
#endif
+#ifdef BLUETOOTH_BLUEFRUIT_LE
+ bluefruit_le_task();
+#endif
+
led_task();
}
diff --git a/quantum/keycode.h b/quantum/keycode.h
index 3c80a386d1..b492e4292a 100644
--- a/quantum/keycode.h
+++ b/quantum/keycode.h
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
-#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
+#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_ASST)
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
@@ -205,6 +205,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KC_MRWD KC_MEDIA_REWIND
#define KC_BRIU KC_BRIGHTNESS_UP
#define KC_BRID KC_BRIGHTNESS_DOWN
+#define KC_CPNL KC_CONTROL_PANEL
+#define KC_ASST KC_ASSISTANT
/* System Specific */
#define KC_BRMU KC_PAUSE
@@ -502,7 +504,9 @@ enum internal_special_keycodes {
KC_MEDIA_FAST_FORWARD,
KC_MEDIA_REWIND,
KC_BRIGHTNESS_UP,
- KC_BRIGHTNESS_DOWN
+ KC_BRIGHTNESS_DOWN,
+ KC_CONTROL_PANEL,
+ KC_ASSISTANT // 0xC0
};
enum mouse_keys {
@@ -510,11 +514,11 @@ enum mouse_keys {
#ifdef VIA_ENABLE
KC_MS_UP = 0xF0,
#else
- KC_MS_UP = 0xED,
+ KC_MS_UP = 0xCD,
#endif
KC_MS_DOWN,
KC_MS_LEFT,
- KC_MS_RIGHT, // 0xF0
+ KC_MS_RIGHT,
KC_MS_BTN1,
KC_MS_BTN2,
KC_MS_BTN3,
@@ -539,7 +543,7 @@ enum mouse_keys {
/* Acceleration */
KC_MS_ACCEL0,
KC_MS_ACCEL1,
- KC_MS_ACCEL2 // 0xFF
+ KC_MS_ACCEL2 // 0xDF, or 0xFF if via enabled
};
#include "keycode_legacy.h"
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index 81a8e61471..eef048d95c 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -39,6 +39,7 @@ typedef union {
bool swap_rctl_rgui : 1;
bool oneshot_enable : 1;
bool swap_escape_capslock : 1;
+ bool autocorrect_enable : 1;
};
} keymap_config_t;
diff --git a/quantum/keymap.h b/quantum/keymap.h
index edff484129..67e35c4e2f 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -19,38 +19,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
+#include "platform_deps.h"
#include "action.h"
-#if defined(__AVR__)
-# include <avr/pgmspace.h>
-#elif defined PROTOCOL_CHIBIOS
-// We need to ensure that chibios is include before redefining reset
-# include <ch.h>
-#endif
#include "keycode.h"
#include "report.h"
#include "host.h"
-// #include "print.h"
#include "debug.h"
#include "keycode_config.h"
#include "gpio.h" // for pin_t
-// ChibiOS uses RESET in its FlagStatus enumeration
-// Therefore define it as QK_BOOTLOADER here, to avoid name collision
-#if defined(PROTOCOL_CHIBIOS)
-# define RESET QK_BOOTLOADER
-#endif
-// Gross hack, remove me and change RESET keycode to QK_BOOT
-#if defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)
-# undef RESET
-#endif
-
#include "quantum_keycodes.h"
-// Gross hack, remove me and change RESET keycode to QK_BOOT
-#if defined(MCU_RP)
-# undef RESET
-#endif
-
// translates key to keycode
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 8d7a8bda9a..1d5ef9b403 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -61,7 +61,7 @@ action_t action_for_keycode(uint16_t keycode) {
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
break;
- case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN:
+ case KC_AUDIO_MUTE ... KC_ASSISTANT:
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
#endif
diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h
index fb6904de22..69bc435961 100644
--- a/quantum/painter/qp.h
+++ b/quantum/painter/qp.h
@@ -432,6 +432,10 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter Drivers
+#ifdef QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+# include "qp_rgb565_surface.h"
+#endif // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+
#ifdef QUANTUM_PAINTER_ILI9163_ENABLE
# include "qp_ili9163.h"
#endif // QUANTUM_PAINTER_ILI9163_ENABLE
diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c
index 5822758dce..e9b975f23a 100644
--- a/quantum/painter/qp_draw_image.c
+++ b/quantum/painter/qp_draw_image.c
@@ -25,10 +25,10 @@ typedef struct qgf_image_handle_t {
static qgf_image_handle_t image_descriptors[QUANTUM_PAINTER_NUM_IMAGES] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_image_mem
+// Helper: load image from stream
-painter_image_handle_t qp_load_image_mem(const void *buffer) {
- qp_dprintf("qp_load_image_mem: entry\n");
+static painter_image_handle_t qp_load_image_internal(bool (*stream_factory)(qgf_image_handle_t *image, void *arg), void *arg) {
+ qp_dprintf("qp_load_image: entry\n");
qgf_image_handle_t *image = NULL;
// Find a free slot
@@ -41,20 +41,18 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Drop out if not found
if (!image) {
- qp_dprintf("qp_load_image_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_image: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- image->mem_stream.length = qgf_get_total_size(&image->stream);
- image->mem_stream.position = 0;
+ if (!stream_factory(image, arg)) {
+ qp_dprintf("qp_load_image: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qgf_validate_stream(&image->stream)) {
- qp_dprintf("qp_load_image_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_image: fail (failed validation)\n");
return NULL;
}
@@ -63,11 +61,31 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Validation success, we can return the handle
image->validate_ok = true;
- qp_dprintf("qp_load_image_mem: ok\n");
+ qp_dprintf("qp_load_image: ok\n");
return (painter_image_handle_t)image;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_image_mem
+
+static inline bool image_mem_stream_factory(qgf_image_handle_t *image, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ image->mem_stream.length = qgf_get_total_size(&image->stream);
+ image->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_image_handle_t qp_load_image_mem(const void *buffer) {
+ return qp_load_image_internal(image_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_image
bool qp_close_image(painter_image_handle_t image) {
@@ -79,6 +97,7 @@ bool qp_close_image(painter_image_handle_t image) {
// Free up this image for use elsewhere.
qgf_image->validate_ok = false;
+ qp_stream_close(&qgf_image->stream);
return true;
}
diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c
index f99e082cad..0f5473abd0 100644
--- a/quantum/painter/qp_draw_text.c
+++ b/quantum/painter/qp_draw_text.c
@@ -36,10 +36,10 @@ typedef struct qff_font_handle_t {
static qff_font_handle_t font_descriptors[QUANTUM_PAINTER_NUM_FONTS] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_font_mem
+// Helper: load font from stream
-painter_font_handle_t qp_load_font_mem(const void *buffer) {
- qp_dprintf("qp_load_font_mem: entry\n");
+static painter_font_handle_t qp_load_font_internal(bool (*stream_factory)(qff_font_handle_t *font, void *arg), void *arg) {
+ qp_dprintf("qp_load_font: entry\n");
qff_font_handle_t *font = NULL;
// Find a free slot
@@ -52,20 +52,18 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
// Drop out if not found
if (!font) {
- qp_dprintf("qp_load_font_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_font: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- font->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qff_font_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- font->mem_stream.length = qff_get_total_size(&font->stream);
- font->mem_stream.position = 0;
+ if (!stream_factory(font, arg)) {
+ qp_dprintf("qp_load_font: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qff_validate_stream(&font->stream)) {
- qp_dprintf("qp_load_font_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_font: fail (failed validation)\n");
return NULL;
}
@@ -76,12 +74,12 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
void *ram_buffer = malloc(font->mem_stream.length);
if (ram_buffer == NULL) {
- qp_dprintf("qp_load_font_mem: could not allocate enough RAM for font, falling back to original\n");
+ qp_dprintf("qp_load_font: could not allocate enough RAM for font, falling back to original\n");
} else {
do {
// Copy the data into RAM
if (qp_stream_read(ram_buffer, 1, font->mem_stream.length, &font->mem_stream) != font->mem_stream.length) {
- qp_dprintf("qp_load_font_mem: could not copy from flash to RAM, falling back to original\n");
+ qp_dprintf("qp_load_font: could not copy from flash to RAM, falling back to original\n");
break;
}
@@ -102,18 +100,38 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
qff_read_font_descriptor(&font->stream, &font->base.line_height, &font->has_ascii_table, &font->num_unicode_glyphs, &font->bpp, &font->has_palette, &font->compression_scheme, NULL);
if (!qp_internal_bpp_capable(font->bpp)) {
- qp_dprintf("qp_load_font_mem: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
+ qp_dprintf("qp_load_font: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
qp_close_font((painter_font_handle_t)font);
return NULL;
}
// Validation success, we can return the handle
font->validate_ok = true;
- qp_dprintf("qp_load_font_mem: ok\n");
+ qp_dprintf("qp_load_font: ok\n");
return (painter_font_handle_t)font;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_font_mem
+
+static inline bool font_mem_stream_factory(qff_font_handle_t *font, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ font->mem_stream = qp_make_memory_stream(buffer, sizeof(qff_font_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ font->mem_stream.length = qff_get_total_size(&font->stream);
+ font->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_font_handle_t qp_load_font_mem(const void *buffer) {
+ return qp_load_font_internal(font_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_font
bool qp_close_font(painter_font_handle_t font) {
@@ -133,6 +151,7 @@ bool qp_close_font(painter_font_handle_t font) {
#endif // QUANTUM_PAINTER_LOAD_FONTS_TO_RAM
// Free up this font for use elsewhere.
+ qp_stream_close(&qff_font->stream);
qff_font->validate_ok = false;
return true;
}
diff --git a/quantum/painter/qp_stream.c b/quantum/painter/qp_stream.c
index f00ae5ed38..1198cf793d 100644
--- a/quantum/painter/qp_stream.c
+++ b/quantum/painter/qp_stream.c
@@ -38,7 +38,7 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Memory streams
-int16_t mem_get(qp_stream_t *stream) {
+static inline int16_t mem_get(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -47,7 +47,7 @@ int16_t mem_get(qp_stream_t *stream) {
return s->buffer[s->position++];
}
-bool mem_put(qp_stream_t *stream, uint8_t c) {
+static inline bool mem_put(qp_stream_t *stream, uint8_t c) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -57,7 +57,7 @@ bool mem_put(qp_stream_t *stream, uint8_t c) {
return true;
}
-int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
// Handle as per fseek
@@ -95,26 +95,23 @@ int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
return 0;
}
-int32_t mem_tell(qp_stream_t *stream) {
+static inline int32_t mem_tell(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->position;
}
-bool mem_is_eof(qp_stream_t *stream) {
+static inline bool mem_is_eof(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->is_eof;
}
+static inline void mem_close(qp_stream_t *stream) {
+ // No-op.
+}
+
qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
qp_memory_stream_t stream = {
- .base =
- {
- .get = mem_get,
- .put = mem_put,
- .seek = mem_seek,
- .tell = mem_tell,
- .is_eof = mem_is_eof,
- },
+ .base = {.get = mem_get, .put = mem_put, .seek = mem_seek, .tell = mem_tell, .is_eof = mem_is_eof, .close = mem_close},
.buffer = (uint8_t *)buffer,
.length = length,
.position = 0,
@@ -127,43 +124,41 @@ qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
#ifdef QP_STREAM_HAS_FILE_IO
-int16_t file_get(qp_stream_t *stream) {
+static inline int16_t file_get(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
int c = fgetc(s->file);
if (c < 0 || feof(s->file)) return STREAM_EOF;
return (uint16_t)c;
}
-bool file_put(qp_stream_t *stream, uint8_t c) {
+static inline bool file_put(qp_stream_t *stream, uint8_t c) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fputc(c, s->file) == c;
}
-int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fseek(s->file, offset, origin);
}
-int32_t file_tell(qp_stream_t *stream) {
+static inline int32_