1 /**
2  * \file
3  *
4  * \brief Monochrome graphic library API header file
5  *
6  * Copyright (c) 2011-2015 Atmel Corporation. All rights reserved.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  *
22  * 3. The name of Atmel may not be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * 4. This software may only be redistributed and used in connection with an
26  *    Atmel microcontroller product.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  * \asf_license_stop
41  *
42  */
43 /*
44  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45  */
46 #ifndef GFX_MONO_TEXT_H_INCLUDED
47 #define GFX_MONO_TEXT_H_INCLUDED
48 
49 #include <stdint.h>
50 
51 #include "compiler.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /**
58  * \ingroup asfdoc_common2_gfx_mono
59  * \defgroup asfdoc_common2_gfx_mono_font GFX Mono Font Library
60  * This modules provides functionality for outputting a monochrome font
61  * to a display.
62  *
63  * \section asfdoc_common2_gfx_mono_font_api_overview API Overview
64  * @{
65  */
66 
67 /**
68  * \brief Valid storage locations for font data
69  *
70  * Add support for fonts in regular ram
71  */
72 enum font_data_type {
73 	/** Font data stored in program/flash memory. */
74 	FONT_LOC_PROGMEM,
75 };
76 
77 /** Storage structure for font meta data. */
78 struct font {
79 	/** Type of storage used for binary font data. See \ref font_data_type. */
80 	enum font_data_type type;
81 	union {
82 		/**
83 		 * Pointer to where the binary font data is stored. This
84 		 * variable is accessed either through hugemem or progmem
85 		 * depending on the value of \a type.
86 		 */
87 #ifdef CONFIG_HAVE_HUGEMEM
88 		hugemem_ptr_t hugemem;
89 #endif
90 		uint8_t PROGMEM_PTR_T progmem;
91 	} data;
92 	/** Width of one font character, in pixels. */
93 	uint8_t width;
94 	/** Height of one font character, in pixels. */
95 	uint8_t height;
96 	/** ASCII value of first character in font set. */
97 	uint8_t first_char;
98 	/** ASCII value of last character in the set. */
99 	uint8_t last_char;
100 };
101 
102 /** \name Strings and characters located in RAM */
103 /** @{ */
104 void gfx_mono_draw_char(const char c, const gfx_coord_t x, const gfx_coord_t y,
105 		const struct font *font);
106 
107 void gfx_mono_draw_string(const char *str, const gfx_coord_t x,
108 		const gfx_coord_t y, const struct font *font);
109 
110 void gfx_mono_get_string_bounding_box(char const *str, const struct font *font,
111 		gfx_coord_t *width, gfx_coord_t *height);
112 
113 /** @} */
114 
115 /** \name Strings located in flash */
116 /** @{ */
117 void gfx_mono_draw_progmem_string(char PROGMEM_PTR_T str, gfx_coord_t x,
118 		gfx_coord_t y, const struct font *font);
119 
120 void gfx_mono_get_progmem_string_bounding_box(char PROGMEM_PTR_T str,
121 		const struct font *font, gfx_coord_t *width,
122 		gfx_coord_t *height);
123 
124 /** @} */
125 
126 /** @} */
127 
128 /**
129  * \page asfdoc_common2_gfx_mono_font_quickstart Quick Start Guide for the mono font service
130  *
131  * This is the quick start guide for the \ref asfdoc_common2_gfx_mono_font
132  * with step-by-step instructions on how to configure and use it for a specific
133  * use case.
134  *
135  * \section asfdoc_common2_gfx_mono_font_quickstart_basic Basic usage of the graphics service
136  * This use case will demonstrate initializing the mono graphics service and
137  * then draw a "Hello world!" sting on the display.
138  *
139  * \section asfdoc_common2_gfx_mono_font_quickstart_depend Dependencies
140  * In order to use this quick start, the following dependencies are needed:
141  * - \ref asfdoc_samd20_system_group
142  * - \ref asfdoc_common2_gfx_mono_font
143  * - \ref conf_sysfont.h Containing the actual font.
144  *
145  * \section asfdoc_common2_gfx_mono_font_basic_usage Usage steps
146  * \subsection gfx_mono_font_basic_usage_code Example code
147  * Add to, e.g., the main function in the application C-file:
148  * \code
149 	     system_init();
150 
151 	     gfx_mono_init();
152 
153 	     gfx_mono_draw_string("Hello world!",0, 0, &sysfont);
154 
155 	     while (1) {
156 
157 	     }
158 \endcode
159  *
160  * \subsection asfdoc_common2_gfx_mono_font_basic_usage_workflow Workflow
161  * -# Initialize system:
162  *  - \code system_init(); \endcode
163  * -# Initialize monochrome graphics service
164  *  - \code gfx_mono_init(); \endcode
165  *  - \note This will call the init function for the low level display
166  *          controller driver and intialize the screen to a cleared background.
167  * -# Draw a string on the screen starting at pixel (0,0)
168  * -  \code gfx_mono_draw_string("Hello world!",0, 0, &sysfont); \endcode
169  * -  \note This uses \ref conf_sysfont.h where sysfont is defines to give the font
170  * to be used on the screen.
171  */
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif /* GFX_MONO_TEXT_H_INCLUDED */
178