/*
 *****************************************************************************
 * Microchip Graphics Library Demo Application
 * This program shows how to use the Graphics Primitives Layer.
 *****************************************************************************
 * FileName:        MainDemo.c
 * Dependencies:    MainDemo.h
 * Processor:       PIC24
 * Compiler:       	MPLAB C30
 * Linker:          MPLAB LINK30
 * Company:         Microchip Technology Incorporated
 *
 * Software License Agreement
 *
 * Copyright ?2007 Microchip Technology Inc.  All rights reserved.
 * Microchip licenses to you the right to use, modify, copy and distribute
 * Software only when embedded on a Microchip microcontroller or digital
 * signal controller, which is integrated into your product or third party
 * product (pursuant to the sublicense terms in the accompanying license
 * agreement).  
 *
 * You should refer to the license agreement accompanying this Software
 * for additional information regarding your rights and obligations.
 *
 * SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS?WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY
 * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
 * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR
 * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION,
 * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT
 * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL,
 * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY
 * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
 * OR OTHER SIMILAR COSTS.
 *
 * Author               Date        Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Anton Alkhimenok		30/05/07	...
 *****************************************************************************
*/

/*
******************************************************************************
* Description: This is a demo program for LVC75Z779 Eval Board Version 1E.
* The microcontroller is PIC24FJ128GA010 on PIC24-Eval-RevC
* stack with a CMOS camera module OV9650_BO. 
* The intention of this project is to develop the drivers for :
* (1) Solomon SSD1928
* (2) OV9650 CMOS camera
* (3) SD card driver for SSD1928 with jpeg encode and decode functions
* 
* Microchip Graphic Library has been used as the GUI because it is a free
* GUI provided that Microchip microcontroller would be used as the host.
* 
* At time of writing (version 23012009), basic support of primitive graphic,
* CMOS camera preview on LCD, and basic IO for SD card has been achieved.
* User may study this source code, compile, and download to the target
* mcu with OV9650_BO and a SD card (1GB for my case) inserted in the microSD
* connection to use this demo. Serial monitoring program such as Hyperterminal
* can be used to learn that the SD card would be initialised successfully, 
* and finally this program will hold at CMOS camera preview. Serial monitoring
* program should be adjusted to 19200bps, 8-n-1 for data monitor.
*
* 
* This project modified for PIC24-Eval RevC from previous PIC24 board version
* There are two changes:
* (1) UART in comm.h changed from uart1 to uart2
* (2) pinout definition under ssd1928.h changed for PIC24 Eval RevC board

* Programmer: John Leung
* Company: TechToys Co.
* Web presence: www.TechToys.com.hk
* Date: 23 Jan 2009
* Version : 23012009
******************************************************************************
*/

#include "MainDemo.h"

// Configuration bits
// Configure fast RC oscillator with PLL and RC15 pin for Fosc/2 function	
_CONFIG2(FNOSC_FRCPLL & OSCIOFNC_OFF)
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF)   // JTAG off, watchdog timer off

///////////////////////////////// FONTS ///////////////////////////////////////
extern FONT_FLASH Font25;
/////////////////////////////// PICTURES ///////////////////////////////////////


int main(void){

CLKDIV = 0x0000;	//FRC postscaler divided by 1 (8MHz from internal RC)
_EI();				//enable interrupt for uart

SHORT width, height;

		uart_init();					//Initialize uart for parameters setup
		DelayMs(1);						//For PLL stablization
		//UART rate at 19200bps, 8-n-1.
		xputs("\nSSD1928 display driver development for PIC24F\n");

	   	ResetDevice();					//For low level pck generation


		//********************************************
		// Demo section for Main Window, simple primitive function performed	
											
		ssd1928_MainWndEnable(FALSE);										//blank display
		ssd1928_MainWndInit(0, SCREEN_HOR_SIZE, 16, 0, 1);					//init display with full physical display width, 16bpp, no rotation, and RGB mode
		ssd1928_FloatWndInit(PAGE_MEM_SIZE, 100, 160, 120, 100, 100, 1);	//init floating window to RGB mode at PAGE_MEM_SIZE
		ssd1928_FocusWnd(0);												//argument '0' indicates the main window

		SetColor(BLACK);
		ClearDevice();
		ssd1928_MainWndEnable(TRUE);
		SetColor(BRIGHTRED);
		ClearDevice();
		DelayMs(2000);
		SetColor(BRIGHTGREEN);
		ClearDevice();
		DelayMs(2000);
		SetColor(BRIGHTBLUE);
		ClearDevice();
		DelayMs(2000);		

        SetFont(&Font25);
        SetColor(BRIGHTGREEN);
        width = GetTextWidth("www.TechToys.com.hk",&Font25);
        height = GetTextHeight(&Font25);

        OutTextXY( (GetMaxX()-width)>>1,
                   (GetMaxY()-height)>>1,
                    "www.TechToys.com.hk");

        DelayMs(1000);

		ssd1928_SDInit(0);

		//********************************************

		//********************************************
		// Demo section for camera module (OV9650 in this example)
		// Only Video Display on the Main Window is supported for 320*240 matrix
		// RGB/YUV Setting Register at REG[1A4h] has to be 0xC0 (i.e. RGB for both Main Window and Floating Window)
		// to preview CMOS camera properly
		camInit();
		camVideoPreview(0,TRUE);
		while(1)
		{
			;
		}//end of while-loop	

}
