ssd1306.h 2.2 KB

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