LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 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 
52 /*****************************************************************************
53  * Private types/enumerations/variables
54  ****************************************************************************/
55 
56 /* pointer to frame buffer */
57 static uint16_t *framebuffer = (uint16_t *) FRAMEBUFFER_ADDR;
58 
59 /* Counts refresh cycles */
60 static volatile uint32_t frame_rate_counter;
61 
62 #define FONT font_x6x13
63 // #define FONT font_rom8x16
64 // #define FONT font_winfreesys14x16
65 #define DISPLAY_WIDTH BOARD_LCD.PPL
66 #define DISPLAY_HEIGHT BOARD_LCD.LPP
67 
68 /*****************************************************************************
69  * Public types/enumerations/variables
70  ****************************************************************************/
71 
72 /*****************************************************************************
73  * Private functions
74  ****************************************************************************/
75 
76 /* @brief Draw color bars and animate ball */
77 static void lcd_colorbars(void)
78 {
79  SWIM_WINDOW_T win1;
80  COLOR_T clr, *fblog;
81  CHAR str[32];
82  short int idx;
83  UNS_16 xgs, ygs = 0, curx, cury = 0, curym, xidx;
84  int last = frame_rate_counter;
85  int oldballx, oldbally, ballx, bally, balldx, balldy;
86 
87  /* Set LCD frame buffer address */
88  fblog = (COLOR_T *) framebuffer;
89 
90  /* Create a SWIM window */
92  DISPLAY_HEIGHT, fblog, 0, 0,
93  (DISPLAY_WIDTH - 1),
94  (DISPLAY_HEIGHT - 1), 1, WHITE, BLACK, BLACK);
95 
96  /* Compute vertical size for 3 color bars */
97  ygs = DISPLAY_HEIGHT / 3;
98 
99  /* Draw red bars */
100  cury = 0;
101  curx = 0; /* Start cursor at X=0 cursor postion */
102  curym = (ygs - 1); /* End Cursor postion of Y */
103  xgs = DISPLAY_WIDTH / RED_COLORS; /* Divide pixels/line by # of red colors possible in this mode (32 shades red in RGB565) */
104  clr = BLACK; /* start with black then increase to full color across the line */
105  for (xidx = 0; xidx < RED_COLORS; xidx++) {
106  swim_set_pen_color(&win1, clr);
107  for (idx = 0; idx <= xgs; idx++) {
108  swim_put_line(&win1, curx, cury, curx, curym); /* Draw line */
109  curx++;
110  }
111  clr = clr + MINRED; /* increment color value for a gradient,(RGB1:5:6:5) */
112  }
113 
114  /* Draw green bars */
115  cury = cury + ygs; /* Start cursor postion of Y */
116  curx = 0; /* Start cursor postion of X */
117  curym = cury + (ygs - 1); /* End Cursor postion of Y at 1/3 of panel */
118  for (xidx = 0; xidx < GREEN_COLORS; xidx++) {
119  swim_set_pen_color(&win1, clr);
120  for (idx = 0; idx <= xgs; idx++) {
121 
122  swim_set_pen_color(&win1, clr);
123  swim_put_line(&win1, curx, cury, curx, curym);
124  curx++;
125  }
126  clr = clr + MINGREEN;
127  }
128 
129  /* Draw blue bars */
130  cury = cury + ygs;
131  curx = 0;
132  curym = cury + (ygs - 1);
133  xgs = DISPLAY_WIDTH / BLUE_COLORS; //
134  clr = BLACK;
135  for (xidx = 0; xidx < BLUE_COLORS; xidx++) {
136  swim_set_pen_color(&win1, clr);
137  for (idx = 0; idx <= xgs; idx++) {
138  swim_put_line(&win1, curx, cury, curx, curym);
139  curx++;
140  }
141  clr = clr + MINBLUE; /* incement blue color value for a gradient, Blue=bits[4:0] in memory (RGB1:5:6:5 mode) */
142  }
143 
144  /* select the font to use */
145  swim_set_font(&win1, (FONT_T *) &FONT);
146 
147  /* set the pen color to use */
148  swim_set_pen_color(&win1, WHITE);
149 
150  /* Add a title bar */
151  swim_set_title(&win1, "NXP SWIM Graphics Library", BLACK);
152 
153  /* set the location to write text */
154  swim_set_xy(&win1, 60, 160);
155 
156  /* set the pen color to use */
158 
159  /* put the timer tick on the panel */
160  oldballx = ballx = 0;
161  oldbally = bally = 0;
162  balldx = balldy = 9;
163 
164  while (1) {
165  if (frame_rate_counter > last) {
166  ballx += balldx;
167  if (ballx >= win1.xvsize) {
168  balldx *= -1, ballx += balldx;
169  }
170  if (ballx < 0) {
171  balldx *= -1, ballx += balldx;
172  }
173 
174  bally += balldy;
175  if (bally >= win1.yvsize) {
176  balldy *= -1, bally += balldy;
177  }
178  if (bally < 0) {
179  balldy *= -1, bally += balldy;
180  }
181 
182  swim_set_pen_color(&win1, BLACK);
183  swim_set_fill_color(&win1, BLACK);
184  swim_put_diamond(&win1, oldballx, oldbally, 7, 7);
185  swim_set_pen_color(&win1, WHITE);
186  swim_set_fill_color(&win1, RED);
187  swim_put_diamond(&win1, ballx, bally, 7, 7);
188 
189  oldballx = ballx;
190  oldbally = bally;
191 
192  swim_set_xy(&win1, 0, 0);
193  swim_put_text(&win1, "Tick #");
194  sprintf(str, "%d", frame_rate_counter);
195  swim_put_text(&win1, str);
196  swim_put_text(&win1, "\n");
197 
198  last = frame_rate_counter + 10;
199  }
200  }
201 }
202 
203 /*****************************************************************************
204  * Public functions
205  ****************************************************************************/
206 
211 void LCD_IRQHandler(void)
212 {
215 }
216 
221 int main(void)
222 {
223  Board_Init();
224  Board_LCD_Init();
225  Chip_GPIO_Init();
226 
227  /* Initialize LCD, setup frame buffer, and enable vertical comp interrupt */
232 
233  NVIC_EnableIRQ(LCD_IRQn);
234 
235  /* Turn on backlight */
237  lcd_colorbars();
238 
239  while (1) {}
240 }
241