mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(i80_lcd): add help function to allocate draw buffer with proper alignment
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -321,6 +321,14 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *esp_lcd_i80_alloc_draw_buffer(esp_lcd_panel_io_handle_t io, size_t size, uint32_t caps)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io, NULL, TAG, "invalid argument");
|
||||
ESP_RETURN_ON_FALSE((caps & MALLOC_CAP_SPIRAM) == 0, NULL, TAG, "external memory is not supported");
|
||||
// DMA can only carry internal memory
|
||||
return heap_caps_aligned_calloc(4, 1, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT | MALLOC_CAP_DMA);
|
||||
}
|
||||
|
||||
static esp_err_t panel_io_i80_del(esp_lcd_panel_io_t *io)
|
||||
{
|
||||
lcd_panel_io_i80_t *i80_device = __containerof(io, lcd_panel_io_i80_t, base);
|
||||
|
||||
@@ -583,6 +583,21 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *esp_lcd_i80_alloc_draw_buffer(esp_lcd_panel_io_handle_t io, size_t size, uint32_t caps)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io, NULL, TAG, "invalid argument");
|
||||
lcd_panel_io_i80_t *i80_device = __containerof(io, lcd_panel_io_i80_t, base);
|
||||
esp_lcd_i80_bus_t *bus = i80_device->bus;
|
||||
void *buf = NULL;
|
||||
// alloc from external memory
|
||||
if (caps & MALLOC_CAP_SPIRAM) {
|
||||
buf = heap_caps_aligned_calloc(bus->ext_mem_align, 1, size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA);
|
||||
} else {
|
||||
buf = heap_caps_aligned_calloc(bus->int_mem_align, 1, size, MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static esp_err_t lcd_i80_bus_configure_gpio(esp_lcd_i80_bus_handle_t bus, const esp_lcd_i80_bus_config_t *bus_config)
|
||||
{
|
||||
int bus_id = bus->bus_id;
|
||||
|
||||
@@ -100,6 +100,18 @@ typedef struct {
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_io_i80(esp_lcd_i80_bus_handle_t bus, const esp_lcd_panel_io_i80_config_t *io_config, esp_lcd_panel_io_handle_t *ret_io);
|
||||
|
||||
/**
|
||||
* @brief Allocate a draw buffer that can be used by I80 interfaced LCD panel
|
||||
*
|
||||
* @note This function differs from the normal 'heap_caps_*' functions in that it can also automatically handle the alignment required by DMA burst, cache line size, etc.
|
||||
*
|
||||
* @param[in] io Panel IO handle, created by `esp_lcd_new_panel_io_i80()`
|
||||
* @param[in] size Size of memory to be allocated
|
||||
* @param[in] caps Bitwise OR of MALLOC_CAP_* flags indicating the type of memory desired for the allocation
|
||||
* @return Pointer to a new buffer of size 'size' with capabilities 'caps', or NULL if allocation failed
|
||||
*/
|
||||
void *esp_lcd_i80_alloc_draw_buffer(esp_lcd_panel_io_handle_t io, size_t size, uint32_t caps);
|
||||
|
||||
#endif // SOC_LCD_I80_SUPPORTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user