/*******************************************************************************
* Company: Actel Corporation
*
* File: main.c
* File history:
*     Revision: Initial version   Date: JUne 01, 2010
*
* Description:
*             This application print the string on OLED display based on user
*             selection.The following options are given:
*
*             1 - Plain Text Display
*             2 - Vertical Scrolling
*             3 - Horizontal Scrolling
*             4 - Sine Wave
*
* Author: Pavan Marisetti
*         pavan.marisetti@actel.com
*         Corporate Applications Engineering
********************************************************************************/

#include <stdio.h>
#include <string.h>


#include "BSP/oled_driver/oled.h"



/**************************************************************************/
/* Firmware Includes */
/**************************************************************************/

#include "hal.h"
#include "core_uart_apb.h"
#include "core_gpio.h"
#include "cortex_nvic.h"
#include "core_i2c.h"
#include "coreai.h"

/**************************************************************************/
/* System Memory Map */
/**************************************************************************/

#include "platform.h"

/**************************************************************************/
/* RTOS Includes */
/**************************************************************************/

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

/**************************************************************************/
/*Declaration of global variables*/
/**************************************************************************/

xSemaphoreHandle stdSemHndl = NULL, htSemHndl = NULL;
xSemaphoreHandle webSemHndl = NULL, ledSemHndl = NULL;
xSemaphoreHandle switchOneSemHndl = NULL;

xTaskHandle stdTaskHndl = NULL, htTaskHndl = NULL, switchOneTaskHndl = NULL;
xTaskHandle webTaskHndl = NULL, aceTaskHndl = NULL, ledTaskHndl = NULL;

/**************************************************************************/
/*TBD*/
/**************************************************************************/

UART_instance_t g_uart;
gpio_instance_t g_gpio;
i2c_instance_t g_i2c_inst;

#define BAUD_VALUE_57600    42

#define FIRST_CHARACTER 0
struct oled_data                write_data;
int main()
{

   /* OLED Initialization */
    OLED_init();


     stdSemHndl       = xSemaphoreCreateCounting( 1, 0);
     webSemHndl       = xSemaphoreCreateCounting( 1, 0);
     ledSemHndl       = xSemaphoreCreateCounting( 1, 0);
     switchOneSemHndl = xSemaphoreCreateCounting( 1, 0);

     /* Creating the tasks for the functional requirement of the demo */
     /* This task is responsible for controlling the demo using the
      * SW1 and SW2 switch inputs from the user */

    while(1)
    {
    	    uint8_t j;
    	    write_data.line1          = FIRST_LINE;
    	    write_data.char_offset1   = FIRST_CHARACTER;
    	    write_data.string1        = "Hi I am SmartFusion";

    	    write_data.line2          = SECOND_LINE;
    	    write_data.char_offset2   = FIRST_CHARACTER;
    	    write_data.string2        = "Want to Play?";

    	    write_data.contrast_val                 = OLED_CONTRAST_VAL;
    	    write_data.hor_scr_on_off                       = OLED_HORIZ_SCROLL_OFF;
    	    write_data.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;
    	    write_data.start_page                   = OLED_START_PAGE;
    	    write_data.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;
    	    write_data.end_page                     = OLED_END_PAGE;

    	    OLED_write_data(&write_data,FIRST_TWO_LINES);
    	    /*This delay is required to show the menu for some time */
    	    for(j=0;j<100;j++)
    	    {
    	        delay(100000);
    	    }

    	    write_data.line1          = FIRST_LINE;
    	    write_data.char_offset1   = FIRST_CHARACTER;
    	    write_data.string1        = "First change";

    	    write_data.line2          = SECOND_LINE;
    	    write_data.char_offset2   = FIRST_CHARACTER;
    	    write_data.string2        = "Hello";

    	    write_data.contrast_val                 = OLED_CONTRAST_VAL;
    	    write_data.hor_scr_on_off                       = OLED_HORIZ_SCROLL_OFF;
    	    write_data.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;
    	    write_data.start_page                   = OLED_START_PAGE;
    	    write_data.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;
    	    write_data.end_page                     = OLED_END_PAGE;

    	    OLED_write_data(&write_data,FIRST_TWO_LINES);
    	    /*This delay is required to show the menu for some time */
    	    for(j=0;j<100;j++)
    	    {
    	        delay(100000);
    	    }

       	    write_data.line1          = FIRST_LINE;
        	    write_data.char_offset1   = FIRST_CHARACTER;
        	    write_data.string1        = "Second change";

        	    write_data.line2          = SECOND_LINE;
        	    write_data.char_offset2   = FIRST_CHARACTER;
        	    write_data.string2        = "Hello1";

        	    write_data.contrast_val                 = OLED_CONTRAST_VAL;
        	    write_data.hor_scr_on_off                       = OLED_HORIZ_SCROLL_OFF;
        	    write_data.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;
        	    write_data.start_page                   = OLED_START_PAGE;
        	    write_data.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;
        	    write_data.end_page                     = OLED_END_PAGE;

        	    OLED_write_data(&write_data,FIRST_TWO_LINES);
        	    /*This delay is required to show the menu for some time */
        	    for(j=0;j<100;j++)
        	    {
        	        delay(100000);
        	    }

        	    write_data.line1          = FIRST_LINE;
            	    write_data.char_offset1   = FIRST_CHARACTER;
            	    write_data.string1        = "Third change";

            	    write_data.line2          = SECOND_LINE;
            	    write_data.char_offset2   = FIRST_CHARACTER;
            	    write_data.string2        = "Hello2";

            	    write_data.contrast_val                 = OLED_CONTRAST_VAL;
            	    write_data.hor_scr_on_off                       = OLED_HORIZ_SCROLL_OFF;
            	    write_data.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;
            	    write_data.start_page                   = OLED_START_PAGE;
            	    write_data.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;
            	    write_data.end_page                     = OLED_END_PAGE;

            	    OLED_write_data(&write_data,FIRST_TWO_LINES);
            	    /*This delay is required to show the menu for some time */
            	    for(j=0;j<100;j++)
            	    {
            	        delay(100000);
            	    }
    }

    return 0;
}
