/*
 *****************************************************************************
 * 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	...
 *****************************************************************************
*/

/*
******************************************************************************
* This is a quality assurance demo for the hardware platform
* PIC24-Eval-B2 Rev B + TY280T-240320-BO Rev 1A
* User required to connect a straight cable from PC's COM PORT to RS232
* connector onboard (J2B) for serial communication. This link is used
* for user interface testing the nandFlash.
* First the LCD shows graphics with the same routine from Microchip
* for Primitive demo, then nandFlash demo is entered with RS232 link.
* The baud rate is 19200bps, no parity, 1-stop bit, no handshake.
* Follow command on Hyperterminal to test nandFlash and Esc to exit nandFlash part.
*
* Programmer : John Leung (www.TechToys.com.hk)
* Date: 18th June 2008
******************************************************************************
*/

/*
******************************************************************************
* 1st Aug 08
* This project was used as the backbone for SSD1928 driver development
* Add _gpioStatus for ssd1928¡¦s SPI
******************************************************************************
*/

/*
******************************************************************************
* 10th Aug 2008
* Introduction of 
* 1) BYTE _page for SetActivePage(page) & SetVisualPage(page)
* 2) DWORD _line_mem_pitch for LINE_MEM_PITCH, change all LINE_MEM_PITCH
*		constants to variable _line_mem_picth
* 3) Change PutPixel(x,y) for _line_mem_pitch
* 4) SetLinePitch(pitch) for InitGraph() under primitive.c
* 5) Change Bar() for _line_mem_pitch
* 6) PAGE_MEM_SIZE for SCREEN_HOR_SIZE*SCREEN_VER_SIZE*2 under ssd1928.h
* 7) floating window definitions
******************************************************************************
*/

/*
******************************************************************************
* 11th Aug 2008
******************************************************************************
*/

/*
******************************************************************************
* Date: 25th Aug 2008
* Add support for uart debug for camera
******************************************************************************
*/

/*
******************************************************************************
* Date: 4th Sept 2008
* Change MCLK from 80MHz to 72MHz for camera requires 24MHz (72/3).
*
******************************************************************************
*/

/*
******************************************************************************
* Date: 5th Sept 2008
* Modified ssd1928_MainWndInit(...)
*
******************************************************************************
*/

/*
******************************************************************************
* Date: 22nd Sept 2008
* Modified ov7660.c
* Register 0x1E of 0v7660 is an important register to set. Somehow this value at bit[3:0] is a secret
* Bit value for bit[0] = 0 doesn't work , but only bit[0]=1 works for my case!

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

/*
******************************************************************************
* 28th Sept 2008
* Added GetRegW(index) under ssd1928.c but it is not tested yet.
* No sd card read file function under ssd1928_jpeg_decode_header(JPEG_DECODE *jpeg)
* which is necessary for the original code
* need to complete ssd1928_jpeg_decode_data(JPEG_DECODE *jpeg) by finishing
* 1. SSD_MEM_WSEEK
* 2. SSD_MEM_WRITEB
* need to finish by finishing ssd1928_jpeg_decode_wait(JPEG_DECODE *jpeg)
* 1. SSD_MEMWB first
******************************************************************************
*/

/*
******************************************************************************
* 30th Sept 2008
* 1) Tested GetRegW(WORD index) with the register at REG_FLOAT_WIN_X_END_POS0
*		which seems OK.
* 2) Problem found at jpeg_decode_data()!
******************************************************************************
*/


/*
******************************************************************************
* 26th Nov 2008
* 1) In order to make CMOS camera OV9650 to work, we need to set the RGB/YUV
*		Setting Register at REG[1A4h] to 0xC0, i.e. RGB mode for both Floating
*		and Main Windows to display CMOS camera preview image properly.
*		Therefore, besides initialization for MainWindow, we also need
*		to initialize the Float Window to RGB mode as well!
******************************************************************************
*/

/*
******************************************************************************
* 28th Nov 2008
* 1) Move low level I/O function prototype incl. 
*		SetRegW(WORD index, WORD value);
*		SetRegL(WORD index, DWORD value);
*		GetRegL(WORD index);
*		to SSD1928.h to solve the pecular error for ssd1928_sdhc.c
******************************************************************************
*/

/*
******************************************************************************
* 19th Dec 2008
* 1) simplified the directory structure by moving all ssd1928 related src files
*		and header files to a folder under \ssd1928 in the project directory
* 2) rename the old directory for ov7660 to camera and create ov9650.c
*		and ov9650.h file inside
* 3) Clean up the project folders, files, and directory for sack of easy
*		code read and follow-up and prepared for higher Microchip Graphic Library e.g. version 1.4
*
* Version ID: 19122008
******************************************************************************
*/

/*
******************************************************************************
* 20th Dec 2008
* 1) Complete the first version for ov9650 CMOS camera driver
* Version ID: 20122008
******************************************************************************
*/

/*
******************************************************************************
* Description: This is a demo program for LVC75Z779 Eval Board Version 1E.
* The microcontroller is PIC24FJ128GA010 on PIC24-Eval-B2 RevB
* 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 20122008), 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.
*  
* Programmer: John Leung
* Company: TechToys Co.
* Web presence: www.TechToys.com.hk
* Date: 20 Dec 2008
* Version : 20122008
******************************************************************************
*/