You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.1 KiB

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