ssd13x6.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef _SSD13X6_H_
  2. #define _SSD13X6_H_
  3. /* For uint(X)_t */
  4. #include <stdint.h>
  5. /* For booooool */
  6. #include <stdbool.h>
  7. #include "sdkconfig.h"
  8. #include "ssd13x6_err.h"
  9. #define SSD_ALWAYS_INLINE __attribute__( ( always_inline ) )
  10. #define CAPS_COLUMN_RANGE 0x01
  11. #define CAPS_PAGE_RANGE 0x02
  12. #define CAPS_ADDRESS_VERTICAL 0x04
  13. #if ! defined BIT
  14. #define BIT( n ) ( 1 << n )
  15. #endif
  16. typedef uint8_t SSDCmd;
  17. typedef enum {
  18. AddressMode_Horizontal = 0,
  19. AddressMode_Vertical,
  20. AddressMode_Page,
  21. AddressMode_Invalid
  22. } SSD13x6_AddressMode;
  23. struct SSD13x6_Device;
  24. /*
  25. * These can optionally return a succeed/fail but are as of yet unused in the driver.
  26. */
  27. typedef bool ( *WriteCommandProc ) ( struct SSD13x6_Device* DeviceHandle, SSDCmd Command );
  28. typedef bool ( *WriteDataProc ) ( struct SSD13x6_Device* DeviceHandle, const uint8_t* Data, size_t DataLength );
  29. typedef bool ( *ResetProc ) ( struct SSD13x6_Device* DeviceHandle );
  30. struct spi_device_t;
  31. typedef struct spi_device_t* spi_device_handle_t;
  32. struct SSD13x6_FontDef;
  33. struct SSD13x6_Device {
  34. /* I2C Specific */
  35. int Address;
  36. /* SPI Specific */
  37. spi_device_handle_t SPIHandle;
  38. int RSTPin;
  39. int CSPin;
  40. /* Everything else */
  41. int Width;
  42. int Height;
  43. enum { SSD1306, SSD1326, SH1106 } Model;
  44. uint8_t ReMap;
  45. uint8_t* Framebuffer, *Shadowbuffer;
  46. int FramebufferSize;
  47. WriteCommandProc WriteCommand;
  48. WriteDataProc WriteData;
  49. ResetProc Reset;
  50. const struct SSD13x6_FontDef* Font;
  51. bool FontForceProportional;
  52. bool FontForceMonospace;
  53. };
  54. void SSD13x6_SetMuxRatio( struct SSD13x6_Device* DeviceHandle, uint8_t Ratio );
  55. void SSD13x6_SetDisplayOffset( struct SSD13x6_Device* DeviceHandle, uint8_t Offset );
  56. void SSD13x6_SetDisplayStartLines( struct SSD13x6_Device* DeviceHandle );
  57. void SSD13x6_SetSegmentRemap( struct SSD13x6_Device* DeviceHandle, bool Remap );
  58. void SSD13x6_SetContrast( struct SSD13x6_Device* DeviceHandle, uint8_t Contrast );
  59. void SSD13x6_EnableDisplayRAM( struct SSD13x6_Device* DeviceHandle );
  60. void SSD13x6_DisableDisplayRAM( struct SSD13x6_Device* DeviceHandle );
  61. void SSD13x6_SetInverted( struct SSD13x6_Device* DeviceHandle, bool Inverted );
  62. void SSD13x6_SetHFlip( struct SSD13x6_Device* DeviceHandle, bool On );
  63. void SSD13x6_SetVFlip( struct SSD13x6_Device* DeviceHandle, bool On );
  64. void SSD13x6_DisplayOn( struct SSD13x6_Device* DeviceHandle );
  65. void SSD13x6_DisplayOff( struct SSD13x6_Device* DeviceHandle );
  66. void SSD13x6_SetDisplayAddressMode( struct SSD13x6_Device* DeviceHandle, SSD13x6_AddressMode AddressMode );
  67. void SSD13x6_Update( struct SSD13x6_Device* DeviceHandle );
  68. void SSD13x6_SetDisplayClocks( struct SSD13x6_Device* DeviceHandle, uint32_t DisplayClockDivider, uint32_t OSCFrequency );
  69. void SSD13x6_SetColumnAddress( struct SSD13x6_Device* DeviceHandle, uint8_t Start, uint8_t End );
  70. void SSD13x6_SetPageAddress( struct SSD13x6_Device* DeviceHandle, uint8_t Start, uint8_t End );
  71. bool SSD13x6_HWReset( struct SSD13x6_Device* DeviceHandle );
  72. bool SSD13x6_Init_I2C( struct SSD13x6_Device* DeviceHandle, int Width, int Height, int I2CAddress, int ResetPin, WriteCommandProc WriteCommand, WriteDataProc WriteData, ResetProc Reset );
  73. bool SSD13x6_Init_SPI( struct SSD13x6_Device* DeviceHandle, int Width, int Height, int ResetPin, int CSPin, spi_device_handle_t SPIHandle, WriteCommandProc WriteCommand, WriteDataProc WriteData, ResetProc Reset );
  74. int SSD13x6_GetCaps( struct SSD13x6_Device* DeviceHandle );
  75. void SSD13x6_WriteRawData( struct SSD13x6_Device* DeviceHandle, uint8_t* Data, size_t DataLength );
  76. #endif