/**
 * \file
 *
 * \brief Screen dump example
 *
 * Copyright (c) 2011 Atmel Corporation. All rights reserved.
 *
 * \asf_license_start
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an
 *    Atmel microcontroller product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * \asf_license_stop
 *
 */

/**
 * \mainpage
 *
 * \section intro Introduction
 * This simple example shows how to use the \ref gfx_mono_screen_dump
 * for dumping the LCD screen in XPM file format trough the USART.
 *
 * \section files Main files:
 * - example_screen_dump.c: the example itself.
 * - conf_st7565r.h: configuration of the ST7565R controller and interface
 * - conf_board.h: configuration for the board
 * - conf_clock.h: configuration for the clocks used in the device
 * - interface configuration files.
 *
 * \section apiinfo XPM Screen dump API
 * The screen dump service API can be found
 * \ref gfx_mono_screen_dump "here".
 *
 * \section deviceinfo Device Info
 * All AVR devices with a USART can be used. There is no need for the physical
 * LCD to be present to use this function. As this function will only rely on a
 * framebuffer. If using the ST7565R LCD in serial mode a local framebuffer will
 * always be created due to that one can not read data back from the LCD.
 *
 * \section exampledescription Description of the example
 * The phantom display is initialized and different gfx functions are used to
 * produce an "image" which is written to the LCD screen (if present) and at the
 * end the entire screen buffer is dumped trough the USART using the XPM image
 * file format.
 *
 * \section compinfo Compilation Info
 * This software was written for the GNU GCC and IAR for AVR.
 * Other compilers may or may not work.
 *
 * \section contactinfo Contact Information
 * For further information, visit
 * <A href="http://www.atmel.com/">Atmel</A>.\n
 */
#include <board.h>
#include <sysclk.h>
#include <gfx_mono.h>
#include <gfx_mono_screen_dump.h>

uint8_t smiley_data[16] = { 0x3C, 0x42, 0x95, 0xA1, 0xA1, 0x95, 0x42, 0x3C,
		0x3C, 0x42, 0x95, 0xA1, 0xA1, 0x95, 0x42, 0x3C};

int main(void){

	struct gfx_mono_bitmap smiley;

	board_init();
	sysclk_init();
	gfx_mono_init();

	usart_serial_options_t options;
	options.baudrate = 115200;
	options.charlength = USART_CHSIZE_8BIT_gc;
	options.paritytype = USART_PMODE_DISABLED_gc;
	options.stopbits = 0;

	gfx_mono_screen_dump_init(&USARTD0, &options);

	smiley.type = GFX_MONO_BITMAP_RAM;
	smiley.width = 8;
	smiley.height = 16;
	smiley.data.pixmap = smiley_data;

	gfx_mono_draw_vertical_line(30, 4, 28, GFX_PIXEL_SET);
	gfx_mono_draw_horizontal_line(20,4,20, GFX_PIXEL_SET);

	gfx_mono_draw_pixel(10, 10, GFX_PIXEL_SET);

	gfx_mono_generic_put_bitmap(&smiley, 50, 0);

	//vertical line
	gfx_mono_draw_vertical_line(20, 4, 28, GFX_PIXEL_SET);

	gfx_mono_draw_vertical_line(20, 10, 22, GFX_PIXEL_SET);

	gfx_mono_draw_vertical_line(29, 1, 31, GFX_PIXEL_SET);

	gfx_mono_draw_horizontal_line(10,10,20, GFX_PIXEL_SET);

	gfx_mono_draw_horizontal_line(20,10,20, GFX_PIXEL_CLR);

	gfx_mono_draw_horizontal_line(10,13,20, GFX_PIXEL_XOR);

	gfx_mono_draw_line(10,10,100,0, GFX_PIXEL_SET);

	gfx_mono_draw_rect(20, 20, 60, 5, GFX_PIXEL_SET);

	gfx_mono_draw_filled_rect(82, 20, 20, 5, GFX_PIXEL_SET);

	//whole circle
	gfx_mono_draw_circle(50, 16, 8, GFX_PIXEL_SET,GFX_WHOLE);

	//half circle
	gfx_mono_draw_circle(60, 16, 8, GFX_PIXEL_SET,  GFX_QUADRANT3 | GFX_QUADRANT0);

	gfx_mono_draw_filled_circle(100, 16, 8, GFX_PIXEL_SET, 0xFF);

	gfx_mono_draw_circle(64, 16, 15, GFX_PIXEL_SET, 0xFF);

	gfx_mono_draw_filled_circle(64, 16, 14, GFX_PIXEL_XOR, 0xFF);

	gfx_mono_screen_dump();

	while(1);
}
