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

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

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

//--------------------------------------------------------------------------
//
// This module implements the ZWheel functionality in the mouse application.
//
//--------------------------------------------------------------------------
// $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Mouse/wheel.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 "appconfig.h"
#include "wheel.h"
#include PLATFORM_H
#include "isr.h"
#include "port.h"


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

#define MOUSE_WHEEL_STATE0        0x01
#define MOUSE_WHEEL_STATE1        0x02

typedef struct
{
    INT8  delta;
    UINT8 last_state[2];

} WHEEL_STATE;


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

static UINT8 wheel_get_state(void);


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

static WHEEL_STATE wheel_state;


//--------------------------------------------------------------------------
// wheel_init
//--------------------------------------------------------------------------

void wheel_init(void)
{
    UINT8 state = 0;


    port_drive_on( MOUSE_ZWHEEL_DRV_PORT, MOUSE_ZWHEEL_1 | MOUSE_ZWHEEL_2 );

    wheel_state.delta = 0;

    wheel_state.last_state[0] = wheel_get_state();
    wheel_state.last_state[1] = wheel_get_state();
    // Get current wheel state
    if( MOUSE_ZWHEEL_PORT & MOUSE_ZWHEEL_1 )
    {
        state |= MOUSE_WHEEL_STATE0;
    }

    if( MOUSE_ZWHEEL_PORT & MOUSE_ZWHEEL_2 )
    {
        state |= MOUSE_WHEEL_STATE1;
    }

    isr_enable(INT_ZWHEEL);
    // Save as history
    wheel_state.last_state[0] = state;
    wheel_state.last_state[1] = state;

    ISR_ENABLE(GPIO_ISR_ZWHEEL_IE_PORT, GPIO_ISR_ZWHEEL_INT);
}


//--------------------------------------------------------------------------
// wheel_get_report
//--------------------------------------------------------------------------

BOOL wheel_get_report(WHEEL_REPORT *report)
{
    M8C_DisableGInt;

        report->z = wheel_state.delta;

        wheel_state.delta = 0;

    M8C_EnableGInt;

    return (report->z == 0) ? FALSE : TRUE;
}


//--------------------------------------------------------------------------
// wheel_power_up
//--------------------------------------------------------------------------

void wheel_power_up(void)
{
    wheel_init();
}


//--------------------------------------------------------------------------
// wheel_power_down
//--------------------------------------------------------------------------

void wheel_power_down(void)
{
    port_drive_off( MOUSE_ZWHEEL_DRV_PORT, MOUSE_ZWHEEL_1 | MOUSE_ZWHEEL_2 );
    
    isr_disable(INT_ZWHEEL);
    ISR_DISABLE(GPIO_ISR_ZWHEEL_IE_PORT, GPIO_ISR_ZWHEEL_INT);
}


//--------------------------------------------------------------------------
// wheel_isr
//--------------------------------------------------------------------------


void wheel_isr(void)
{
    UINT8 state = 0;
    UINT8 last_state;
    UINT8 prev_last_state;
    INT8  delta;
    

    state = wheel_get_state();

    // Get wheel state
    if( MOUSE_ZWHEEL_PORT & MOUSE_ZWHEEL_1 )
    {
        state |= MOUSE_WHEEL_STATE0;
    }

    if( MOUSE_ZWHEEL_PORT & MOUSE_ZWHEEL_2 )
    {
        state |= MOUSE_WHEEL_STATE1;
    }
    
    last_state = wheel_state.last_state[1];
    
    if( state == last_state )
    {
        return;
    }
    
    prev_last_state = wheel_state.last_state[0];

    wheel_state.last_state[0] = last_state;
    wheel_state.last_state[1] = state;
    
    if( prev_last_state == 0 && state == 3 )
    {
        if( last_state == 1 )
        {
            ++wheel_state.delta;
        }
        else if( last_state == 2 )
        {
            --wheel_state.delta;
        }
    }
    else if( prev_last_state == 3 && state == 0 )
    {
        if( last_state == 1 )
        {
            --wheel_state.delta;
        }
        else if( last_state == 2 )
        {
            ++wheel_state.delta;
        }
    }
}


//--------------------------------------------------------------------------
// wheel_get_state
//--------------------------------------------------------------------------

static UINT8 wheel_get_state()
{
    UINT8 reg;
    UINT8 state = 0;

    reg = MOUSE_ZWHEEL_PORT;
    
    if( reg & MOUSE_ZWHEEL_1 )
    {
        state |= MOUSE_WHEEL_STATE0;
    }

    if( reg & MOUSE_ZWHEEL_2 )
    {
        state |= MOUSE_WHEEL_STATE1;
    }

    return state;
}