]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A2F200_SoftConsole/MicroSemi_Code/drivers/OLED/oled.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_A2F200_SoftConsole / MicroSemi_Code / drivers / OLED / oled.c
1 /*****************************************************************************\r
2  * (c) Copyright 2009 Actel Corporation.  All rights reserved.\r
3  *\r
4  * Author : Actel Application Team\r
5  * Rev    : 1.0.0.0\r
6  * Description: Device driver for the on-board OLED for SmartFusion KITS\r
7  *  Implementation of sample basic driver for OLED display found on Actel\r
8  *  SmartFusion development boards.\r
9  *  This code is intended as an example of using the SmartFusion I2C driver.\r
10  *****************************************************************************/\r
11 \r
12   #include "oled.h"\r
13 #include "../bsp_config.h"\r
14 \r
15 /***************************************************************************//**\r
16   Command definitions for the SSD300 controller inside the OLED display module.\r
17  */\r
18 #define CMD_DISPLAY_OFF_SET   0xD3\r
19 #define CMD_PANEL_ON          0xAF\r
20 #define CMD_PANEL_OFF         0xAE\r
21 #define CMD_DC_DC             0xAD\r
22 #define CMD_DC_DC_DEFAULT_ON  0x8B\r
23 #define CMD_DC_DC_OFF         0x8A\r
24 #define CMD_DISPLAY_ALL_ON    0xA5\r
25 #define CMD_DISPLAY_ALL_OFF   0xA4\r
26 #define CMD_DISPLAY_NON_INV   0xA6\r
27 #define CMD_DISPLAY_INV       0xA7\r
28 #define CMD_ARECOL_LPM        0xD8\r
29 #define CMD_ARECOL_MONO       0x00\r
30 #define CMD_ARECOL_COLOR      0x30\r
31 #define CMD_LPM_ON            0x05\r
32 #define CMD_LPM_OFF           0x00\r
33 #define CMD_CONTRAST          0x81\r
34 #define CMD_MIRROR_HORI_ON    0xC8\r
35 #define CMD_MIRROR_HORI_OFF   0xC0\r
36 #define CMD_MIRROR_VERT_ON    0xA1\r
37 #define CMD_MIRROR_VERT_OFF   0xA0\r
38 #define CMD_HORI_SCRL         0x26\r
39 #define CMD_HORI_SCRL_ON      0x2F\r
40 #define CMD_HORI_SCRL_OFF     0x2E\r
41 #define CMD_MUX_RATIO          0xA8\r
42 #define CMD_MUX_RATIO_31      0x23\r
43 \r
44 #define CMD_PAGE_0            0xB0\r
45 #define CMD_PAGE_1            0xB1\r
46 #define CMD_PAGE_2            0xB2\r
47 #define CMD_PAGE_3            0xB3\r
48 #define CMD_PAGE_4            0xB4\r
49 #define CMD_PAGE_5            0xB5\r
50 \r
51 #define CMD_LOW_NIB_COL       0x00\r
52 #define CMD_HIGH_NIB_COL      0x10\r
53 \r
54 #define CMD_START_LINE        0x50\r
55 #define CONTRAST_DEFAULT      0xFF\r
56 #define CONTRAST_25_PERC      0x40\r
57 #define CONTRAST_100_PERC     0xFF\r
58 #define CONTRAST_0_PERC       0x00\r
59 #define SCROLL_1_COLUMN       0x01\r
60 #define SCROLL_2_COLUMN       0x02\r
61 #define SCROLL_3_COLUMN       0x03\r
62 #define SCROLL_4_COLUMN       0x04\r
63 #define SCROLL_PAGE_0         0x00\r
64 #define SCROLL_PAGE_1         0x01\r
65 #define SCROLL_PAGE_2         0x02\r
66 #define SCROLL_PAGE_3         0x03\r
67 #define SCROLL_PAGE_4         0x04\r
68 #define SCROLL_PAGE_5         0x05\r
69 #define SCROLL_12_FRAMES      0x00\r
70 #define SCROLL_64_FRAMES      0x01\r
71 #define SCROLL_128_FRAMES     0x02\r
72 #define SCROLL_256_FRAMES     0x03\r
73 #define SCROLL_PER_STEP       0x01\r
74 #define PAGE0_COLOR_BAG       0x92\r
75 #define PAGE1_COLOR_BAG       0x93\r
76 \r
77 /***************************************************************************//**\r
78   OLED display I2C communication protocol control byte values. Used to indicate\r
79   whether the byte following the control byte is to be interpreted by the OLED\r
80   display as a command or data byte.\r
81  */\r
82 #define  OLED_COMMAND_CODE  0x80\r
83 #define  OLED_DATA_CODE     0xC0\r
84 \r
85 /***************************************************************************//**\r
86   I2C serial address of OLED display.\r
87  */\r
88 #define OLED_SLAVE_ADDRESS    0x78\r
89 \r
90 /***************************************************************************//**\r
91   Bitmaps of the character set.\r
92   Each character is 5 pixels wide and 7 pixels high.\r
93   The table is indexed on ASCII character codes.\r
94  */\r
95 #define CHARACTER_WIDTH   5\r
96 \r
97 const unsigned char oled_ascii_character_set[255][CHARACTER_WIDTH] =\r
98 {\r
99     {0x00, 0x00, 0x00, 0x00, 0x00},\r
100     {0x00, 0x00, 0x00, 0x00, 0x00},\r
101     {0x00, 0x00, 0x00, 0x00, 0x00},\r
102     {0x00, 0x00, 0x00, 0x00, 0x00},\r
103     {0x00, 0x00, 0x00, 0x00, 0x00},\r
104     {0x00, 0x00, 0x00, 0x00, 0x00},\r
105     {0x00, 0x00, 0x00, 0x00, 0x00},\r
106     {0x00, 0x00, 0x00, 0x00, 0x00},\r
107     {0x00, 0x00, 0x00, 0x00, 0x00},\r
108     {0x00, 0x00, 0x00, 0x00, 0x00},\r
109     {0x00, 0x00, 0x00, 0x00, 0x00},\r
110     {0x00, 0x00, 0x00, 0x00, 0x00},\r
111     {0x00, 0x00, 0x00, 0x00, 0x00},\r
112     {0x00, 0x00, 0x00, 0x00, 0x00},\r
113     {0x00, 0x00, 0x00, 0x00, 0x00},\r
114     {0x00, 0x00, 0x00, 0x00, 0x00},\r
115     {0x00, 0x00, 0x00, 0x00, 0x00},\r
116     {0x00, 0x00, 0x00, 0x00, 0x00},\r
117     {0x00, 0x00, 0x00, 0x00, 0x00},\r
118     {0x00, 0x00, 0x00, 0x00, 0x00},\r
119     {0x00, 0x00, 0x00, 0x00, 0x00},\r
120     {0x00, 0x00, 0x00, 0x00, 0x00},\r
121     {0x00, 0x00, 0x00, 0x00, 0x00},\r
122     {0x00, 0x00, 0x00, 0x00, 0x00},\r
123     {0x00, 0x00, 0x00, 0x00, 0x00},\r
124     {0x00, 0x00, 0x00, 0x00, 0x00},\r
125     {0x00, 0x00, 0x00, 0x00, 0x00},\r
126     {0x00, 0x00, 0x00, 0x00, 0x00},\r
127     {0x00, 0x00, 0x00, 0x00, 0x00},\r
128     {0x00, 0x00, 0x00, 0x00, 0x00},\r
129     {0x00, 0x00, 0x00, 0x00, 0x00},\r
130     {0x00, 0x00, 0x00, 0x00, 0x00},\r
131     {0x00, 0x00, 0x00, 0x00, 0x00},\r
132 \r
133     {0x00, 0x00, 0x5F, 0x00, 0x00},\r
134     {0x00, 0x07, 0x00, 0x07, 0x00},\r
135     {0x14, 0x7F, 0x14, 0x7F, 0x14},\r
136     {0x24, 0x2A, 0x7F, 0x2A, 0x12},\r
137     {0x23, 0x13, 0x08, 0x64, 0x62},\r
138     {0x36, 0x49, 0x55, 0x22, 0x50},\r
139     {0x00, 0x05, 0x03, 0x00, 0x00},\r
140     {0x00, 0x1C, 0x22, 0x41, 0x00},\r
141     {0x00, 0x41, 0x22, 0x1C, 0x00},\r
142     {0x14, 0x08, 0x3E, 0x08, 0x14},\r
143     {0x08, 0x08, 0x3E, 0x08, 0x08},\r
144     {0x00, 0x50, 0x30, 0x00, 0x00},\r
145     {0x08, 0x08, 0x08, 0x08, 0x08},\r
146     {0x00, 0x60, 0x60, 0x00, 0x00},\r
147     {0x20, 0x10, 0x08, 0x04, 0x02},\r
148     {0x3E, 0x51, 0x49, 0x45, 0x3E},\r
149     {0x00, 0x42, 0x7F, 0x40, 0x00},\r
150     {0x42, 0x61, 0x51, 0x49, 0x46},\r
151     {0x21, 0x41, 0x45, 0x4B, 0x31},\r
152     {0x18, 0x14, 0x12, 0x7F, 0x10},\r
153     {0x27, 0x45, 0x45, 0x45, 0x39},\r
154     {0x3C, 0x4A, 0x49, 0x49, 0x30},\r
155     {0x01, 0x71, 0x09, 0x05, 0x03},\r
156     {0x36, 0x49, 0x49, 0x49, 0x36},\r
157     {0x06, 0x49, 0x49, 0x29, 0x1E},\r
158     {0x00, 0x36, 0x36, 0x00, 0x00},\r
159     {0x00, 0x56, 0x36, 0x00, 0x00},\r
160     {0x08, 0x14, 0x22, 0x41, 0x00},\r
161     {0x14, 0x14, 0x14, 0x14, 0x14},\r
162     {0x00, 0x41, 0x22, 0x14, 0x08},\r
163     {0x02, 0x01, 0x51, 0x09, 0x06},\r
164     {0x32, 0x49, 0x79, 0x41, 0x3E},\r
165     {0x7E, 0x11, 0x11, 0x11, 0x7E},\r
166     {0x7F, 0x49, 0x49, 0x49, 0x36},\r
167     {0x3E, 0x41, 0x41, 0x41, 0x22},\r
168     {0x7F, 0x41, 0x41, 0x22, 0x1C},\r
169     {0x7F, 0x49, 0x49, 0x49, 0x41},\r
170     {0x7F, 0x09, 0x09, 0x09, 0x01},\r
171     {0x3E, 0x41, 0x49, 0x49, 0x7A},\r
172     {0x7F, 0x08, 0x08, 0x08, 0x7F},\r
173     {0x00, 0x41, 0x7F, 0x41, 0x00},\r
174     {0x20, 0x40, 0x41, 0x3F, 0x01},\r
175     {0x7F, 0x08, 0x14, 0x22, 0x41},\r
176     {0x3F, 0x40, 0x40, 0x40, 0x40},\r
177     {0x7F, 0x02, 0x0C, 0x02, 0x7F},\r
178     {0x7F, 0x04, 0x08, 0x10, 0x7F},\r
179     {0x3E, 0x41, 0x41, 0x41, 0x3E},\r
180     {0x7F, 0x09, 0x09, 0x09, 0x06},\r
181     {0x3E, 0x41, 0x51, 0x21, 0x5E},\r
182     {0x7F, 0x09, 0x19, 0x29, 0x46},\r
183     {0x46, 0x49, 0x49, 0x49, 0x31},\r
184     {0x01, 0x01, 0x7F, 0x01, 0x01},\r
185     {0x3F, 0x40, 0x40, 0x40, 0x3F},\r
186     {0x1F, 0x20, 0x40, 0x20, 0x1F},\r
187     {0x3F, 0x40, 0x38, 0x40, 0x3F},\r
188     {0x63, 0x14, 0x08, 0x14, 0x63},\r
189     {0x07, 0x08, 0x70, 0x08, 0x07},\r
190     {0x61, 0x51, 0x49, 0x45, 0x43},\r
191     {0x00, 0x7F, 0x41, 0x41, 0x00},\r
192     {0x02, 0x04, 0x08, 0x10, 0x20},\r
193     {0x00, 0x41, 0x41, 0x7F, 0x00},\r
194     {0x04, 0x02, 0x01, 0x02, 0x04},\r
195     {0x40, 0x40, 0x40, 0x40, 0x40},\r
196     {0x00, 0x01, 0x02, 0x04, 0x00},\r
197     {0x20, 0x54, 0x54, 0x54, 0x78},\r
198     {0x7F, 0x48, 0x44, 0x44, 0x38},\r
199     {0x38, 0x44, 0x44, 0x44, 0x20},\r
200     {0x30, 0x48, 0x48, 0x50, 0x7F},\r
201     {0x38, 0x54, 0x54, 0x54, 0x18},\r
202     {0x10, 0x7E, 0x11, 0x01, 0x02},\r
203     {0x0C, 0x52, 0x52, 0x52, 0x3E},\r
204     {0x7F, 0x08, 0x04, 0x04, 0x78},\r
205     {0x00, 0x44, 0x7D, 0x40, 0x00},\r
206     {0x20, 0x40, 0x44, 0x3D, 0x00},\r
207     {0x7F, 0x10, 0x28, 0x44, 0x00},\r
208     {0x00, 0x41, 0x7F, 0x40, 0x00},\r
209     {0x7C, 0x04, 0x18, 0x04, 0x78},\r
210     {0x7C, 0x08, 0x04, 0x04, 0x78},\r
211     {0x38, 0x44, 0x44, 0x44, 0x38},\r
212     {0x7C, 0x14, 0x14, 0x14, 0x08},\r
213     {0x08, 0x14, 0x14, 0x18, 0x7C},\r
214     {0x7C, 0x08, 0x04, 0x04, 0x08},\r
215     {0x48, 0x54, 0x54, 0x54, 0x20},\r
216     {0x04, 0x3F, 0x44, 0x40, 0x20},\r
217     {0x3C, 0x40, 0x40, 0x20, 0x7C},\r
218     {0x1C, 0x20, 0x40, 0x20, 0x1C},\r
219     {0x3C, 0x40, 0x30, 0x40, 0x3C},\r
220     {0x44, 0x28, 0x10, 0x28, 0x44},\r
221     {0x0C, 0x50, 0x50, 0x50, 0x3C},\r
222     {0x44, 0x64, 0x54, 0x4C, 0x44},\r
223 \r
224     {0x00, 0x00, 0x00, 0x00, 0x00},\r
225     {0x00, 0x00, 0x00, 0x00, 0x00},\r
226     {0x00, 0x00, 0x00, 0x00, 0x00},\r
227 \r
228     {0x07, 0x05, 0x07, 0x00, 0x00},\r
229     {0x12, 0x19, 0x16, 0x00, 0x00},\r
230     {0x00, 0x00, 0x00, 0x00, 0x00}\r
231 \r
232 };\r
233 \r
234 #define FIRST_CHARACTER       0\r
235 \r
236 /***************************************************************************//**\r
237   The g_p_oled_i2c global variable is only used inside the OLED driver. It\r
238   identifies the MSS I2C block used to communicate with the OLED display.\r
239  */\r
240 static mss_i2c_instance_t * g_p_oled_i2c = OLED_I2C_INSTANCE;\r
241 \r
242 /***************************************************************************//**\r
243   The OLED_set_cursor function sets the cursor position.\r
244 \r
245   @param line\r
246   The line parameter specifies the line at which to set the cursor. It can\r
247   take the values:\r
248   - FIRST_LINE\r
249   - SECOND_LINE\r
250 \r
251   @param char_offset\r
252   The char_offset paraemter specifies the character offset on a line where to\r
253   set the cursor location. It can be set to FIRST_CHARACTER to set the cursor\r
254   at the start of a line.\r
255  */\r
256 void OLED_set_cursor\r
257 (\r
258     uint8_t line,\r
259     uint8_t char_offset\r
260 );\r
261 /***************************************************************************//**\r
262   The OLED_write_string function displays the input string to the OLED panel.\r
263 \r
264   @param string\r
265   The string parameter is a pointer to the zero-terminated to display on the\r
266   OLED.\r
267  */\r
268 void OLED_write_string( const char *string);\r
269 \r
270 /***************************************************************************//**\r
271   The OLED_write_char function displays a single character to the display.\r
272 \r
273   @param data_char\r
274     The data_char parameter is the ASCII code of the character to display.\r
275 */\r
276 void OLED_write_char( const uint8_t data_char );\r
277 /***************************************************************************//**\r
278   OLED_init()\r
279   See "oled.h" for details of how to use this function.\r
280  */\r
281 void OLED_init(void )\r
282 {\r
283     uint8_t oled_init_sequence1[] =\r
284     {\r
285         OLED_COMMAND_CODE, CMD_DISPLAY_NON_INV,\r
286         OLED_COMMAND_CODE, CMD_DISPLAY_ALL_OFF,\r
287         OLED_COMMAND_CODE, CMD_MIRROR_HORI_ON,\r
288         OLED_COMMAND_CODE, CMD_MIRROR_VERT_OFF,\r
289         OLED_COMMAND_CODE, CMD_HORI_SCRL_OFF,\r
290         OLED_COMMAND_CODE, CMD_CONTRAST,\r
291         OLED_COMMAND_CODE, CONTRAST_DEFAULT,\r
292         OLED_COMMAND_CODE, CMD_ARECOL_LPM,\r
293         OLED_COMMAND_CODE, CMD_ARECOL_MONO^CMD_LPM_OFF\r
294     };\r
295 \r
296     uint8_t oled_init_sequence2[] =\r
297     {\r
298         OLED_COMMAND_CODE, CMD_START_LINE,\r
299         OLED_COMMAND_CODE, CMD_PANEL_ON\r
300     };\r
301 \r
302     MSS_I2C_init( g_p_oled_i2c, OLED_SLAVE_ADDRESS, MSS_I2C_PCLK_DIV_60 );\r
303 \r
304     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence1, sizeof(oled_init_sequence1), MSS_I2C_RELEASE_BUS );\r
305     MSS_I2C_wait_complete( g_p_oled_i2c );\r
306 \r
307     OLED_clear_display(BOTH_LINES);\r
308 \r
309     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence2, sizeof(oled_init_sequence2), MSS_I2C_RELEASE_BUS );\r
310     MSS_I2C_wait_complete( g_p_oled_i2c );\r
311 \r
312     OLED_set_cursor( FIRST_LINE, FIRST_CHARACTER );\r
313 }\r
314 \r
315 /***************************************************************************//**\r
316   OLED_clear_display()\r
317   See "oled.h" for details of how to use this function.\r
318  */\r
319 void OLED_clear_display( oled_no_of_line LINES )\r
320 {\r
321     uint8_t i, j,start_line = 0,end_line = 0;\r
322     uint8_t clear_8_columns[] =\r
323     {\r
324         OLED_DATA_CODE, 0x00,\r
325         OLED_DATA_CODE, 0x00,\r
326         OLED_DATA_CODE, 0x00,\r
327         OLED_DATA_CODE, 0x00,\r
328         OLED_DATA_CODE, 0x00,\r
329         OLED_DATA_CODE, 0x00,\r
330         OLED_DATA_CODE, 0x00,\r
331         OLED_DATA_CODE, 0x00\r
332     };\r
333 \r
334     switch(LINES)\r
335     {\r
336         case FIRST_LINE:\r
337         {\r
338             start_line = FIRST_LINE;\r
339             end_line = FIRST_LINE;\r
340         }\r
341 \r
342         case SECOND_LINE:\r
343         {\r
344             start_line = SECOND_LINE;\r
345             end_line = SECOND_LINE;\r
346         }\r
347 \r
348         case BOTH_LINES:\r
349         {\r
350             start_line = FIRST_LINE;\r
351             end_line = SECOND_LINE;\r
352         }\r
353 \r
354     }\r
355 \r
356     for( j = start_line; j <= end_line; ++j )\r
357     {\r
358         OLED_set_cursor( j, FIRST_CHARACTER );\r
359         for( i = 0; i < 13; ++i )\r
360         {\r
361             MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, clear_8_columns, sizeof(clear_8_columns), MSS_I2C_RELEASE_BUS );\r
362             MSS_I2C_wait_complete( g_p_oled_i2c );\r
363         }\r
364     }\r
365 }\r
366 \r
367 /***************************************************************************//**\r
368   OLED_set_cursor()\r
369   See definition of OLED_set_cursor() for details of how to use this function.\r
370  */\r
371 void OLED_set_cursor\r
372 (\r
373     uint8_t line,\r
374     uint8_t char_offset\r
375 )\r
376 {\r
377     uint8_t command_sequence[] =\r
378     {\r
379         OLED_COMMAND_CODE, CMD_LOW_NIB_COL,\r
380         OLED_COMMAND_CODE, CMD_HIGH_NIB_COL,\r
381         OLED_COMMAND_CODE, CMD_PAGE_0\r
382     };\r
383     uint8_t low_nib, high_nib;\r
384 \r
385     ++char_offset;\r
386     char_offset *= CHARACTER_WIDTH;\r
387     low_nib = 0x0F & char_offset;\r
388     high_nib = (0xF0 & char_offset) >> 4;\r
389     line += 2;\r
390 \r
391     command_sequence[1] |= low_nib;\r
392     command_sequence[3] |= high_nib;\r
393     command_sequence[5] |= line;\r
394     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, command_sequence, sizeof(command_sequence), MSS_I2C_RELEASE_BUS );\r
395     MSS_I2C_wait_complete( g_p_oled_i2c );\r
396 }\r
397 \r
398 /***************************************************************************//**\r
399   OLED_write_string()\r
400   See definition of OLED_write_string for details of how to use this function.\r
401  */\r
402 void OLED_write_string\r
403 (\r
404     const char *string\r
405 )\r
406 {\r
407   while (*string != 0)\r
408   {\r
409       OLED_write_char( *string );\r
410       ++string;\r
411   }\r
412 }\r
413 \r
414 /***************************************************************************//**\r
415   OLED_write_char()\r
416   See definition of OLED_write_char()  for details of how to use this function.\r
417  */\r
418 void OLED_write_char\r
419 (\r
420     const uint8_t data_char\r
421 )\r
422 {\r
423     uint8_t txbuff[10];\r
424     uint8_t i;\r
425 \r
426     for ( i = 0; i < CHARACTER_WIDTH; ++i )\r
427     {\r
428         txbuff[i * 2] = OLED_DATA_CODE;\r
429         txbuff[(i * 2) + 1] = oled_ascii_character_set[data_char][i];\r
430     }\r
431     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, txbuff, sizeof(txbuff), MSS_I2C_RELEASE_BUS );\r
432     MSS_I2C_wait_complete( g_p_oled_i2c );\r
433 }\r
434 \r
435 /***************************************************************************//**\r
436   OLED_horizontal_scroll()\r
437   See "oled.h" for details of how to use this function.\r
438  */\r
439 void OLED_horizontal_scroll(struct oled_data * horiz_scroll)\r
440 {\r
441     uint8_t horiz_scroll_on_off[] =\r
442     {\r
443         OLED_COMMAND_CODE, CMD_HORI_SCRL_OFF,\r
444     };\r
445 \r
446     uint8_t horiz_scroll_setup_data[] =\r
447     {\r
448         OLED_COMMAND_CODE, CMD_HORI_SCRL,\r
449         OLED_COMMAND_CODE, SCROLL_PER_STEP,\r
450         OLED_COMMAND_CODE, SCROLL_PAGE_0,\r
451         OLED_COMMAND_CODE, SCROLL_12_FRAMES,\r
452         OLED_COMMAND_CODE, SCROLL_PAGE_1,\r
453     };\r
454     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_on_off, sizeof(horiz_scroll_on_off), MSS_I2C_RELEASE_BUS );\r
455     MSS_I2C_wait_complete( g_p_oled_i2c );\r
456 \r
457     if(horiz_scroll->on_off == 1)\r
458     {\r
459         horiz_scroll_setup_data[3] = horiz_scroll->column_scrool_per_step;\r
460         horiz_scroll_setup_data[5] = horiz_scroll->start_page;\r
461         horiz_scroll_setup_data[7] = horiz_scroll->time_intrval_btw_scroll_step;\r
462         horiz_scroll_setup_data[9] = horiz_scroll->end_page;\r
463         MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_setup_data, sizeof(horiz_scroll_setup_data), MSS_I2C_RELEASE_BUS );\r
464         MSS_I2C_wait_complete( g_p_oled_i2c );\r
465 \r
466         horiz_scroll_on_off[1] = CMD_HORI_SCRL_ON;\r
467         MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_on_off, sizeof(horiz_scroll_on_off), MSS_I2C_RELEASE_BUS );\r
468         MSS_I2C_wait_complete( g_p_oled_i2c );\r
469     }\r
470 }\r
471 \r
472 /***************************************************************************//**\r
473   OLED_contrast()\r
474   See "oled.h" for details of how to use this function.\r
475  */\r
476 void OLED_contrast(uint8_t color_contrast)\r
477 {\r
478     uint8_t oled_contrast[] =\r
479     {\r
480         OLED_COMMAND_CODE, CMD_CONTRAST,\r
481         OLED_COMMAND_CODE, CONTRAST_DEFAULT,\r
482     };\r
483 \r
484     oled_contrast[3] = color_contrast;\r
485     MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_contrast, sizeof(oled_contrast), MSS_I2C_RELEASE_BUS );\r
486     MSS_I2C_wait_complete( g_p_oled_i2c );\r
487 \r
488 }\r
489 \r
490 /***************************************************************************//**\r
491   OLED_write_data()\r
492   See "oled.h" for details of how to use this function.\r
493  */\r
494 void OLED_write_data(struct oled_data* data, oled_no_of_line LINES)\r
495 {\r
496     uint8_t line;\r
497     uint8_t char_offset;\r
498     char *string;\r
499 \r
500     switch(LINES)\r
501     {\r
502 \r
503         case FIRST_LINE:\r
504         {\r
505             OLED_clear_display(FIRST_LINE);\r
506             line = data->line1;\r
507             char_offset = data->char_offset1;\r
508             string = data->string1;\r
509         }\r
510 \r
511         case SECOND_LINE:\r
512         {\r
513             OLED_clear_display(SECOND_LINE);\r
514             line = data->line2;\r
515             char_offset = data->char_offset2;\r
516            string = data->string2;\r
517         }\r
518 \r
519         case BOTH_LINES:\r
520         {\r
521             OLED_clear_display(BOTH_LINES);\r
522             line = data->line1;\r
523             char_offset = data->char_offset1;\r
524             string = data->string1;\r
525             OLED_set_cursor(line,char_offset);\r
526             OLED_write_string(string);\r
527             line = data->line2;\r
528             char_offset = data->char_offset2;\r
529             string = data->string2;\r
530         }\r
531 \r
532         OLED_set_cursor(line,char_offset);\r
533         OLED_write_string(string);\r
534         OLED_contrast(data->contrast_val);\r
535     }\r
536 }\r