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

Base file: C:\CY4632_RDK_1_21\Firmware\Source Code\RDK Bridge\rdk_mouse.asm

Modified file: C:\CY4632_RDK_1_3\Firmware\Source Code\RDK Bridge\rdk_mouse.asm

;****************************************************************************
;
;   file:   rdk_mouse.asm
;   Description: This file contains Mouse application functionality
;                   app_data_received_a
;                   app_idle
;
;   Target:  Cypress CY7C63723 Encore Chip
;   $Header: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Bridge/rdk_mouse.asm 8     7/02/04 3:42p9     10/01/04 2:52p Ary $
;   Version:        1.3.0000
;
;****************************************************************************
; Copyright (2003), Cypress Semiconductor Corporation
; This software is owned by Cypress Semiconductor Corporation (Cypress) and  is
; protected by 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 ("Licensee Product") to be used
; only in conjunction with a Cypress integrated circuit. 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’ products described herein are
; not authorized for use as components in life-support devices.
; This software is protected by and subject to worldwide patent coverage,
; including U.S. and foreign patents. Use may be limited by and subject to the
; Cypress Software License Agreement.
;
;****************************************************************************
                                  
;****************************************************************************
; Global Variables AND  Frameworks Related Variables
;****************************************************************************
IFNDEF DEVICE_RDK_COMBO
null_packet_data:       equ C0h
byte_len_report:        equ C1h
upkey_timer_b:          equ C7h

APP_IDLE_TIMEOUT:       equ 30h
ENDIF ; DEVICE_RDK_COMBO

;****************************************************************************
; app_data_received_b
; Input:
; X Reg = byte_len_report = Byte length of input report (-2 for hdr, chksum)
; A Reg = null_packet_data = additional info
;         0x02 => KeepAlive
; Mouse Report bytes in rx_buffer[], app_buffer[]
;
; Background:
; rx_buffer[] contains the input bytes from the radio including the header.
; app_buffer[] points to the first data byte.
; app_buffer is currently 1 byte offset from rx_buffer to skip the 1 byte
; header, but app_buffer[] should be used to allow changes in the length
; of the header (i.e. to allow it to use A two byte header).
;
; Note: hdr=HeaderByte sc=ScanCode  mod=modifier chk=checksum res=reserved
;       ReptType = report type, ConsumerKeys = Multimedia Keys
;
; Input Examples:
; rx_buffer[]= 45 01 01 ; Move X=1, Y=1
;     app_buffer[]= 01 01 ; Move X=1, Y=1
;     app_buffer[]= 01 01 20 ; Move X=1, Y=1, LButton
;
; Old Format:
; rx_buffer[]= xx 00 01 01 00 ; Move X=1, Y=1
;     app_buffer[]= 00 01 01 00 ; Move X=1, Y=1
;     app_buffer[]= 20 01 01 00 ; Move X=1, Y=1, LButton
;
; Processing:
; Forms the USB report (translate button bits) AND  sends data to USB.
;
; Upkey detection -
; The mouse does not use A special condition (as the keyboard does) to
; identify mouse UpKeys. Instead, A mouse UpKey is A normal mouse report
; with the button values set to 0. The wireless mouse will send this
; normally when A mouse button is released.
; This routine will still handle A null report as an UpKey because
; the UpKey timeout results in A null report being generated.
;
; KeepAlive detection -
; The mouse does use A special condition to represent A KeepAlive message
; when A mouse button is held down.
; For the mouse, the KeepAlive message is A Null Packet header byte with
; the KeepAlive bit set. The calling routine puts this information into
; the A register - null_packet_data.
;
; report_type_battery -
; if (byte_len_report == 4) then report_type_battery
;
; So A sequence would be:
; byte_len_report null_packet_data    app_buffer:
;          2               0     01 01         ; Move X=1, Y=1
;          3               0     01 01 20      ; Move X=1, Y=1, LButton
;          3               0     00 00 00      ; UpKeyMouse
;
; A KeepAlive sequence would be:
;          3               0     00 00 20      ; LButton
;          0               2 ; KeepAlive
;          0               2 ; KeepAlive ...
;          3               0     00 00 00      ; UpKeyMouse
;
; Output:
; Sends USB packet out EP2.
; ep2_dmabuff = data to USB
;
; Output Examples:
; Button mod res key
;     00  01  01  00  ; Move X=1, Y=1
;     01  00  00  00  ; LButton
;     00  00  00  00  ; UpKeyMouse
;
;****************************************************************************
;****************************************************************************
; Global Variables AND  Frameworks Related Variables
;****************************************************************************

app_init_b:
    MOV A, 00h
    MOV [battery_b],A

    MOV A, 01h                      ; At startup, request battery level
    MOV [batt_report_req_b],A
    RET

app_data_received_b:
    DI                              ; Disable interrupts so that the USB doesn't
                                    ; try to send the packet before it is ready
    
    MOV   [null_packet_data],A       ; null_packet_data = AC; ; retain A = null_packet_data
    SWAP  A,X                       ; byte_len_report = IX; ; retain X = byte_len_report
    MOV   [byte_len_report],A     
    SWAP  A,X         

    IOWR  watchdog                  ; WATCHDOG = AC;

init_ep2_out:
    MOV   A,00h                     ; ep2_dmabuff[0] = 0x00;
    MOV   [ep2_dmabuff+0],A     
    MOV   [ep2_dmabuff+1],A         ; ep2_dmabuff[1] = 0x00;
    MOV   [ep2_dmabuff+2],A         ; ep2_dmabuff[2] = 0x00;
    MOV   [ep2_dmabuff+3],A         ; ep2_dmabuff[3] = 0x00;
    MOV   [ep2_dmabuff+4],A         ; ep2_dmabuff[4] = 0x00;

    MOV   A,[byte_len_report]           ; If byte_len_report == 1 
    CMP   A,01h       
    JZ    do_1_byte       

    CMP   A,02h                     ; If byte_len_report == 2
    JZ    do_2_bytes       

    CMP   A,03h                     ; If byte_len_report != 3
    JNZ   ep2_send_end              ; shouldn't happen due to verify routine
    
    MOV   A,[app_buffer+2]          ; byte_len_report == 3, 
    ASR   A                         ; Buttons
    ASR   A           
    ASR   A           
    ASR   A           
    ASR   A           
    AND   A,07h       
    MOV   [ep2_dmabuff+1],A

    MOV   A,[app_buffer+2]          ; ZDeltaBits
    ASL
    ASL
    ASL
    ASR
    ASR
    ASR
    MOV   [ep2_dmabuff+4],A

do_2_bytes:
    MOV   A,[app_buffer+0]          ; X delta
    MOV   [ep2_dmabuff+2],A
    MOV   A,[app_buffer+1]          ; Y delta
    MOV   [ep2_dmabuff+3],A
    JMP   ep2_send                  ; send packet
                  
do_1_byte:
    MOV   A,[configuration]         ; if(configuration)
    CMP   A,00h
    JZ    ep2_send_end

report_type_battery:
    MOV   A,[app_buffer]            ; ep2_dmabuff[1] = app_buffer Battery Level
    AND   A, 0fh                    ; mask-off high-order nibble
    MOV   [battery_b],A             ; save the reading
    JMP   ep2_send_end              ; Don't send this report up the endpoint

ep2_send:
    MOV   A, 01h                    ; ReportID = 1, and
    MOV   [ep2_dmabuff+0],A

    MOV   A,80h                     ; ep2_data_toggle ^= 0x80;
    XOR   [ep2_data_toggle],A
    MOV   A,[ep2_data_toggle]       
    OR    A, 05h                    ; the report length

    IOWR  ep2_count
    MOV   A,ACK_IN                  ; EP_A2_MODE = USB_MODE_ACK_IN;
    IOWR  ep2_mode

ep2_send_end:
    MOV   A,0h                     ; led_timer = 0x01; ; BLINK_BIND diag LED
    MOV   [led_timer],A     

    EI                             ; Enable interrupts
    RET      


;-------------------------------------------------------
;   app_verify_packet_b
;
;-------------------------------------------------------
app_verify_packet_b:
    SWAP A, X                   ; A = packet length
    CMP  A, 04h
    JNC  app_verify_packet_b_failed

    IORD ep2_mode               ; If still waiting for USB to ACK last data, fail
    AND  A, 0Fh     
    CMP  A, ACK_IN
    JZ   app_verify_packet_b_failed                    
    MOV  A, 1
    RET     

app_verify_packet_b_failed:
    MOV A, 0
    RET


IFDEF DEVICE_RDK_MOUSE
app_idle:
app_data_received_a:
    RET 
ENDIF ; DEVICE_RDK_MOUSE

;****************************************************************************
;   endfile:       rdk_mouse.asm
;****************************************************************************