| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
swim_color_bars.c
Go to the documentation of this file.
1 /*
2 * @brief Color bar examples for LCDs using SWIM
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "board.h"
33 #include "lpc_swim.h"
34 #include "lpc_swim_font.h"
35 #include "lpc_rom8x16.h"
36 #include "lpc_winfreesystem14x16.h"
37 #include "lpc_x6x13.h"
38
63 /*****************************************************************************
64 * Private types/enumerations/variables
65 ****************************************************************************/
66
67 /* pointer to frame buffer */
68 static uint16_t *framebuffer = (uint16_t *) FRAMEBUFFER_ADDR;
69
70 /* Counts refresh cycles */
71 static volatile uint32_t frame_rate_counter;
72
73 #define FONT font_x6x13
74 // #define FONT font_rom8x16
75 // #define FONT font_winfreesys14x16
76 #define DISPLAY_WIDTH BOARD_LCD.PPL
77 #define DISPLAY_HEIGHT BOARD_LCD.LPP
78
79 /*****************************************************************************
80 * Public types/enumerations/variables
81 ****************************************************************************/
82
83 /*****************************************************************************
84 * Private functions
85 ****************************************************************************/
86
87 /* @brief Draw color bars and animate ball */
88 static void lcd_colorbars(void)
89 {
90 SWIM_WINDOW_T win1;
91 COLOR_T clr, *fblog;
92 CHAR str[32];
93 short int idx;
94 UNS_16 xgs, ygs = 0, curx, cury = 0, curym, xidx;
95 int last = frame_rate_counter;
96 int oldballx, oldbally, ballx, bally, balldx, balldy;
97
98 /* Set LCD frame buffer address */
99 fblog = (COLOR_T *) framebuffer;
100
101 /* Create a SWIM window */
102 swim_window_open(&win1, DISPLAY_WIDTH,
103 DISPLAY_HEIGHT, fblog, 0, 0,
104 (DISPLAY_WIDTH - 1),
105 (DISPLAY_HEIGHT - 1), 1, WHITE, BLACK, BLACK);
106
107 /* Compute vertical size for 3 color bars */
108 ygs = DISPLAY_HEIGHT / 3;
109
110 /* Draw red bars */
111 cury = 0;
112 curx = 0; /* Start cursor at X=0 cursor postion */
113 curym = (ygs - 1); /* End Cursor postion of Y */
114 xgs = DISPLAY_WIDTH / RED_COLORS; /* Divide pixels/line by # of red colors possible in this mode (32 shades red in RGB565) */
115 clr = BLACK; /* start with black then increase to full color across the line */
116 for (xidx = 0; xidx < RED_COLORS; xidx++) {
117 swim_set_pen_color(&win1, clr);
118 for (idx = 0; idx <= xgs; idx++) {
119 swim_put_line(&win1, curx, cury, curx, curym); /* Draw line */
120 curx++;
121 }
122 clr = clr + MINRED; /* increment color value for a gradient,(RGB1:5:6:5) */
123 }
124
125 /* Draw green bars */
126 cury = cury + ygs; /* Start cursor postion of Y */
127 curx = 0; /* Start cursor postion of X */
128 curym = cury + (ygs - 1); /* End Cursor postion of Y at 1/3 of panel */
129 for (xidx = 0; xidx < GREEN_COLORS; xidx++) {
130 swim_set_pen_color(&win1, clr);
131 for (idx = 0; idx <= xgs; idx++) {
132
133 swim_set_pen_color(&win1, clr);
134 swim_put_line(&win1, curx, cury, curx, curym);
135 curx++;
136 }
137 clr = clr + MINGREEN;
138 }
139
140 /* Draw blue bars */
141 cury = cury + ygs;
142 curx = 0;
143 curym = cury + (ygs - 1);
144 xgs = DISPLAY_WIDTH / BLUE_COLORS; //
145 clr = BLACK;
146 for (xidx = 0; xidx < BLUE_COLORS; xidx++) {
147 swim_set_pen_color(&win1, clr);
148 for (idx = 0; idx <= xgs; idx++) {
149 swim_put_line(&win1, curx, cury, curx, curym);
150 curx++;
151 }
152 clr = clr + MINBLUE; /* incement blue color value for a gradient, Blue=bits[4:0] in memory (RGB1:5:6:5 mode) */
153 }
154
155 /* select the font to use */
156 swim_set_font(&win1, (FONT_T *) &FONT);
157
158 /* set the pen color to use */
159 swim_set_pen_color(&win1, WHITE);
160
161 /* Add a title bar */
162 swim_set_title(&win1, "NXP SWIM Graphics Library", BLACK);
163
164 /* set the location to write text */
165 swim_set_xy(&win1, 60, 160);
166
167 /* set the pen color to use */
168 swim_set_pen_color(&win1, LIGHTGRAY);
169
170 /* put the timer tick on the panel */
171 oldballx = ballx = 0;
172 oldbally = bally = 0;
173 balldx = balldy = 9;
174
175 while (1) {
176 if (frame_rate_counter > last) {
177 ballx += balldx;
178 if (ballx >= win1.xvsize) {
179 balldx *= -1, ballx += balldx;
180 }
181 if (ballx < 0) {
182 balldx *= -1, ballx += balldx;
183 }
184
185 bally += balldy;
186 if (bally >= win1.yvsize) {
187 balldy *= -1, bally += balldy;
188 }
189 if (bally < 0) {
190 balldy *= -1, bally += balldy;
191 }
192
193 swim_set_pen_color(&win1, BLACK);
194 swim_set_fill_color(&win1, BLACK);
195 swim_put_diamond(&win1, oldballx, oldbally, 7, 7);
196 swim_set_pen_color(&win1, WHITE);
197 swim_set_fill_color(&win1, RED);
198 swim_put_diamond(&win1, ballx, bally, 7, 7);
199
200 oldballx = ballx;
201 oldbally = bally;
202
203 swim_set_xy(&win1, 0, 0);
204 swim_put_text(&win1, "Tick #");
205 sprintf(str, "%d", frame_rate_counter);
206 swim_put_text(&win1, str);
207 swim_put_text(&win1, "\n");
208
209 last = frame_rate_counter + 10;
210 }
211 }
212 }
213
214 /*****************************************************************************
215 * Public functions
216 ****************************************************************************/
217
222 void LCD_IRQHandler(void)
223 {
224 frame_rate_counter++;
225 Chip_LCD_ClearInts(LPC_LCD, LCD_INTMSK_VCOMPIM);
226 }
227
232 int main(void)
233 {
234 Board_Init();
235 Board_LCD_Init();
236
237 /* Initialize LCD, setup frame buffer, and enable vertical comp interrupt */
238 Chip_LCD_Init(LPC_LCD, (LCD_Config_T *) &BOARD_LCD);
239 Chip_LCD_SetUPFrameBuffer(LPC_LCD, (void *) framebuffer);
240 Chip_LCD_PowerOn(LPC_LCD);
241 Chip_LCD_EnableInts(LPC_LCD, LCD_INTMSK_VCOMPIM);
242
243 NVIC_EnableIRQ(LCD_IRQn);
244
245 /* Turn on backlight */
246 Board_SetLCDBacklight(1);
247 lcd_colorbars();
248
249 while (1) {}
250 }
251