1 /*
2  * Copyright (c) 2018 Phytec Messtechnik GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 
8 #ifndef __SSD1306_REGS_H__
9 #define __SSD1306_REGS_H__
10 
11 /* All following bytes will contain commands */
12 #define SSD1306_CONTROL_ALL_BYTES_CMD		0x00
13 /* All following bytes will contain data */
14 #define SSD1306_CONTROL_ALL_BYTES_DATA		0x40
15 /* The next byte will contain a command */
16 #define SSD1306_CONTROL_BYTE_CMD		0x80
17 /* The next byte will contain data */
18 #define SSD1306_CONTROL_BYTE_DATA		0xc0
19 #define SSD1306_READ_STATUS_MASK		0xc0
20 #define SSD1306_READ_STATUS_BUSY		0x80
21 #define SSD1306_READ_STATUS_ON			0x40
22 
23 /*
24  * Fundamental Command Table
25  */
26 #define SSD1306_SET_CONTRAST_CTRL		0x81 /* double byte command */
27 
28 #define SSD1306_SET_ENTIRE_DISPLAY_OFF		0xa4
29 #define SSD1306_SET_ENTIRE_DISPLAY_ON		0xa5
30 
31 /* RAM data of 1 indicates an "ON" pixel */
32 #define SSD1306_SET_NORMAL_DISPLAY		0xa6
33 /* RAM data of 0 indicates an "ON" pixel */
34 #define SSD1306_SET_REVERSE_DISPLAY		0xa7
35 
36 #define SSD1306_DISPLAY_OFF			0xae
37 #define SSD1306_DISPLAY_ON			0xaf
38 
39 /*
40  * Addressing Setting Command Table
41  */
42 #define SSD1306_SET_LOWER_COL_ADDRESS		0x00
43 #define SSD1306_SET_LOWER_COL_ADDRESS_MASK	0x0f
44 
45 #define SSD1306_SET_HIGHER_COL_ADDRESS		0x10
46 #define SSD1306_SET_HIGHER_COL_ADDRESS_MASK	0x0f
47 
48 #define SSD1306_SET_MEM_ADDRESSING_MODE		0x20 /* double byte command */
49 #define SSD1306_SET_MEM_ADDRESSING_HORIZONTAL	0x00
50 #define SSD1306_SET_MEM_ADDRESSING_VERTICAL	0x01
51 #define SSD1306_SET_MEM_ADDRESSING_PAGE		0x02
52 
53 #define SSD1306_SET_COLUMN_ADDRESS		0x21 /* triple byte command */
54 
55 #define SSD1306_SET_PAGE_ADDRESS		0x22 /* triple byte command */
56 
57 #define SSD1306_SET_PAGE_START_ADDRESS		0xb0
58 #define SSD1306_SET_PAGE_START_ADDRESS_MASK	0x07
59 
60 
61 /*
62  * Hardware Configuration Command Table
63  */
64 #define SSD1306_SET_START_LINE			0x40
65 #define SSD1306_SET_START_LINE_MASK		0x3f
66 
67 #define SSD1306_SET_SEGMENT_MAP_NORMAL		0xa0
68 #define SSD1306_SET_SEGMENT_MAP_REMAPED		0xa1
69 
70 #define SSD1306_SET_MULTIPLEX_RATIO		0xa8 /* double byte command */
71 
72 #define SSD1306_SET_COM_OUTPUT_SCAN_NORMAL	0xc0
73 #define SSD1306_SET_COM_OUTPUT_SCAN_FLIPPED	0xc8
74 
75 #define SSD1306_SET_DISPLAY_OFFSET		0xd3 /* double byte command */
76 
77 #define SSD1306_SET_PADS_HW_CONFIG		0xda /* double byte command */
78 #define SSD1306_SET_PADS_HW_SEQUENTIAL		0x02
79 #define SSD1306_SET_PADS_HW_ALTERNATIVE         0x12
80 
81 #define SSD1306_SET_IREF_MODE			0xad
82 #define SSD1306_SET_IREF_MODE_INTERNAL		0x30
83 #define SSD1306_SET_IREF_MODE_EXTERNAL		0x00
84 
85 
86 /*
87  * Timing and Driving Scheme Setting Command Table
88  */
89 #define SSD1306_SET_CLOCK_DIV_RATIO		0xd5 /* double byte command */
90 
91 #define SSD1306_SET_CHARGE_PERIOD		0xd9 /* double byte command */
92 
93 #define SSD1306_SET_VCOM_DESELECT_LEVEL		0xdb /* double byte command */
94 
95 #define SSD1306_NOP				0xe3
96 
97 /*
98  * Charge Pump Command Table
99  */
100 #define SSD1306_SET_CHARGE_PUMP_ON		0x8d /* double byte command */
101 #define SSD1306_SET_CHARGE_PUMP_ON_DISABLED	0x10
102 #define SSD1306_SET_CHARGE_PUMP_ON_ENABLED	0x14
103 
104 #define SH1106_SET_DCDC_MODE			0xad /* double byte command */
105 #define SH1106_SET_DCDC_DISABLED		0x8a
106 #define SH1106_SET_DCDC_ENABLED			0x8b
107 
108 #define SSD1306_SET_PUMP_VOLTAGE_64		0x30
109 #define SSD1306_SET_PUMP_VOLTAGE_74		0x31
110 #define SSD1306_SET_PUMP_VOLTAGE_80		0x32
111 #define SSD1306_SET_PUMP_VOLTAGE_90		0x33
112 
113 /*
114  * Read modify write
115  */
116 #define SSD1306_READ_MODIFY_WRITE_START		0xe0
117 #define SSD1306_READ_MODIFY_WRITE_END		0xee
118 
119 /* time constants in ms */
120 #define SSD1306_RESET_DELAY			1
121 
122 #endif
123