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