summaryrefslogtreecommitdiff
path: root/drivers/qwiic/micro_oled.h
blob: 5d6a1029ed7a958d8786b771dca87ca1614d1d92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Jim Lindblom @ SparkFun Electronics
 * October 26, 2014
 * https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED
 *
 * Modified by:
 * Emil Varughese @ Edwin Robotics Pvt. Ltd.
 * July 27, 2015
 * https://github.com/emil01/SparkFun_Micro_OLED_Arduino_Library/
 *
 * This code was heavily based around the MicroView library, written by GeekAmmo
 * (https://github.com/geekammo/MicroView-Arduino-Library).
 *
 * Adapted for QMK by:
 * Jack Humbert <jack.humb@gmail.com>
 * October 11, 2018
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once

#include "qwiic.h"

void micro_oled_init(void);

void send_command(uint8_t command);
void send_data(uint8_t data);
void set_page_address(uint8_t address);
void set_column_address(uint8_t address);
void clear_screen(void);
void clear_buffer(void);
void send_buffer(void);
void draw_pixel(uint8_t x, uint8_t y, uint8_t color, uint8_t mode);
void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color, uint8_t mode);
void draw_line_hori(uint8_t x, uint8_t y, uint8_t width, uint8_t color, uint8_t mode);
void draw_line_vert(uint8_t x, uint8_t y, uint8_t height, bool color, uint8_t mode);
void draw_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
void draw_rect_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
void draw_rect_filled(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
void draw_rect_filled_soft(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t mode);
void draw_char(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode, uint8_t font);
void draw_string(uint8_t x, uint8_t y, char * string, uint8_t color, uint8_t mode, uint8_t font);

#define I2C_ADDRESS_SA0_0 0b0111100
#ifndef I2C_ADDRESS_SA0_1
#define I2C_ADDRESS_SA0_1 0b0111101
#endif
#define I2C_COMMAND 0x00
#define I2C_DATA 0x40
#define PIXEL_OFF 0
#define PIXEL_ON  1

#ifndef LCDWIDTH
#define LCDWIDTH      64
#endif
#ifndef LCDWIDTH
#define LCDHEIGHT     48
#endif
#define FONTHEADERSIZE    6

#define NORM        0
#define XOR         1

#define PAGE        0
#define ALL         1

#define WIDGETSTYLE0      0
#define WIDGETSTYLE1      1
#define WIDGETSTYLE2      2

#define SETCONTRAST     0x81
#define DISPLAYALLONRESUME  0xA4
#define DISPLAYALLON    0xA5
#define NORMALDISPLAY     0xA6
#define INVERTDISPLAY     0xA7
#define DISPLAYOFF      0xAE
#define DISPLAYON       0xAF
#define SETDISPLAYOFFSET  0xD3
#define SETCOMPINS      0xDA
#define SETVCOMDESELECT   0xDB
#define SETDISPLAYCLOCKDIV  0xD5
#define SETPRECHARGE    0xD9
#define SETMULTIPLEX    0xA8
#define SETLOWCOLUMN    0x00
#define SETHIGHCOLUMN     0x10
#define SETSTARTLINE    0x40
#define MEMORYMODE      0x20
#define COMSCANINC      0xC0
#define COMSCANDEC      0xC8
#define SEGREMAP      0xA0
#define CHARGEPUMP      0x8D
#define EXTERNALVCC     0x01
#define SWITCHCAPVCC    0x02

// Scroll
#define ACTIVATESCROLL          0x2F
#define DEACTIVATESCROLL        0x2E
#define SETVERTICALSCROLLAREA       0xA3
#define RIGHTHORIZONTALSCROLL       0x26
#define LEFT_HORIZONTALSCROLL       0x27
#define VERTICALRIGHTHORIZONTALSCROLL 0x29
#define VERTICALLEFTHORIZONTALSCROLL  0x2A

typedef enum CMD {
  CMD_CLEAR,      //0
  CMD_INVERT,     //1
  CMD_CONTRAST,   //2
  CMD_DISPLAY,    //3
  CMD_SETCURSOR,    //4
  CMD_PIXEL,      //5
  CMD_LINE,     //6
  CMD_LINEH,      //7
  CMD_LINEV,      //8
  CMD_RECT,     //9
  CMD_RECTFILL,   //10
  CMD_CIRCLE,     //11
  CMD_CIRCLEFILL,   //12
  CMD_DRAWCHAR,   //13
  CMD_DRAWBITMAP,   //14
  CMD_GETLCDWIDTH,  //15
  CMD_GETLCDHEIGHT, //16
  CMD_SETCOLOR,   //17
  CMD_SETDRAWMODE   //18
} commCommand_t;