gds_private.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. struct GDS_Device;
  39. struct GDS_FontDef;
  40. /*
  41. * These can optionally return a succeed/fail but are as of yet unused in the driver.
  42. */
  43. typedef bool ( *WriteCommandProc ) ( struct GDS_Device* Device, uint8_t Command );
  44. typedef bool ( *WriteDataProc ) ( struct GDS_Device* Device, const uint8_t* Data, size_t DataLength );
  45. struct spi_device_t;
  46. typedef struct spi_device_t* spi_device_handle_t;
  47. #define IF_SPI 0
  48. #define IF_I2C 1
  49. struct GDS_Device {
  50. uint8_t IF;
  51. union {
  52. // I2C Specific
  53. struct {
  54. uint8_t Address;
  55. };
  56. // SPI specific
  57. struct {
  58. spi_device_handle_t SPIHandle;
  59. int8_t RSTPin;
  60. int8_t CSPin;
  61. };
  62. };
  63. // cooked text mode
  64. struct {
  65. int16_t Y, Space;
  66. const struct GDS_FontDef* Font;
  67. } Lines[MAX_LINES];
  68. uint16_t Width;
  69. uint16_t Height;
  70. uint8_t Depth;
  71. uint8_t* Framebuffer, *Shadowbuffer;
  72. uint16_t FramebufferSize;
  73. bool Dirty;
  74. // default fonts when using direct draw
  75. const struct GDS_FontDef* Font;
  76. bool FontForceProportional;
  77. bool FontForceMonospace;
  78. // various driver-specific method
  79. bool (*Init)( struct GDS_Device* Device);
  80. void (*SetContrast)( struct GDS_Device* Device, uint8_t Contrast );
  81. void (*DisplayOn)( struct GDS_Device* Device );
  82. void (*DisplayOff)( struct GDS_Device* Device );
  83. void (*Update)( struct GDS_Device* Device );
  84. void (*DrawPixelFast)( struct GDS_Device* Device, int X, int Y, int Color );
  85. void (*SetHFlip)( struct GDS_Device* Device, bool On );
  86. void (*SetVFlip)( struct GDS_Device* Device, bool On );
  87. // interface-specific methods
  88. WriteCommandProc WriteCommand;
  89. WriteDataProc WriteData;
  90. };
  91. bool GDS_Reset( struct GDS_Device* Device );
  92. void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color );
  93. void IRAM_ATTR GDS_DrawPixel4Fast( struct GDS_Device* Device, int X, int Y, int Color );
  94. inline bool IsPixelVisible( struct GDS_Device* Device, int x, int y ) {
  95. bool Result = (
  96. ( x >= 0 ) &&
  97. ( x < Device->Width ) &&
  98. ( y >= 0 ) &&
  99. ( y < Device->Height )
  100. ) ? true : false;
  101. #if CONFIG_GDS_CLIPDEBUG > 0
  102. if ( Result == false ) {
  103. ClipDebug( x, y );
  104. }
  105. #endif
  106. return Result;
  107. }
  108. inline void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int x, int y, int Color ) {
  109. if ( IsPixelVisible( Device, x, y ) == true ) {
  110. Device->DrawPixelFast( Device, x, y, Color );
  111. }
  112. }
  113. inline void IRAM_ATTR GDS_DrawPixel4( struct GDS_Device* Device, int x, int y, int Color ) {
  114. if ( IsPixelVisible( Device, x, y ) == true ) {
  115. Device->DrawPixelFast( Device, x, y, Color );
  116. }
  117. }