feat(ppa): add PPA driver support for ESP32P4

Added doxygen
Refactored driver to malloc trans_elm memory when registering the client
Cleaned up driver
Added API check
One client now only responsible for one operation
This commit is contained in:
Song Ruo Jing 2024-04-08 16:41:19 +08:00
parent 95ee1595f9
commit 346bc077c5
9 changed files with 781 additions and 662 deletions

View File

@ -6,6 +6,6 @@ endif()
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${public_include}
PRIV_REQUIRES esp_mm
PRIV_REQUIRES esp_mm esp_pm
# LDFRAGMENTS "linker.lf"
)

View File

@ -14,32 +14,57 @@
extern "C" {
#endif
/**
* @brief Enumeration of all PPA available operations
*/
typedef enum {
PPA_OPERATION_SRM, /*!< Do scale-rotate-mirror operation */
PPA_OPERATION_BLEND, /*!< Do blend operation */
PPA_OPERATION_FILL, /*!< Do fill operation */
PPA_OPERATION_NUM, /*!< Quantity of PPA operations */
} ppa_operation_t;
/**
* @brief Type of PPA invoker handle
*/
typedef struct ppa_invoker_t *ppa_invoker_handle_t;
/**
* @brief PPA operation type flags
*
* These flags are supposed to be used to specify the PPA operations that are going to be used by the invoker, so that
* the corresponding engines can be acquired when registering the invoker with `ppa_register_invoker`.
* @brief Type of PPA transaction handle
*/
#define PPA_OPERATION_FLAG_SRM (1 << 0)
#define PPA_OPERATION_FLAG_BLEND (1 << 1)
#define PPA_OPERATION_FLAG_FILL (1 << 2)
typedef struct ppa_trans_t *ppa_trans_handle_t;
/**
* @brief Type of PPA event data
*/
typedef struct {
;
} ppa_event_data_t;
/**
* @brief Type of PPA event callback
*
* @param ppa_invoker PPA invoker handle
* @param event_data PPA event data
* @param user_data User registered data from calling `ppa_do_xxx` to perform an operation
*
* @return Whether a task switch is needed after the callback function returns, this is usually due to the callback
* wakes up some high priority task.
*/
typedef bool (*ppa_event_callback_t)(ppa_invoker_handle_t ppa_invoker, ppa_event_data_t *event_data, void *user_data);
/**
* @brief A collection of configuration items that used for registering a PPA invoker
*/
typedef struct {
uint32_t operation_flag; /*!< Bitwise OR of `PPA_OPERATION_FLAG_*` flags indicating the required operations for the invoker */
// done_cb
// user_data
ppa_operation_t oper_type; /*!< The desired PPA operation for the invoker */
ppa_event_callback_t done_cb; /*!< Callback function to be executed when a PPA transaction finishes */
uint32_t max_pending_trans_num; /*!< The maximum number of pending transactions for the invoker.
By default, it will be 1, which is sufficient if all transactions are performed with `PPA_TRANS_MODE_BLOCKING` */
} ppa_invoker_config_t;
/**
* @brief Register a PPA invoker
* @brief Register a PPA invoker to do a specific PPA operation
*
* @param[in] config Pointer to a collection of configurations for the invoker
* @param[out] ret_invoker Returned invoker handle
@ -57,9 +82,50 @@ esp_err_t ppa_register_invoker(const ppa_invoker_config_t *config, ppa_invoker_h
* @param[in] ppa_invoker PPA invoker handle, allocated by `ppa_register_invoker`
* @return
* - ESP_OK: Unregister the PPA invoker successfully
* - ESP_ERR_INVALID_ARG: Unregister the PPA invoker failed because of invalid argument
* - ESP_ERR_INVALID_STATE: Unregister the PPA invoker failed because there are unfinished transactions
*/
esp_err_t ppa_unregister_invoker(ppa_invoker_handle_t ppa_invoker);
/**
* @brief A collection of configuration items for an input picture and the target block inside the picture
*/
typedef struct {
void *buffer; /*!< Pointer to the input picture buffer */
uint32_t pic_w; /*!< Input picture width (unit: pixel) */
uint32_t pic_h; /*!< Input picture height (unit: pixel) */
uint32_t block_w; /*!< Target block width (unit: pixel) */
uint32_t block_h; /*!< Target block height (unit: pixel) */
uint32_t block_offset_x; /*!< Target block offset in x direction in the picture (unit: pixel) */
uint32_t block_offset_y; /*!< Target block offset in y direction in the picture (unit: pixel) */
union {
ppa_srm_color_mode_t srm_cm; /*!< Color mode of the picture in a PPA SRM operation. Supported color mode in `ppa_srm_color_mode_t` */
ppa_blend_color_mode_t blend_cm; /*!< Color mode of the picture in a PPA blend operation. Supported color mode in `ppa_blend_color_mode_t` */
ppa_fill_color_mode_t fill_cm; /*!< Color mode of the picture in a PPA fill operation. Supported color mode in `ppa_fill_color_mode_t` */
};
color_range_t yuv_range; /*!< When the color mode is any YUV color space, this field is to describe its color range */
color_conv_std_rgb_yuv_t yuv_std; /*!< When the color mode is any YUV color space, this field is to describe its YUV<->RGB conversion standard */
} ppa_in_pic_blk_config_t;
/**
* @brief A collection of configuration items for an output picture and the target block inside the picture
*/
typedef struct {
void *buffer; /*!< Pointer to the output picture buffer (requires align to the cache line size) */
uint32_t buffer_size; /*!< Size of the output picture buffer (requires align to the cache line size) */
uint32_t pic_w; /*!< Output picture width (unit: pixel) */
uint32_t pic_h; /*!< Output picture height (unit: pixel) */
uint32_t block_offset_x; /*!< Target block offset in x direction in the picture (unit: pixel) */
uint32_t block_offset_y; /*!< Target block offset in y direction in the picture (unit: pixel) */
union {
ppa_srm_color_mode_t srm_cm; /*!< Color mode of the picture in a PPA SRM operation. Supported color mode in `ppa_srm_color_mode_t` */
ppa_blend_color_mode_t blend_cm; /*!< Color mode of the picture in a PPA blend operation. Supported color mode in `ppa_blend_color_mode_t` */
ppa_fill_color_mode_t fill_cm; /*!< Color mode of the picture in a PPA fill operation. Supported color mode in `ppa_fill_color_mode_t` */
};
color_range_t yuv_range; /*!< When the color mode is any YUV color space, this field is to describe its color range */
color_conv_std_rgb_yuv_t yuv_std; /*!< When the color mode is any YUV color space, this field is to describe its YUV<->RGB conversion standard */
} ppa_out_pic_blk_config_t;
/**
* @brief Modes to perform the PPA operations
*/
@ -68,75 +134,148 @@ typedef enum {
PPA_TRANS_MODE_NON_BLOCKING, /*!< `ppa_do_xxx` function will return immediately after the PPA operation is pushed to the internal queue */
} ppa_trans_mode_t;
/**
* @brief A collection of configuration items to do a PPA SRM operation transaction
*/
typedef struct {
ppa_in_pic_blk_config_t in; /*!< Information of the input picture and the target block */
ppa_out_pic_blk_config_t out; /*!< Information of the output picture and the target block */
// scale-rotate-mirror manipulation
ppa_srm_rotation_angle_t rotation_angle; /*!< Rotation (counter-clockwise) to the target block, select from `ppa_srm_rotation_angle_t` */
float scale_x; /*!< Scaling factor to the target block in the x direction */
float scale_y; /*!< Scaling factor to the target block in the y direction */
bool mirror_x; /*!< Whether to mirror the target block in the x direction */
bool mirror_y; /*!< Whether to mirror the target block in the y direction */
// input data manipulation
bool rgb_swap; /*!< Whether to swap the input data in RGB (e.g. ARGB becomes BGRA, RGB becomes BGR) */
bool byte_swap; /*!< Whether to swap the input data in byte. Only available feature if input picture color mode is ARGB8888 or RGB565 */
ppa_alpha_update_mode_t alpha_update_mode; /*!< Select whether the alpha channel of the input picture needs update */
uint32_t alpha_value; /*!< Range: 0 ~ 255
When PPA_ALPHA_FIX_VALUE mode is selected, alpha_value is the alpha value to be replaced with (output_alpha = alpha_value)
When PPA_ALPHA_SCALE mode is selected, alpha_value/256 is the multiplier to the input alpha value (output_alpha = input_alpha * alpha_value / 256)
When other alpha modes are selected, this field is not used */
ppa_trans_mode_t mode; /*!< Determines whether to block inside the operation functions, see `ppa_trans_mode_t` */
// uint32_t timeout;
void *user_data; /*!< User registered data to be passed into `done_cb` callback function */
} ppa_srm_oper_trans_config_t;
/**
* @brief A collection of configuration items to perform a PPA transaction
*/
typedef struct {
ppa_trans_mode_t mode; /*!< Determines whether to block inside the operation functions, see `ppa_trans_mode_t` */
void *user_data; /*!< User registered data to be passed into `done_cb` callback function */
} ppa_trans_config_t;
#define PPA_SRM_OPERATION_CONFIG struct { \
void *in_buffer; /*!< TODO: could be a buffer list, link descriptors together, process a batch
uint32_t batch_num; However, is it necessary? psram can not store too many pictures */ \
uint32_t in_pic_w; \
uint32_t in_pic_h; \
uint32_t in_block_w; \
uint32_t in_block_h; \
uint32_t in_block_offset_x; \
uint32_t in_block_offset_y; \
\
void *out_buffer; \
uint32_t out_buffer_size; \
uint32_t out_pic_w; \
uint32_t out_pic_h; \
uint32_t out_block_offset_x; \
uint32_t out_block_offset_y; \
\
ppa_srm_rotation_angle_t rotation_angle; \
float scale_x; \
float scale_y; \
bool mirror_x; \
bool mirror_y; \
\
struct { \
ppa_srm_color_mode_t mode; \
color_range_t yuv_range; \
color_conv_std_rgb_yuv_t yuv_std; \
bool rgb_swap; \
bool byte_swap; \
ppa_alpha_update_mode_t alpha_update_mode; \
uint32_t alpha_value; /*!< When PPA_ALPHA_FIX_VALUE mode is selected, alpha_value is the alpha value to be replaced with (output_alpha = alpha_value)
When PPA_ALPHA_SCALE mode is selected, alpha_value/256 is the multiplier to the input alpha value (output_alpha = input_alpha * alpha_value / 256)
When other alpha modes are selected, this field is not used */ \
} in_color; \
\
struct { \
ppa_srm_color_mode_t mode; \
color_range_t yuv_range; \
color_conv_std_rgb_yuv_t yuv_std; \
} out_color; \
}
/**
* @brief A collection of configuration items to perform a PPA SRM operation
*/
typedef PPA_SRM_OPERATION_CONFIG ppa_srm_operation_config_t;
typedef struct {
void *in_buffer; /*!< TODO: could be a buffer list, link descriptors together, process a batch
uint32_t batch_num; However, is it necessary? psram can not store too many pictures */
uint32_t in_pic_w;
uint32_t in_pic_h;
uint32_t in_block_w;
uint32_t in_block_h;
uint32_t in_block_offset_x;
uint32_t in_block_offset_y;
void *out_buffer;
uint32_t out_buffer_size;
uint32_t out_pic_w;
uint32_t out_pic_h;
uint32_t out_block_offset_x;
uint32_t out_block_offset_y;
ppa_srm_rotation_angle_t rotation_angle;
float scale_x;
float scale_y;
bool mirror_x;
bool mirror_y;
struct {
ppa_srm_color_mode_t mode;
color_range_t yuv_range;
color_conv_std_rgb_yuv_t yuv_std;
bool rgb_swap;
bool byte_swap;
ppa_alpha_update_mode_t alpha_update_mode;
uint32_t alpha_value; /*!< When PPA_ALPHA_FIX_VALUE mode is selected, alpha_value is the alpha value to be replaced with (output_alpha = alpha_value)
When PPA_ALPHA_SCALE mode is selected, alpha_value/256 is the multiplier to the input alpha value (output_alpha = input_alpha * alpha_value / 256)
When other alpha modes are selected, this field is not used */
} in_color;
struct {
ppa_srm_color_mode_t mode;
color_range_t yuv_range;
color_conv_std_rgb_yuv_t yuv_std;
} out_color;
} ppa_srm_operation_config_t;
/**
* @brief Perform a scaling-rotating-mirroring (SRM) operation to a picture
*
* @param[in] ppa_invoker PPA invoker handle that has acquired the PPA SRM engine
* @param[in] ppa_invoker PPA invoker handle that has been registered to do SRM operations
* @param[in] oper_config Pointer to a collection of configurations for the SRM operation, ppa_srm_operation_config_t
* @param[in] trans_config Pointer to a collection of configurations for the transaction, ppa_trans_config_t
*
* @return
* - ESP_OK:
* - ESP_ERR_INVALID_ARG:
* - ESP_ERR_NO_MEM:
* - ESP_FAIL:
* - ESP_OK: Perform a SRM operation successfully
* - ESP_ERR_INVALID_ARG: Perform a SRM operation failed because of invalid argument
* - ESP_ERR_NO_MEM: Perform a SRM operation failed because out of memory
* - ESP_FAIL: Perform a SRM operation failed because the invoker cannot accept transaction now
*/
esp_err_t ppa_do_scale_rotate_mirror(ppa_invoker_handle_t ppa_invoker, const ppa_srm_operation_config_t *oper_config, const ppa_trans_config_t *trans_config);
/**
* @brief A collection of configuration items to do a PPA blend operation transaction
*/
typedef struct {
ppa_in_pic_blk_config_t in_bg; /*!< Information of the input background picture and the target block */
ppa_in_pic_blk_config_t in_fg; /*!< Information of the input foreground picture and the target block */
ppa_out_pic_blk_config_t out; /*!< Information of the output picture and the target block */
// input data manipulation
bool bg_rgb_swap; /*!< Whether to swap the background input data in RGB (e.g. ARGB becomes BGRA, RGB becomes BGR) */
bool bg_byte_swap; /*!< Whether to swap the background input data in byte. Only available feature if input BG picture color mode is ARGB8888 or RGB565 */
ppa_alpha_update_mode_t bg_alpha_update_mode; /*!< Select whether the alpha channel of the input background picture needs update */
uint32_t bg_alpha_value; /*!< Range: 0 ~ 255
When PPA_ALPHA_FIX_VALUE mode is selected, alpha_value is the alpha value to be replaced with (output_alpha = alpha_value)
When PPA_ALPHA_SCALE mode is selected, alpha_value/256 is the multiplier to the input alpha value (output_alpha = input_alpha * alpha_value / 256)
When other alpha modes are selected, this field is not used */
bool fg_rgb_swap; /*!< Whether to swap the foreground input data in RGB (e.g. ARGB becomes BGRA, RGB becomes BGR) */
bool fg_byte_swap; /*!< Whether to swap the foreground input data in byte. Only available feature if input FG picture color mode is ARGB8888 or RGB565 */
ppa_alpha_update_mode_t fg_alpha_update_mode; /*!< Select whether the alpha channel of the input foreground picture needs update */
uint32_t fg_alpha_value; /*!< Range: 0 ~ 255
When PPA_ALPHA_FIX_VALUE mode is selected, alpha_value is the alpha value to be replaced with (output_alpha = alpha_value)
When PPA_ALPHA_SCALE mode is selected, alpha_value/256 is the multiplier to the input alpha value (output_alpha = input_alpha * alpha_value / 256)
When other alpha modes are selected, this field is not used */
uint32_t fg_fix_rgb_val; /*!< When in_fg.blend_cm is PPA_BLEND_COLOR_MODE_A8/4, this field can be used to set a fixed color for the foreground, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
// color-keying
// A pixel, where its background element and foreground element are both out of their color-keying ranges, will follow Alpha Blending
bool bg_ck_en; /*!< Whether to enable color keying for background
If not enabled, all background pixels are considered as out of the color-keying range */
uint32_t bg_ck_rgb_low_thres; /*!< The lower threshold of the color-keying range for the background, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
uint32_t bg_ck_rgb_high_thres; /*!< The higher threshold of the color-keying range for the background, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
bool fg_ck_en; /*!< Whether to enable color keying for foreground
If not enabled, all foreground pixels are considered as out of the color-keying range */
uint32_t fg_ck_rgb_low_thres; /*!< The lower threshold of the color-keying range for the foreground, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
uint32_t fg_ck_rgb_high_thres; /*!< The higher threshold of the color-keying range for the foreground, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
uint32_t ck_rgb_default_val; /*!< The color to overwrite when a pixel, where its background element and foreground element are both within their color-keying ranges, in RGB888 format (R[23:16], G[15: 8], B[7:0]) */
bool ck_reverse_bg2fg; /*!< If this bit is set, in color-keying, for the pixel, where its background element is in the color range, but its foreground element is not in the color range, it will output the foreground element instead of the background element */
ppa_trans_mode_t mode; /*!< Determines whether to block inside the operation functions, see `ppa_trans_mode_t` */
// uint32_t timeout;
void *user_data; /*!< User registered data to be passed into `done_cb` callback function */
} ppa_blend_oper_trans_config_t;
/**
* @brief A collection of configuration items to perform a PPA blend operation
*/
typedef struct {
void *in_bg_buffer;
uint32_t in_bg_pic_w;
@ -193,18 +332,36 @@ typedef struct {
/**
* @brief Perform a blending operation to a picture
*
* @param[in] ppa_invoker PPA invoker handle that has acquired the PPA Blend engine
* @param[in] oper_config Pointer to a collection of configurations for the blending operation, ppa_blend_operation_config_t
* @param[in] ppa_invoker PPA invoker handle that has been registered to do blend operations
* @param[in] oper_config Pointer to a collection of configurations for the blend operation, ppa_blend_operation_config_t
* @param[in] trans_config Pointer to a collection of configurations for the transaction, ppa_trans_config_t
*
* @return
* - ESP_OK:
* - ESP_ERR_INVALID_ARG:
* - ESP_ERR_NO_MEM:
* - ESP_FAIL:
* - ESP_OK: Perform a blend operation successfully
* - ESP_ERR_INVALID_ARG: Perform a blend operation failed because of invalid argument
* - ESP_ERR_NO_MEM: Perform a blend operation failed because out of memory
* - ESP_FAIL: Perform a blend operation failed because the invoker cannot accept transaction now
*/
esp_err_t ppa_do_blend(ppa_invoker_handle_t ppa_invoker, const ppa_blend_operation_config_t *oper_config, const ppa_trans_config_t *trans_config);
/**
* @brief A collection of configuration items to do a PPA fill operation transaction
*/
typedef struct {
ppa_out_pic_blk_config_t out; /*!< Information of the output picture and the target block */
uint32_t fill_block_w; /*!< The width of the block to be filled (unit: pixel) */
uint32_t fill_block_h; /*!< The height of the block to be filled (unit: pixel) */
uint32_t fill_argb_color; /*!< The color to be filled, in ARGB8888 format ((A[31:24], R[23:16], G[15: 8], B[7:0])) */
ppa_trans_mode_t mode; /*!< Determines whether to block inside the operation functions, see `ppa_trans_mode_t` */
// uint32_t timeout;
void *user_data; /*!< User registered data to be passed into `done_cb` callback function */
} ppa_fill_oper_trans_config_t;
/**
* @brief A collection of configuration items to perform a PPA fill operation
*/
typedef struct {
uint32_t fill_block_w;
uint32_t fill_block_h;
@ -225,28 +382,18 @@ typedef struct {
/**
* @brief Perform a filling operation to a picture
*
* @param[in] ppa_invoker PPA invoker handle that has acquired the PPA Blend engine
* @param[in] oper_config Pointer to a collection of configurations for the filling operation, ppa_fill_operation_config_t
* @param[in] ppa_invoker PPA invoker handle that has been registered to do fill operations
* @param[in] oper_config Pointer to a collection of configurations for the fill operation, ppa_fill_operation_config_t
* @param[in] trans_config Pointer to a collection of configurations for the transaction, ppa_trans_config_t
*
* @return
* - ESP_OK:
* - ESP_ERR_INVALID_ARG:
* - ESP_ERR_NO_MEM:
* - ESP_FAIL:
* - ESP_OK: Perform a fill operation successfully
* - ESP_ERR_INVALID_ARG: Perform a fill operation failed because of invalid argument
* - ESP_ERR_NO_MEM: Perform a fill operation failed because out of memory
* - ESP_FAIL: Perform a fill operation failed because the invoker cannot accept transaction now
*/
esp_err_t ppa_do_fill(ppa_invoker_handle_t ppa_invoker, const ppa_fill_operation_config_t *oper_config, const ppa_trans_config_t *trans_config);
// argb color conversion (bypass blend)
// SRM and Blending are independent, can work at the same time
// Fill is in blend, so fill and blend cannot work at the same time
// Consider blocking and non-blocking options
// Non-blocking may require notification of process done event
// cache writeback/invalidate
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,153 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <sys/queue.h>
#include "sdkconfig.h"
#include "driver/ppa.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp_private/dma2d.h"
#include "hal/dma2d_types.h"
#include "hal/ppa_types.h"
#include "esp_pm.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PPA_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) // TODO...
#define PPA_PM_LOCK_NAME_LEN_MAX 16
/******************************** ENGINE *************************************/
// PPA module contains SRM engine and Blending engine
typedef struct ppa_engine_t ppa_engine_t;
struct ppa_engine_t {
ppa_engine_type_t type; // Type of the PPA engine
portMUX_TYPE spinlock; // Engine level spinlock
SemaphoreHandle_t sem; // Semaphore for whether the engine is processing a transaction
STAILQ_HEAD(trans, ppa_trans_s) trans_stailq; // link head of pending transactions for the PPA engine
#if CONFIG_PM_ENABLE
esp_pm_lock_handle_t pm_lock; // Power management lock
#endif
};
typedef struct ppa_srm_engine_t {
ppa_engine_t base; // PPA engine base structure
dma2d_descriptor_t *dma_tx_desc; // Into PPA SRM engine direction 2D-DMA descriptor
dma2d_descriptor_t *dma_rx_desc; // Out from PPA SRM engine direction 2D-DMA descriptor
} ppa_srm_engine_t;
typedef struct ppa_blend_engine_t {
ppa_engine_t base; // PPA engine base structure
dma2d_descriptor_t *dma_tx_bg_desc; // Into PPA Blending engine direction background channel 2D-DMA descriptor
dma2d_descriptor_t *dma_tx_fg_desc; // Into PPA Blending engine direction foreground channel 2D-DMA descriptor
dma2d_descriptor_t *dma_rx_desc; // Out from PPA blending engine direction 2D-DMA descriptor
} ppa_blend_engine_t;
typedef struct {
ppa_engine_type_t engine; // Engine type
} ppa_engine_config_t;
/******************************** CLIENT *************************************/
typedef struct ppa_invoker_t ppa_invoker_t;
struct ppa_invoker_t {
ppa_operation_t oper_type; // The PPA operation type that the invoker wants to do in speciality
ppa_engine_t *engine; // Pointer to the PPA engine that in charge of performing the PPA operation
uint32_t trans_cnt; // Number of pending PPA transactions
portMUX_TYPE spinlock; // Client level spinlock
bool in_accepting_trans_state; // Indicates whether the invoker can accept new PPA transaction requests now
ppa_event_callback_t done_cb; // Transaction done callback
QueueHandle_t trans_elm_ptr_queue; // Queue that contains the pointers to the allocated memory to save the transaction contexts
};
/****************************** OPERATION ************************************/
// The elements in this structure listed first are identical to the elements in structure `ppa_blend_operation_config_t`
// With adding a few extra elements in the end
// This allows memcpy
typedef struct {
void *in_buffer;
uint32_t in_pic_w;
uint32_t in_pic_h;
uint32_t in_block_w;
uint32_t in_block_h;
uint32_t in_block_offset_x;
uint32_t in_block_offset_y;
void *out_buffer;
uint32_t out_buffer_size;
uint32_t out_pic_w;
uint32_t out_pic_h;
uint32_t out_block_offset_x;
uint32_t out_block_offset_y;
ppa_srm_rotation_angle_t rotation_angle;
float scale_x;
float scale_y;
bool mirror_x;
bool mirror_y;
struct {
ppa_srm_color_mode_t mode;
color_range_t yuv_range;
color_conv_std_rgb_yuv_t yuv_std;
bool rgb_swap;
bool byte_swap;
ppa_alpha_update_mode_t alpha_update_mode;
uint32_t alpha_value;
} in_color;
struct {
ppa_srm_color_mode_t mode;
color_range_t yuv_range;
color_conv_std_rgb_yuv_t yuv_std;
} out_color;
uint32_t scale_x_int;
uint32_t scale_x_frag;
uint32_t scale_y_int;
uint32_t scale_y_frag;
} ppa_srm_oper_t;
typedef ppa_blend_operation_config_t ppa_blend_oper_t;
typedef ppa_fill_operation_config_t ppa_fill_oper_t;
/***************************** TRANSACTION ***********************************/
// PPA transaction element
typedef struct ppa_trans_s {
STAILQ_ENTRY(ppa_trans_s) entry; // Link entry
dma2d_trans_config_t *trans_desc; // Pointer to the structure containing the configurations for a 2D-DMA transaction
dma2d_trans_t *dma_trans_placeholder; // Pointer to the memory to store the 2D-DMA transaction context
SemaphoreHandle_t sem; // Semaphore to block when the transaction has not finished
ppa_invoker_t *invoker; // Pointer to the invoker who requested the transaction
void *user_data; // User registered event data (per transaction)
} ppa_trans_t;
typedef struct {
union {
ppa_srm_oper_t *srm_desc; // Pointer to the structure containing the configurations for a PPA SRM operation transaction
ppa_blend_oper_t *blend_desc; // Pointer to the structure containing the configurations for a PPA blend operation transaction
ppa_fill_oper_t *fill_desc; // Pointer to the structure containing the configurations for a PPA fill operation transaction
void *op_desc; // General pointer to the structure containing the configurations for a PPA transaction
};
ppa_engine_t *ppa_engine; // Pointer to the PPA engine
ppa_trans_t *trans_elm; // Pointer to the PPA transaction element
dma2d_trigger_peripheral_t trigger_periph; // The 2D-DMA trigger peripheral
} ppa_dma2d_trans_on_picked_config_t;
#ifdef __cplusplus
}
#endif

View File

@ -222,6 +222,10 @@ if(NOT BOOTLOADER_BUILD)
list(APPEND srcs "jpeg_hal.c")
endif()
if(CONFIG_SOC_PPA_SUPPORTED)
list(APPEND srcs "ppa_hal.c")
endif()
if(CONFIG_SOC_GPSPI_SUPPORTED)
list(APPEND srcs
"spi_hal.c"

View File

@ -308,7 +308,7 @@ static inline void ppa_ll_srm_set_tx_yuv_range(ppa_dev_t *dev, color_range_t ran
}
/**
* @brief Enable PPA SRM input data wrap in RGB (e.g. ARGB becomes BGRA, RGB becomes BGR)
* @brief Enable PPA SRM input data swap in RGB (e.g. ARGB becomes BGRA, RGB becomes BGR)
*
* @param dev Peripheral instance address
* @param enable True to enable; False to disable

View File

@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*******************************************************************************
* NOTICE
* The HAL is not public api, don't use in application code.
* See readme.md in soc/README.md
******************************************************************************/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ppa_dev_t *ppa_soc_handle_t; // PPA SOC layer handle
/**
* Context that should be maintained by both the driver and the HAL
*/
typedef struct {
ppa_soc_handle_t dev; // PPA SOC layer handle (i.e. register base address)
} ppa_hal_context_t;
/**
* @brief Init the PPA hal. This function should be called first before other hal layer function is called
*
* @param hal Context of the HAL layer
*/
void ppa_hal_init(ppa_hal_context_t *hal);
/**
* @brief De-init the PPA hal
*
* @param hal Context of the HAL layer
*/
void ppa_hal_deinit(ppa_hal_context_t *hal);
#ifdef __cplusplus
}
#endif

View File

@ -47,26 +47,38 @@ typedef enum {
} ppa_srm_color_mode_t;
/**
* @brief Enumeration of PPA Blending available color mode
* @brief Enumeration of PPA blend available color mode
*/
typedef enum {
PPA_BLEND_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA Blending color mode: ARGB8888 */
PPA_BLEND_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA Blending color mode: RGB888 */
PPA_BLEND_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA Blending color mode: RGB565 */
PPA_BLEND_COLOR_MODE_L8 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L8), /*!< PPA Blending color mode: L8, only available on blending inputs */
PPA_BLEND_COLOR_MODE_L4 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L4), /*!< PPA Blending color mode: L4, only available on blending inputs */
PPA_BLEND_COLOR_MODE_A8 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A8), /*!< PPA Blending color mode: A8, only available on blending foreground input */
PPA_BLEND_COLOR_MODE_A4 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A4), /*!< PPA Blending color mode: A4, only available on blending foreground input */
PPA_BLEND_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA blend color mode: ARGB8888 */
PPA_BLEND_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA blend color mode: RGB888 */
PPA_BLEND_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA blend color mode: RGB565 */
PPA_BLEND_COLOR_MODE_L8 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L8), /*!< PPA blend color mode: L8, only available on blend inputs */
PPA_BLEND_COLOR_MODE_L4 = COLOR_TYPE_ID(COLOR_SPACE_CLUT, COLOR_PIXEL_L4), /*!< PPA blend color mode: L4, only available on blend inputs */
PPA_BLEND_COLOR_MODE_A8 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A8), /*!< PPA blend color mode: A8, only available on blend foreground input */
PPA_BLEND_COLOR_MODE_A4 = COLOR_TYPE_ID(COLOR_SPACE_ALPHA, COLOR_PIXEL_A4), /*!< PPA blend color mode: A4, only available on blend foreground input */
} ppa_blend_color_mode_t;
/**
* @brief Enumeration of PPA fill available color mode
*/
typedef enum {
PPA_FILL_COLOR_MODE_ARGB8888 = COLOR_TYPE_ID(COLOR_SPACE_ARGB, COLOR_PIXEL_ARGB8888), /*!< PPA fill color mode: ARGB8888 */
PPA_FILL_COLOR_MODE_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), /*!< PPA fill color mode: RGB888 */
PPA_FILL_COLOR_MODE_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), /*!< PPA fill color mode: RGB565 */
} ppa_fill_color_mode_t;
/**
* @brief Enumeration of PPA alpha compositing update mode
*/
typedef enum {
PPA_ALPHA_NO_CHANGE = 0, /*!< Do not replace alpha value. If input format does not contain alpha info, alpha value 255 will be used. */
PPA_ALPHA_FIX_VALUE, /*!< Replace the alpha value in received pixel with a new, fixed alpha value */
PPA_ALPHA_SCALE, /*!< Scale the alpha value in received pixel to be a new alpha value */
PPA_ALPHA_INVERT, /*!< Invert the alpha value in received pixel */
PPA_ALPHA_NO_CHANGE = 0, /*!< Do not replace alpha value (A' = A).
If input format does not contain alpha info, alpha value 255 will be used. */
PPA_ALPHA_FIX_VALUE, /*!< Replace the alpha value in received pixel with a new, fixed alpha value (A' = val) */
PPA_ALPHA_SCALE, /*!< Scale the alpha value in received pixel to be a new alpha value (A' = (A * val) >> 8).
If input format does not contain alpha info, A' = (255 * val) >> 8. */
PPA_ALPHA_INVERT, /*!< Invert the alpha value in received pixel (A' = 255 - A).
If input format does not contain alpha info, A' = 0, i.e. a layer with 0% opacity. */
} ppa_alpha_update_mode_t;
#ifdef __cplusplus

19
components/hal/ppa_hal.c Normal file
View File

@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stddef.h>
#include "hal/ppa_hal.h"
#include "hal/ppa_ll.h"
void ppa_hal_init(ppa_hal_context_t *hal)
{
hal->dev = PPA_LL_GET_HW;
}
void ppa_hal_deinit(ppa_hal_context_t *hal)
{
hal->dev = NULL;
}