esp_lcd_common.h 2.2 KB

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