Update esp_lvgl_port (#230)
Updated to espressif/esp-bsp@531ad57 https://github.com/espressif/esp-bsp/commit/531ad57f6abe178d6b43d898fac495c59747803f
This commit is contained in:
committed by
GitHub
parent
ee88a563dc
commit
44b366b557
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -56,6 +56,7 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
/* Previous button */
|
||||
if (buttons_cfg->button_prev != NULL) {
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = iot_button_create(buttons_cfg->button_prev);
|
||||
@@ -73,11 +74,23 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = iot_button_create(buttons_cfg->button_enter);
|
||||
ESP_GOTO_ON_FALSE(buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
|
||||
}
|
||||
#else
|
||||
ESP_GOTO_ON_FALSE(buttons_cfg->button_prev && buttons_cfg->button_next && buttons_cfg->button_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid some button handler!");
|
||||
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = buttons_cfg->button_prev;
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_NEXT] = buttons_cfg->button_next;
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = buttons_cfg->button_enter;
|
||||
#endif
|
||||
|
||||
/* Button handlers */
|
||||
for (int i = 0; i < LVGL_PORT_NAV_BTN_CNT; i++) {
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, lvgl_port_btn_down_handler, buttons_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, lvgl_port_btn_up_handler, buttons_ctx));
|
||||
#else
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, NULL, lvgl_port_btn_down_handler, buttons_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, NULL, lvgl_port_btn_up_handler, buttons_ctx));
|
||||
#endif
|
||||
}
|
||||
|
||||
buttons_ctx->btn_prev = false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -19,7 +19,8 @@ typedef struct {
|
||||
knob_handle_t knob_handle; /* Encoder knob handlers */
|
||||
button_handle_t btn_handle; /* Encoder button handlers */
|
||||
lv_indev_drv_t indev_drv; /* LVGL input device driver */
|
||||
bool btn_enter; /* Encoder button enter state */
|
||||
bool btn_enter; /* Encoder button enter state */
|
||||
int32_t diff; /* Encoder diff */
|
||||
} lvgl_port_encoder_ctx_t;
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -29,6 +30,9 @@ typedef struct {
|
||||
static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
|
||||
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_left_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_right_handler(void *arg, void *arg2);
|
||||
static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event);
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API functions
|
||||
@@ -54,16 +58,30 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg)
|
||||
ESP_GOTO_ON_FALSE(encoder_ctx->knob_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for knob create!");
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_left_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_right_handler, encoder_ctx));
|
||||
|
||||
/* Encoder Enter */
|
||||
if (encoder_cfg->encoder_enter != NULL) {
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
encoder_ctx->btn_handle = iot_button_create(encoder_cfg->encoder_enter);
|
||||
ESP_GOTO_ON_FALSE(encoder_ctx->btn_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
|
||||
#else
|
||||
ESP_GOTO_ON_FALSE(encoder_cfg->encoder_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid button handler!");
|
||||
encoder_ctx->btn_handle = encoder_cfg->encoder_enter;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, lvgl_port_encoder_btn_down_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx));
|
||||
#else
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, NULL, lvgl_port_encoder_btn_down_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, NULL, lvgl_port_encoder_btn_up_handler, encoder_ctx));
|
||||
#endif
|
||||
|
||||
encoder_ctx->btn_enter = false;
|
||||
encoder_ctx->diff = 0;
|
||||
|
||||
/* Register a encoder input device */
|
||||
lv_indev_drv_init(&encoder_ctx->indev_drv);
|
||||
@@ -118,22 +136,13 @@ esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder)
|
||||
|
||||
static void lvgl_port_encoder_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
|
||||
{
|
||||
static int32_t last_v = 0;
|
||||
|
||||
assert(indev_drv);
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *)indev_drv->user_data;
|
||||
assert(ctx);
|
||||
|
||||
int32_t invd = iot_knob_get_count_value(ctx->knob_handle);
|
||||
knob_event_t event = iot_knob_get_event(ctx->knob_handle);
|
||||
|
||||
if (last_v ^ invd) {
|
||||
last_v = invd;
|
||||
data->enc_diff = (KNOB_LEFT == event) ? (-1) : ((KNOB_RIGHT == event) ? (1) : (0));
|
||||
} else {
|
||||
data->enc_diff = 0;
|
||||
}
|
||||
data->enc_diff = ctx->diff;
|
||||
data->state = (true == ctx->btn_enter) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
ctx->diff = 0;
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2)
|
||||
@@ -159,3 +168,47 @@ static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_left_handler(void *arg, void *arg2)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
knob_handle_t knob = (knob_handle_t)arg;
|
||||
if (ctx && knob) {
|
||||
/* LEFT */
|
||||
if (knob == ctx->knob_handle) {
|
||||
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT);
|
||||
ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_right_handler(void *arg, void *arg2)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
knob_handle_t knob = (knob_handle_t)arg;
|
||||
if (ctx && knob) {
|
||||
/* RIGHT */
|
||||
if (knob == ctx->knob_handle) {
|
||||
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT);
|
||||
ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event)
|
||||
{
|
||||
static int32_t last_v = 0;
|
||||
|
||||
int32_t diff = 0;
|
||||
int32_t invd = iot_knob_get_count_value(knob);
|
||||
|
||||
if (last_v ^ invd) {
|
||||
|
||||
diff = (int32_t)((uint32_t)invd - (uint32_t)last_v);
|
||||
diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT :
|
||||
(event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0;
|
||||
last_v = invd;
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
#include "esp_lvgl_port_priv.h"
|
||||
#include "lvgl.h"
|
||||
@@ -30,7 +31,7 @@ typedef struct lvgl_port_ctx_s {
|
||||
TaskHandle_t lvgl_task;
|
||||
SemaphoreHandle_t lvgl_mux;
|
||||
SemaphoreHandle_t timer_mux;
|
||||
QueueHandle_t lvgl_queue;
|
||||
EventGroupHandle_t lvgl_events;
|
||||
SemaphoreHandle_t task_init_mux;
|
||||
esp_timer_handle_t tick_timer;
|
||||
bool running;
|
||||
@@ -79,17 +80,22 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
|
||||
lvgl_port_ctx.task_init_mux = xSemaphoreCreateMutex();
|
||||
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_init_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");
|
||||
/* Task queue */
|
||||
lvgl_port_ctx.lvgl_queue = xQueueCreate(100, sizeof(lvgl_port_event_t));
|
||||
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_queue, ESP_ERR_NO_MEM, err, TAG, "Create LVGL queue fail!");
|
||||
lvgl_port_ctx.lvgl_events = xEventGroupCreate();
|
||||
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_events, ESP_ERR_NO_MEM, err, TAG, "Create LVGL Event Group fail!");
|
||||
|
||||
BaseType_t res;
|
||||
if (cfg->task_affinity < 0) {
|
||||
res = xTaskCreate(lvgl_port_task, "taskLVGL", cfg->task_stack, NULL, cfg->task_priority, &lvgl_port_ctx.lvgl_task);
|
||||
res = xTaskCreate(lvgl_port_task, "taskLVGL", cfg->task_stack, xTaskGetCurrentTaskHandle(), cfg->task_priority, &lvgl_port_ctx.lvgl_task);
|
||||
} else {
|
||||
res = xTaskCreatePinnedToCore(lvgl_port_task, "taskLVGL", cfg->task_stack, NULL, cfg->task_priority, &lvgl_port_ctx.lvgl_task, cfg->task_affinity);
|
||||
res = xTaskCreatePinnedToCore(lvgl_port_task, "taskLVGL", cfg->task_stack, xTaskGetCurrentTaskHandle(), cfg->task_priority, &lvgl_port_ctx.lvgl_task, cfg->task_affinity);
|
||||
}
|
||||
ESP_GOTO_ON_FALSE(res == pdPASS, ESP_FAIL, err, TAG, "Create LVGL task fail!");
|
||||
|
||||
// Wait until taskLVGL starts
|
||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(5000)) == 0) {
|
||||
ret = ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
err:
|
||||
if (ret != ESP_OK) {
|
||||
lvgl_port_deinit();
|
||||
@@ -164,23 +170,30 @@ void lvgl_port_unlock(void)
|
||||
|
||||
esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param)
|
||||
{
|
||||
if (!lvgl_port_ctx.lvgl_queue) {
|
||||
EventBits_t bits = 0;
|
||||
if (!lvgl_port_ctx.lvgl_events) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
lvgl_port_event_t ev = {
|
||||
.type = event,
|
||||
.param = param,
|
||||
};
|
||||
/* Get unprocessed bits */
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
bits = xEventGroupGetBitsFromISR(lvgl_port_ctx.lvgl_events);
|
||||
} else {
|
||||
bits = xEventGroupGetBits(lvgl_port_ctx.lvgl_events);
|
||||
}
|
||||
|
||||
/* Set event */
|
||||
bits |= event;
|
||||
|
||||
/* Save */
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
xQueueSendFromISR(lvgl_port_ctx.lvgl_queue, &ev, &xHigherPriorityTaskWoken);
|
||||
xEventGroupSetBitsFromISR(lvgl_port_ctx.lvgl_events, bits, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken) {
|
||||
portYIELD_FROM_ISR( );
|
||||
}
|
||||
} else {
|
||||
xQueueSend(lvgl_port_ctx.lvgl_queue, &ev, 0);
|
||||
xEventGroupSetBits(lvgl_port_ctx.lvgl_events, bits);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
@@ -206,7 +219,8 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value)
|
||||
|
||||
static void lvgl_port_task(void *arg)
|
||||
{
|
||||
lvgl_port_event_t event;
|
||||
TaskHandle_t task_to_notify = (TaskHandle_t)arg;
|
||||
EventBits_t events = 0;
|
||||
uint32_t task_delay_ms = 0;
|
||||
lv_indev_t *indev = NULL;
|
||||
|
||||
@@ -219,6 +233,8 @@ static void lvgl_port_task(void *arg)
|
||||
|
||||
/* LVGL init */
|
||||
lv_init();
|
||||
/* LVGL is initialized, notify lvgl_port_init() function about it */
|
||||
xTaskNotifyGive(task_to_notify);
|
||||
/* Tick init */
|
||||
lvgl_port_tick_init();
|
||||
|
||||
@@ -227,21 +243,17 @@ static void lvgl_port_task(void *arg)
|
||||
while (lvgl_port_ctx.running) {
|
||||
/* Wait for queue or timeout (sleep task) */
|
||||
TickType_t wait = (pdMS_TO_TICKS(task_delay_ms) >= 1 ? pdMS_TO_TICKS(task_delay_ms) : 1);
|
||||
xQueueReceive(lvgl_port_ctx.lvgl_queue, &event, wait);
|
||||
events = xEventGroupWaitBits(lvgl_port_ctx.lvgl_events, 0xFF, pdTRUE, pdFALSE, wait);
|
||||
|
||||
if (lv_display_get_default() && lvgl_port_lock(0)) {
|
||||
|
||||
/* Call read input devices */
|
||||
if (event.type == LVGL_PORT_EVENT_TOUCH) {
|
||||
if (events & LVGL_PORT_EVENT_TOUCH) {
|
||||
xSemaphoreTake(lvgl_port_ctx.timer_mux, portMAX_DELAY);
|
||||
if (event.param != NULL) {
|
||||
lv_indev_read(event.param);
|
||||
} else {
|
||||
indev = lv_indev_get_next(NULL);
|
||||
while (indev != NULL) {
|
||||
lv_indev_read(indev);
|
||||
indev = lv_indev_get_next(indev);
|
||||
}
|
||||
indev = lv_indev_get_next(NULL);
|
||||
while (indev != NULL) {
|
||||
lv_indev_read(indev);
|
||||
indev = lv_indev_get_next(indev);
|
||||
}
|
||||
xSemaphoreGive(lvgl_port_ctx.timer_mux);
|
||||
}
|
||||
@@ -279,8 +291,8 @@ static void lvgl_port_task_deinit(void)
|
||||
if (lvgl_port_ctx.task_init_mux) {
|
||||
vSemaphoreDelete(lvgl_port_ctx.task_init_mux);
|
||||
}
|
||||
if (lvgl_port_ctx.lvgl_queue) {
|
||||
vQueueDelete(lvgl_port_ctx.lvgl_queue);
|
||||
if (lvgl_port_ctx.lvgl_events) {
|
||||
vEventGroupDelete(lvgl_port_ctx.lvgl_events);
|
||||
}
|
||||
memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));
|
||||
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -56,6 +56,7 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
/* Previous button */
|
||||
if (buttons_cfg->button_prev != NULL) {
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = iot_button_create(buttons_cfg->button_prev);
|
||||
@@ -73,11 +74,23 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = iot_button_create(buttons_cfg->button_enter);
|
||||
ESP_GOTO_ON_FALSE(buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
|
||||
}
|
||||
#else
|
||||
ESP_GOTO_ON_FALSE(buttons_cfg->button_prev && buttons_cfg->button_next && buttons_cfg->button_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid some button handler!");
|
||||
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = buttons_cfg->button_prev;
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_NEXT] = buttons_cfg->button_next;
|
||||
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = buttons_cfg->button_enter;
|
||||
#endif
|
||||
|
||||
/* Button handlers */
|
||||
for (int i = 0; i < LVGL_PORT_NAV_BTN_CNT; i++) {
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, lvgl_port_btn_down_handler, buttons_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, lvgl_port_btn_up_handler, buttons_ctx));
|
||||
#else
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, NULL, lvgl_port_btn_down_handler, buttons_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, NULL, lvgl_port_btn_up_handler, buttons_ctx));
|
||||
#endif
|
||||
}
|
||||
|
||||
buttons_ctx->btn_prev = false;
|
||||
|
||||
@@ -251,6 +251,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
ESP_RETURN_ON_FALSE(disp_cfg->color_format == 0 || disp_cfg->color_format == LV_COLOR_FORMAT_RGB565 || disp_cfg->color_format == LV_COLOR_FORMAT_RGB888 || disp_cfg->color_format == LV_COLOR_FORMAT_XRGB8888 || disp_cfg->color_format == LV_COLOR_FORMAT_ARGB8888 || disp_cfg->color_format == LV_COLOR_FORMAT_I1, NULL, TAG, "Not supported display color format!");
|
||||
|
||||
lv_color_format_t display_color_format = (disp_cfg->color_format != 0 ? disp_cfg->color_format : LV_COLOR_FORMAT_RGB565);
|
||||
uint8_t color_bytes = lv_color_format_get_size(display_color_format);
|
||||
if (disp_cfg->flags.swap_bytes) {
|
||||
/* Swap bytes can be used only in RGB565 color format */
|
||||
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "Swap bytes can be used only in display color format RGB565!");
|
||||
@@ -258,7 +259,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
|
||||
if (disp_cfg->flags.buff_dma) {
|
||||
/* DMA buffer can be used only in RGB565 color format */
|
||||
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "DMA buffer can be used only in display color format RGB565 (not alligned copy)!");
|
||||
ESP_RETURN_ON_FALSE(display_color_format == LV_COLOR_FORMAT_RGB565, NULL, TAG, "DMA buffer can be used only in display color format RGB565 (not aligned copy)!");
|
||||
}
|
||||
|
||||
/* Display context */
|
||||
@@ -307,10 +308,10 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
} else {
|
||||
/* alloc draw buffers used by LVGL */
|
||||
/* it's recommended to choose the size of the draw buffer(s) to be at least 1/10 screen sized */
|
||||
buf1 = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
|
||||
buf1 = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
|
||||
ESP_GOTO_ON_FALSE(buf1, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (buf1) allocation!");
|
||||
if (disp_cfg->double_buffer) {
|
||||
buf2 = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
|
||||
buf2 = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
|
||||
ESP_GOTO_ON_FALSE(buf2, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (buf2) allocation!");
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Monochromatic display must using full buffer!");
|
||||
|
||||
disp_ctx->flags.monochrome = 1;
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_FULL);
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL);
|
||||
|
||||
if (display_color_format == LV_COLOR_FORMAT_I1) {
|
||||
/* OLED monochrome buffer */
|
||||
@@ -350,15 +351,15 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Direct mode must using full buffer!");
|
||||
|
||||
disp_ctx->flags.direct_mode = 1;
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_DIRECT);
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_DIRECT);
|
||||
} else if (disp_cfg->flags.full_refresh) {
|
||||
/* When using full_refresh, there must be used full bufer! */
|
||||
ESP_GOTO_ON_FALSE((disp_cfg->hres * disp_cfg->vres == buffer_size), ESP_ERR_INVALID_ARG, err, TAG, "Full refresh must using full buffer!");
|
||||
|
||||
disp_ctx->flags.full_refresh = 1;
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_FULL);
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL);
|
||||
} else {
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
lv_display_set_buffers(disp, buf1, buf2, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
}
|
||||
|
||||
lv_display_set_flush_cb(disp, lvgl_port_flush_callback);
|
||||
@@ -371,7 +372,7 @@ static lv_display_t *lvgl_port_add_disp_priv(const lvgl_port_display_cfg_t *disp
|
||||
|
||||
/* Use SW rotation */
|
||||
if (disp_cfg->flags.sw_rotate) {
|
||||
disp_ctx->draw_buffs[2] = heap_caps_malloc(buffer_size * sizeof(lv_color_t), buff_caps);
|
||||
disp_ctx->draw_buffs[2] = heap_caps_malloc(buffer_size * color_bytes, buff_caps);
|
||||
ESP_GOTO_ON_FALSE(disp_ctx->draw_buffs[2], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for LVGL buffer (rotation buffer) allocation!");
|
||||
}
|
||||
|
||||
@@ -567,7 +568,7 @@ static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, u
|
||||
int offsety2 = area->y2;
|
||||
|
||||
/* SW rotation enabled */
|
||||
if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0 || disp_ctx->flags.swap_bytes)) {
|
||||
if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0)) {
|
||||
/* SW rotation */
|
||||
if (disp_ctx->draw_buffs[2]) {
|
||||
int32_t ww = lv_area_get_width(area);
|
||||
@@ -589,7 +590,9 @@ static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, u
|
||||
offsety1 = area->y1;
|
||||
offsety2 = area->y2;
|
||||
}
|
||||
} else if (disp_ctx->flags.swap_bytes) {
|
||||
}
|
||||
|
||||
if (disp_ctx->flags.swap_bytes) {
|
||||
size_t len = lv_area_get_size(area);
|
||||
lv_draw_sw_rgb565_swap(color_map, len);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -20,6 +20,7 @@ typedef struct {
|
||||
button_handle_t btn_handle; /* Encoder button handlers */
|
||||
lv_indev_t *indev; /* LVGL input device driver */
|
||||
bool btn_enter; /* Encoder button enter state */
|
||||
int32_t diff; /* Encoder diff */
|
||||
} lvgl_port_encoder_ctx_t;
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -27,9 +28,11 @@ typedef struct {
|
||||
*******************************************************************************/
|
||||
|
||||
static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data);
|
||||
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_knob_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_btn_down_handler(void *button_handle, void *usr_data);
|
||||
static void lvgl_port_encoder_btn_up_handler(void *button_handle, void *usr_data);
|
||||
static void lvgl_port_encoder_left_handler(void *arg, void *arg2);
|
||||
static void lvgl_port_encoder_right_handler(void *arg, void *arg2);
|
||||
static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event);
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API functions
|
||||
@@ -54,20 +57,31 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg)
|
||||
encoder_ctx->knob_handle = iot_knob_create(encoder_cfg->encoder_a_b);
|
||||
ESP_GOTO_ON_FALSE(encoder_ctx->knob_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for knob create!");
|
||||
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_knob_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_knob_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_LEFT, lvgl_port_encoder_left_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_knob_register_cb(encoder_ctx->knob_handle, KNOB_RIGHT, lvgl_port_encoder_right_handler, encoder_ctx));
|
||||
}
|
||||
|
||||
/* Encoder Enter */
|
||||
if (encoder_cfg->encoder_enter != NULL) {
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
encoder_ctx->btn_handle = iot_button_create(encoder_cfg->encoder_enter);
|
||||
ESP_GOTO_ON_FALSE(encoder_ctx->btn_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
|
||||
#else
|
||||
ESP_GOTO_ON_FALSE(encoder_cfg->encoder_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid button handler!");
|
||||
encoder_ctx->btn_handle = encoder_cfg->encoder_enter;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUTTON_VER_MAJOR < 4
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, lvgl_port_encoder_btn_down_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx));
|
||||
#else
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, NULL, lvgl_port_encoder_btn_down_handler, encoder_ctx));
|
||||
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, NULL, lvgl_port_encoder_btn_up_handler, encoder_ctx));
|
||||
#endif
|
||||
|
||||
encoder_ctx->btn_enter = false;
|
||||
encoder_ctx->diff = 0;
|
||||
|
||||
lvgl_port_lock(0);
|
||||
/* Register a encoder input device */
|
||||
@@ -130,27 +144,19 @@ esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder)
|
||||
|
||||
static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data)
|
||||
{
|
||||
static int32_t last_v = 0;
|
||||
assert(indev_drv);
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *)lv_indev_get_driver_data(indev_drv);
|
||||
assert(ctx);
|
||||
|
||||
int32_t invd = iot_knob_get_count_value(ctx->knob_handle);
|
||||
knob_event_t event = iot_knob_get_event(ctx->knob_handle);
|
||||
|
||||
if (last_v ^ invd) {
|
||||
last_v = invd;
|
||||
data->enc_diff = (KNOB_LEFT == event) ? (-1) : ((KNOB_RIGHT == event) ? (1) : (0));
|
||||
} else {
|
||||
data->enc_diff = 0;
|
||||
}
|
||||
data->enc_diff = ctx->diff;
|
||||
data->state = (true == ctx->btn_enter) ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
|
||||
ctx->diff = 0;
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2)
|
||||
static void lvgl_port_encoder_btn_down_handler(void *button_handle, void *usr_data)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
button_handle_t button = (button_handle_t)arg;
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) usr_data;
|
||||
button_handle_t button = (button_handle_t)button_handle;
|
||||
if (ctx && button) {
|
||||
/* ENTER */
|
||||
if (button == ctx->btn_handle) {
|
||||
@@ -162,10 +168,10 @@ static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2)
|
||||
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2)
|
||||
static void lvgl_port_encoder_btn_up_handler(void *button_handle, void *usr_data)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
button_handle_t button = (button_handle_t)arg;
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) usr_data;
|
||||
button_handle_t button = (button_handle_t)button_handle;
|
||||
if (ctx && button) {
|
||||
/* ENTER */
|
||||
if (button == ctx->btn_handle) {
|
||||
@@ -177,9 +183,51 @@ static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2)
|
||||
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_knob_handler(void *arg, void *arg2)
|
||||
static void lvgl_port_encoder_left_handler(void *arg, void *arg2)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
/* Wake LVGL task, if needed */
|
||||
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
|
||||
knob_handle_t knob = (knob_handle_t)arg;
|
||||
if (ctx && knob) {
|
||||
/* LEFT */
|
||||
if (knob == ctx->knob_handle) {
|
||||
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_LEFT);
|
||||
ctx->diff = (ctx->diff > 0) ? diff : ctx->diff + diff;
|
||||
}
|
||||
/* Wake LVGL task, if needed */
|
||||
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
|
||||
}
|
||||
}
|
||||
|
||||
static void lvgl_port_encoder_right_handler(void *arg, void *arg2)
|
||||
{
|
||||
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
|
||||
knob_handle_t knob = (knob_handle_t)arg;
|
||||
if (ctx && knob) {
|
||||
/* RIGHT */
|
||||
if (knob == ctx->knob_handle) {
|
||||
int32_t diff = lvgl_port_calculate_diff(knob, KNOB_RIGHT);
|
||||
ctx->diff = (ctx->diff < 0) ? diff : ctx->diff + diff;
|
||||
}
|
||||
/* Wake LVGL task, if needed */
|
||||
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event)
|
||||
{
|
||||
static int32_t last_v = 0;
|
||||
|
||||
int32_t diff = 0;
|
||||
int32_t invd = iot_knob_get_count_value(knob);
|
||||
|
||||
if (last_v ^ invd) {
|
||||
|
||||
diff = (int32_t)((uint32_t)invd - (uint32_t)last_v);
|
||||
diff += (event == KNOB_RIGHT && invd < last_v) ? CONFIG_KNOB_HIGH_LIMIT :
|
||||
(event == KNOB_LEFT && invd > last_v) ? CONFIG_KNOB_LOW_LIMIT : 0;
|
||||
last_v = invd;
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@
|
||||
|
||||
lv_color_blend_to_argb8888_esp:
|
||||
|
||||
entry a1, 32
|
||||
ee.zero.q q0 // dummy TIE instruction, to enable the TIE
|
||||
entry a1, 32
|
||||
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint32_t
|
||||
|
||||
@@ -31,8 +31,7 @@
|
||||
|
||||
lv_color_blend_to_rgb565_esp:
|
||||
|
||||
entry a1, 32
|
||||
ee.zero.q q0 // dummy TIE instruction, to enable the TIE
|
||||
entry a1, 32
|
||||
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint16_t
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// This is LVGL RGB888 simple fill for ESP32 processor
|
||||
|
||||
.section .text
|
||||
.align 4
|
||||
.global lv_color_blend_to_rgb888_esp
|
||||
.type lv_color_blend_to_rgb888_esp,@function
|
||||
// The function implements the following C code:
|
||||
// void lv_color_blend_to_rgb888(_lv_draw_sw_blend_fill_dsc_t * dsc);
|
||||
|
||||
// Input params
|
||||
//
|
||||
// dsc - a2
|
||||
|
||||
// typedef struct {
|
||||
// uint32_t opa; l32i 0
|
||||
// void * dst_buf; l32i 4
|
||||
// uint32_t dst_w; l32i 8
|
||||
// uint32_t dst_h; l32i 12
|
||||
// uint32_t dst_stride; l32i 16
|
||||
// const void * src_buf; l32i 20
|
||||
// uint32_t src_stride; l32i 24
|
||||
// const lv_opa_t * mask_buf; l32i 28
|
||||
// uint32_t mask_stride; l32i 32
|
||||
// } asm_dsc_t;
|
||||
|
||||
lv_color_blend_to_rgb888_esp:
|
||||
|
||||
entry a1, 32
|
||||
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint24_t
|
||||
l32i.n a5, a2, 12 // a5 - dest_h in uint16_t
|
||||
l32i.n a6, a2, 16 // a6 - dest_stride in bytes
|
||||
l32i.n a7, a2, 20 // a7 - src_buff (color)
|
||||
l32i.n a8, a7, 0 // a8 - color as value
|
||||
|
||||
// a11 - dest_w_bytes = sizeof(uint24_t) * dest_w = 3 * a4
|
||||
slli a11, a4, 1 // a11 - dest_w_bytes = sizeof(uint16_t) * dest_w
|
||||
add a11, a11, a4 // a11 - dest_w_bytes = a11 + a4
|
||||
|
||||
// Prepare register combinations
|
||||
// a13 - 0xBBRRGGBB a14 - 0xGGBBRRGG a15 - 0xRRGGBBRR
|
||||
l8ui a13, a7, 0 // blue 000B
|
||||
slli a13, a13, 24 // shift to B000
|
||||
or a13, a13, a8 // a13 BRGB
|
||||
|
||||
srli a14, a8, 8 // a14 00RG
|
||||
slli a10, a8, 16 // a10 GB00
|
||||
or a14, a14, a10 // a14 GBRG
|
||||
|
||||
slli a15, a8, 8 // a15 RGB0
|
||||
l8ui a10, a7, 2 // a7 000R
|
||||
or a15, a15, a10 // a15 RGBR
|
||||
|
||||
sub a6, a6, a11 // dest_stride = dest_stride - dest_w_bytes
|
||||
|
||||
// Prepare main loop length and dest_w_bytes
|
||||
srli a9, a4, 2 // a9 = loop_len = dest_w / 4, calculate main loop_len for original dest_w
|
||||
movi.n a8, 0x3 // a8 = 0x3, remainder mask
|
||||
and a10, a4, a8 // a10 - remainder after division by 4 = a4 and 0x3
|
||||
|
||||
.outer_loop:
|
||||
|
||||
// Run main loop which sets 12 bytes (4 rgb888) in one loop run
|
||||
loopnez a9, ._main_loop
|
||||
s32i.n a13, a3, 0 // save 32 bits from 32-bit color a13 to dest_buff a3, offset 0
|
||||
s32i.n a14, a3, 4 // save 32 bits from 32-bit color a14 to dest_buff a3, offset 4
|
||||
s32i.n a15, a3, 8 // save 32 bits from 32-bit color a15 to dest_buff a3, offset 8
|
||||
addi.n a3, a3, 12 // increment dest_buff pointer by 12
|
||||
._main_loop:
|
||||
|
||||
bnei a10, 0x3, _less_than_3 // branch if less than 3 values left
|
||||
s32i.n a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s32i.n a14, a3, 4 // save 32 bits from a14 to dest_buff a3, offset 4 bytes
|
||||
s8i a15, a3, 8 // save 8 bits from a15 to dest_buff a3, offset 8 bytes
|
||||
addi.n a3, a3, 9 // increment dest_buff pointer by 9 bytes
|
||||
j _less_than_1
|
||||
_less_than_3:
|
||||
|
||||
bnei a10, 0x2, _less_than_2 // branch if less than 2 values left
|
||||
s32i.n a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s16i a14, a3, 4 // save 16 bits from a14 to dest_buff a3, offset 4 bytes
|
||||
addi.n a3, a3, 6 // increment dest_buff pointer by 6 bytes
|
||||
j _less_than_1
|
||||
_less_than_2:
|
||||
|
||||
bnei a10, 0x1, _less_than_1 // branch if less than 1 value left
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s8i a15, a3, 2 // save 8 bits from a15 to dest_buff a3, offset 2 bytes
|
||||
addi.n a3, a3, 3 // increment dest_buff pointer by 3 bytes
|
||||
_less_than_1:
|
||||
|
||||
add a3, a3, a6 // dest_buff + dest_stride
|
||||
addi.n a5, a5, -1 // decrease the outer loop
|
||||
and a7, a8, a3 // a7 = dest_buff AND 0x3 (check if the address is 4-byte aligned)
|
||||
bnez a5, .outer_loop
|
||||
|
||||
movi.n a2, 1 // return LV_RESULT_OK = 1
|
||||
retw.n // return
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// This is LVGL RGB888 simple fill for ESP32S3 processor
|
||||
|
||||
.section .text
|
||||
.align 4
|
||||
.global lv_color_blend_to_rgb888_esp
|
||||
.type lv_color_blend_to_rgb888_esp,@function
|
||||
// The function implements the following C code:
|
||||
// void lv_color_blend_to_rgb888(_lv_draw_sw_blend_fill_dsc_t * dsc);
|
||||
|
||||
// Input params
|
||||
//
|
||||
// dsc - a2
|
||||
|
||||
// typedef struct {
|
||||
// uint32_t opa; l32i 0
|
||||
// void * dst_buf; l32i 4
|
||||
// uint32_t dst_w; l32i 8
|
||||
// uint32_t dst_h; l32i 12
|
||||
// uint32_t dst_stride; l32i 16
|
||||
// const void * src_buf; l32i 20
|
||||
// uint32_t src_stride; l32i 24
|
||||
// const lv_opa_t * mask_buf; l32i 28
|
||||
// uint32_t mask_stride; l32i 32
|
||||
// } asm_dsc_t;
|
||||
|
||||
lv_color_blend_to_rgb888_esp:
|
||||
|
||||
entry a1, 32
|
||||
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint24_t
|
||||
l32i.n a5, a2, 12 // a5 - dest_h in uint16_t
|
||||
l32i.n a6, a2, 16 // a6 - dest_stride in bytes
|
||||
l32i.n a7, a2, 20 // a7 - src_buff (color)
|
||||
l32i.n a8, a7, 0 // a8 - color as value
|
||||
|
||||
// a11 - dest_w_bytes = sizeof(uint24_t) * dest_w = 3 * a4
|
||||
slli a11, a4, 1 // a11 - dest_w_bytes = 2 * dest_w
|
||||
add a11, a11, a4 // a11 - dest_w_bytes = a11 + a4
|
||||
|
||||
// Prepare register combinations
|
||||
// a13 - 0xBBRRGGBB a14 - 0xGGBBRRGG a15 - 0xRRGGBBRR
|
||||
l8ui a13, a7, 0 // blue 000B
|
||||
slli a13, a13, 24 // shift to B000
|
||||
or a13, a13, a8 // a13 BRGB
|
||||
|
||||
srli a14, a8, 8 // a14 00RG
|
||||
slli a10, a8, 16 // a10 GB00
|
||||
or a14, a14, a10 // a14 GBRG
|
||||
|
||||
slli a15, a8, 8 // a15 RGB0
|
||||
l8ui a10, a7, 2 // a7 000R
|
||||
or a15, a15, a10 // a15 RGBR
|
||||
|
||||
sub a6, a6, a11 // dest_stride = dest_stride - dest_w_bytes
|
||||
|
||||
// Check for short lengths
|
||||
// dest_w should be at least 12, othewise it's not worth using esp32s3 TIE
|
||||
bgei a4, 12, _esp32s3_implementation // Branch if dest_w is greater than or equal to 12
|
||||
j .lv_color_blend_to_rgb888_esp32_body // Jump to esp32 implementation
|
||||
|
||||
_esp32s3_implementation:
|
||||
|
||||
// Prepare q registers for the main loop
|
||||
ee.movi.32.q q3, a13, 0 // fill q3 register from a13 by 32 bits
|
||||
ee.movi.32.q q3, a14, 1 // fill q3 register from a14 by 32 bits
|
||||
ee.movi.32.q q3, a15, 2 // fill q3 register from a15 by 32 bits
|
||||
ee.movi.32.q q3, a13, 3 // fill q3 register from a13 by 32 bits
|
||||
|
||||
ee.movi.32.q q4, a14, 0 // fill q4 register from a14 by 32 bits
|
||||
ee.movi.32.q q4, a15, 1 // fill q4 register from a15 by 32 bits
|
||||
ee.movi.32.q q4, a13, 2 // fill q4 register from a13 by 32 bits
|
||||
ee.movi.32.q q4, a14, 3 // fill q4 register from a14 by 32 bits
|
||||
|
||||
ee.movi.32.q q5, a15, 0 // fill q5 register from a15 by 32 bits
|
||||
ee.movi.32.q q5, a13, 1 // fill q5 register from a13 by 32 bits
|
||||
ee.movi.32.q q5, a14, 2 // fill q5 register from a14 by 32 bits
|
||||
ee.movi.32.q q5, a15, 3 // fill q5 register from a15 by 32 bits
|
||||
|
||||
.outer_loop_aligned:
|
||||
|
||||
// q registers will get shifted and clobbered, need to reinitialize them before using them again
|
||||
// Clear q registers
|
||||
ee.zero.q q0 // clear q0
|
||||
ee.zero.q q1 // clear q1
|
||||
ee.zero.q q2 // clear q2
|
||||
|
||||
// Reinitialize q registers
|
||||
ee.orq q0, q0, q3 // copy q3 to q0
|
||||
ee.orq q1, q1, q4 // copy q4 to q1
|
||||
ee.orq q2, q2, q5 // copy q5 to q2
|
||||
|
||||
// alignment check
|
||||
extui a8, a3, 0, 4 // address_alignment (a8) = dest_buff address (a3) AND 0xf
|
||||
|
||||
movi.n a12, 16 // a12 = 16
|
||||
mov.n a2, a8 // unalignment (a2) = a8
|
||||
// following instruction is here to avoid branching
|
||||
// need to adjust a8 == 0 to 16 to make the unalignment computation work
|
||||
moveqz a2, a12, a8 // modified unalignment (a2) = 16 if unalignment (a8) == 0
|
||||
|
||||
sub a2, a12, a2 // a2 = 16 - unalignment (lower 4 bits of dest_buff address)
|
||||
sub a10, a11, a2 // local_dest_w_bytes = len - (16 - unalignment)
|
||||
|
||||
movi.n a12, 48 // a12 = 48 (main loop copies 48 bytes)
|
||||
quou a9, a10, a12 // main_loop counter (a9) = local_dest_w_bytes (a10) DIV 48 (a12)
|
||||
remu a10, a10, a12 // a10 = local_dest_w_bytes (a10) MOD 48 (a12)
|
||||
|
||||
beqz a8, _dest_buff_aligned // If already aligned, skip aligning
|
||||
|
||||
movi.n a7, unalignment_table // Load unalignment_table address
|
||||
|
||||
addx4 a7, a8, a7 // jump_table handle (a7) = offset (a8) * 4 + jump_table address (a7)
|
||||
l32i a7, a7, 0 // Load target address from jump table
|
||||
jx a7 // Jump to the corresponding handler
|
||||
|
||||
|
||||
// a13 - 0xBBRRGGBB a14 - 0xGGBBRRGG a15 - 0xRRGGBBRR
|
||||
handle_0:
|
||||
handle_1:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s16i a14, a3, 0 // save 16 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
s32i a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
ee.vst.l.64.ip q1, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_2:
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
s32i a15, a3, 0 // save 32 bits from a15 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
ee.vst.l.64.ip q0, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_3:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s32i a14, a3, 0 // save 32 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
ee.vst.l.64.ip q2, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_4:
|
||||
s32i a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
ee.vst.l.64.ip q1, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_5:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s16i a14, a3, 0 // save 16 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
ee.vst.l.64.ip q0, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_6:
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 byte
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
ee.vst.l.64.ip q2, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_7:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
ee.vst.l.64.ip q1, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
handle_8:
|
||||
ee.vst.l.64.ip q0, a3, 8 // save lower 64 bits from q0 to dest_buff a3, increase dest_buff pointer by 8 bytes
|
||||
j _shift_q_regs
|
||||
|
||||
handle_9:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s16i a14, a3, 0 // save 16 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
s32i a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
j _shift_q_regs
|
||||
handle_10:
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
s32i a15, a3, 0 // save 32 bits from a15 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
j _shift_q_regs
|
||||
handle_11:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s32i a14, a3, 0 // save 32 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
j _shift_q_regs
|
||||
handle_12:
|
||||
s32i a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
j _shift_q_regs
|
||||
handle_13:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
s16i a14, a3, 0 // save 16 bits from a14 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
j _shift_q_regs
|
||||
handle_14:
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
j _shift_q_regs
|
||||
handle_15:
|
||||
s8i a13, a3, 0 // save 8 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
j _shift_q_regs
|
||||
|
||||
.align 4
|
||||
|
||||
unalignment_table:
|
||||
.word handle_0 // Case 0: Dummy case for easier address computation
|
||||
.word handle_1 // Case 1: Align 15 bytes
|
||||
.word handle_2 // Case 2: Align 14 bytes
|
||||
.word handle_3 // Case 3: Align 13 bytes
|
||||
.word handle_4 // Case 4: Align 12 bytes
|
||||
.word handle_5 // Case 5: Align 11 bytes
|
||||
.word handle_6 // Case 6: Align 10 bytes
|
||||
.word handle_7 // Case 7: Align 9 bytes
|
||||
.word handle_8 // Case 8: Align 8 bytes
|
||||
.word handle_9 // Case 9: Align 7 bytes
|
||||
.word handle_10 // Case 10: Align 6 bytes
|
||||
.word handle_11 // Case 11: Align 5 bytes
|
||||
.word handle_12 // Case 12: Align 4 bytes
|
||||
.word handle_13 // Case 13: Align 3 bytes
|
||||
.word handle_14 // Case 14: Align 2 bytes
|
||||
.word handle_15 // Case 15: Align 1 byte
|
||||
|
||||
|
||||
_shift_q_regs:
|
||||
wur.sar_byte a2 // apply unalignment to the SAR_BYTE
|
||||
ee.src.q q0, q0, q1 // shift concat. of q0 and q1 to q0 by SAR_BYTE amount
|
||||
ee.src.q q1, q1, q2 // shift concat. of q1 and q2 to q1 by SAR_BYTE amount
|
||||
ee.src.q q2, q2, q3 // shift concat. of q2 and q3 to q2 by SAR_BYTE amount
|
||||
|
||||
_dest_buff_aligned:
|
||||
loopnez a9, ._main_loop_aligned // 48 bytes (16 rgb888) in one loop
|
||||
ee.vst.128.ip q0, a3, 16 // store 16 bytes from q0 to dest_buff a3
|
||||
ee.vst.128.ip q1, a3, 16 // store 16 bytes from q1 to dest_buff a3
|
||||
ee.vst.128.ip q2, a3, 16 // store 16 bytes from q2 to dest_buff a3
|
||||
._main_loop_aligned:
|
||||
|
||||
// Check modulo 32 of the unalignment, if - then set 32 bytes
|
||||
bbci a10, 5, .lt_32 // branch if 5-th bit of local_dest_w_bytes a10 is clear
|
||||
ee.vst.128.ip q0, a3, 16 // store 16 bytes from q0 to dest_buff a3
|
||||
ee.vst.128.ip q1, a3, 16 // store 16 bytes from q1 to dest_buff a3
|
||||
|
||||
ee.srci.2q q0, q1, 1 // shift q0 register to have next bytes to store ready from LSB
|
||||
.lt_32:
|
||||
|
||||
// Check modulo 16 of the unalignment, if - then set 16 bytes
|
||||
bbci a10, 4, .lt_16 // branch if 4-th bit of local_dest_w_bytes a10 is clear
|
||||
ee.vst.128.ip q0, a3, 16 // store 16 bytes from q0 to dest_buff a3
|
||||
|
||||
ee.srci.2q q0, q1, 0 // shift q0 register to have next bytes to store ready from LSB
|
||||
.lt_16:
|
||||
|
||||
// Check modulo 8 of the unalignment, if - then set 8 bytes
|
||||
bbci a10, 3, .lt_8
|
||||
ee.vst.l.64.ip q0, a3, 8 // store 8 bytes from q0 to dest_buff a3
|
||||
|
||||
ee.srci.2q q0, q1, 1 // shift q0 register to have next bytes to store ready from LSB
|
||||
.lt_8:
|
||||
|
||||
// Check modulo 4 of the unalignment, if - then set 4 bytes
|
||||
bbci a10, 2, .lt_4
|
||||
ee.movi.32.a q0, a2, 0 // move lowest 32 bits of q0 to a2
|
||||
s32i.n a2, a3, 0 // save 32 bits from a2 to dest_buff a3, offset 0
|
||||
addi.n a3, a3, 4 // increment dest_buff pointer by 4 bytes
|
||||
|
||||
ee.srci.2q q0, q1, 0 // shift q0 register to have next bytes to store ready from LSB
|
||||
.lt_4:
|
||||
|
||||
// Check modulo 2 of the unalignment, if - then set 2 bytes
|
||||
bbci a10, 1, .lt_2
|
||||
ee.movi.32.a q0, a2, 0 // move lowest 32 bits of q0 to a2
|
||||
s16i a2, a3, 0 // save 16 bits from a2 to dest_buff a3, offset 0
|
||||
addi.n a3, a3, 2 // increment dest_buff pointer by 2 bytes
|
||||
|
||||
ee.srci.2q q0, q1, 1 // shift q0 register to have next bytes to store ready from LSB
|
||||
.lt_2:
|
||||
|
||||
// Check modulo 1 of the unalignment, if - then set 1 byte
|
||||
bbci a10, 0, .lt_1
|
||||
ee.movi.32.a q0, a2, 0 // move lowest 32 bits of q0 to a2
|
||||
s8i a2, a3, 0 // save 8 bits from a2 to dest_buff a3, offset 0
|
||||
addi.n a3, a3, 1 // increment dest_buff pointer by 1 byte
|
||||
.lt_1:
|
||||
|
||||
add a3, a3, a6 // dest_buff + dest_stride
|
||||
addi.n a5, a5, -1 // decrease the outer loop
|
||||
bnez a5, .outer_loop_aligned
|
||||
|
||||
movi.n a2, 1 // return LV_RESULT_OK = 1
|
||||
retw.n // return
|
||||
|
||||
.lv_color_blend_to_rgb888_esp32_body:
|
||||
|
||||
// Prepare main loop length and dest_w_bytes
|
||||
srli a9, a4, 2 // a9 = loop_len = dest_w / 4, calculate main loop_len for original dest_w
|
||||
movi.n a8, 0x3 // a8 = 0x3, remainder mask
|
||||
and a10, a4, a8 // a10 - remainder after division by 4 = a4 & 0x3
|
||||
|
||||
.outer_loop:
|
||||
|
||||
// Run main loop which sets 12 bytes (4 rgb888) in one loop run
|
||||
loopnez a9, ._main_loop
|
||||
s32i.n a13, a3, 0 // save 32 bits from 32-bit color a13 to dest_buff a3, offset 0
|
||||
s32i.n a14, a3, 4 // save 32 bits from 32-bit color a14 to dest_buff a3, offset 4
|
||||
s32i.n a15, a3, 8 // save 32 bits from 32-bit color a15 to dest_buff a3, offset 8
|
||||
addi.n a3, a3, 12 // increment dest_buff pointer by 12
|
||||
._main_loop:
|
||||
|
||||
bnei a10, 0x3, _less_than_3 // branch if less than 3 values left
|
||||
s32i.n a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s32i.n a14, a3, 4 // save 32 bits from a14 to dest_buff a3, offset 4 bytes
|
||||
s8i a15, a3, 8 // save 8 bits from a15 to dest_buff a3, offset 8 bytes
|
||||
addi.n a3, a3, 9 // increment dest_buff pointer by 9 bytes
|
||||
j _less_than_1
|
||||
_less_than_3:
|
||||
|
||||
bnei a10, 0x2, _less_than_2 // branch if less than 2 values left
|
||||
s32i.n a13, a3, 0 // save 32 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s16i a14, a3, 4 // save 16 bits from a14 to dest_buff a3, offset 4 bytes
|
||||
addi.n a3, a3, 6 // increment dest_buff pointer by 6 bytes
|
||||
j _less_than_1
|
||||
_less_than_2:
|
||||
|
||||
bnei a10, 0x1, _less_than_1 // branch if less than 1 value left
|
||||
s16i a13, a3, 0 // save 16 bits from a13 to dest_buff a3, offset 0 bytes
|
||||
s8i a15, a3, 2 // save 8 bits from a15 to dest_buff a3, offset 2 bytes
|
||||
addi.n a3, a3, 3 // increment dest_buff pointer by 3 bytes
|
||||
_less_than_1:
|
||||
|
||||
add a3, a3, a6 // dest_buff + dest_stride
|
||||
addi.n a5, a5, -1 // decrease the outer loop
|
||||
and a7, a8, a3 // a7 = dest_buff AND 0x3 (chck if the address is 4-byte aligned)
|
||||
bnez a5, .outer_loop
|
||||
|
||||
movi.n a2, 1 // return LV_RESULT_OK = 1
|
||||
retw.n // return
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// Memcpy macros for modulo checking
|
||||
// After running the main loop, there is need to check remaining bytes to be copied out of the main loop
|
||||
// Macros work with both, aligned and unaligned (4-byte boundary) memories
|
||||
// but performance is significantly lower when using unaligned memory, because of the unaligned memory access exception
|
||||
|
||||
|
||||
// Macro for checking modulo 8
|
||||
.macro macro_memcpy_mod_8 src_buf, dest_buf, condition, x1, x2, JUMP_TAG
|
||||
// Check modulo 8 of the \condition, if - then copy 8 bytes
|
||||
bbci \condition, 3, ._mod_8_check_\JUMP_TAG // Branch if 3-rd bit of \condition is clear
|
||||
l32i.n \x1, \src_buf, 0 // Load 32 bits from \src_buff to \x1, offset 0
|
||||
l32i.n \x2, \src_buf, 4 // Load 32 bits from \src_buff to \x2, offset 4
|
||||
s32i.n \x1, \dest_buf, 0 // Save 32 bits from \x1 to \dest_buff, offset 0
|
||||
s32i.n \x2, \dest_buf, 4 // Save 32 bits from \x2 to \dest_buff, offset 4
|
||||
addi.n \src_buf, \src_buf, 8 // Increment \src_buff pointer by 8
|
||||
addi.n \dest_buf, \dest_buf, 8 // Increment \dest_buff pointer 8
|
||||
._mod_8_check_\JUMP_TAG:
|
||||
.endm // macro_memcpy_mod_8
|
||||
|
||||
|
||||
// Macro for checking modulo 4
|
||||
.macro macro_memcpy_mod_4 src_buf, dest_buf, condition, x1, JUMP_TAG
|
||||
// Check modulo 4 of the \condition, if - then copy 4 bytes
|
||||
bbci \condition, 2, ._mod_4_check_\JUMP_TAG // Branch if 2-nd bit of \condition is clear
|
||||
l32i.n \x1, \src_buf, 0 // Load 32 bits from \src_buff to \x1, offset 0
|
||||
addi.n \src_buf, \src_buf, 4 // Increment \src_buff pointer by 4
|
||||
s32i.n \x1, \dest_buf, 0 // Save 32 bits from \x1 to \dest_buff, offset 0
|
||||
addi.n \dest_buf, \dest_buf, 4 // Increment \dest_buff pointer 4
|
||||
._mod_4_check_\JUMP_TAG:
|
||||
.endm // macro_memcpy_mod_4
|
||||
|
||||
|
||||
// Macro for checking modulo 2
|
||||
.macro macro_memcpy_mod_2 src_buf, dest_buf, condition, x1, JUMP_TAG
|
||||
// Check modulo 2 of the \condition, if - then copy 2 bytes
|
||||
bbci \condition, 1, ._mod_2_check_\JUMP_TAG // Branch if 1-st bit of \condition is clear
|
||||
l16ui \x1, \src_buf, 0 // Load 16 bits from \src_buff to \x1, offset 0
|
||||
addi.n \src_buf, \src_buf, 2 // Increment \src_buff pointer by 2
|
||||
s16i \x1, \dest_buf, 0 // Save 16 bits from \x1 to \dest_buff, offset 0
|
||||
addi.n \dest_buf, \dest_buf, 2 // Increment \dest_buff pointer 2
|
||||
._mod_2_check_\JUMP_TAG:
|
||||
.endm // macro_memcpy_mod_2
|
||||
|
||||
|
||||
// Macro for checking modulo 1
|
||||
.macro macro_memcpy_mod_1 src_buf, dest_buf, condition, x1, JUMP_TAG
|
||||
// Check modulo 1 of the \condition, if - then copy 1 byte
|
||||
bbci \condition, 0, ._mod_1_check_\JUMP_TAG // Branch if 0-th bit of \condition is clear
|
||||
l8ui \x1, \src_buf, 0 // Load 8 bits from \src_buff to \x1, offset 0
|
||||
addi.n \src_buf, \src_buf, 1 // Increment \src_buff pointer by 1
|
||||
s8i \x1, \dest_buf, 0 // Save 8 bits from \x1 to \dest_buff, offset 0
|
||||
addi.n \dest_buf, \dest_buf, 1 // Increment \dest_buff pointer 1
|
||||
._mod_1_check_\JUMP_TAG:
|
||||
.endm // macro_memcpy_mod_1
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "lv_macro_memcpy.S" // Memcpy macros
|
||||
|
||||
// This is LVGL RGB565 image blend to RGB565 for ESP32 processor
|
||||
|
||||
.section .text
|
||||
.align 4
|
||||
.global lv_rgb565_blend_normal_to_rgb565_esp
|
||||
.type lv_rgb565_blend_normal_to_rgb565_esp,@function
|
||||
// The function implements the following C code:
|
||||
// void rgb565_image_blend(_lv_draw_sw_blend_image_dsc_t * dsc);
|
||||
|
||||
// Input params
|
||||
//
|
||||
// dsc - a2
|
||||
|
||||
// typedef struct {
|
||||
// uint32_t opa; l32i 0
|
||||
// void * dst_buf; l32i 4
|
||||
// uint32_t dst_w; l32i 8
|
||||
// uint32_t dst_h; l32i 12
|
||||
// uint32_t dst_stride; l32i 16
|
||||
// const void * src_buf; l32i 20
|
||||
// uint32_t src_stride; l32i 24
|
||||
// const lv_opa_t * mask_buf; l32i 28
|
||||
// uint32_t mask_stride; l32i 32
|
||||
// } asm_dsc_t;
|
||||
|
||||
lv_rgb565_blend_normal_to_rgb565_esp:
|
||||
|
||||
entry a1, 32
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint16_t
|
||||
l32i.n a5, a2, 12 // a5 - dest_h in uint16_t
|
||||
l32i.n a6, a2, 16 // a6 - dest_stride in bytes
|
||||
l32i.n a7, a2, 20 // a7 - src_buff
|
||||
l32i.n a8, a2, 24 // a8 - src_stride in bytes
|
||||
slli a11, a4, 1 // a11 - dest_w_bytes = sizeof(uint16_t) * dest_w
|
||||
|
||||
// No need to convert any colors here, we are copying from rgb565 to rgb565
|
||||
|
||||
// Check dest_w length
|
||||
bltui a4, 8, _matrix_width_check // Branch if dest_w (a4) is lower than 8
|
||||
|
||||
// Check memory alignment and input parameters lengths and decide which implementation to use
|
||||
movi.n a10, 0x3 // a10 = 0x3 alignment mask (4-byte alignment)
|
||||
or a15, a7, a3 // a15 = src_buff (a7) OR dest_buff (a3)
|
||||
or a15, a15, a6 // a15 = a15 OR dest_stride (a6)
|
||||
or a15, a15, a8 // a15 = a15 OR src_stride (a8)
|
||||
or a15, a15, a11 // a15 = a15 OR dest_w_bytes (a11)
|
||||
and a15, a15, a10 // a15 = a15 AND alignment mask (a10)
|
||||
bnez a15, _alignment_check // Branch if a15 not equals to zero
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// The most ideal case - both arrays aligned, both strides and dest_w are multiples of 4
|
||||
|
||||
// dest_buff (a3) - 4-byte aligned
|
||||
// src_buff (a7) - 4-byte aligned
|
||||
// dest_stride (a6) - 4-byte multiple
|
||||
// src_stride (a8) - 4-byte multiple
|
||||
// dest_w (a4) - 4-byte multiple
|
||||
|
||||
srli a9, a4, 3 // a9 - loop_len = dest_w / 8
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_align:
|
||||
|
||||
// Run main loop which copies 16 bytes (8 RGB565 pixels) in one loop run
|
||||
loopnez a9, ._main_loop_aligned
|
||||
l32i.n a15, a7, 0 // Load 32 bits from src_buff a7 to a15, offset 0
|
||||
l32i.n a14, a7, 4 // Load 32 bits from src_buff a7 to a14, offset 4
|
||||
l32i.n a13, a7, 8 // Load 32 bits from src_buff a7 to a13, offset 8
|
||||
l32i.n a12, a7, 12 // Load 32 bits from src_buff a7 to a12, offset 12
|
||||
s32i.n a15, a3, 0 // Save 32 bits from a15 to dest_buff a3, offset 0
|
||||
s32i.n a14, a3, 4 // Save 32 bits from a15 to dest_buff a3, offset 4
|
||||
s32i.n a13, a3, 8 // Save 32 bits from a15 to dest_buff a3, offset 8
|
||||
s32i.n a12, a3, 12 // Save 32 bits from a15 to dest_buff a3, offset 12
|
||||
addi.n a7, a7, 16 // Increment src_buff pointer a7 by 16
|
||||
addi.n a3, a3, 16 // Increment dest_buff pointer a3 by 16
|
||||
._main_loop_aligned:
|
||||
|
||||
// Finish the remaining bytes out of the main loop
|
||||
|
||||
// Check modulo 8 of the dest_w_bytes (a11), if - then copy 8 bytes (4 RGB565 pixels)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy registers a14 a15
|
||||
macro_memcpy_mod_8 a7, a3, a11, a14, a15 __LINE__
|
||||
|
||||
// Check modulo 4 of the dest_w_bytes (a11), if - then copy 4 bytes (2 RGB565 pixels)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy register a15
|
||||
macro_memcpy_mod_4 a7, a3, a11, a15 __LINE__
|
||||
|
||||
// Check modulo 2 of the dest_w_bytes (a11), if - then copy 2 bytes (1 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy register a15
|
||||
macro_memcpy_mod_2 a7, a3, a11, a15 __LINE__
|
||||
|
||||
// Check modulo 1 of the dest_w_bytes (a11), if - then copy 1 byte (1/2 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy register a15
|
||||
macro_memcpy_mod_1 a7, a3, a11, a15 __LINE__
|
||||
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_align
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// The most general case - at leas one array is not aligned, or one parameter is not multiple of 4
|
||||
_alignment_check:
|
||||
|
||||
// dest_buff (a3) - 4-byte aligned, or not
|
||||
// src_buff (a7) - 4-byte aligned, or not
|
||||
// dest_stride (a6) - 4-byte multiple, or not
|
||||
// src_stride (a8) - 4-byte multiple, or not
|
||||
// dest_w (a4) - 4-byte multiple, or not
|
||||
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_unalign:
|
||||
|
||||
extui a13, a3, 0, 2 // Get last two bits of the dest_buff address a3, to a13
|
||||
movi.n a15, 4 // Move 4 to a15, for calculation of the destination alignment loop
|
||||
sub a14, a15, a13 // Calculate destination alignment loop length (a14 = 4 - a13)
|
||||
|
||||
// In case of the dest_buff a3 being already aligned (for example by matrix padding), correct a14 value,
|
||||
// to prevent the destination aligning loop to run 4 times (to prevent aligning already aligned memory)
|
||||
moveqz a14, a13, a13 // If a13 is zero, move a13 to a14, move 0 to a14
|
||||
|
||||
sub a10, a11, a14 // Get the dest_w_bytes after the aligning loop
|
||||
srli a9, a10, 4 // Calculate main loop len (a9 = dest_w_bytes_local / 16)
|
||||
|
||||
// Run dest_buff aligning loop byte by byte
|
||||
loopnez a14, ._dest_aligning_loop
|
||||
l8ui a15, a7, 0 // Load 8 bits from src_buff a7 to a15, offset 0
|
||||
addi.n a7, a7, 1 // Increment src_buff pointer a7 by 1
|
||||
s8i a15, a3, 0 // Save 8 bits from a15 to dest_buff a3, offset 0
|
||||
addi.n a3, a3, 1 // Increment dest_buff pointer a3 by 1
|
||||
._dest_aligning_loop:
|
||||
|
||||
// Destination is aligned, source is unaligned
|
||||
|
||||
// For more information about this implementation, see chapter 3.3.2 Shifts and the Shift Amount Register (SAR)
|
||||
// in Xtensa Instruction Set Architecture (ISA) Reference Manual
|
||||
|
||||
ssa8l a7 // Set SAR_BYTE from src_buff a7 unalignment
|
||||
extui a4, a7, 0, 2 // Get last 2 bits of the src_buff, a4 = src_buff_unalignment
|
||||
sub a7, a7, a4 // "align" the src_buff a7, to 4-byte boundary by decreasing it's pointer to the nearest aligned boundary
|
||||
|
||||
// First preload for the loopnez cycle
|
||||
l32i.n a15, a7, 0 // Load 32 bits from 4-byte aligned src_buff a7 to a15, offset 0
|
||||
|
||||
// Run main loop which copies 16 bytes (8 RGB565 pixels) in one loop run
|
||||
loopnez a9, ._main_loop_unalign
|
||||
l32i.n a14, a7, 4 // Load 32 bits from 4-byte aligned src_buff a7 to a14, offset 4
|
||||
l32i.n a13, a7, 8 // Load 32 bits from 4-byte aligned src_buff a7 to a13, offset 8
|
||||
src a15, a14, a15 // Concatenate a14 and a15 and shift by SAR_BYTE amount to a15
|
||||
s32i.n a15, a3, 0 // Save 32 bits from shift-corrected a15 to dest_buff a3, offset 0
|
||||
l32i.n a12, a7, 12 // Load 32 bits from 4-byte aligned src_buff a7 to a12, offset 12
|
||||
src a14, a13, a14 // Concatenate a13 and a14 and shift by SAR_BYTE amount to a14
|
||||
s32i.n a14, a3, 4 // Save 32 bits from shift-corrected a14 to dest_buff a3, offset 4
|
||||
l32i.n a15, a7, 16 // Load 32 bits from 4-byte aligned src_buff a7 to a15, offset 16
|
||||
src a13, a12, a13 // Concatenate a12 and a13 and shift by SAR_BYTE amount to a13
|
||||
s32i.n a13, a3, 8 // Save 32 bits from shift-corrected a13 to dest_buff a3, offset 8
|
||||
addi.n a7, a7, 16 // Increment src_buff pointer a7 by 16
|
||||
src a12, a15, a12 // Concatenate a15 and a12 and shift by SAR_BYTE amount to a12
|
||||
s32i.n a12, a3, 12 // Save 32 bits from shift-corrected a12 to dest_buff a3, offset 12
|
||||
addi.n a3, a3, 16 // Increment dest_buff pointer a3 by 16
|
||||
._main_loop_unalign:
|
||||
|
||||
// Finish the remaining bytes out of the loop
|
||||
// Check modulo 8 of the dest_w_bytes_local (a10), if - then copy 8 bytes
|
||||
bbci a10, 3, _mod_8_check // Branch if 3-rd bit of dest_w_bytes_local is clear
|
||||
l32i.n a14, a7, 4 // Load 32 bits from 4-byte aligned src_buff a7 to a14, offset 4
|
||||
l32i.n a13, a7, 8 // Load 32 bits from 4-byte aligned src_buff a7 to a13, offset 8
|
||||
src a15, a14, a15 // Concatenate a14 and a15 and shift by SAR_BYTE amount to a15 (value in a15 is already prepared from previous steps)
|
||||
s32i.n a15, a3, 0 // Save 32 bits from shift-corrected a15 to dest_buff a3, offset 0
|
||||
addi.n a7, a7, 8 // Increment src_buff pointer a7 by 8
|
||||
src a14, a13, a14 // Concatenate a13 and a14 and shift by SAR_BYTE amount to a14
|
||||
s32i.n a14, a3, 4 // Save 32 bits from shift-corrected a14 to dest_buff a3, offset 4
|
||||
addi.n a3, a3, 8 // Increment dest_buff pointer a3 by 8
|
||||
mov a15, a13 // Prepare a15 for the next steps (copy a13 to a15)
|
||||
_mod_8_check:
|
||||
|
||||
// Check modulo 4 of the dest_w_bytes_local (a10), if - then copy 4 bytes
|
||||
bbci a10, 2, _mod_4_check // Branch if 2-nd bit of dest_w_bytes_local is clear
|
||||
l32i.n a14, a7, 4 // Load 32 bits from 4-byte aligned src_buff a7 to a14, offset 4
|
||||
addi.n a7, a7, 4 // Increment src_buff pointer a7 by 4
|
||||
src a15, a14, a15 // Concatenate a14 and a15 and shift by SAR_BYTE amount to a15 (value in a15 is already prepared from previous steps)
|
||||
s32i.n a15, a3, 0 // Save 32 bits from shift-corrected a15 to dest_buff a3, offset 0
|
||||
addi.n a3, a3, 4 // Increment dest_buff pointer a3 by 4
|
||||
mov a15, a14 // Prepare a15 for the next steps (copy a14 to a15)
|
||||
_mod_4_check:
|
||||
|
||||
extui a13, a10, 0, 2 // Get the last 2 bytes of the dest_w_bytes_local (a10), a13 = a10[1:0], to find out how many bytes are needs copied and to increase src and dest pointer accordingly
|
||||
beqz a13, _mod_1_2_check // Branch if a13 equal to zero, E.G. if there are no bytes to be copied
|
||||
l32i.n a14, a7, 4 // Load 32 bits from 4-byte aligned src_buff a7 to a14, offset 4
|
||||
l32i.n a12, a3, 0 // Get dest_buff value: Load 32 bits from 4-byte aligned dest_buff a3 to a12, offset 0
|
||||
src a15, a14, a15 // Concatenate a14 and a15 and shift by SAR_BYTE amount to a15 (value in a15 is already prepared from previous steps)
|
||||
ssa8l a10 // Set SAR_BYTE from dest_w_bytes_local a10 length
|
||||
sll a15, a15 // Shift the dest word a15 by SAR_BYTE amount
|
||||
srl a12, a12 // Shift the src word a12 by SAR_BYTE amount
|
||||
ssa8b a10 // Set SAR_BYTE from dest_w_bytes_local a10 length
|
||||
src a12, a12, a15 // Concatenate a12 and a15 and shift by SAR_BYTE amount to a12
|
||||
s32i.n a12, a3, 0 // Save 32 bits from shift-corrected a12 to dest_buff a3, offset 0
|
||||
add a7, a7, a13 // Increment src_buff pointer a7, by amount of copied bytes (a13)
|
||||
add a3, a3, a13 // Increment dest_buff pointer a3, by amount of copied bytes (a13)
|
||||
_mod_1_2_check:
|
||||
|
||||
add a7, a7, a4 // Correct the src_buff back by src_buff_unalignment (a4), after we have force-aligned it to 4-byte boundary before the main loop
|
||||
add a3, a3, a6 // dest_buff + dest_stride
|
||||
add a7, a7, a8 // src_buff + src_stride
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_unalign
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// Small matrix width, keep it simple for lengths less than 8 pixels
|
||||
_matrix_width_check: // Matrix width is greater or equal 8 pixels
|
||||
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_short_matrix_length:
|
||||
|
||||
// Run main loop which copies 2 bytes (one RGB565 pixel) in one loop run
|
||||
loopnez a4, ._main_loop_short_matrix_length
|
||||
l8ui a15, a7, 0 // Load 8 bits from src_buff a7 to a15, offset 0
|
||||
l8ui a14, a7, 1 // Load 8 bits from src_buff a7 to a14, offset 1
|
||||
s8i a15, a3, 0 // Save 8 bits from a15 to dest_buff a3, offset 0
|
||||
s8i a14, a3, 1 // Save 8 bits from a14 to dest_buff a3, offset 1
|
||||
addi.n a7, a7, 2 // Increment src_buff pointer a7 by 1
|
||||
addi.n a3, a3, 2 // Increment dest_buff pointer a3 by 2
|
||||
._main_loop_short_matrix_length:
|
||||
|
||||
// Finish remaining byte out of the main loop
|
||||
|
||||
// Check modulo 1 of the dest_w_bytes (a11), if - then copy 1 byte (1/2 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy register a15
|
||||
macro_memcpy_mod_1 a7, a3, a11, a15, __LINE__
|
||||
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_short_matrix_length
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "lv_macro_memcpy.S" // Memcpy macros
|
||||
|
||||
// This is LVGL RGB565 image blend to RGB565 for ESP32S3 processor
|
||||
|
||||
.section .text
|
||||
.align 4
|
||||
.global lv_rgb565_blend_normal_to_rgb565_esp
|
||||
.type lv_rgb565_blend_normal_to_rgb565_esp,@function
|
||||
// The function implements the following C code:
|
||||
// void lv_color_blend_to_rgb565(_lv_draw_sw_blend_fill_dsc_t * dsc);
|
||||
|
||||
// Input params
|
||||
//
|
||||
// dsc - a2
|
||||
|
||||
// typedef struct {
|
||||
// uint32_t opa; l32i 0
|
||||
// void * dst_buf; l32i 4
|
||||
// uint32_t dst_w; l32i 8
|
||||
// uint32_t dst_h; l32i 12
|
||||
// uint32_t dst_stride; l32i 16
|
||||
// const void * src_buf; l32i 20
|
||||
// uint32_t src_stride; l32i 24
|
||||
// const lv_opa_t * mask_buf; l32i 28
|
||||
// uint32_t mask_stride; l32i 32
|
||||
// } asm_dsc_t;
|
||||
|
||||
lv_rgb565_blend_normal_to_rgb565_esp:
|
||||
|
||||
entry a1, 32
|
||||
l32i.n a3, a2, 4 // a3 - dest_buff
|
||||
l32i.n a4, a2, 8 // a4 - dest_w in uint16_t
|
||||
l32i.n a5, a2, 12 // a5 - dest_h in uint16_t
|
||||
l32i.n a6, a2, 16 // a6 - dest_stride in bytes
|
||||
l32i.n a7, a2, 20 // a7 - src_buff
|
||||
l32i.n a8, a2, 24 // a8 - src_stride in bytes
|
||||
movi.n a10, 0xf // 0xf alignment mask (16-byte alignment)
|
||||
slli a11, a4, 1 // a11 - dest_w_bytes = sizeof(uint16_t) * dest_w
|
||||
|
||||
// No need to convert any colors here, we are copying from rgb565 to rgb565
|
||||
|
||||
// Check dest_w length
|
||||
bltui a4, 8, _matrix_width_check // Branch if dest_w (a4) is lower than 8
|
||||
|
||||
// Check dest_buff alignment fist
|
||||
and a15, a10, a3 // 16-byte alignment mask AND dest_buff pointer a3
|
||||
bnez a15, _src_unalign_dest_unalign // Branch if a15 not equals to zero
|
||||
// Jump straight to the last implementation, since this is the only one which deals with unaligned destination arrays
|
||||
|
||||
// Check src_buff alignment
|
||||
and a15, a10, a7 // 16-byte alignment mask AND src_buff pointer a7
|
||||
bnez a15, _src_align_dest_unalign // Branch if a15 not equals to zero
|
||||
// Jump to check, if the second or third implementation can be used (depends on both strides and dest_w)
|
||||
|
||||
// Check dest_stride alignment
|
||||
and a15, a10, a6 // 16-byte alignment mask AND dest_stride a6
|
||||
bnez a15, _src_unalign_dest_unalign // Branch if a15 not equals to zero
|
||||
// Jump straight to the last implementation, since this is the only one which deals with destination stride not aligned
|
||||
|
||||
// Check src_stride alignment
|
||||
and a15, a10, a8 // 16-byte alignment mask AND src_stride a8
|
||||
bnez a15, _src_align_dest_unalign // Branch if a15 not equals to zero
|
||||
// Jump to check, if the second or third implementation can be used (depends on dest_w_bytes)
|
||||
|
||||
// Check dest_w_bytes alignment
|
||||
and a15, a10, a11 // 16-byte alignment mask AND dest_w_bytes
|
||||
bnez a15, _src_unalign_dest_unalign // Branch if a15 not equals to zero
|
||||
// Jump straight to the last implementation, since this is the only one which deals with dest_w_bytes not aligned
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// The most ideal case - both arrays aligned, both strides and dest_w are multiples of 16
|
||||
|
||||
// dest_buff (a3) - 16-byte aligned
|
||||
// src_buff (a7) - 16-byte aligned
|
||||
// dest_stride (a6) - 16-byte multiple
|
||||
// src_stride (a8) - 16-byte multiple
|
||||
// dest_w (a4) - 16-byte multiple
|
||||
|
||||
srli a9, a4, 4 // a9 - loop_len = dest_w / 16
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_align:
|
||||
|
||||
// Run main loop which copies 32 bytes (16 RGB565 pixels) in one loop run
|
||||
loopnez a9, ._main_loop_align // 32 bytes (16 RGB565 pixels) in one loop run
|
||||
ee.vld.128.ip q0, a7, 16 // Load 16 bytes from src_buff a7 to q0, increase src_buf pointer a7 by 16
|
||||
ee.vld.128.ip q1, a7, 16 // Load 16 bytes from src_buff a7 to q1, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q0, a3, 16 // Store 16 bytes from q0 to dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.vst.128.ip q1, a3, 16 // Store 16 bytes from q1 to dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
._main_loop_align:
|
||||
|
||||
// Finish remaining bytes out of the main loop
|
||||
|
||||
// Check modulo 16 of the dest_w, if - then copy 16 bytes (8 RGB565 pixels)
|
||||
bbci a11, 4, _align_mod_16_check // Branch if 4-th bit of dest_w_bytes a11 is clear
|
||||
ee.vld.128.ip q0, a7, 16 // Load 16 bytes from src_buff a7 to q0, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q0, a3, 16 // Store 16 bytes from q0 to dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
_align_mod_16_check:
|
||||
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_align
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
|
||||
|
||||
_src_align_dest_unalign:
|
||||
|
||||
// Check dest_stride alignment
|
||||
and a15, a10, a6 // 16-byte alignment mask AND dest_stride a6
|
||||
bnez a15, _src_unalign_dest_unalign // Branch if a15 not equals to zero
|
||||
|
||||
// Check dest_w_bytes alignment
|
||||
and a15, a10, a11 // 16-byte alignment mask AND dest_w_bytes a11
|
||||
bnez a15, _src_unalign_dest_unalign // Branch if a15 not equals to zero
|
||||
|
||||
// We don't check src_stride alignment for this implementation, as it can be either align, or unalign
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// Less ideal case - Only destination array is aligned, src array is unaligned
|
||||
// Source stride is either aligned or unaligned, destination stride must be aligned, dest_w_bytes must be aligned
|
||||
|
||||
// dest_buff (a3) - 16-byte aligned
|
||||
// src_buff (a7) - unaligned
|
||||
// dest_stride (a6) - 16-byte multiple
|
||||
// src_stride (a8) - does not matter if 16-byte multiple
|
||||
// dest_w (a4) - 16-byte multiple
|
||||
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
// Calculate modulo for non-aligned data
|
||||
movi a15, 48 // a15 = 48 (main loop copies 48 bytes)
|
||||
quou a9, a11, a15 // a9 = dest_w_bytes (a11) DIV 48 (15)
|
||||
remu a12, a11, a15 // a12 = dest_w_bytes (a11) remainder after DIV 48 (15)
|
||||
|
||||
.outer_loop_src_unalign_dest_align:
|
||||
|
||||
ee.ld.128.usar.ip q2, a7, 16 // Preload 16 bytes from src_buff a7 to q2, get value of the SAR_BYTE, increase src_buf pointer a7 by 16
|
||||
ee.ld.128.usar.ip q3, a7, 16 // Preload 16 bytes from src_buff a7 to q3, get value of the SAR_BYTE, increase src_buf pointer a7 by 16
|
||||
|
||||
// Run main loop which copies 48 bytes (24 RGB565 pixels) in one loop run
|
||||
loopnez a9, ._main_loop_src_unalign_dest_align // 48 bytes (24 RGB565 pixels) in one loop
|
||||
ee.src.q.ld.ip q4, a7, 16, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q.ld.ip q2, a7, 16, q3, q4 // Load 16 bytes from src_buff a7 to q2, concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q3, a3, 16 // Store 16 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q.ld.ip q3, a7, 16, q4, q2 // Load 16 bytes from src_buff a7 to q3, concatenate q4 and q2 and shift to q4 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q4, a3, 16 // Store 16 bytes from q4 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
._main_loop_src_unalign_dest_align:
|
||||
|
||||
// Finish the main loop outside of the loop from Q registers preloads
|
||||
|
||||
// Check modulo 32 of the loop_len_remainder, if - then copy 32 bytes (16 RGB565 pixels)
|
||||
bbci a12, 5, _unalign_mod_32_check // Branch if 5-th bit of loop_len_remainder a12 is clear
|
||||
ee.src.q.ld.ip q4, a7, 0, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, don't increase src_buf pointer a7
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q q3, q3, q4 // Concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount
|
||||
ee.vst.128.ip q3, a3, 16 // Store 16 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
j _end_of_row_src_unalign_dest_align
|
||||
_unalign_mod_32_check:
|
||||
|
||||
// Check modulo 16 of the loop_len_remainder, if - then copy 16 bytes (8 RGB565 pixels)
|
||||
bbci a12, 4, _unalign_mod_16_check // Branch if 4-th bit of loop_len_remainder a12 is clear
|
||||
ee.src.q q2, q2, q3 // Concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
addi a7, a7, -16 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
j _end_of_row_src_unalign_dest_align
|
||||
_unalign_mod_16_check:
|
||||
|
||||
// Nothing to copy outside of the main loop
|
||||
addi a7, a7, -32 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
|
||||
_end_of_row_src_unalign_dest_align:
|
||||
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_src_unalign_dest_align
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
|
||||
|
||||
_src_unalign_dest_unalign:
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// The most general case, can handle all the possible combinations
|
||||
|
||||
// dest_buff (a3) - unaligned
|
||||
// src_buff (a7) - unaligned
|
||||
// dest_stride (a6) - not 16-byte multiple
|
||||
// src_stride (a8) - not 16-byte multiple
|
||||
// dest_w (a4) - not 16-byte multiple
|
||||
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_all_unalign:
|
||||
|
||||
// dest_buff alignment check
|
||||
and a13, a10, a3 // Alignment mask 0xf (a10) AND dest_buff pointer
|
||||
beqz a13, _dest_buff_aligned // Branch if a13 = 0 (if dest_buff is aligned)
|
||||
|
||||
movi.n a14, 16 // a14 = 16
|
||||
sub a13, a14, a13 // a13 = 16 - unalignment
|
||||
|
||||
// Check modulo 8 of the unalignment a13, if - then copy 8 bytes (4 RGB565 pixels)
|
||||
// src_buff a7, dest_buff a3, unalignment a13, copy registers a14, a15
|
||||
macro_memcpy_mod_8 a7, a3, a13, a15, a14, __LINE__
|
||||
|
||||
// Check modulo 4 of the unalignment, if - then copy 4 bytes (2 RGB565 pixels)
|
||||
// src_buff a7, dest_buff a3, unalignment a13, copy register a15
|
||||
macro_memcpy_mod_4 a7, a3, a13, a15, __LINE__
|
||||
|
||||
// Check modulo 2 of the unalignment, if - then copy 2 bytes (1 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, unalignment a13, copy register a15
|
||||
macro_memcpy_mod_2 a7, a3, a13, a15, __LINE__
|
||||
|
||||
// Check modulo 1 of the unalignment, if - then copy 1 byte (1/2 of RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, unalignment a13, copy register a15
|
||||
macro_memcpy_mod_1 a7, a3, a13, a15, __LINE__
|
||||
|
||||
_dest_buff_aligned:
|
||||
|
||||
// Calculate modulo for non-aligned data
|
||||
sub a11, a11, a13 // a11 = local_dest_w_bytes (a11) = dest_w_bytes (a11) - (16 - unalignment)
|
||||
movi a15, 48 // a15 = 48
|
||||
quou a9, a11, a15 // a9 = local_dest_w_bytes (a11) DIV 48 (a15)
|
||||
remu a12, a11, a15 // a12 = local_dest_w_bytes (a11) remainder after div 48 (a15)
|
||||
|
||||
ee.ld.128.usar.ip q2, a7, 16 // Preload 16 bytes from src_buff a7 to q2, get value of the SAR_BYTE, increase src_buf pointer a7 by 16
|
||||
ee.ld.128.usar.ip q3, a7, 16 // Preload 16 bytes from src_buff a7 to q3, get value of the SAR_BYTE, increase src_buf pointer a7 by 16
|
||||
|
||||
// Run main loop which copies 48 bytes (24 RGB565 pixels) in one loop run
|
||||
loopnez a9, ._main_loop_all_unalign // 48 bytes (24 RGB565 pixels) in one loop
|
||||
ee.src.q.ld.ip q4, a7, 16, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q.ld.ip q2, a7, 16, q3, q4 // Load 16 bytes from src_buff a7 to q2, concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q3, a3, 16 // Store 16 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q.ld.ip q3, a7, 16, q4, q2 // Load 16 bytes from src_buff a7 to q3, concatenate q4 and q2 and shift to q4 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q4, a3, 16 // Store 16 bytes from q4 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
._main_loop_all_unalign:
|
||||
|
||||
// Finish the main loop outside of the loop from Q registers preloads
|
||||
|
||||
// Check modulo 32 and modulo 8 of the loop_len_remainder a12
|
||||
bbci a12, 5, _all_unalign_mod_32_check // Branch if 5-th bit of loop_len_remainder a12 is clear
|
||||
bbsi a12, 3, _all_unalign_mod_32_mod_8_check // Branch if 3-rd bif of loop_len_remainder a12 is set
|
||||
|
||||
// Copy 32 bytes (16 RGB565 pixels) (47 - 40)
|
||||
ee.src.q.ld.ip q4, a7, 0, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, don't increase src_buf pointer a7
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q q3, q3, q4 // Concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount
|
||||
ee.vst.128.ip q3, a3, 16 // Store 16 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
j _skip_mod16
|
||||
|
||||
_all_unalign_mod_32_mod_8_check:
|
||||
// Copy 40 bytes (20 RGB565 pixels)
|
||||
ee.src.q.ld.ip q4, a7, 16, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, increase src_buf pointer a7 by 16
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q.ld.ip q2, a7, 0, q3, q4 // Load 16 bytes from src_buff a7 to q2, concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount, don't increase src_buf pointer a7
|
||||
ee.vst.128.ip q3, a3, 16 // Store 16 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q q4, q4, q2 // Concatenate q4 and q2 and shift to q4 by the SAR_BYTE amount
|
||||
ee.vst.l.64.ip q4, a3, 8 // Store lower 8 bytes from q4 to aligned dest_buff a3, increase dest_buff pointer a3 by 8
|
||||
addi a7, a7, -8 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
j _skip_mod16
|
||||
|
||||
_all_unalign_mod_32_check:
|
||||
|
||||
// Check modulo 16 and modulo 8 of the loop_len_remainder a12
|
||||
bbci a12, 4, _all_unalign_mod_16_check // branch if 4-th bit of loop_len_remainder a12 is clear
|
||||
bbsi a12, 3, _all_unalign_mod_16_mod_8_check // branch if 3-rd bit of loop_len_remainder a12 is set
|
||||
|
||||
// Copy 16 bytes (8 RGB565 pixels)
|
||||
ee.src.q q2, q2, q3 // Concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
addi a7, a7, -16 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
j _skip_mod16
|
||||
|
||||
_all_unalign_mod_16_mod_8_check:
|
||||
// Copy 24 bytes (12 RGB565 pixels)
|
||||
ee.src.q.ld.ip q4, a7, 0, q2, q3 // Load 16 bytes from src_buff a7 to q4, concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount, don't increase src_buf pointer a7
|
||||
ee.vst.128.ip q2, a3, 16 // Store 16 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 16
|
||||
ee.src.q q3, q3, q4 // Concatenate q3 and q4 and shift to q3 by the SAR_BYTE amount
|
||||
ee.vst.l.64.ip q3, a3, 8 // Store lower 8 bytes from q3 to aligned dest_buff a3, increase dest_buff pointer a3 by 8
|
||||
addi a7, a7, -8 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
j _skip_mod16
|
||||
_all_unalign_mod_16_check:
|
||||
|
||||
bbci a12, 3, _all_unalign_mod_8_check // Branch if 3-rd bit of loop_len_remainder a12 is clear
|
||||
// Copy 8 bytes (4 RGB565 pixels)
|
||||
ee.src.q q2, q2, q3 // Concatenate q2 and q3 and shift to q2 by the SAR_BYTE amount
|
||||
ee.vst.l.64.ip q2, a3, 8 // Store lower 8 bytes from q2 to aligned dest_buff a3, increase dest_buff pointer a3 by 8
|
||||
addi a7, a7, -24 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
j _skip_mod16
|
||||
_all_unalign_mod_8_check:
|
||||
|
||||
addi a7, a7, -32 // Correct the src_buff pointer a7, caused by q reg preload
|
||||
|
||||
_skip_mod16:
|
||||
|
||||
// Check modulo 4 of the loop_len_remainder, if - then copy 4 bytes (2 RGB565 pixels)
|
||||
// src_buff a7, dest_buff a3, loop_len_remainder a12, copy register a15
|
||||
macro_memcpy_mod_4 a7, a3, a12, a15, __LINE__
|
||||
|
||||
// Check modulo 2 of the loop_len_remainder, if - then copy 2 bytes (1 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, loop_len_remainder a12, copy register a15
|
||||
macro_memcpy_mod_2 a7, a3, a12, a15, __LINE__
|
||||
|
||||
// Check modulo 1 of the loop_len_remainder, if - then copy 1 byte (1/2 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, loop_len_remainder a12, copy register a15
|
||||
macro_memcpy_mod_1 a7, a3, a12, a15, __LINE_
|
||||
|
||||
slli a11, a4, 1 // Refresh dest_w_bytes
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_all_unalign
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
|
||||
//**********************************************************************************************************************
|
||||
|
||||
// Small matrix width, keep it simple for lengths less than 8 pixels
|
||||
_matrix_width_check: // Matrix width is greater or equal 8 pixels
|
||||
|
||||
// Convert strides to matrix paddings
|
||||
sub a6, a6, a11 // dest_matrix_padding (a6) = dest_stride (a6) - dest_w_bytes (a11)
|
||||
sub a8, a8, a11 // src_matrix_padding (a8) = src_stride (a8) - dest_w_bytes (a11)
|
||||
|
||||
.outer_loop_short_matrix_length:
|
||||
|
||||
// Run main loop which copies 2 bytes (one RGB565 pixel) in one loop run
|
||||
loopnez a4, ._main_loop_short_matrix_length
|
||||
l8ui a15, a7, 0 // Load 8 bits from src_buff a7 to a15, offset 0
|
||||
l8ui a14, a7, 1 // Load 8 bits from src_buff a7 to a14, offset 1
|
||||
s8i a15, a3, 0 // Save 8 bits from a15 to dest_buff a3, offset 0
|
||||
s8i a14, a3, 1 // Save 8 bits from a14 to dest_buff a3, offset 1
|
||||
addi.n a7, a7, 2 // Increment src_buff pointer a7 by 1
|
||||
addi.n a3, a3, 2 // Increment dest_buff pointer a3 by 2
|
||||
._main_loop_short_matrix_length:
|
||||
|
||||
// Finish remaining byte out of the main loop
|
||||
|
||||
// Check modulo 1 of the dest_w_bytes (a11), if - then copy 1 byte (1/2 RGB565 pixel)
|
||||
// src_buff a7, dest_buff a3, dest_w_bytes a11, copy register a15
|
||||
macro_memcpy_mod_1 a7, a3, a11, a15, __LINE__
|
||||
|
||||
add a3, a3, a6 // dest_buff (a3) = dest_buff (a3) + dest_matrix_padding (a6)
|
||||
add a7, a7, a8 // src_buff (a7) = src_buff (a7) + src_matrix_padding (a8)
|
||||
addi.n a5, a5, -1 // Decrease the outer loop
|
||||
bnez a5, .outer_loop_short_matrix_length
|
||||
|
||||
movi.n a2, 1 // Return LV_RESULT_OK = 1
|
||||
retw.n // Return
|
||||
Reference in New Issue
Block a user