gds_private.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include "esp_attr.h"
  5. #include "gds.h"
  6. #include "gds_err.h"
  7. #define GDS_CLIPDEBUG_NONE 0
  8. #define GDS_CLIPDEBUG_WARNING 1
  9. #define GDS_CLIPDEBUG_ERROR 2
  10. #define SHADOW_BUFFER
  11. #if CONFIG_GDS_CLIPDEBUG == GDS_CLIPDEBUG_NONE
  12. /*
  13. * Clip silently with no console output.
  14. */
  15. #define ClipDebug( x, y )
  16. #elif CONFIG_GDS_CLIPDEBUG == GDS_CLIPDEBUG_WARNING
  17. /*
  18. * Log clipping to the console as a warning.
  19. */
  20. #define ClipDebug( x, y ) { \
  21. ESP_LOGW( __FUNCTION__, "Line %d: Pixel at %d, %d CLIPPED", __LINE__, x, y ); \
  22. }
  23. #elif CONFIG_GDS_CLIPDEBUG == GDS_CLIPDEBUG_ERROR
  24. /*
  25. * Log clipping as an error to the console.
  26. * Also invokes an abort with stack trace.
  27. */
  28. #define ClipDebug( x, y ) { \
  29. ESP_LOGE( __FUNCTION__, "Line %d: Pixel at %d, %d CLIPPED, ABORT", __LINE__, x, y ); \
  30. abort( ); \
  31. }
  32. #endif
  33. #define GDS_ALWAYS_INLINE __attribute__( ( always_inline ) )
  34. #define MAX_LINES 8
  35. #if ! defined BIT
  36. #define BIT( n ) ( 1 << n )
  37. #endif
  38. typedef enum {
  39. AddressMode_Horizontal = 0,
  40. AddressMode_Vertical,
  41. AddressMode_Page,
  42. AddressMode_Invalid
  43. } GDS_AddressMode;
  44. struct GDS_Device;
  45. struct GDS_FontDef;
  46. /*
  47. * These can optionally return a succeed/fail but are as of yet unused in the driver.
  48. */
  49. typedef bool ( *WriteCommandProc ) ( struct GDS_Device* Device, uint8_t Command );
  50. typedef bool ( *WriteDataProc ) ( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength );
  51. struct spi_device_t;
  52. typedef struct spi_device_t* spi_device_handle_t;
  53. #define IF_SPI 0
  54. #define IF_I2C 1
  55. struct GDS_Device {
  56. uint8_t IF;
  57. union {
  58. // I2C Specific
  59. struct {
  60. uint8_t Address;
  61. };
  62. // SPI specific
  63. struct {
  64. spi_device_handle_t SPIHandle;
  65. int8_t RSTPin;
  66. int8_t CSPin;
  67. };
  68. };
  69. // cooked text mode
  70. struct {
  71. int16_t Y, Space;
  72. const struct GDS_FontDef* Font;
  73. } Lines[MAX_LINES];
  74. uint16_t Width;
  75. uint16_t Height;
  76. uint8_t Depth;
  77. uint8_t* Framebuffer, *Shadowbuffer;
  78. uint16_t FramebufferSize;
  79. bool Dirty;
  80. // default fonts when using direct draw
  81. const struct GDS_FontDef* Font;
  82. bool FontForceProportional;
  83. bool FontForceMonospace;
  84. // various driver-specific method
  85. bool (*Init)( struct GDS_Device* Device);
  86. void (*SetContrast)( struct GDS_Device* Device, uint8_t Contrast );
  87. void (*DisplayOn)( struct GDS_Device* Device );
  88. void (*DisplayOff)( struct GDS_Device* Device );
  89. void (*Update)( struct GDS_Device* Device );
  90. void (*DrawPixel)( struct GDS_Device* Device, int X, int Y, int Color );
  91. void (*DrawPixelFast)( struct GDS_Device* Device, int X, int Y, int Color );
  92. void (*SetHFlip)( struct GDS_Device* Device, bool On );
  93. void (*SetVFlip)( struct GDS_Device* Device, bool On );
  94. // interface-specific methods
  95. WriteCommandProc WriteCommand;
  96. WriteDataProc WriteData;
  97. };
  98. bool GDS_Reset( struct GDS_Device* Device );
  99. /*
  100. inline void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color );
  101. void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int x, int y, int Color );
  102. inline void IRAM_ATTR GDS_DrawPixel4Fast( struct GDS_Device* Device, int X, int Y, int Color );
  103. void IRAM_ATTR GDS_DrawPixel4( struct GDS_Device* Device, int x, int y, int Color );
  104. */
  105. void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color );
  106. void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int x, int y, int Color );
  107. void IRAM_ATTR GDS_DrawPixel4Fast( struct GDS_Device* Device, int X, int Y, int Color );
  108. void IRAM_ATTR GDS_DrawPixel4( struct GDS_Device* Device, int x, int y, int Color );