1 /*
2  * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #pragma once
7 
8 #include <stddef.h>
9 #include "soc/soc_caps.h"
10 #include "hal/dma_types.h"
11 #if SOC_LCDCAM_SUPPORTED
12 #include "hal/lcd_hal.h"
13 #endif
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #define LCD_PERIPH_CLOCK_PRE_SCALE (2) // This is the minimum divider that can be applied to LCD peripheral
20 
21 #if SOC_LCDCAM_SUPPORTED
22 
23 typedef enum {
24     LCD_COM_DEVICE_TYPE_I80,
25     LCD_COM_DEVICE_TYPE_RGB
26 } lcd_com_device_type_t;
27 
28 /**
29  * @brief Register a LCD device to platform
30  *
31  * @param device_type Device type, refer to lcd_com_device_type_t
32  * @param device_obj Device object
33  * @return >=0: member_id, <0: no free lcd bus/panel slots
34  */
35 int lcd_com_register_device(lcd_com_device_type_t device_type, void *device_obj);
36 
37 /**
38  * @brief Remove a device from platform
39  *
40  * @param device_type Device type, refer to lcd_com_device_type_t
41  * @param member_id member ID
42  */
43 void lcd_com_remove_device(lcd_com_device_type_t device_type, int member_id);
44 #endif // SOC_LCDCAM_SUPPORTED
45 
46 /**
47  * @brief Mount data to DMA descriptors
48  *
49  * @param desc_head Point to the head of DMA descriptor chain
50  * @param buffer Data buffer
51  * @param len Size of the data buffer, in bytes
52  */
53 void lcd_com_mount_dma_data(dma_descriptor_t *desc_head, const void *buffer, size_t len);
54 
55 /**
56  * @brief Reverse the bytes in the buffer
57  *
58  * @note  LCD is big-endian, e.g. to send command 0x1234, byte 0x12 should appear on the bus first
59  *        However, the low level peripheral (like i80, i2s) will send 0x34 first.
60  *        This helper function is used to reverse the bytes order
61  *
62  * @param buf buffer address
63  * @param start start index of the buffer
64  * @param end end index of the buffer
65  */
lcd_com_reverse_buffer_bytes(uint8_t * buf,int start,int end)66 static inline void lcd_com_reverse_buffer_bytes(uint8_t *buf, int start, int end)
67 {
68     uint8_t temp = 0;
69     while (start < end) {
70         temp = buf[start];
71         buf[start] = buf[end];
72         buf[end] = temp;
73         start++;
74         end--;
75     }
76 }
77 
78 #ifdef __cplusplus
79 }
80 #endif
81