1313
1414static const char * TAG = "swap_byte" ;
1515
16+ #if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
1617BITSCRAMBLER_PROGRAM (esp_video_swap_byte , "esp_video_swap_byte" );
18+ #elif CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_RISCV
19+ extern void esp_video_swap_byte_riscv (void * src , void * dst , uint32_t size );
20+ #endif
1721
1822/**
1923 * @brief Create video swap byte
@@ -22,14 +26,17 @@ BITSCRAMBLER_PROGRAM(esp_video_swap_byte, "esp_video_swap_byte");
2226 */
2327esp_video_swap_byte_t * esp_video_swap_byte_create (void )
2428{
25- esp_err_t ret ;
2629 esp_video_swap_byte_t * swap_byte ;
2730
2831 swap_byte = heap_caps_calloc (1 , sizeof (esp_video_swap_byte_t ), MALLOC_CAP_8BIT | MALLOC_CAP_8BIT );
2932 if (!swap_byte ) {
33+ ESP_LOGE (TAG , "Failed to allocate memory for swap byte" );
3034 return NULL ;
3135 }
3236
37+ #if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
38+ esp_err_t ret ;
39+
3340 bitscrambler_config_t bs_config = {
3441 .dir = BITSCRAMBLER_DIR_RX ,
3542 .attach_to = SOC_BITSCRAMBLER_ATTACH_LCD_CAM ,
@@ -52,6 +59,9 @@ esp_video_swap_byte_t *esp_video_swap_byte_create(void)
5259exit_0 :
5360 heap_caps_free (swap_byte );
5461 return NULL ;
62+ #else
63+ return swap_byte ;
64+ #endif
5565}
5666
5767/**
@@ -65,6 +75,7 @@ esp_video_swap_byte_t *esp_video_swap_byte_create(void)
6575 */
6676esp_err_t IRAM_ATTR esp_video_swap_byte_start (esp_video_swap_byte_t * swap_byte )
6777{
78+ #if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
6879 esp_err_t ret ;
6980
7081 if ((ret = bitscrambler_reset (swap_byte -> bs )) != ESP_OK ) {
@@ -78,6 +89,9 @@ esp_err_t IRAM_ATTR esp_video_swap_byte_start(esp_video_swap_byte_t *swap_byte)
7889 }
7990
8091 return ESP_OK ;
92+ #else
93+ return ESP_OK ;
94+ #endif
8195}
8296
8397/**
@@ -89,8 +103,35 @@ esp_err_t IRAM_ATTR esp_video_swap_byte_start(esp_video_swap_byte_t *swap_byte)
89103 */
90104void esp_video_swap_byte_free (esp_video_swap_byte_t * swap_byte )
91105{
106+ #if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
92107 bitscrambler_reset (swap_byte -> bs );
93108 bitscrambler_disable (swap_byte -> bs );
94109 bitscrambler_free (swap_byte -> bs );
95- swap_byte -> bs = NULL ;
110+ #endif
111+
112+ heap_caps_free (swap_byte );
113+ }
114+
115+ /**
116+ * @brief Process video swap byte
117+ *
118+ * @param swap_byte Video swap byte object pointer
119+ * @param src Source buffer pointer
120+ * @param src_size Source buffer size
121+ * @param dst Destination buffer pointer
122+ * @param dst_size Destination buffer size
123+ * @param ret_size Result data size buffer
124+ *
125+ * @return
126+ * - ESP_OK on success
127+ * - Others if failed
128+ */
129+ esp_err_t esp_video_swap_byte_process (esp_video_swap_byte_t * swap_byte , void * src , size_t src_size ,
130+ void * dst , size_t dst_size , size_t * ret_size )
131+ {
132+ #if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_RISCV
133+ esp_video_swap_byte_riscv (src , dst , src_size );
134+ #endif
135+ * ret_size = src_size ;
136+ return ESP_OK ;
96137}
0 commit comments