ssd1306.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef _SSD1306_H_
  2. #define _SSD1306_H_
  3. /* For uint(X)_t */
  4. #include <stdint.h>
  5. /* For booooool */
  6. #include <stdbool.h>
  7. #include "sdkconfig.h"
  8. #include "ssd1306_err.h"
  9. #define SSD_ALWAYS_INLINE __attribute__( ( always_inline ) )
  10. #define SSD1306_Max_Col 127
  11. #define SSD1306_Max_Row 7
  12. #if ! defined BIT
  13. #define BIT( n ) ( 1 << n )
  14. #endif
  15. typedef enum {
  16. SSDCmd_Set_Contrast = 0x81,
  17. SSDCmd_Set_Display_Show_RAM = 0xA4,
  18. SSDCmd_Set_Display_Ignore_RAM = 0xA5,
  19. SSDCmd_Set_Normal_Display = 0xA6,
  20. SSDCmd_Set_Inverted_Display = 0xA7,
  21. SSDCmd_Set_Display_Off = 0xAE,
  22. SSDCmd_Set_Display_On = 0xAF,
  23. SSDCmd_Set_Memory_Addressing_Mode = 0x20,
  24. SSDCmd_Set_Mux_Ratio = 0xA8,
  25. SSDCmd_Nop = 0xE3,
  26. SSDCmd_Set_Display_Offset = 0xD3,
  27. SSDCmd_Set_Display_Start_Line = 0x40,
  28. SSDCmd_Set_Display_HFlip_Off = 0xA0,
  29. SSDCmd_Set_Display_HFlip_On = 0xA1,
  30. SSDCmd_Set_Display_VFlip_Off = 0xC0,
  31. SSDCmd_Set_Display_VFlip_On = 0xC8,
  32. SSDCmd_Set_COM_Pin_Config = 0xDA,
  33. SSDCmd_Set_Display_CLK = 0xD5,
  34. SSDCmd_Enable_Charge_Pump_Regulator = 0x8D,
  35. SSDCmd_Set_Column_Address = 0x21,
  36. SSDCmd_Set_Page_Address = 0x22
  37. } SSDCmd;
  38. typedef enum {
  39. AddressMode_Horizontal = 0,
  40. AddressMode_Vertical,
  41. AddressMode_Page,
  42. AddressMode_Invalid
  43. } SSD1306_AddressMode;
  44. struct SSD1306_Device;
  45. /*
  46. * These can optionally return a succeed/fail but are as of yet unused in the driver.
  47. */
  48. typedef bool ( *WriteCommandProc ) ( struct SSD1306_Device* DeviceHandle, SSDCmd Command );
  49. typedef bool ( *WriteDataProc ) ( struct SSD1306_Device* DeviceHandle, const uint8_t* Data, size_t DataLength );
  50. typedef bool ( *ResetProc ) ( struct SSD1306_Device* DeviceHandle );
  51. struct spi_device_t;
  52. typedef struct spi_device_t* spi_device_handle_t;
  53. struct SSD1306_FontDef;
  54. struct SSD1306_Device {
  55. /* I2C Specific */
  56. int Address;
  57. /* SPI Specific */
  58. spi_device_handle_t SPIHandle;
  59. int RSTPin;
  60. int CSPin;
  61. /* Everything else */
  62. int Width;
  63. int Height;
  64. uint8_t* Framebuffer;
  65. int FramebufferSize;
  66. WriteCommandProc WriteCommand;
  67. WriteDataProc WriteData;
  68. ResetProc Reset;
  69. const struct SSD1306_FontDef* Font;
  70. bool FontForceProportional;
  71. bool FontForceMonospace;
  72. };
  73. void SSD1306_SetMuxRatio( struct SSD1306_Device* DeviceHandle, uint8_t Ratio );
  74. void SSD1306_SetDisplayOffset( struct SSD1306_Device* DeviceHandle, uint8_t Offset );
  75. void SSD1306_SetDisplayStartLines( struct SSD1306_Device* DeviceHandle );
  76. void SSD1306_SetSegmentRemap( struct SSD1306_Device* DeviceHandle, bool Remap );
  77. void SSD1306_SetContrast( struct SSD1306_Device* DeviceHandle, uint8_t Contrast );
  78. void SSD1306_EnableDisplayRAM( struct SSD1306_Device* DeviceHandle );
  79. void SSD1306_DisableDisplayRAM( struct SSD1306_Device* DeviceHandle );
  80. void SSD1306_SetInverted( struct SSD1306_Device* DeviceHandle, bool Inverted );
  81. void SSD1306_SetHFlip( struct SSD1306_Device* DeviceHandle, bool On );
  82. void SSD1306_SetVFlip( struct SSD1306_Device* DeviceHandle, bool On );
  83. void SSD1306_DisplayOn( struct SSD1306_Device* DeviceHandle );
  84. void SSD1306_DisplayOff( struct SSD1306_Device* DeviceHandle );
  85. void SSD1306_SetDisplayAddressMode( struct SSD1306_Device* DeviceHandle, SSD1306_AddressMode AddressMode );
  86. void SSD1306_Update( struct SSD1306_Device* DeviceHandle );
  87. void SSD1306_SetDisplayClocks( struct SSD1306_Device* DeviceHandle, uint32_t DisplayClockDivider, uint32_t OSCFrequency );
  88. void SSD1306_WriteRawData( struct SSD1306_Device* DeviceHandle, uint8_t* Data, size_t DataLength );
  89. void SSD1306_SetColumnAddress( struct SSD1306_Device* DeviceHandle, uint8_t Start, uint8_t End );
  90. void SSD1306_SetPageAddress( struct SSD1306_Device* DeviceHandle, uint8_t Start, uint8_t End );
  91. bool SSD1306_HWReset( struct SSD1306_Device* DeviceHandle );
  92. bool SSD1306_Init_I2C( struct SSD1306_Device* DeviceHandle, int Width, int Height, int I2CAddress, int ResetPin, WriteCommandProc WriteCommand, WriteDataProc WriteData, ResetProc Reset );
  93. bool SSD1306_Init_SPI( struct SSD1306_Device* DeviceHandle, int Width, int Height, int ResetPin, int CSPin, spi_device_handle_t SPIHandle, WriteCommandProc WriteCommand, WriteDataProc WriteData, ResetProc Reset );
  94. #endif