oled.h (2427B)
1 /* 2 MNT Reform 2.0 Keyboard Firmware 3 See keyboard.c for Copyright 4 SPDX-License-Identifier: MIT 5 */ 6 7 #ifndef _OLED_H_ 8 #define _OLED_H_ 9 10 #include <stdbool.h> 11 #include <stdint.h> 12 13 enum ssd1306_cmds { 14 DisplayOff = 0xAE, 15 DisplayOn = 0xAF, 16 17 SetContrast = 0x81, 18 DisplayAllOnResume = 0xA4, 19 20 DisplayAllOn = 0xA5, 21 NormalDisplay = 0xA6, 22 InvertDisplay = 0xA7, 23 SetDisplayOffset = 0xD3, 24 SetComPins = 0xda, 25 SetVComDetect = 0xdb, 26 SetDisplayClockDiv = 0xD5, 27 SetPreCharge = 0xd9, 28 SetMultiPlex = 0xa8, 29 SetLowColumn = 0x00, 30 SetHighColumn = 0x10, 31 SetStartLine = 0x40, 32 33 SetMemoryMode = 0x20, 34 ColumnAddr = 0x21, 35 PageAddr = 0x22, 36 37 ComScanInc = 0xc0, 38 ComScanDec = 0xc8, 39 SegRemap = 0xa0, 40 SetChargePump = 0x8d, 41 ExternalVcc = 0x01, 42 SwitchCapVcc = 0x02, 43 44 ActivateScroll = 0x2f, 45 DeActivateScroll = 0x2e, 46 SetVerticalScrollArea = 0xa3, 47 RightHorizontalScroll = 0x26, 48 LeftHorizontalScroll = 0x27, 49 VerticalAndRightHorizontalScroll = 0x29, 50 VerticalAndLeftHorizontalScroll = 0x2a, 51 }; 52 53 #define SSD1306_ADDRESS 0x3C 54 55 #define DisplayHeight 32 56 #define DisplayWidth 128 57 58 #define FontHeight 8 59 #define FontWidth 6 60 61 #define MatrixRows (DisplayHeight / FontHeight) 62 #define MatrixCols (DisplayWidth / FontWidth) 63 64 struct CharacterMatrix { 65 uint8_t display[MatrixRows][MatrixCols]; 66 uint8_t invert[MatrixRows][MatrixCols]; 67 uint8_t *cursor; 68 bool dirty; 69 }; 70 71 void gfx_poke(uint8_t x, uint8_t y, uint8_t c); 72 void gfx_poke_str(uint8_t x, uint8_t y, char* str); 73 void gfx_clear_invert(void); 74 void gfx_invert_row(uint8_t y); 75 bool gfx_init(bool rotate); 76 void gfx_task(void); 77 bool gfx_off(void); 78 bool gfx_on(void); 79 void gfx_flush(void); 80 void gfx_clear(void); 81 void gfx_write_char(uint8_t c); 82 void gfx_write(const char *data); 83 void gfx_write_P(const char *data); 84 void gfx_clear_screen(void); 85 void gfx_contrast(int c); 86 87 void matrix_clear(struct CharacterMatrix *matrix); 88 void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c); 89 void matrix_write_char(struct CharacterMatrix *matrix, uint8_t c); 90 void matrix_write(struct CharacterMatrix *matrix, const char *data); 91 void matrix_write_ln(struct CharacterMatrix *matrix, const char *data); 92 void matrix_write_P(struct CharacterMatrix *matrix, const char *data); 93 void matrix_render(struct CharacterMatrix *matrix); 94 void matrix_render_direct(uint8_t* bitmap); 95 96 void oled_clear(void); 97 void oled_brightness_inc(void); 98 void oled_brightness_dec(void); 99 100 #endif