ts_example.c

来自「Sharp LH7A400 BSP平台无关部分的代码,有很高的参考价值,尤其是系」· C语言 代码 · 共 246 行

C
246
字号
/***********************************************************************
 * $Workfile:   ts_example.c  $
 * $Revision:   1.0  $
 * $Author:   WellsK  $
 * $Date:   Dec 03 2003 13:53:20  $
 *
 * Project: Touchscreen driver example
 *
 * Description:
 *     A touchscreen driver (polled mode) example.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a400/bsps/sdk7a400/examples/ts_polled/ts_example.c-arc  $
 * 
 *    Rev 1.0   Dec 03 2003 13:53:20   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 "sdk7a400_cpld_driver.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 and LCD device handles */
STATIC INT_32 tsdev, lcddev;

/***********************************************************************
 *
 * 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)
{
    INT_32 samples;
    TS_DATA_T tsample;
    SWIM_WINDOW_T win1;
    COLOR_T *fblog;
    CHAR str[32];

    /* 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());

    /* 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;
    }

    /* Perform 3000 samples and display the raw coordinates */
    samples = 0;
    while (samples < 3000)
    {
        /* (Re)enable the touchscreen interrupt */
        ts_ioctl(tsdev, TS_ENABLE_INT, 1);

        /* Perform a touchscreen sample */
        ts_ioctl(tsdev, TS_REQUEST_DATA, 0);

        /* Read the data */
        ts_read(tsdev, &tsample, sizeof(tsample));

        /* Only update if pendown was detected */
        if (tsample.pendown == TRUE)
        {
            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, "    ");

            samples++;
        }

        /* Re-enable the touchscreen interrupt */
        ts_ioctl(tsdev, TS_ENABLE_INT, 1);
    }

    /* Close touchscreen */
    ts_close(tsdev);

    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 + =
减小字号Ctrl + -
显示快捷键?