📄 demo.c
字号:
/***********************************************************************
* $Workfile: demo.c $
* $Revision: 1.0 $
* $Author: AnvikE $
* $Date: Jul 03 2003 17:32:12 $
*
* Project: kev75401 BSP (board support package)
*
* Description:
*
* Revision History:
* $Log:
***********************************************************************
*
* Copyright (c) 2002 Sharp Microelectronics of the Americas
*
* All rights reserved
*
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
**********************************************************************/
/*
* board specific code
* location - [sharpmcu/software/csps/lh754xx/bsps/kev75401/include]
*/
#include "kev75401.h"
/*
* demo specific code
* location - .
*/
#include "demo.h"
/*
* pcm specific code
* location - .
*/
#include "pcm.h"
/*
* board level lcd specific code
* location - .
*/
#include "framebuffer.h"
/*
* chip specific timer0 driver
* location - [sharpmcu/software/csps/lh754xx/include]
*/
#include "lh754xx_timer0_driver.h"
/*
* chip specific timer1/2 driver
* location - [sharpmcu/software/csps/lh754xx/include]
*/
#include "lh754xx_timer_driver.h"
/*
* abl generic window manager
* location - [sharpmcu/software/abl/include]
*/
#include "abl_swim.h"
#include "abl_fonts.h"
#include "abl_swim_font.h"
EXTERN INT_32 pwm0; /* PWM output to the chip */
EXTERN INT_32 pwm1; /* PWM output to the chip */
EXTERN INT_32 tmr0; /* PCM output to the chip */
/* Allocate a couple of window buffers */
SWIM_WINDOW_T window[3];
STATIC UNS_32 clip_is_done = 1;
STATIC void demo_run (void);
STATIC void end_of_clip (void);
/************************************************************************
*
* Function: demo_init
*
* Purpose:
* To initialize the windewing manager task.
*
* Processing:
*
* Parameters:
* None
*
* Outputs:
* None
*
* Returns:
* None
*
* Notes:
*
************************************************************************/
void demo_init (void)
{
/*
* Open the event windows
* win : Preallocated windows structure to fill
* xsize : Physical horizontal dimension of the display
* ysize : Physical vertical dimension of the display
* fbaddr : Address of the display's frame buffer
* xwin_min : Physical window left coordinate
* ywin_min : Physical window top coordinate
* xwin_max : Physical window right coordinate
* ywin_max : Physical window bottom coordinate
* border_width : Width of the window border in pixels
* pcolor : Pen color
* bkcolor : Background color
* fcolor : Fill color
*/
/* Open window 1 */
swim_window_open (&window[0],
DISPLAY_WIDTH,
DISPLAY_HEIGHT,
(COLOR_T*)framebuffer,
DISPLAY_WIDTH-DISPLAY_WIDTH,
DISPLAY_HEIGHT-DISPLAY_HEIGHT,
(DISPLAY_WIDTH>>1)+20,
DISPLAY_HEIGHT>>1,
0,
BLACK,
BLUE,
LIGHTGRAY);
swim_set_title (&window[0], "CONSOLE", RED);
/* Open window 2 */
swim_window_open (&window[1],
DISPLAY_WIDTH,
DISPLAY_HEIGHT,
(COLOR_T*)framebuffer,
DISPLAY_WIDTH-DISPLAY_WIDTH,
(DISPLAY_HEIGHT>>1)+1,
DISPLAY_WIDTH-1,
DISPLAY_HEIGHT-1,
1,
GREEN,
WHITE,
LIGHTGRAY);
swim_set_title (&window[1], "GRAPHICS", BLACK);
/* Open window 3 */
swim_window_open (&window[2],
DISPLAY_WIDTH,
DISPLAY_HEIGHT,
(COLOR_T*)framebuffer,
(DISPLAY_WIDTH>>1)+20,
DISPLAY_HEIGHT-DISPLAY_HEIGHT,
DISPLAY_WIDTH-1,
DISPLAY_HEIGHT>>1,
1,
BLACK,
BLACK,
LIGHTGRAY);
swim_set_title (&window[2], "STRINGS", GREEN);
/* Init the codec */
clip_is_done = 1;
pcm_init_codec ((void*)end_of_clip, PCM_DIFFERENTIAL);
//pcm_init_codec ((void*)end_of_clip, PCM_SINGLE_ENDED);
}
/************************************************************************
*
* Function: demo
*
* Purpose:
* To play pcm audio samples while performing a graphics test.
*
* Processing:
*
* Parameters:
* None
*
* Outputs:
* None
*
* Returns:
* None
*
* Notes:
*
************************************************************************/
void demo (INT_32 hclk)
{
UNS_32 clip = 0;
UNS_32 srate = 0;
UNS_32 nclips = 0;
UNS_32 sys_clk = 0;
UNS_32 period = 0;
UNS_32 subperiod = 0;
UNS_32 filter_cutoff = 330750;
UNS_32 n_oversamples = 0;
COLOR_T colors0[] = {GREEN, YELLOW, BLACK};
/* system clock */
sys_clk = hclk/2;
/* get the max number of clips */
nclips = pcm_get_max_clips ();
/* Start the demo loop */
while (1)
{
/* look for a touchscreen event to indicate start of the
sound demo */
if (clip_is_done == 1)
{
DELAY(500000);
/* reset the sound clip state flag */
clip_is_done = 0;
/* update the console window */
swim_set_pen_color
(&window[0], colors0[clip]);
swim_put_text
(&window[0], (CHAR*)pcm_get_clip_name (clip));
swim_set_pen_color
(&window[0], colors0[1]);
/* n samples per second */
srate = pcm_get_sample_rate (clip);
/* n counts per period */
period = sys_clk/srate;
/* calulate the number of oversamples */
n_oversamples = filter_cutoff/srate;
/* n sub periods per period */
subperiod = period/n_oversamples;
/* n bits of resolution max */
timer0_ioctl (tmr0, TIMER_SET_CMP1, period);
/* n bits of resolution max div n oversamples */
timer_ioctl (pwm0, TIMER_SET_CMP1, subperiod);
/* Set the PWM duty cycle to 100% as the default */
timer_ioctl (pwm0, TIMER_SET_CMP0, subperiod+1);
/* 11 bits of resolution max */
timer_ioctl (pwm1, TIMER_SET_CMP1, subperiod);
/* Set the PWM duty cycle to 100% as the default */
timer_ioctl (pwm1, TIMER_SET_CMP0, subperiod+1);
/* Play the sound clip */
pcm_start_codec (clip, sys_clk, n_oversamples);
/* Update the next clip to be played */
clip++;
if (clip > (nclips-2))
{
clip = 0;
}
}
/* run the demo */
demo_run ();
}
}
/************************************************************************
*
* Function: end_of_clip
*
* Purpose:
* To tell the demo that the current clip is finished.
*
* Processing:
*
* Parameters:
* None
*
* Outputs:
* None
*
* Returns:
* None
*
* Notes:
*
************************************************************************/
STATIC void end_of_clip (void)
{
clip_is_done = 1;
/* stop the codec */
pcm_stop_codec ();
/* update the console window */
swim_set_pen_color(&window[0], WHITE);
swim_put_text (&window[0], "Finished pcm sound clip\n");
}
/************************************************************************
*
* Function: demo_run
*
* Purpose:
* To start the window manager task.
*
* Processing:
*
* Parameters:
* None
*
* Outputs:
* None
*
* Returns:
* None
*
* Notes:
*
************************************************************************/
STATIC void demo_run (void)
{
static INT_32 xa;
INT_32 tempx;
INT_32 tempy;
static UNS_32 color = 0;
static COLOR_T colors1[] = {BLUE, BLUE, BLUE, BLUE, BLUE,
GREEN, GREEN, GREEN, GREEN, GREEN,
RED, RED, RED, RED, RED};
SWIM_WINDOW_T* pwin = (SWIM_WINDOW_T*)&window[1];
for (xa = 0; xa < (pwin->yvsize/2); xa++)
{
tempx = pwin->xvsize - xa - 1;
tempy = pwin->yvsize - xa - 1;
if (color == 15)
{
color = 0;
}
else
{
color++;
}
swim_set_pen_color (pwin, colors1[color]);
swim_put_line (pwin, xa, xa, tempx, xa);
swim_put_line (pwin, tempx, xa, tempx, tempy);
swim_put_line (pwin, tempx, tempy, xa, tempy);
swim_put_line (pwin, xa, tempy, xa, xa);
}
/* Update window 2 */
swim_set_pen_color(&window[2], colors1[color]);
swim_put_text (&window[2], "TEST STRING 0\n");
for (xa = (pwin->yvsize/2); xa > 0; xa--)
{
tempx = pwin->xvsize - xa - 1;
tempy = pwin->yvsize - xa - 1;
if (color == 15)
{
color = 0;
}
else
{
color++;
}
swim_set_pen_color (pwin, colors1[color]);
swim_put_line (pwin, xa, xa, tempx, xa);
swim_put_line (pwin, tempx, xa, tempx, tempy);
swim_put_line (pwin, tempx, tempy, xa, tempy);
swim_put_line (pwin, xa, tempy, xa, xa);
}
/* Update window 2 */
swim_set_pen_color(&window[2], colors1[color]);
swim_put_text (&window[2], "TEST STRING 1\n");
for (xa = 0; xa < (pwin->yvsize/2); xa++)
{
tempy = pwin->xvsize + xa - 1;
tempx = pwin->yvsize + xa - 1;
if (color == 15)
{
color = 0;
}
else
{
color++;
}
swim_set_pen_color (pwin, colors1[color]);
swim_put_line (pwin, xa, xa, tempx, xa);
swim_put_line (pwin, tempx, xa, tempx, tempy);
swim_put_line (pwin, tempx, tempy, xa, tempy);
swim_put_line (pwin, xa, tempy, xa, xa);
}
/* Update window 2 */
swim_set_pen_color(&window[2], colors1[color]);
swim_put_text (&window[2], "TEST STRING 2\n");
for (xa = (pwin->yvsize/2); xa > 0; xa--)
{
tempy = pwin->xvsize + xa - 1;
tempx = pwin->yvsize + xa - 1;
if (color == 15)
{
color = 0;
}
else
{
color++;
}
swim_set_pen_color (pwin, colors1[color]);
swim_put_line (pwin, xa, xa, tempx, xa);
swim_put_line (pwin, tempx, xa, tempx, tempy);
swim_put_line (pwin, tempx, tempy, xa, tempy);
swim_put_line (pwin, xa, tempy, xa, xa);
}
/* Update window 2 */
swim_set_pen_color(&window[2], colors1[color]);
swim_put_text (&window[2], "TEST STRING 3\n");
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -