?? ts_example.c
字號:
/***********************************************************************
* $Workfile: ts_example.c $
* $Revision: 1.0 $
* $Author: WellsK $
* $Date: Dec 03 2003 13:53:34 $
*
* Project: Touchscreen driver example
*
* Description:
* A touchscreen driver (interrupt mode) example.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a400/bsps/sdk7a400/examples/ts_int/ts_example.c-arc $
*
* Rev 1.0 Dec 03 2003 13:53:34 WellsK
* Initial revision.
*
*
***********************************************************************
* 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.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "abl_types.h"
#include "abl_irq_fiq.h"
#include "abl_swim.h"
#include "abl_swim_font.h"
#include "abl_arm922t_cp15_driver.h"
#include "lh7a400_clcdc_driver.h"
#include "lh7a400_gpio_driver.h"
#include "lh7a400_int_driver.h"
#include "lh7a400_timer_driver.h"
#include "sdk7a400_cpld_driver.h"
#include "sdk7a400_cpld_int_router.h"
#include "sdk7a400_ts_driver.h"
/* Logical address of LCD frame buffer */
#define FBLOG 0xC1C00000
/* Pick only one display! */
#define LCD_DISPLAY sharp_lq035
//#define LCD_DISPLAY sharp_lq039
//#define LCD_DISPLAY sharp_lq057
//#define LCD_DISPLAY sharp_lq064
//#define LCD_DISPLAY sharp_lq104
//#define LCD_DISPLAY sharp_lq121
/* Touchscreen, timer, and LCD device handles */
STATIC INT_32 tsdev, lcddev, timerdev;
/* Sample counter */
volatile INT_32 samples;
/***********************************************************************
*
* Function: timer_user_interrupt
*
* Purpose: Timer 1 interrupt handler
*
* Processing:
* Clear the touchscreen and timer interrupts.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void timer_user_interrupt(void)
{
/* Re-enable the touchscreen interrupt */
ts_ioctl(tsdev, TS_ENABLE_INT, 1);
/* Clear the timer interrupt */
timer_ioctl(timerdev, TIMER_INT_CLEAR, 0);
}
/***********************************************************************
*
* Function: ts_callback
*
* Purpose: Touchscreen controller driver callback function
*
* Processing:
* This function is called whenever a touchscreen interrupt occurs
* and the touchscreen data has been placed into the queue. All
* this does is increment the sample count.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void ts_callback(void)
{
samples++;
}
/***********************************************************************
*
* Function: make_hex_str
*
* Purpose: Convert a number to a hex string
*
* Processing:
* Using successive nibble computation, compute the base16 value of
* a number into a string and return the string value to the caller.
*
* Parameters:
* str : Where to place the generated string
* iteration: Number to generate a string from
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void make_hex_str(CHAR *str,
UNS_16 iteration)
{
INT_32 cnt = 0;
UNS_8 li;
while (cnt < 4)
{
li = (UNS_8) ((iteration >> ((3 - cnt) * 4)) & 0xF);
if (li > 9)
{
str[cnt] = 'A' + li - 10;
}
else
{
str[cnt] = '0' + li;
}
cnt++;
}
str[cnt] = '\0';
}
/***********************************************************************
*
* Function: c_entry
*
* Purpose: Touchscreen example code without interrupts
*
* Processing:
* Initialize the LCD display and the touchscreen controller.
* While valid touchscreen controller samples are read, display
* the coordinates for the sample on the display. After 3000 samples
* are read, quit the program.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Always returns 1
*
* Notes: None
*
**********************************************************************/
int c_entry(void)
{
TS_DATA_T tsample;
SWIM_WINDOW_T win1;
COLOR_T *fblog;
CHAR str[32];
INT_32 bytesr;
/* Disable interrupts in ARM core */
disable_irq_fiq();
/* Initialize CPLD */
cpld_init();
/* Set virtual address of MMU table (needed for VIC driver
functions) */
cp15_set_vmmu_addr((UNS_32 *) cp15_get_ttb());
/* Initialize interrupt system */
int_initialize(0xC0000000);
/* Install standard IRQ dispatcher at ARM IRQ vector */
int_install_handler(IRQ_VEC, (PFV) irq_dispatcher);
/* Setup LCD muxing for all 16 data bits */
gpio_lcd_signal_select(GPIO_LCDV_0_15);
/* Setup LCD paramaters in the LCD controller */
lcddev = lcd_open(CLCDC, (INT_32) &LCD_DISPLAY);
/* Set frame buffer address */
lcd_ioctl(lcddev, LCD_SET_UP_FB,
(INT_32) cp15_map_virtual_to_physical((UNS_32 *) FBLOG));
/* Make sure shared JTAG signal on PA2 is not active */
gpio_set_data_dir(GPIO_PORT_A, 0x04, GPIO_OUTPUT);
gpio_data_write(GPIO_PORT_A, 0x04);
/* Turn on the LCD backlight */
cpld_enable_lcd_veeen(TRUE);
/* Set color depth to 16 bits per pixel */
lcd_ioctl(lcddev, LCD_SET_BPP, 16);
/* For displays that require more bandwidth, set DMA to request
a transfer on 4 words empty instead of the default 8. This may
help prevent 'display tearing' due to a starved LCD controller */
samples = lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_XSIZE) *
lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_YSIZE) *
sizeof (COLOR_T);
if (samples >= (800 * 600 * 2))
{
/* Displays of 800x600 pixels and 16-bits of color (or larger)
will use faster DMA requests */
lcd_ioctl(lcddev, LCD_DMA_ON_4MT, 1);
}
/* Enable LCD controller and power signals */
lcd_ioctl(lcddev, LCD_PWENABLE, 1);
/* Get virtual address of frame buffer */
fblog = (COLOR_T *) FBLOG;
/* Create a SWIM window */
swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
LCD_DISPLAY.lines_per_panel, fblog, 0,
0, (LCD_DISPLAY.pixels_per_line - 1),
(LCD_DISPLAY.lines_per_panel - 1), 0, WHITE, RED, DARKGRAY);
/* Open the touchscreen interface */
if ((tsdev = ts_open(0, 0)) == 0x00000000)
{
return 0;
}
/* Install touchscreen callback function */
ts_ioctl(tsdev, TS_INSTALL_TSCB, (INT_32) ts_callback);
/* Open timer 1 */
if ((timerdev = timer_open(TIMER1, 0)) == 0x00000000)
{
return 0;
}
/* Setup timer 1 for a 10Hz tick */
timer_ioctl(timerdev, TIMER_SET_USECS, (100 * TIMER_MSEC));
/* Enable timer (starts counting) */
timer_ioctl(timerdev, TIMER_ENABLE, 1);
/* Clear any latched timer interrupts */
timer_ioctl(timerdev, TIMER_INT_CLEAR, 0);
/* Install timer handler in the IRQ dispatcher */
int_install_irq_handler(INT_TC1UINTR, (PFV) timer_user_interrupt);
/* Enable timer interrupt in the interrupt controller */
int_enable(INT_TC1UINTR);
/* Install CPLD handler in the IRQ dispatcher and enable CPLD
interrupts */
cpld_int_router_init();
cpld_int_router_enable(TRUE);
samples = 0;
/* Enable IRQ interrupts in the ARM core */
enable_irq();
/* Perform about 10 seconds of samples and display the raw
coordinates */
while (samples < (10 * 10))
{
/* Read the data */
bytesr = ts_read(tsdev, &tsample, sizeof(tsample));
/* Only update if pendown was detected */
if ((tsample.pendown == TRUE) && (bytesr > 0))
{
swim_put_text_xy(&win1, "Events: ", 5, 5);
make_hex_str(str, samples);
swim_put_text(&win1, str);
swim_put_text(&win1, " ");
swim_put_text_xy(&win1, "X: ", 5, 30);
make_hex_str(str, tsample.xraw);
swim_put_text(&win1, str);
swim_put_text(&win1, " ");
swim_put_text_xy(&win1, "Y: ", 5, 55);
make_hex_str(str, tsample.yraw);
swim_put_text(&win1, str);
swim_put_text(&win1, " ");
}
}
/* Disable interrupts */
cpld_int_router_enable(TRUE);
int_disable(INT_TC1UINTR);
/* Disable interrupts in ARM core */
disable_irq_fiq();
/* Close touchscreen, LCD, and timer */
ts_close(tsdev);
ts_close(timerdev);
ts_close(lcddev);
return 1;
}
#ifndef __GNUC__
/* With ARM and GHS toolsets, the entry point is main() - this will
allow the linker to generate wrapper code to setup stacks, allocate
heap area, and initialize and copy code and data segments. For GNU
toolsets, the entry point is through __start() in the crt0_gnu.asm
file, and that startup code will setup stacks and data */
int main(void)
{
return c_entry();
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -