--- /dev/null
+/*****************************************************************************\r
+ * (c) Copyright 2009 Actel Corporation. All rights reserved.\r
+ *\r
+ * Author : Actel Application Team\r
+ * Rev : 1.0.0.0\r
+ * Description: Device driver for the on-board OLED for SmartFusion KITS\r
+ * Implementation of sample basic driver for OLED display found on Actel\r
+ * SmartFusion development boards.\r
+ * This code is intended as an example of using the SmartFusion I2C driver.\r
+ *****************************************************************************/\r
+\r
+ #include "oled.h"\r
+#include "../bsp_config.h"\r
+\r
+/***************************************************************************//**\r
+ Command definitions for the SSD300 controller inside the OLED display module.\r
+ */\r
+#define CMD_DISPLAY_OFF_SET 0xD3\r
+#define CMD_PANEL_ON 0xAF\r
+#define CMD_PANEL_OFF 0xAE\r
+#define CMD_DC_DC 0xAD\r
+#define CMD_DC_DC_DEFAULT_ON 0x8B\r
+#define CMD_DC_DC_OFF 0x8A\r
+#define CMD_DISPLAY_ALL_ON 0xA5\r
+#define CMD_DISPLAY_ALL_OFF 0xA4\r
+#define CMD_DISPLAY_NON_INV 0xA6\r
+#define CMD_DISPLAY_INV 0xA7\r
+#define CMD_ARECOL_LPM 0xD8\r
+#define CMD_ARECOL_MONO 0x00\r
+#define CMD_ARECOL_COLOR 0x30\r
+#define CMD_LPM_ON 0x05\r
+#define CMD_LPM_OFF 0x00\r
+#define CMD_CONTRAST 0x81\r
+#define CMD_MIRROR_HORI_ON 0xC8\r
+#define CMD_MIRROR_HORI_OFF 0xC0\r
+#define CMD_MIRROR_VERT_ON 0xA1\r
+#define CMD_MIRROR_VERT_OFF 0xA0\r
+#define CMD_HORI_SCRL 0x26\r
+#define CMD_HORI_SCRL_ON 0x2F\r
+#define CMD_HORI_SCRL_OFF 0x2E\r
+#define CMD_MUX_RATIO 0xA8\r
+#define CMD_MUX_RATIO_31 0x23\r
+\r
+#define CMD_PAGE_0 0xB0\r
+#define CMD_PAGE_1 0xB1\r
+#define CMD_PAGE_2 0xB2\r
+#define CMD_PAGE_3 0xB3\r
+#define CMD_PAGE_4 0xB4\r
+#define CMD_PAGE_5 0xB5\r
+\r
+#define CMD_LOW_NIB_COL 0x00\r
+#define CMD_HIGH_NIB_COL 0x10\r
+\r
+#define CMD_START_LINE 0x50\r
+#define CONTRAST_DEFAULT 0xFF\r
+#define CONTRAST_25_PERC 0x40\r
+#define CONTRAST_100_PERC 0xFF\r
+#define CONTRAST_0_PERC 0x00\r
+#define SCROLL_1_COLUMN 0x01\r
+#define SCROLL_2_COLUMN 0x02\r
+#define SCROLL_3_COLUMN 0x03\r
+#define SCROLL_4_COLUMN 0x04\r
+#define SCROLL_PAGE_0 0x00\r
+#define SCROLL_PAGE_1 0x01\r
+#define SCROLL_PAGE_2 0x02\r
+#define SCROLL_PAGE_3 0x03\r
+#define SCROLL_PAGE_4 0x04\r
+#define SCROLL_PAGE_5 0x05\r
+#define SCROLL_12_FRAMES 0x00\r
+#define SCROLL_64_FRAMES 0x01\r
+#define SCROLL_128_FRAMES 0x02\r
+#define SCROLL_256_FRAMES 0x03\r
+#define SCROLL_PER_STEP 0x01\r
+#define PAGE0_COLOR_BAG 0x92\r
+#define PAGE1_COLOR_BAG 0x93\r
+\r
+/***************************************************************************//**\r
+ OLED display I2C communication protocol control byte values. Used to indicate\r
+ whether the byte following the control byte is to be interpreted by the OLED\r
+ display as a command or data byte.\r
+ */\r
+#define OLED_COMMAND_CODE 0x80\r
+#define OLED_DATA_CODE 0xC0\r
+\r
+/***************************************************************************//**\r
+ I2C serial address of OLED display.\r
+ */\r
+#define OLED_SLAVE_ADDRESS 0x78\r
+\r
+/***************************************************************************//**\r
+ Bitmaps of the character set.\r
+ Each character is 5 pixels wide and 7 pixels high.\r
+ The table is indexed on ASCII character codes.\r
+ */\r
+#define CHARACTER_WIDTH 5\r
+\r
+const unsigned char oled_ascii_character_set[255][CHARACTER_WIDTH] =\r
+{\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+\r
+ {0x00, 0x00, 0x5F, 0x00, 0x00},\r
+ {0x00, 0x07, 0x00, 0x07, 0x00},\r
+ {0x14, 0x7F, 0x14, 0x7F, 0x14},\r
+ {0x24, 0x2A, 0x7F, 0x2A, 0x12},\r
+ {0x23, 0x13, 0x08, 0x64, 0x62},\r
+ {0x36, 0x49, 0x55, 0x22, 0x50},\r
+ {0x00, 0x05, 0x03, 0x00, 0x00},\r
+ {0x00, 0x1C, 0x22, 0x41, 0x00},\r
+ {0x00, 0x41, 0x22, 0x1C, 0x00},\r
+ {0x14, 0x08, 0x3E, 0x08, 0x14},\r
+ {0x08, 0x08, 0x3E, 0x08, 0x08},\r
+ {0x00, 0x50, 0x30, 0x00, 0x00},\r
+ {0x08, 0x08, 0x08, 0x08, 0x08},\r
+ {0x00, 0x60, 0x60, 0x00, 0x00},\r
+ {0x20, 0x10, 0x08, 0x04, 0x02},\r
+ {0x3E, 0x51, 0x49, 0x45, 0x3E},\r
+ {0x00, 0x42, 0x7F, 0x40, 0x00},\r
+ {0x42, 0x61, 0x51, 0x49, 0x46},\r
+ {0x21, 0x41, 0x45, 0x4B, 0x31},\r
+ {0x18, 0x14, 0x12, 0x7F, 0x10},\r
+ {0x27, 0x45, 0x45, 0x45, 0x39},\r
+ {0x3C, 0x4A, 0x49, 0x49, 0x30},\r
+ {0x01, 0x71, 0x09, 0x05, 0x03},\r
+ {0x36, 0x49, 0x49, 0x49, 0x36},\r
+ {0x06, 0x49, 0x49, 0x29, 0x1E},\r
+ {0x00, 0x36, 0x36, 0x00, 0x00},\r
+ {0x00, 0x56, 0x36, 0x00, 0x00},\r
+ {0x08, 0x14, 0x22, 0x41, 0x00},\r
+ {0x14, 0x14, 0x14, 0x14, 0x14},\r
+ {0x00, 0x41, 0x22, 0x14, 0x08},\r
+ {0x02, 0x01, 0x51, 0x09, 0x06},\r
+ {0x32, 0x49, 0x79, 0x41, 0x3E},\r
+ {0x7E, 0x11, 0x11, 0x11, 0x7E},\r
+ {0x7F, 0x49, 0x49, 0x49, 0x36},\r
+ {0x3E, 0x41, 0x41, 0x41, 0x22},\r
+ {0x7F, 0x41, 0x41, 0x22, 0x1C},\r
+ {0x7F, 0x49, 0x49, 0x49, 0x41},\r
+ {0x7F, 0x09, 0x09, 0x09, 0x01},\r
+ {0x3E, 0x41, 0x49, 0x49, 0x7A},\r
+ {0x7F, 0x08, 0x08, 0x08, 0x7F},\r
+ {0x00, 0x41, 0x7F, 0x41, 0x00},\r
+ {0x20, 0x40, 0x41, 0x3F, 0x01},\r
+ {0x7F, 0x08, 0x14, 0x22, 0x41},\r
+ {0x3F, 0x40, 0x40, 0x40, 0x40},\r
+ {0x7F, 0x02, 0x0C, 0x02, 0x7F},\r
+ {0x7F, 0x04, 0x08, 0x10, 0x7F},\r
+ {0x3E, 0x41, 0x41, 0x41, 0x3E},\r
+ {0x7F, 0x09, 0x09, 0x09, 0x06},\r
+ {0x3E, 0x41, 0x51, 0x21, 0x5E},\r
+ {0x7F, 0x09, 0x19, 0x29, 0x46},\r
+ {0x46, 0x49, 0x49, 0x49, 0x31},\r
+ {0x01, 0x01, 0x7F, 0x01, 0x01},\r
+ {0x3F, 0x40, 0x40, 0x40, 0x3F},\r
+ {0x1F, 0x20, 0x40, 0x20, 0x1F},\r
+ {0x3F, 0x40, 0x38, 0x40, 0x3F},\r
+ {0x63, 0x14, 0x08, 0x14, 0x63},\r
+ {0x07, 0x08, 0x70, 0x08, 0x07},\r
+ {0x61, 0x51, 0x49, 0x45, 0x43},\r
+ {0x00, 0x7F, 0x41, 0x41, 0x00},\r
+ {0x02, 0x04, 0x08, 0x10, 0x20},\r
+ {0x00, 0x41, 0x41, 0x7F, 0x00},\r
+ {0x04, 0x02, 0x01, 0x02, 0x04},\r
+ {0x40, 0x40, 0x40, 0x40, 0x40},\r
+ {0x00, 0x01, 0x02, 0x04, 0x00},\r
+ {0x20, 0x54, 0x54, 0x54, 0x78},\r
+ {0x7F, 0x48, 0x44, 0x44, 0x38},\r
+ {0x38, 0x44, 0x44, 0x44, 0x20},\r
+ {0x30, 0x48, 0x48, 0x50, 0x7F},\r
+ {0x38, 0x54, 0x54, 0x54, 0x18},\r
+ {0x10, 0x7E, 0x11, 0x01, 0x02},\r
+ {0x0C, 0x52, 0x52, 0x52, 0x3E},\r
+ {0x7F, 0x08, 0x04, 0x04, 0x78},\r
+ {0x00, 0x44, 0x7D, 0x40, 0x00},\r
+ {0x20, 0x40, 0x44, 0x3D, 0x00},\r
+ {0x7F, 0x10, 0x28, 0x44, 0x00},\r
+ {0x00, 0x41, 0x7F, 0x40, 0x00},\r
+ {0x7C, 0x04, 0x18, 0x04, 0x78},\r
+ {0x7C, 0x08, 0x04, 0x04, 0x78},\r
+ {0x38, 0x44, 0x44, 0x44, 0x38},\r
+ {0x7C, 0x14, 0x14, 0x14, 0x08},\r
+ {0x08, 0x14, 0x14, 0x18, 0x7C},\r
+ {0x7C, 0x08, 0x04, 0x04, 0x08},\r
+ {0x48, 0x54, 0x54, 0x54, 0x20},\r
+ {0x04, 0x3F, 0x44, 0x40, 0x20},\r
+ {0x3C, 0x40, 0x40, 0x20, 0x7C},\r
+ {0x1C, 0x20, 0x40, 0x20, 0x1C},\r
+ {0x3C, 0x40, 0x30, 0x40, 0x3C},\r
+ {0x44, 0x28, 0x10, 0x28, 0x44},\r
+ {0x0C, 0x50, 0x50, 0x50, 0x3C},\r
+ {0x44, 0x64, 0x54, 0x4C, 0x44},\r
+\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00},\r
+\r
+ {0x07, 0x05, 0x07, 0x00, 0x00},\r
+ {0x12, 0x19, 0x16, 0x00, 0x00},\r
+ {0x00, 0x00, 0x00, 0x00, 0x00}\r
+\r
+};\r
+\r
+#define FIRST_CHARACTER 0\r
+\r
+/***************************************************************************//**\r
+ The g_p_oled_i2c global variable is only used inside the OLED driver. It\r
+ identifies the MSS I2C block used to communicate with the OLED display.\r
+ */\r
+static mss_i2c_instance_t * g_p_oled_i2c = OLED_I2C_INSTANCE;\r
+\r
+/***************************************************************************//**\r
+ The OLED_set_cursor function sets the cursor position.\r
+\r
+ @param line\r
+ The line parameter specifies the line at which to set the cursor. It can\r
+ take the values:\r
+ - FIRST_LINE\r
+ - SECOND_LINE\r
+\r
+ @param char_offset\r
+ The char_offset paraemter specifies the character offset on a line where to\r
+ set the cursor location. It can be set to FIRST_CHARACTER to set the cursor\r
+ at the start of a line.\r
+ */\r
+void OLED_set_cursor\r
+(\r
+ uint8_t line,\r
+ uint8_t char_offset\r
+);\r
+/***************************************************************************//**\r
+ The OLED_write_string function displays the input string to the OLED panel.\r
+\r
+ @param string\r
+ The string parameter is a pointer to the zero-terminated to display on the\r
+ OLED.\r
+ */\r
+void OLED_write_string( const char *string);\r
+\r
+/***************************************************************************//**\r
+ The OLED_write_char function displays a single character to the display.\r
+\r
+ @param data_char\r
+ The data_char parameter is the ASCII code of the character to display.\r
+*/\r
+void OLED_write_char( const uint8_t data_char );\r
+/***************************************************************************//**\r
+ OLED_init()\r
+ See "oled.h" for details of how to use this function.\r
+ */\r
+void OLED_init(void )\r
+{\r
+ uint8_t oled_init_sequence1[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_DISPLAY_NON_INV,\r
+ OLED_COMMAND_CODE, CMD_DISPLAY_ALL_OFF,\r
+ OLED_COMMAND_CODE, CMD_MIRROR_HORI_ON,\r
+ OLED_COMMAND_CODE, CMD_MIRROR_VERT_OFF,\r
+ OLED_COMMAND_CODE, CMD_HORI_SCRL_OFF,\r
+ OLED_COMMAND_CODE, CMD_CONTRAST,\r
+ OLED_COMMAND_CODE, CONTRAST_DEFAULT,\r
+ OLED_COMMAND_CODE, CMD_ARECOL_LPM,\r
+ OLED_COMMAND_CODE, CMD_ARECOL_MONO^CMD_LPM_OFF\r
+ };\r
+\r
+ uint8_t oled_init_sequence2[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_START_LINE,\r
+ OLED_COMMAND_CODE, CMD_PANEL_ON\r
+ };\r
+\r
+ MSS_I2C_init( g_p_oled_i2c, OLED_SLAVE_ADDRESS, MSS_I2C_PCLK_DIV_60 );\r
+\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence1, sizeof(oled_init_sequence1), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+\r
+ OLED_clear_display(BOTH_LINES);\r
+\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence2, sizeof(oled_init_sequence2), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+\r
+ OLED_set_cursor( FIRST_LINE, FIRST_CHARACTER );\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_clear_display()\r
+ See "oled.h" for details of how to use this function.\r
+ */\r
+void OLED_clear_display( oled_no_of_line LINES )\r
+{\r
+ uint8_t i, j,start_line,end_line;\r
+ uint8_t clear_8_columns[] =\r
+ {\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00,\r
+ OLED_DATA_CODE, 0x00\r
+ };\r
+\r
+ switch(LINES)\r
+ {\r
+ case FIRST_LINE:\r
+ {\r
+ start_line = FIRST_LINE;\r
+ end_line = FIRST_LINE;\r
+ }\r
+\r
+ case SECOND_LINE:\r
+ {\r
+ start_line = SECOND_LINE;\r
+ end_line = SECOND_LINE;\r
+ }\r
+\r
+ case BOTH_LINES:\r
+ {\r
+ start_line = FIRST_LINE;\r
+ end_line = SECOND_LINE;\r
+ }\r
+\r
+ }\r
+\r
+ for( j = start_line; j <= end_line; ++j )\r
+ {\r
+ OLED_set_cursor( j, FIRST_CHARACTER );\r
+ for( i = 0; i < 13; ++i )\r
+ {\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, clear_8_columns, sizeof(clear_8_columns), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+ }\r
+ }\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_set_cursor()\r
+ See definition of OLED_set_cursor() for details of how to use this function.\r
+ */\r
+void OLED_set_cursor\r
+(\r
+ uint8_t line,\r
+ uint8_t char_offset\r
+)\r
+{\r
+ uint8_t command_sequence[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_LOW_NIB_COL,\r
+ OLED_COMMAND_CODE, CMD_HIGH_NIB_COL,\r
+ OLED_COMMAND_CODE, CMD_PAGE_0\r
+ };\r
+ uint8_t low_nib, high_nib;\r
+\r
+ ++char_offset;\r
+ char_offset *= CHARACTER_WIDTH;\r
+ low_nib = 0x0F & char_offset;\r
+ high_nib = (0xF0 & char_offset) >> 4;\r
+ line += 2;\r
+\r
+ command_sequence[1] |= low_nib;\r
+ command_sequence[3] |= high_nib;\r
+ command_sequence[5] |= line;\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, command_sequence, sizeof(command_sequence), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_write_string()\r
+ See definition of OLED_write_string for details of how to use this function.\r
+ */\r
+void OLED_write_string\r
+(\r
+ const char *string\r
+)\r
+{\r
+ while (*string != 0)\r
+ {\r
+ OLED_write_char( *string );\r
+ ++string;\r
+ }\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_write_char()\r
+ See definition of OLED_write_char() for details of how to use this function.\r
+ */\r
+void OLED_write_char\r
+(\r
+ const uint8_t data_char\r
+)\r
+{\r
+ uint8_t txbuff[10];\r
+ uint8_t i;\r
+\r
+ for ( i = 0; i < CHARACTER_WIDTH; ++i )\r
+ {\r
+ txbuff[i * 2] = OLED_DATA_CODE;\r
+ txbuff[(i * 2) + 1] = oled_ascii_character_set[data_char][i];\r
+ }\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, txbuff, sizeof(txbuff), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_horizontal_scroll()\r
+ See "oled.h" for details of how to use this function.\r
+ */\r
+void OLED_horizontal_scroll(struct oled_data * horiz_scroll)\r
+{\r
+ uint8_t horiz_scroll_on_off[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_HORI_SCRL_OFF,\r
+ };\r
+\r
+ uint8_t horiz_scroll_setup_data[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_HORI_SCRL,\r
+ OLED_COMMAND_CODE, SCROLL_PER_STEP,\r
+ OLED_COMMAND_CODE, SCROLL_PAGE_0,\r
+ OLED_COMMAND_CODE, SCROLL_12_FRAMES,\r
+ OLED_COMMAND_CODE, SCROLL_PAGE_1,\r
+ };\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_on_off, sizeof(horiz_scroll_on_off), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+\r
+ if(horiz_scroll->on_off == 1)\r
+ {\r
+ horiz_scroll_setup_data[3] = horiz_scroll->column_scrool_per_step;\r
+ horiz_scroll_setup_data[5] = horiz_scroll->start_page;\r
+ horiz_scroll_setup_data[7] = horiz_scroll->time_intrval_btw_scroll_step;\r
+ horiz_scroll_setup_data[9] = horiz_scroll->end_page;\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_setup_data, sizeof(horiz_scroll_setup_data), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+\r
+ horiz_scroll_on_off[1] = CMD_HORI_SCRL_ON;\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, horiz_scroll_on_off, sizeof(horiz_scroll_on_off), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+ }\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_contrast()\r
+ See "oled.h" for details of how to use this function.\r
+ */\r
+void OLED_contrast(uint8_t color_contrast)\r
+{\r
+ uint8_t oled_contrast[] =\r
+ {\r
+ OLED_COMMAND_CODE, CMD_CONTRAST,\r
+ OLED_COMMAND_CODE, CONTRAST_DEFAULT,\r
+ };\r
+\r
+ oled_contrast[3] = color_contrast;\r
+ MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_contrast, sizeof(oled_contrast), MSS_I2C_RELEASE_BUS );\r
+ MSS_I2C_wait_complete( g_p_oled_i2c );\r
+\r
+}\r
+\r
+/***************************************************************************//**\r
+ OLED_write_data()\r
+ See "oled.h" for details of how to use this function.\r
+ */\r
+void OLED_write_data(struct oled_data* data, oled_no_of_line LINES)\r
+{\r
+ uint8_t line;\r
+ uint8_t char_offset;\r
+ char *string;\r
+\r
+ switch(LINES)\r
+ {\r
+\r
+ case FIRST_LINE:\r
+ {\r
+ OLED_clear_display(FIRST_LINE);\r
+ line = data->line1;\r
+ char_offset = data->char_offset1;\r
+ string = data->string1;\r
+ }\r
+\r
+ case SECOND_LINE:\r
+ {\r
+ OLED_clear_display(SECOND_LINE);\r
+ line = data->line2;\r
+ char_offset = data->char_offset2;\r
+ string = data->string2;\r
+ }\r
+\r
+ case BOTH_LINES:\r
+ {\r
+ OLED_clear_display(BOTH_LINES);\r
+ line = data->line1;\r
+ char_offset = data->char_offset1;\r
+ string = data->string1;\r
+ OLED_set_cursor(line,char_offset);\r
+ OLED_write_string(string);\r
+ line = data->line2;\r
+ char_offset = data->char_offset2;\r
+ string = data->string2;\r
+ }\r
+\r
+ OLED_set_cursor(line,char_offset);\r
+ OLED_write_string(string);\r
+ OLED_contrast(data->contrast_val);\r
+ }\r
+}\r
--- /dev/null
+/*****************************************************************************\r
+ * (c) Copyright 2009 Actel Corporation. All rights reserved.\r
+ *\r
+ * Author : Actel Application Team\r
+ * Rev : 1.0.0.0\r
+ * Description: Device driver for the on-board OLED for SmartFusion KITS\r
+ * API of sample basic driver for OLED display found on Actel SmartFusion\r
+ * development boards.\r
+ * This code is intended as an example of using the SmartFusion I2C driver.\r
+ *\r
+ */\r
+#ifndef OLED_H_\r
+#define OLED_H_\r
+\r
+#include "../BSP/i2c_driver/i2c.h"\r
+\r
+#define OLED_HORIZ_SCROLL_ON 0x01\r
+#define OLED_HORIZ_SCROLL_OFF 0x00\r
+#define OLED_HORIZ_SCROLL_STEP 0x08\r
+#define OLED_CONTRAST_VAL 0xFF\r
+#define OLED_START_PAGE 0x01\r
+#define OLED_HORIZ_SCROLL_TINVL 0x00\r
+#define OLED_END_PAGE 0x05\r
+/*-------------------------------------------------------------------------*/\r
+/* The oled_no_of_line type represents number of lines to be written on OLED.\r
+ FIRST LINE : The OLED cursor is set to line number 1 and only 1 line is\r
+ printed on OLED\r
+ SECOND_LINE : The OLED cursor is set to line number 2 and only 1 line is\r
+ printed on OLED\r
+ BOTH_LINES : The OLED cursor is set to line number 1 and line 1 and line 2\r
+ are printed on OLED\r
+*/\r
+typedef enum {\r
+ FIRST_LINE = 0,\r
+ SECOND_LINE,\r
+ BOTH_LINES\r
+} oled_no_of_line;\r
+\r
+/*-------------------------------------------------------------------------*//**\r
+ oled_data\r
+ ------------------------------------------------------------------------------\r
+ There is one instance of this structure for OLED data. Instances of this\r
+ structure is used to provide the data to OLED. A pointer to an instance of\r
+ the oled_data structure is passed as the parameter OLED driver functions.\r
+ */\r
+struct oled_data\r
+{\r
+ /* Represents line number, where String 1 has to be printed */\r
+ uint8_t line1;\r
+ /* Represents character offset within the line1, from where String 1 has to be\r
+ * printed */\r
+ uint8_t char_offset1;\r
+ /* Represents line number, where String 2 has to be printed */\r
+ uint8_t line2;\r
+ /* Represents character offset within the line2, from where String 2 has to be\r
+ * printed */\r
+ uint8_t char_offset2;\r
+ /* String 1 holds the data to be displayed on line 1 of OLED, It has to be\r
+ * less that 49 characters*/\r
+ char *string1;\r
+ /* String 1 holds the data to be displayed on line 2 of OLED, It has to be\r
+ * less that 49 characters*/\r
+ char *string2;\r
+ /* Holds the contrast value to be set for String 1 and String 2 */\r
+ uint8_t contrast_val;\r
+ /* Represents ON or OFF for horizontal scrolling */\r
+ uint8_t on_off;\r
+ /* Represents number of coumns scrolls per step for horizontal scroll*/\r
+ unsigned char column_scrool_per_step;\r
+ /* Represents start page for horizontal scroll*/\r
+ unsigned char start_page;\r
+ /* Represents time interval for horizontal scroll*/\r
+ unsigned char time_intrval_btw_scroll_step;\r
+ /* Represents end page for horizontal scroll*/\r
+ unsigned char end_page;\r
+\r
+};\r
+/***************************************************************************//**\r
+ The following defines can be used as parameter to the OLED_set_cursor()\r
+ function.\r
+ */\r
+\r
+/***************************************************************************//**\r
+ The OLED_init function initializes the OLED display.\r
+ */\r
+void OLED_init( void );\r
+\r
+/***************************************************************************//**\r
+ This function(OLED_clear_display) clears the content of the display RAM\r
+ based on the LINES input.\r
+ ------------------------------------------------------------------------------\r
+ @param oled_no_of_line:\r
+ The oled_no_of_line parameter enum that holds Number of lines.\r
+ If FIRST_LINE is passed as parameter to this function thnen, this functions\r
+ clears only First line that is 0\r
+ If SECOND_LINE is passed as parameter to this function thnen, this functions\r
+ clears only Second line that is 1\r
+ If BOTH_LINE is passed as parameter to this function thnen, this functions\r
+ clears entire OLED display.\r
+ */\r
+void OLED_clear_display( oled_no_of_line LINES );\r
+\r
+/*-------------------------------------------------------------------------*//**\r
+ OLED Write data.\r
+ ------------------------------------------------------------------------------\r
+ This function (OLED_write_data ) writes the data to OLED basedon the\r
+ parameters passed to this function.\r
+ ------------------------------------------------------------------------------\r
+ @param data:\r
+ The data parameter is a pointer to an oled_data structure, that holds\r
+ different fields of data to be required for OLED (see the oled_data structure\r
+ definition).\r
+\r
+ @param oled_no_of_line:\r
+ The oled_no_of_line parameter enum that holds Number of lines.\r
+ If FIRST_LINE is passed as parameter to this function thnen, this functions\r
+ wtites string 1 at FIRST LINE\r
+ If SECOND_LINE is passed as parameter to this function thnen, this functions\r
+ wtites string 1 at SECOND LINE\r
+ If BOTH_LINE is passed as parameter to this function thnen, this functions\r
+ wtites string 1 and string 2 at FIRST LINE and SECOND LINE respectively.\r
+Example:\r
+ @code\r
+#include "drivers/mss_watchdog/mss_watchdog.h"\r
+#include "oled.h"\r
+#define FIRST_CHARACTER 0\r
+\r
+int main()\r
+{\r
+\r
+ char *string1="SmartFusion";\r
+ char *string2="INNOVATIVE ";\r
+ struct oled_data write_data;\r
+\r
+ write_data.line1 = FIRST_LINE;\r
+ write_data.char_offset1 = FIRST_CHARACTER;\r
+ write_data.string1 = string1;\r
+ write_data.line2 = SECOND_LINE;\r
+ write_data.char_offset2 = FIRST_CHARACTER;\r
+ write_data.string2 = string2;\r
+ write_data.contrast_val = 0x01;\r
+\r
+ MSS_WD_disable();\r
+ OLED_init();\r
+ OLED_write_data(&write_data,BOTH_LINES);\r
+ return 0;\r
+}\r
+ @endcode\r
+ */\r
+\r
+void OLED_write_data(struct oled_data * data, oled_no_of_line flag);\r
+\r
+/*-------------------------------------------------------------------------*//**\r
+ OLED Horizontal scrolling.\r
+ ------------------------------------------------------------------------------\r
+ This function (OLED_horizontal_scroll ) enbles the Horizontal scrolling.\r
+ ------------------------------------------------------------------------------\r
+ @param data:\r
+ The horiz_scroll parameter is a pointer to an oled_data structure, that holds\r
+ different fields of data to be required for OLED (see the oled_data structure\r
+ definition).\r
+Example:\r
+ @code\r
+\r
+int main()\r
+{\r
+\r
+ char *string1="SmartFusion";\r
+ char *string2="INNOVATIVE ";\r
+ struct oled_data write_data;\r
+\r
+ write_data.line1 = FIRST_LINE;\r
+ write_data.char_offset1 = FIRST_CHARACTER;\r
+ write_data.string1 = string1;\r
+ write_data.line2 = SECOND_LINE;\r
+ write_data.char_offset2 = FIRST_CHARACTER;\r
+ write_data.string2 = string2;\r
+ write_data.contrast_val = 0x01;\r
+ write_data.on_off = 0x01;\r
+ write_data.column_scrool_per_step = 0x08;\r
+ write_data.start_page = 0x01;\r
+ write_data.time_intrval_btw_scroll_step = 0x00;\r
+ write_data.end_page = 0x05;\r
+\r
+ MSS_WD_disable();\r
+ OLED_init();\r
+ OLED_write_data(&write_data,BOTH_LINES);\r
+ OLED_horizontal_scroll(&write_data);\r
+ return 0;\r
+}\r
+ @endcode\r
+ */\r
+\r
+void OLED_horizontal_scroll(struct oled_data * horiz_scroll);\r
+\r
+/***************************************************************************//**\r
+ This function(OLED_contrast) sets ths conrtast to the data displayed on the\r
+ OLED.\r
+ ------------------------------------------------------------------------------\r
+ @param color_contrast:\r
+ The color_contrast parameter that holds contrast value.\r
+ The color_contrast values should be in the range of 1 to 256.\r
+ */\r
+void OLED_contrast(uint8_t color_contrast);\r
+\r
+#endif\r
+\r
+\r
+\r