Hexiwear OLED

Dependents:   Hexi

Fork of Hexi_OLED_SSD1351 by Hexiwear

Committer:
khuang
Date:
Thu Aug 18 23:01:06 2016 +0000
Revision:
1:3b5be0ee5f0c
Parent:
0:06f42dd3eab3
Child:
2:fc06b5b5bf6a
Hexiwear OLED Display Driver enabled.; Allow images and text to be displayed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
khuang 0:06f42dd3eab3 1 /**
khuang 0:06f42dd3eab3 2 * OLED screen SSD1351-related info
khuang 0:06f42dd3eab3 3 * Project HEXIWEAR, 2015
khuang 0:06f42dd3eab3 4 */
khuang 0:06f42dd3eab3 5
khuang 0:06f42dd3eab3 6 #ifndef HG_OLED_INFO
khuang 0:06f42dd3eab3 7 #define HG_OLED_INFO
khuang 0:06f42dd3eab3 8
khuang 0:06f42dd3eab3 9 // command byte number
khuang 0:06f42dd3eab3 10 #define FIRST_BYTE (1)
khuang 0:06f42dd3eab3 11 #define OTHER_BYTE (0)
khuang 0:06f42dd3eab3 12
khuang 0:06f42dd3eab3 13 #define OLED_COLUMN_OFFSET (16)
khuang 0:06f42dd3eab3 14 #define OLED_ROW_OFFSET (0)
khuang 0:06f42dd3eab3 15
khuang 0:06f42dd3eab3 16 #define OLED_SCREEN_WIDTH (96)
khuang 0:06f42dd3eab3 17 #define OLED_SCREEN_HEIGHT (96)
khuang 0:06f42dd3eab3 18
khuang 0:06f42dd3eab3 19 #define OLED_SCREEN_WIDTH_END ( (OLED_SCREEN_WIDTH-1) + OLED_COLUMN_OFFSET )
khuang 0:06f42dd3eab3 20 #define OLED_SCREEN_HEIGHT_END ( (OLED_SCREEN_HEIGHT-1) + OLED_ROW_OFFSET )
khuang 0:06f42dd3eab3 21
khuang 0:06f42dd3eab3 22 #define OLED_BYTES_PER_PIXEL ( 2 )
khuang 0:06f42dd3eab3 23
khuang 0:06f42dd3eab3 24 #define OLED_TRANSITION_STEP ( 1 )
khuang 0:06f42dd3eab3 25 #define OLED_ACTION_DCON ( 0xFE )
khuang 0:06f42dd3eab3 26 #define OLED_ACTION_DCOFF ( 0xFF )
khuang 0:06f42dd3eab3 27
khuang 0:06f42dd3eab3 28 #define OLED_CHAR_WIDTH_AUTO ( 0xFF )
khuang 0:06f42dd3eab3 29 #define OLED_CHAR_WIDTH_MAX ( 0xFE )
khuang 0:06f42dd3eab3 30 #define OLED_CHAR_WIDTH_NUM ( 0xFD )
khuang 0:06f42dd3eab3 31 #define OLED_CHAR_WIDTH_KEEP ( 0xFC )
khuang 0:06f42dd3eab3 32 #define OLED_CHAR_HEIGHT_AUTO ( 0xFB )
khuang 0:06f42dd3eab3 33 #define OLED_CHAR_HEIGHT_KEEP ( 0xFA )
khuang 0:06f42dd3eab3 34
khuang 0:06f42dd3eab3 35 #define OLED_SCREEN_SIZE ( OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT )
khuang 0:06f42dd3eab3 36 #define OLED_GRAM_SIZE ( OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT * OLED_BYTES_PER_PIXEL )
khuang 0:06f42dd3eab3 37
khuang 0:06f42dd3eab3 38 #define OLED_TEXT_HALIGN_SHIFT ( 0 )
khuang 0:06f42dd3eab3 39 #define OLED_TEXT_HALIGN_MASK ( 0x03 << OLED_TEXT_HALIGN_SHIFT )
khuang 0:06f42dd3eab3 40
khuang 0:06f42dd3eab3 41 #define OLED_TEXT_VALIGN_SHIFT ( 4 )
khuang 0:06f42dd3eab3 42 #define OLED_TEXT_VALIGN_MASK ( 0x03 << OLED_TEXT_VALIGN_SHIFT )
khuang 0:06f42dd3eab3 43
khuang 0:06f42dd3eab3 44 #define BMP_HEADER_BYTE_SIZE (6)
khuang 0:06f42dd3eab3 45
khuang 0:06f42dd3eab3 46
khuang 0:06f42dd3eab3 47
khuang 0:06f42dd3eab3 48 /**
khuang 0:06f42dd3eab3 49 * remap settings
khuang 0:06f42dd3eab3 50 */
khuang 0:06f42dd3eab3 51
khuang 0:06f42dd3eab3 52 #define REMAP_HORIZONTAL_INCREMENT ( 0 )
khuang 0:06f42dd3eab3 53 #define REMAP_VERTICAL_INCREMENT ( 1 << 0 )
khuang 0:06f42dd3eab3 54
khuang 0:06f42dd3eab3 55 #define REMAP_COLUMNS_LEFT_TO_RIGHT ( 0 )
khuang 0:06f42dd3eab3 56 #define REMAP_COLUMNS_RIGHT_TO_LEFT ( 1 << 1 )
khuang 0:06f42dd3eab3 57
khuang 0:06f42dd3eab3 58 #define REMAP_ORDER_ABC ( 0 )
khuang 0:06f42dd3eab3 59 #define REMAP_ORDER_CBA ( 1 << 2 )
khuang 0:06f42dd3eab3 60
khuang 0:06f42dd3eab3 61 #define REMAP_SCAN_UP_TO_DOWN ( 0 )
khuang 0:06f42dd3eab3 62 #define REMAP_SCAN_DOWN_TO_UP ( 1 << 4 )
khuang 0:06f42dd3eab3 63
khuang 0:06f42dd3eab3 64 #define REMAP_COM_SPLIT_ODD_EVEN_DIS ( 0 )
khuang 0:06f42dd3eab3 65 #define REMAP_COM_SPLIT_ODD_EVEN_EN ( 1 << 5 )
khuang 0:06f42dd3eab3 66
khuang 0:06f42dd3eab3 67 #define REMAP_COLOR_RGB565 ( 1 << 6 )
khuang 0:06f42dd3eab3 68
khuang 0:06f42dd3eab3 69 #define OLED_REMAP_SETTINGS ( REMAP_ORDER_ABC | REMAP_COM_SPLIT_ODD_EVEN_EN | REMAP_COLOR_RGB565 | REMAP_COLUMNS_LEFT_TO_RIGHT | REMAP_SCAN_UP_TO_DOWN | REMAP_HORIZONTAL_INCREMENT )
khuang 0:06f42dd3eab3 70
khuang 0:06f42dd3eab3 71 /**
khuang 0:06f42dd3eab3 72 * macros
khuang 0:06f42dd3eab3 73 */
khuang 0:06f42dd3eab3 74
khuang 0:06f42dd3eab3 75 #define OLED_SwapMe(x) x = ( ( x & 0xFF00 ) >> 8 ) | ( ( x & 0x00FF ) << 8 )
khuang 0:06f42dd3eab3 76 #define OLED_AdjustRowOffset(y) y += OLED_ROW_OFFSET
khuang 0:06f42dd3eab3 77 #define OLED_AdjustColumnOffset(x) x += OLED_COLUMN_OFFSET
khuang 0:06f42dd3eab3 78
khuang 0:06f42dd3eab3 79 #define BMP_SkipHeader( imgPtr ) ( (const uint8_t*)(imgPtr) + BMP_HEADER_BYTE_SIZE )
khuang 0:06f42dd3eab3 80
khuang 0:06f42dd3eab3 81
khuang 0:06f42dd3eab3 82 #define CheckLimits( x, y, w, h ) ( ( ( x + w - 1 ) > OLED_SCREEN_WIDTH ) || ( x < 0 ) || ( ( y + h - 1 ) > OLED_SCREEN_HEIGHT ) || ( y < 0 ) )
khuang 0:06f42dd3eab3 83 #define AreCoordsValid( x, y, w, h ) ( 0 == CheckLimits( x, y, w ,h ) )
khuang 0:06f42dd3eab3 84 #define AreCoordsNotValid( x, y, w, h ) ( 0 != CheckLimits( x, y, w, h ) )
khuang 0:06f42dd3eab3 85
khuang 0:06f42dd3eab3 86
khuang 0:06f42dd3eab3 87 /**
khuang 0:06f42dd3eab3 88 * set start/end column/row
khuang 0:06f42dd3eab3 89 * the 2nd and 3rd byte represent the start and the end address, respectively
khuang 0:06f42dd3eab3 90 */
khuang 0:06f42dd3eab3 91 #define OLED_CMD_SET_COLUMN ( 0x15 )
khuang 0:06f42dd3eab3 92 #define OLED_CMD_SET_ROW ( 0x75 )
khuang 0:06f42dd3eab3 93
khuang 0:06f42dd3eab3 94 /**
khuang 0:06f42dd3eab3 95 * scanning direction
khuang 0:06f42dd3eab3 96 */
khuang 0:06f42dd3eab3 97
khuang 0:06f42dd3eab3 98 #define OLED_DIRECTION_HORIZONTAL (0)
khuang 0:06f42dd3eab3 99 #define OLED_DIRECTION_VERTICAL (1)
khuang 0:06f42dd3eab3 100
khuang 0:06f42dd3eab3 101 /**
khuang 0:06f42dd3eab3 102 * SPI-related
khuang 0:06f42dd3eab3 103 */
khuang 0:06f42dd3eab3 104
khuang 0:06f42dd3eab3 105 #define OLED_SPI_CHUNK (511)
khuang 0:06f42dd3eab3 106
khuang 0:06f42dd3eab3 107 /**
khuang 0:06f42dd3eab3 108 * set display
khuang 0:06f42dd3eab3 109 */
khuang 0:06f42dd3eab3 110 #define OLED_CMD_SET_DISPLAY_MODE_ALL_OFF (0xA4)
khuang 0:06f42dd3eab3 111 #define OLED_CMD_SET_DISPLAY_MODE_ALL_ON (0xA5)
khuang 0:06f42dd3eab3 112 #define OLED_CMD_SET_DISPLAY_MODE_NORMAL (0xA6)
khuang 0:06f42dd3eab3 113 #define OLED_CMD_SET_DISPLAY_MODE_INVERSE (0xA7)
khuang 0:06f42dd3eab3 114
khuang 0:06f42dd3eab3 115 /**
khuang 0:06f42dd3eab3 116 * set lock command
khuang 0:06f42dd3eab3 117 * the locked OLED driver MCU interface prohibits all commands
khuang 0:06f42dd3eab3 118 * and memory access, except the 0xFD command
khuang 0:06f42dd3eab3 119 */
khuang 0:06f42dd3eab3 120 #define OLED_CMD_SET_CMD_LOCK ( 0xFD /* << 8 */ )
khuang 0:06f42dd3eab3 121 // unlock OLED driver MCU interface for entering command (default upon reset)
khuang 0:06f42dd3eab3 122 #define OLED_UNLOCK (0x12)
khuang 0:06f42dd3eab3 123 // lock OLED driver MCU interface for entering command
khuang 0:06f42dd3eab3 124 #define OLED_LOCK (0x16)
khuang 0:06f42dd3eab3 125 // commands 0xA2, 0xB1, 0xB3, 0xBB, 0xBE, 0xC1 are inaccessible in both lock and unlock state (default upon reset)
khuang 0:06f42dd3eab3 126 #define OLED_ACC_TO_CMD_NO (0xB0)
khuang 0:06f42dd3eab3 127 // commands 0xA2, 0xB1, 0xB3, 0xBB, 0xBE, 0xC1 are accessible in unlock state
khuang 0:06f42dd3eab3 128 #define OLED_ACC_TO_CMD_YES (0xB1)
khuang 0:06f42dd3eab3 129
khuang 0:06f42dd3eab3 130 /**
khuang 0:06f42dd3eab3 131 * NOP
khuang 0:06f42dd3eab3 132 */
khuang 0:06f42dd3eab3 133 #define OLED_CMD_NOP (0xD1) // also, 0xE3
khuang 0:06f42dd3eab3 134
khuang 0:06f42dd3eab3 135 /**
khuang 0:06f42dd3eab3 136 * set MUX ratio
khuang 0:06f42dd3eab3 137 */
khuang 0:06f42dd3eab3 138 #define OLED_CMD_SET_MUX_RATIO (0xCA)
khuang 0:06f42dd3eab3 139
khuang 0:06f42dd3eab3 140 /**
khuang 0:06f42dd3eab3 141 * set re-map / color depth
khuang 0:06f42dd3eab3 142 */
khuang 0:06f42dd3eab3 143 #define OLED_CMD_SET_REMAP ( 0xA0 )
khuang 0:06f42dd3eab3 144
khuang 0:06f42dd3eab3 145 // set horisontal or vertical increment
khuang 0:06f42dd3eab3 146 #define OLED_ADDR_INC_HOR (0x00)
khuang 0:06f42dd3eab3 147 #define OLED_ADDR_INC_VER (0x01)
khuang 0:06f42dd3eab3 148
khuang 0:06f42dd3eab3 149 // column address mapping
khuang 0:06f42dd3eab3 150 #define OLED_COLUMN_ADDR_REMAP_0_TO_SEG0 (0x00)
khuang 0:06f42dd3eab3 151 #define OLED_COLUMN_ADDR_REMAP_127_TO_SEG0 (0x02)
khuang 0:06f42dd3eab3 152
khuang 0:06f42dd3eab3 153 // color sequence order
khuang 0:06f42dd3eab3 154 #define OLED_COLOR_SEQ_A_B_C (0x00)
khuang 0:06f42dd3eab3 155 #define OLED_COLOR_SEQ_C_B_A (0x04)
khuang 0:06f42dd3eab3 156
khuang 0:06f42dd3eab3 157 // scanning order (MR == MUX ratio)
khuang 0:06f42dd3eab3 158 #define OLED_SCAN_FROM_COM_0_TO_MR (0x00)
khuang 0:06f42dd3eab3 159 #define OLED_SCAN_FROM_COM_MR_TO_0 (0x10)
khuang 0:06f42dd3eab3 160
khuang 0:06f42dd3eab3 161 // COM splitting to odd and even
khuang 0:06f42dd3eab3 162 #define OLED_COM_SPLIT_DISABLE (0x00)
khuang 0:06f42dd3eab3 163 #define OLED_COM_SPLIT_ENABLE (0x20)
khuang 0:06f42dd3eab3 164
khuang 0:06f42dd3eab3 165 // screen color depth
khuang 0:06f42dd3eab3 166 #define OLED_COLOR_DEPTH_256 (0x00)
khuang 0:06f42dd3eab3 167 #define OLED_COLOR_DEPTH_65K (0x40)
khuang 0:06f42dd3eab3 168 #define OLED_COLOR_DEPTH_262K_1 (0x80)
khuang 0:06f42dd3eab3 169 #define OLED_COLOR_DEPTH_262K_2 (0xC0)
khuang 0:06f42dd3eab3 170
khuang 0:06f42dd3eab3 171 /**
khuang 0:06f42dd3eab3 172 * set reset (phase 1) / pre-charge (phase 2) period in [DCLK]
khuang 0:06f42dd3eab3 173 * this command is locked by command 0xFD by default
khuang 0:06f42dd3eab3 174 */
khuang 0:06f42dd3eab3 175 #define OLED_CMD_SET_RESET_AND_PRECHARGE_PERIOD (0xB1)
khuang 0:06f42dd3eab3 176
khuang 0:06f42dd3eab3 177 #define OLED_RESET_PERIOD_5 (0x02)
khuang 0:06f42dd3eab3 178 #define OLED_RESET_PERIOD_7 (0x03)
khuang 0:06f42dd3eab3 179 #define OLED_RESET_PERIOD_9 (0x04)
khuang 0:06f42dd3eab3 180 #define OLED_RESET_PERIOD_11 (0x05)
khuang 0:06f42dd3eab3 181 #define OLED_RESET_PERIOD_13 (0x06)
khuang 0:06f42dd3eab3 182 #define OLED_RESET_PERIOD_15 (0x07)
khuang 0:06f42dd3eab3 183 #define OLED_RESET_PERIOD_17 (0x08)
khuang 0:06f42dd3eab3 184 #define OLED_RESET_PERIOD_19 (0x09)
khuang 0:06f42dd3eab3 185 #define OLED_RESET_PERIOD_21 (0x0A)
khuang 0:06f42dd3eab3 186 #define OLED_RESET_PERIOD_23 (0x0B)
khuang 0:06f42dd3eab3 187 #define OLED_RESET_PERIOD_25 (0x0C)
khuang 0:06f42dd3eab3 188 #define OLED_RESET_PERIOD_27 (0x0D)
khuang 0:06f42dd3eab3 189 #define OLED_RESET_PERIOD_29 (0x0E)
khuang 0:06f42dd3eab3 190 #define OLED_RESET_PERIOD_31 (0x0F)
khuang 0:06f42dd3eab3 191
khuang 0:06f42dd3eab3 192 #define OLED_PRECHARGE_PERIOD_3 (0x03)
khuang 0:06f42dd3eab3 193 #define OLED_PRECHARGE_PERIOD_4 (0x04)
khuang 0:06f42dd3eab3 194 #define OLED_PRECHARGE_PERIOD_5 (0x05)
khuang 0:06f42dd3eab3 195 #define OLED_PRECHARGE_PERIOD_6 (0x06)
khuang 0:06f42dd3eab3 196 #define OLED_PRECHARGE_PERIOD_7 (0x07)
khuang 0:06f42dd3eab3 197 #define OLED_PRECHARGE_PERIOD_8 (0x08)
khuang 0:06f42dd3eab3 198 #define OLED_PRECHARGE_PERIOD_9 (0x09)
khuang 0:06f42dd3eab3 199 #define OLED_PRECHARGE_PERIOD_10 (0x0A)
khuang 0:06f42dd3eab3 200 #define OLED_PRECHARGE_PERIOD_11 (0x0B)
khuang 0:06f42dd3eab3 201 #define OLED_PRECHARGE_PERIOD_12 (0x0C)
khuang 0:06f42dd3eab3 202 #define OLED_PRECHARGE_PERIOD_13 (0x0D)
khuang 0:06f42dd3eab3 203 #define OLED_PRECHARGE_PERIOD_14 (0x0E)
khuang 0:06f42dd3eab3 204 #define OLED_PRECHARGE_PERIOD_15 (0x0F)
khuang 0:06f42dd3eab3 205
khuang 0:06f42dd3eab3 206 /**
khuang 0:06f42dd3eab3 207 * set front clock divider (divset) / oscillator frequency
khuang 0:06f42dd3eab3 208 * this command is locked by command 0xFD by default
khuang 0:06f42dd3eab3 209 */
khuang 0:06f42dd3eab3 210 #define OLED_CMD_SET_OSC_FREQ_AND_CLOCKDIV (0xB3)
khuang 0:06f42dd3eab3 211
khuang 0:06f42dd3eab3 212 // clock divider
khuang 0:06f42dd3eab3 213 #define OLED_CLOCKDIV_1 (0x00)
khuang 0:06f42dd3eab3 214 #define OLED_CLOCKDIV_2 (0x01)
khuang 0:06f42dd3eab3 215 #define OLED_CLOCKDIV_4 (0x02)
khuang 0:06f42dd3eab3 216 #define OLED_CLOCKDIV_8 (0x03)
khuang 0:06f42dd3eab3 217 #define OLED_CLOCKDIV_16 (0x04)
khuang 0:06f42dd3eab3 218 #define OLED_CLOCKDIV_32 (0x05)
khuang 0:06f42dd3eab3 219 #define OLED_CLOCKDIV_64 (0x06)
khuang 0:06f42dd3eab3 220 #define OLED_CLOCKDIV_128 (0x07)
khuang 0:06f42dd3eab3 221 #define OLED_CLOCKDIV_256 (0x08)
khuang 0:06f42dd3eab3 222 #define OLED_CLOCKDIV_512 (0x09)
khuang 0:06f42dd3eab3 223 #define OLED_CLOCKDIV_1024 (0x0A)
khuang 0:06f42dd3eab3 224
khuang 0:06f42dd3eab3 225 // oscillator frequency, frequency increases as level increases
khuang 0:06f42dd3eab3 226 #define OLED_OSC_FREQ (0xB0)
khuang 0:06f42dd3eab3 227
khuang 0:06f42dd3eab3 228 #define OLED_CMD_STARTLINE (0xA1)
khuang 0:06f42dd3eab3 229
khuang 0:06f42dd3eab3 230 #define OLED_CMD_WRITERAM (0x5C)
khuang 0:06f42dd3eab3 231 #define OLED_CMD_READRAM (0x5D)
khuang 0:06f42dd3eab3 232 #define OLED_CMD_DISPLAYOFFSET (0xA2)
khuang 0:06f42dd3eab3 233 #define OLED_CMD_DISPLAYALLOFF (0xA4)
khuang 0:06f42dd3eab3 234 #define OLED_CMD_DISPLAYALLON (0xA5)
khuang 0:06f42dd3eab3 235 #define OLED_CMD_NORMALDISPLAY (0xA6)
khuang 0:06f42dd3eab3 236 #define OLED_CMD_INVERTDISPLAY (0xA7)
khuang 0:06f42dd3eab3 237 #define OLED_CMD_FUNCTIONSELECT (0xAB)
khuang 0:06f42dd3eab3 238 #define OLED_CMD_DISPLAYOFF (0xAE)
khuang 0:06f42dd3eab3 239 #define OLED_CMD_DISPLAYON (0xAF)
khuang 0:06f42dd3eab3 240 #define OLED_CMD_PRECHARGE (0xB1)
khuang 0:06f42dd3eab3 241 #define OLED_CMD_DISPLAYENHANCE (0xB2)
khuang 0:06f42dd3eab3 242 #define OLED_CMD_SETVSL (0xB4)
khuang 0:06f42dd3eab3 243 #define OLED_CMD_SETGPIO (0xB5)
khuang 0:06f42dd3eab3 244 #define OLED_CMD_PRECHARGE2 (0xB6)
khuang 0:06f42dd3eab3 245 #define OLED_CMD_SETGRAY (0xB8)
khuang 0:06f42dd3eab3 246 #define OLED_CMD_USELUT (0xB9)
khuang 0:06f42dd3eab3 247 #define OLED_CMD_PRECHARGELEVEL (0xBB)
khuang 0:06f42dd3eab3 248 #define OLED_CMD_VCOMH (0xBE)
khuang 0:06f42dd3eab3 249 #define OLED_CMD_CONTRASTABC (0xC1)
khuang 0:06f42dd3eab3 250 #define OLED_CMD_CONTRASTMASTER (0xC7)
khuang 0:06f42dd3eab3 251 #define OLED_CMD_MUXRATIO (0xCA)
khuang 0:06f42dd3eab3 252 #define OLED_CMD_COMMANDLOCK (0xFD)
khuang 0:06f42dd3eab3 253 #define OLED_CMD_HORIZSCROLL (0x96)
khuang 0:06f42dd3eab3 254 #define OLED_CMD_STOPSCROLL (0x9E)
khuang 0:06f42dd3eab3 255 #define OLED_CMD_STARTSCROLL (0x9F)
khuang 0:06f42dd3eab3 256
khuang 0:06f42dd3eab3 257 #endif
khuang 1:3b5be0ee5f0c 258