ssd1306.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. //#include "action.h"
  5. enum ssd1306_cmds {
  6. DisplayOff = 0xAE,
  7. DisplayOn = 0xAF,
  8. SetContrast = 0x81,
  9. DisplayAllOnResume = 0xA4,
  10. DisplayAllOn = 0xA5,
  11. NormalDisplay = 0xA6,
  12. InvertDisplay = 0xA7,
  13. SetDisplayOffset = 0xD3,
  14. SetComPins = 0xda,
  15. SetVComDetect = 0xdb,
  16. SetDisplayClockDiv = 0xD5,
  17. SetPreCharge = 0xd9,
  18. SetMultiPlex = 0xa8,
  19. SetLowColumn = 0x00,
  20. SetHighColumn = 0x10,
  21. SetStartLine = 0x40,
  22. SetMemoryMode = 0x20,
  23. ColumnAddr = 0x21,
  24. PageAddr = 0x22,
  25. ComScanInc = 0xc0,
  26. ComScanDec = 0xc8,
  27. SegRemap = 0xa0,
  28. SetChargePump = 0x8d,
  29. ExternalVcc = 0x01,
  30. SwitchCapVcc = 0x02,
  31. ActivateScroll = 0x2f,
  32. DeActivateScroll = 0x2e,
  33. SetVerticalScrollArea = 0xa3,
  34. RightHorizontalScroll = 0x26,
  35. LeftHorizontalScroll = 0x27,
  36. VerticalAndRightHorizontalScroll = 0x29,
  37. VerticalAndLeftHorizontalScroll = 0x2a,
  38. };
  39. // Controls the SSD1306 128x32 OLED display via i2c
  40. #ifndef SSD1306_ADDRESS
  41. #define SSD1306_ADDRESS 0x3C
  42. #endif
  43. #define DisplayHeight 32
  44. #define DisplayWidth 128
  45. #define FontHeight 8
  46. #define FontWidth 6
  47. #define MatrixRows (DisplayHeight / FontHeight)
  48. #define MatrixCols (DisplayWidth / FontWidth)
  49. struct CharacterMatrix {
  50. uint8_t display[MatrixRows][MatrixCols];
  51. uint8_t *cursor;
  52. bool dirty;
  53. };
  54. struct CharacterMatrix display;
  55. void gfx_poke(uint8_t x, uint8_t y, uint8_t c);
  56. void gfx_poke_str(uint8_t x, uint8_t y, char* str);
  57. bool iota_gfx_init(bool rotate);
  58. void iota_gfx_task(void);
  59. bool iota_gfx_off(void);
  60. bool iota_gfx_on(void);
  61. void iota_gfx_flush(void);
  62. void iota_gfx_write_char(uint8_t c);
  63. void iota_gfx_write(const char *data);
  64. void iota_gfx_write_P(const char *data);
  65. void iota_gfx_clear_screen(void);
  66. void iota_gfx_contrast(int c);
  67. void iota_gfx_task_user(void);
  68. void matrix_clear(struct CharacterMatrix *matrix);
  69. void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c);
  70. void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c);
  71. void matrix_write(struct CharacterMatrix *matrix, const char *data);
  72. void matrix_write_ln(struct CharacterMatrix *matrix, const char *data);
  73. void matrix_write_P(struct CharacterMatrix *matrix, const char *data);
  74. void matrix_render(struct CharacterMatrix *matrix);
  75. //bool process_record_gfx(uint16_t keycode, keyrecord_t *record);