Difference Analysis Generated by HtmlDiff on 10/26/2004 1:35 PM  

Base file: C:\CY4632_RDK_1_21\Firmware\Source Code\RDK Mouse\testmode.c

Modified file: C:\CY4632_RDK_1_3\Firmware\Source Code\RDK Mouse\testmode.c

//--------------------------------------------------------------------------
//
// This module implements testmodes that can optionally be compiled in for
// the mouse application.
//
//--------------------------------------------------------------------------
// $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Mouse/testmode.c $
// $Modtime: 6/16/04 4:38p10/01/04 1:18p $
// $Revision: 910 $
//--------------------------------------------------------------------------
//
// Copyright 2003-2004, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international 
// treaty provisions. Cypress hereby grants to licensee a personal, 
// non-exclusive, non-transferable license to copy, use, modify, create 
// derivative works of, and compile the Cypress Source Code and derivative 
// works for the sole purpose of creating custom software in support of 
// licensee product to be used only in conjunction with a Cypress integrated 
// circuit as specified in the applicable agreement. Any reproduction, 
// modification, translation, compilation, or representation of this 
// software except as specified above is prohibited without the express 
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, 
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress’ product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------


//--------------------------------------
// Included files
//--------------------------------------

#include "testmode.h"
#include "buttons.h"
#include "timer.h"
#include "mouse.h"
#include "isr.h"
#include "protocol.h"
#include "mfgtest.h"


// Remove complete module if testmodes is not defined
#ifdef MOUSE_TEST_MODES

//--------------------------------------
// Local Definitions and Types
//--------------------------------------

typedef enum
{
    TEST_UNKNOWN = 0,
    TEST_MODE_1,         // MFG Test mode
    TEST_MODE_2,         // Square box draw demo (no pen down)
    TEST_MODE_3,         // USB vector draw demo

} TEST_MODES;


#define BUTTON_POLL_MS    10
#define VECTOR_POLL_MS    10


//--------------------------------------
// Local Function Declarations
//--------------------------------------

static UINT8 test_get_testmode(void);
static void  test_wait_buttons_up(BUTTON_REPORT*);
static void  test_power_up(void);
static void  test_power_down(void);
static void  test_mode_1(void);
static void  test_mode_2(void);
static void  test_mode_3(void);
static void vector_draw(const UINT8*, UINT16);


//--------------------------------------
// Local Definitions
//--------------------------------------


#ifdef MOUSE_TEST_MODE_2
// square vector draw
static const UINT8 square_vector_table[] = 
{
    0x00, 0x1e, 0,
    0x1e, 0x00, 0,
    0x00, 0xe2, 0,
    0xe2, 0x00, 0
};
#endif


#ifdef MOUSE_TEST_MODE_3
// USB vector draw table
static const UINT8 usb_vector_table[] = 
{
    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x05, 0x1E, LEFT_BUTTON_REPORT_BIT,   // draw "W"
    0x05, 0xF1, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x0F, LEFT_BUTTON_REPORT_BIT,
    0x05, 0xE2, 0,                        // pen up
    0x05, 0x0A, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x00, 0x01, LEFT_BUTTON_REPORT_BIT,   // draw "i"
    0x01, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x00, 0xFF, LEFT_BUTTON_REPORT_BIT,
    0xFF, 0x00, 0,                        // pen up
    0x00, 0x05, 0,
    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x00, 0x0F, 0,                        // pen up
    0x05, 0xF1, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x00, 0x0F, LEFT_BUTTON_REPORT_BIT,   // draw "r"
    0x00, 0xF6, LEFT_BUTTON_REPORT_BIT,
    0x05, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0x02, 0x02, 0,                        // pen up
    0x03, 0x03, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x0A, 0x00, LEFT_BUTTON_REPORT_BIT,   // draw "e"
    0xFB, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x00, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x00, 0,                        // pen up
    0x05, 0xE2, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x00, 0x1E, 0,                        // draw "l", pen up
    0x05, 0xF6, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x0A, 0x00, LEFT_BUTTON_REPORT_BIT,   // draw "e"
    0xFB, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x00, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x00, 0,                        // pen up
    0x0C, 0xF3, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0xFE, 0xFE, LEFT_BUTTON_REPORT_BIT,   // draw "s"
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x0A, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xFE, 0xFE, 0,                        // pen up
    0x13, 0xF5, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0xFE, 0xFE, LEFT_BUTTON_REPORT_BIT,   // draw "s"
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x0A, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xFE, 0xFE, 0,                        // pen up
    0x0C, 0xE4, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x00, 0x19, LEFT_BUTTON_REPORT_BIT,   // draw "U"
    0x05, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x0A, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x05, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0x00, 0xE7, 0,                        // pen up
    0x19, 0x05, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0xFB, 0xFB, LEFT_BUTTON_REPORT_BIT,   // draw "S"
    0xF6, 0x00, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x00, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x0A, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x05, 0x05, LEFT_BUTTON_REPORT_BIT,
    0x00, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0x05, LEFT_BUTTON_REPORT_BIT,
    0xF6, 0x00, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0xFB, 0,                        // pen up
    0x19, 0x05, 0,

    0x00, 0x00, LEFT_BUTTON_REPORT_BIT,   // pen down
    0x0F, 0x00, LEFT_BUTTON_REPORT_BIT,   // draw "B"
    0x05, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0x00, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xF1, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x0F, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x05, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0x00, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xFB, 0xFB, LEFT_BUTTON_REPORT_BIT,
    0xF1, 0x00, LEFT_BUTTON_REPORT_BIT,
    0x00, 0x1E, 0,                        // pen up
    0xCE, 0xE2, 0,                        // back to start
    0x97, 0x00, 0
};
#endif


//--------------------------------------------------------------------------
// test_execute
//--------------------------------------------------------------------------

void test_execute(void)
{
    BUTTON_REPORT buttons;
    UINT8 i;

    for( i=0; i<3; i++ )
    {
        timer_delay_incremental( timer_get_time_stamp(), BUTTON_POLL_MS );
        buttons_get_report(&buttons);
    }

    if( (buttons.buttons &  LEFT_BUTTON_REPORT_BIT) &&
        (buttons.buttons & RIGHT_BUTTON_REPORT_BIT) )
    {
        test_power_down();

        switch( test_get_testmode() )
        {

        case TEST_MODE_1:
            test_mode_1();
            break;

        case TEST_MODE_2:
            test_mode_2();
            break;

        case TEST_MODE_3:
            test_mode_3();
            break;

        default:
            break;

        }

        test_power_up();
    }
}


//--------------------------------------------------------------------------
// test_get_testmode
//--------------------------------------------------------------------------

static UINT8 test_get_testmode(void)
{
    BUTTON_REPORT buttons;
    UINT8         mode = TEST_UNKNOWN;


    test_wait_buttons_up(&buttons);

    // Count button presses for mode
    do
    {
        timer_delay_incremental( timer_get_time_stamp(), BUTTON_POLL_MS );
        
        buttons_get_report(&buttons);

        if( buttons.buttons & LEFT_BUTTON_REPORT_BIT )
        {
            ++mode;

            test_wait_buttons_up(&buttons);
        }
    }
    while( (buttons.buttons & RIGHT_BUTTON_REPORT_BIT) == 0 );

    test_wait_buttons_up(&buttons);

    return mode;
}


//--------------------------------------------------------------------------
// test_wait_buttons_up
//--------------------------------------------------------------------------

static void test_wait_buttons_up(BUTTON_REPORT *buttons)
{
    do
    {
        timer_delay_incremental( timer_get_time_stamp(), BUTTON_POLL_MS );
        buttons_get_report(buttons);
    } 
    while( buttons->buttons != 0 );
}


//--------------------------------------------------------------------------
// test_power_up
//--------------------------------------------------------------------------

static void  test_power_up()
{
    mouse_power_up();
}


//--------------------------------------------------------------------------
// test_power_down
//--------------------------------------------------------------------------

static void  test_power_down()
{
    mouse_power_down();
    buttons_init();       // turn the buttons back on
    MOTION_INIT();        // turn off motion detection
}


//--------------------------------------------------------------------------
// test_mode_1
//--------------------------------------------------------------------------
// Manufacturing test mode

static void test_mode_1(void)
{
#ifdef MOUSE_TEST_MODE_1
    MFG_TEST();
#endif
}


//--------------------------------------------------------------------------
// test_mode_2
//--------------------------------------------------------------------------
// Square box vector draw demo (no pen down)
//
// Left button starts and stops drawing.  When not drawing mouse can be
// moved.  In this state, right button exits test mode.
//
// Note: Be sure to turn off acceleration in mouse control panel on PC

static void test_mode_2(void)
{
#ifdef MOUSE_TEST_MODE_2
    vector_draw(square_vector_table, sizeof(square_vector_table));
#endif
}


//--------------------------------------------------------------------------
// test_mode_3
//--------------------------------------------------------------------------
// USB vector draw demo
//
// Left button starts and stops drawing.  When not drawing mouse can be
// moved.  In this state, right button exits test mode.
//
// Note: Be sure to turn off acceleration in mouse control panel on PC

static void test_mode_3(void)
{
#ifdef MOUSE_TEST_MODE_3
    vector_draw(usb_vector_table, sizeof(usb_vector_table));
#endif
}


//--------------------------------------------------------------------------
// vector_draw
//--------------------------------------------------------------------------
// Support fuction for test_mode_2 and test_mode_3

static void vector_draw(const UINT8 *vector_table, UINT16 table_len)
{
#if defined MOUSE_TEST_MODE_2 || defined MOUSE_TEST_MODE_3

    BUTTON_REPORT buttons;
    TIME_STAMP    ts;
    TX_PACKET    *pkt;
    UINT16        idx;
    UINT8         resp;
    UINT8         tx_key = 1;
    UINT8         send_key = 1;


    test_power_up();

    pkt = (TX_PACKET*)protocol_get_tx_pkt();

    do
    {
        idx = 0;
        ts = timer_get_time_stamp();

        buttons_get_report(&buttons);

        if( (buttons.buttons & LEFT_BUTTON_REPORT_BIT) != 0  )
        {
            test_wait_buttons_up(&buttons);

            test_power_down();

            while( (buttons.buttons & LEFT_BUTTON_REPORT_BIT) == 0 )
            {
                idx = (idx >= table_len) ? send_key=1, 0 : idx;

                if( idx == 0 && send_key != 0 )
                {
                    // Send identifier for debug
                    do
                    {
                        pkt->shared.optical.x = tx_key;
                        pkt->shared.optical.y = 0;
                        pkt->combi            = RIGHT_BUTTON_REPORT_BIT;
                        resp = protocol_send_packet(3);
                        timer_delay_msec(VECTOR_POLL_MS);
                    }
                    while( !(resp == DATA_SENT || resp == ACK_DATA) );


                    do
                    {
                        pkt->shared.optical.x = -tx_key;
                        pkt->shared.optical.y = 0;
                        resp = protocol_send_packet(2);
                        timer_delay_msec(VECTOR_POLL_MS);
                    }
                    while( !(resp == DATA_SENT || resp == ACK_DATA) );

                    if( ++tx_key > 0x7f )
                    {
                        tx_key = 1;
                    }

                    send_key = 0;
                }

                ts = timer_get_time_stamp();

                pkt->shared.optical.x = vector_table[idx++];
                pkt->shared.optical.y = vector_table[idx++];
                pkt->combi            = vector_table[idx++];

                resp = protocol_send_packet( (pkt->combi != 0) ? 3 : 2 );

                if( !(resp == DATA_SENT || resp == ACK_DATA) )
                {
                    idx -= 3;
                }

                timer_delay_incremental( ts, VECTOR_POLL_MS );
                
                buttons_get_report(&buttons);
            }

            test_wait_buttons_up(&buttons);

            // Send button up
            pkt->shared.optical.x = 0;
            pkt->shared.optical.y = 0;
            protocol_send_packet( 2 );

            test_power_up();
        }

        if( mouse_get_report(pkt) )
        {
            // Don't send button presses, just X, Y movement
            protocol_send_packet(2);
        }

        timer_delay_incremental( ts, MOUSE_POLL_IN_MS );

    }
    while( (buttons.buttons & RIGHT_BUTTON_REPORT_BIT) == 0 );
    
    test_wait_buttons_up(&buttons);

#endif  // defined MOUSE_TEST_MODE_2 || defined MOUSE_TEST_MODE_3
}

#endif    // MOUSE_TEST_MODES