⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 637mouse.asm

📁 这是使用CYPRESS的7C637xx芯片完成USB鼠标的例子。
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;***************************************************************************
;
; File: 637mouse.asm
; Version: 1.02
; Description: This code provides both PS/2 and USB support for a combi
;              mouse
; Target: Cypress CY7C63743
;
; Overview
;        On power up, the firmware starts executing code at address 0h. 
; After some housekeeping tasks it will determine whether it is attached to
; a USB or a PS2 interface. From that, it will branch either to USB_Main or
; PS2_Main.
;
; PS2 Overview
;        There are four main tasks:
;        * PS2_Main
;        * buttons (common to USB and PS2)
;        * optics (common to USB and PS2)
;        * PS2_DoCommand - processing of PS2 commands from host
;
; PS2_Main
;        This routine initializes the PS2 variables, the IO ports, computes
; the (X,Y) coordinates of mouse movement, the Z-coordinate of wheel motion,
; if needed, determines which button has been pressed and sends out a mouse 
; packet to a host.
;
; PS2_DoCommand
;        When a host wants to send data to the mouse it will drive the
; SDATA line low. The PS2_Main task will continuously poll it and will clock 
; in the data. The latter will be parsed and processed.
;
; USB Overview
;        There are also four main tasks: 
;        * USB_Main
;        * buttons (common to USB and PS2)
;        * optics (common to USB and PS2)
;        * suspend/resume 
;
; USB_Main
;        This routine initializes the USB variables, the IO ports, the mouse
; logic, and the data space. All USB communication occurs on an interrupt 
; basis.
; 
;        Endpoint 0 is used to support Control Transfers and vendor specific
; requests.  During enumeration setup commands are sent to endpoint1 to 
; initialize the USB device and to extract configuration information from the
; device
;
;        Endpoint 1 is used to transfer interrupt data back to the host.  
; In this case we transfer data from the button and optics back to the host. 
;
; Buttons
;        The buttons are polled every millisecond inside the 1ms handler and
; processed in the main task loop.
;
; Optics
;        The optics for mouse mouvement (X,Y,Z) are continuously polled
; and processed in the main task loop.  The quadrature state of the optics
; tells us which direction the mouse is moving in. This data is sent back to
; the host as an offset from the last time the mouse was polled for data by
; the host. Further, for PS/2, the optics will be polled and processed every
; time a bit is sent out or received. This prevents missing any optics count
; during PS2 data transfer.
;
; Suspend/Resume
;        Every millisecond, the USB is polled for activity. If no activity
; occurs for three milliseconds, then it is assumed that the USB is in 
; suspend.  Because this device supports remote wakeup, pressing the buttons
; or moving the mouse causes the firmware to send resume signalling back 
; to the host to wakeup and resume operation.
;
; Endpoint1 packet definition
;     Byte      Usage
;      0    Button Data 7-3 Not used, 2=middle, 1=right, 0=left
;      1    horizontal displacement measured via the optics
;      2    vertical displacement measured via the optics
;      3    z-displacement (wheel) measured via the optics
;
; Revisions:
;    10/09/00: Original Version. Taken from u5combi.asm, v.1.03
;
;    1.00    
;       Fixed the Chapter 9 Test - device remote wakeup
;
;    1.01    
;       Fixed the suspend current requirements by explicitly writing SUSPEND
; and RUN bits of the processor status control register when going into 
; suspend
;
;    1.02
;	Convert TABS into spaces. No code change.
;    
;***************************************************************************
;
;        Copyright 2000 Cypress Semiconductor
;    This code is provided by Cypress as a reference.  Cypress makes no
;    claims or warranties to this firmware's suitability for any 
;    application. 
;
;*************************************************************************** 

    CPU    63743

    XPAGEON

    INCLUDE "637xx.inc"
    INCLUDE "USB.inc"
    INCLUDE "PS2.inc"
    INCLUDE "macros.inc"

;
; Supported Interfaces 
;
USB_MOUSE:                      equ    01h
PS2_MOUSE:                      equ    00h

;
; EP0 In-Transaction State Machine
;
EP0_IN_IDLE:                    equ    00h
CONTROL_READ_DATA:              equ    02h
NO_DATA_STATUS:                 equ    04h
EP0_IN_STALL:                   equ    06h

;
; EP0 No-Data Control Flags
;
ADDRESS_CHANGE_PENDING:         equ    00h
NO_CHANGE_PENDING:              equ    02h

;
; Response Sizes
;
DEVICE_STATUS_LENGTH:           equ    2
DEVICE_CONFIG_LENGTH:           equ    1
ENDPOINT_STALL_LENGTH:          equ    2
INTERFACE_STATUS_LENGTH:        equ    2
INTERFACE_ALTERNATE_LENGTH:     equ    1
INTERFACE_PROTOCOL_LENGTH:      equ    1

;
; General Constants
;
BIT0:                           equ    01h
BIT1:                           equ    02h
BIT2:                           equ    04h
BIT3:                           equ    08h
BIT4:                           equ    10h
BIT5:                           equ    20h
BIT6:                           equ    40h
BIT7:                           equ    80h

;
; Interface Constants - they need to be redefined for a new hardware platform
;
DUAL_DSP_DATA:                  equ    20h      ; top of data stack 
                                                ; (for PUSH/POP instructions)
LEFT_BUTTON_PORT:               equ    PORT0
LEFT_BUTTON_MASK:               equ    BIT7

RIGHT_BUTTON_PORT:              equ    PORT1
RIGHT_BUTTON_MASK:              equ    BIT0

MIDDLE_BUTTON_PORT:             equ    PORT1
MIDDLE_BUTTON_MASK:             equ    BIT1

OPTICS_PORT:                    equ    PORT0

X_LEFT_OPTICS_PORT:             equ    PORT0
X_LEFT_OPTICS_MASK:             equ    BIT0
X_RIGHT_OPTICS_PORT:            equ    PORT0
X_RIGHT_OPTICS_MASK:            equ    BIT1

Y_LEFT_OPTICS_PORT:             equ    PORT0
Y_LEFT_OPTICS_MASK:             equ    BIT2
Y_RIGHT_OPTICS_PORT:            equ    PORT0
Y_RIGHT_OPTICS_MASK:            equ    BIT3

Z_UP_OPTICS_PORT:               equ    PORT0
Z_UP_OPTICS_MASK:               equ    BIT4
Z_DOWN_OPTICS_PORT:             equ    PORT0
Z_DOWN_OPTICS_MASK:             equ    BIT5

LED_PORT:                       equ    PORT0
LED_MASK:                       equ    BIT6
    ;
    ; Normal operating mode - configure buttons as resistive/CMOS
    ; LED as medium sink/CMOS and optics (x,y,z) as HI-Z/CMOS
    ;
PORT0_NORMAL:                   equ    80h
PORT0_MODE1_NORMAL:             equ    80h
PORT0_MODE0_NORMAL:             equ    40h

PORT1_NORMAL:                   equ    03h
PORT1_MODE1_NORMAL:             equ    03h
PORT1_MODE0_NORMAL:             equ    00h

    ;
    ; Suspend operating mode (no wake up) - configure buttons as 
    ; medium sink/CMOS, LED as resistive/CMOS and 
    ; optics (x,y,z) as HI-Z/CMOS
    ;
PORT0_SUSPEND:                  equ    40h
PORT0_MODE1_SUSPEND:            equ    40h
PORT0_MODE0_SUSPEND:            equ    80h

PORT1_SUSPEND:                  equ    00h
PORT1_MODE1_SUSPEND:            equ    00h
PORT1_MODE0_SUSPEND:            equ    03h

    ;
    ; Suspend with remote wake-up - configure buttons as resistive/CMOS
    ; LED as resistive/CMOS and optics (x,y,z) as HI-Z/CMOS
    ;
PORT0_SUSRW:                    equ    0C0h
PORT0_MODE1_SUSRW:              equ    0C0h
PORT0_MODE0_SUSRW:              equ    00h

PORT1_SUSRW:                    equ    03h
PORT1_MODE1_SUSRW:              equ    03h
PORT1_MODE0_SUSRW:              equ    00h

BUTTON_DEBOUNCE:                equ    15       ; 15ms debouce time
MOUSE_PACKET_4:                 equ    4        ; 4-byte mouse packet
MOUSE_PACKET_3:                 equ    3        ; 3-byte mouse packet

;
; Button State Machine
;
NO_BUTTON_DATA_PENDING:         equ    00h
BUTTON_DATA_PENDING:            equ    02h       ; state defined any time
                                                 ; we read a button
;
; Optics State Machine
;
NO_OPTIC_DATA_PENDING:          equ    00h
OPTIC_DATA_PENDING:             equ    02h       ; state defined any time
                                                 ; we read the optics
;
; Event State Machine
;
NO_EVENT_PENDING:               equ    00h
EVENT_PENDING:                  equ    02h       ; state defined any time 
                                                 ; we have mouse packet to
                                                 ; be sent back to host
;
; Transaction Types
;
TRANS_NONE:                     equ    00h
TRANS_CONTROL_READ:             equ    02h
TRANS_CONTROL_WRITE:            equ    04h
TRANS_NO_DATA_CONTROL:          equ    06h

;
; Optics & Button Variables
;
debounceCount:                  equ    20h      ; debounce counters for buttons
currentButtonState:             equ    21h      ; current button status 
lastButtonState:                equ    22h      ; last read value of buttons

opticStatus:                    equ    23h      ; current optic status
xCount:                         equ    24h      ; current optics x state
yCount:                         equ    25h      ; current optics y state
zCount:                         equ    26h      ; current wheel button state
                            
buttonMachine:                  equ    27h      ; buttons/optics state machine
eventMachine:                   equ    28h      ; state machine for sending data back to host
vertMachine:                    equ    29h      ; y-axis state machine
horzMachine:                    equ    2Ah      ; x-axis state machine
zMachine:                       equ    2Bh      ; z-axis (wheel) state machine

lastVertState:                  equ    2Ch      ; last read y-axis optics
lastHorzState:                  equ    2Dh      ; last read x-axis optics
lastZstate:                     equ    2Eh      ; last read z-axis optics
                                                ; (wheel)

temp:                           equ    2Fh      ; temporary register
buttonValue:                    equ    30h
buttonTemp:                     equ    31h

;
; Dual Interface Variables
;
                                          
dualInterfaceMouse:             equ    32h      ; mouse type
delayCounter:                   equ    33h      ; delay counter
dualInterface1ms:               equ    34h      ; 1ms counter

;
; USB Variables
;
suspendCount:                   equ    35h      ; usb suspend counter
ep1DataToggle:                  equ    36h      ; endpoint 1 data toggle
ep0DataToggle:                  equ    37h      ; endpoint 0 data toggle
dataStart:                      equ    38h      ; ROM table address, start of data
dataCount:                      equ    39h      ; data count to return to host
maximumDataCount:               equ    3Ah      ; maximum size of data to return to host
ep0InMachine:                   equ    3Bh      ; endpoint 0 IN state machine
ep0InFlag:                      equ    3Ch      ; endpoint 0 flag for no-data control
configuration:                  equ    3Dh      ; configured/not configured state
remoteWakeup:                   equ    3Eh      ; remote wakeup on/off
ep1Stall:                       equ    3Fh      ; endpoint 1 stall on/off
idle:                           equ    40h      ; HID idle timer
intTemp:                        equ    41h      ; interrupt routine temp variable
idleTimer:                      equ    42h      ; HID idle timer
idlePrescaler:                  equ    43h      ; HID idle prescale (4ms)
ep0Transtype:                   equ    44h      ; Endpoint 0 transaction type
pendingData:                    equ    45h      ; data pending during no-data control
protocol:                       equ    46h      ; mouse protocol boot/report

;
; PS2 Variables - written on top of USB variables
;
ps2Temp0:                       equ    35h

ps2LastValidCmd:                equ    36h
ps2InvalidCmdCount:             equ    37h
ps2ReportRate:                  equ    38h
ps2ReportInterval:              equ    39h
ps2Scale:                       equ    3Ah
ps2StreamMode:                  equ    3Bh
ps2Resolution:                  equ    3Ch
ps2MouseEnabled:                equ    3Dh
ps2Wheel:                       equ    3Eh
ps2WrapMode:                    equ    3Fh

ps2IntervalCount:               equ    40h       ; send back a mouse packet
                                                 ; when this interval expires
sequence:                       equ    41h
saveCmd:                        equ    42h
ps2XmitBuffer:                  equ    43h
ps2XmitBuffer0:                 equ    ps2XmitBuffer+0
ps2XmitBuffer1:                 equ    ps2XmitBuffer+1
ps2XmitBuffer2:                 equ    ps2XmitBuffer+2
ps2XmitBuffer3:                 equ    ps2XmitBuffer+3

ps2XmitBufferLen:               equ    ps2XmitBuffer+4    ; total bytes to send
ps2XmitLen:                     equ    ps2XmitBuffer+5    ; remaining bytes to send


;********************************************************************
;
; Interrupt Vector Table
;
;********************************************************************
    ORG 00h            

jmp    dualMain                         ; power up        
jmp    dualUsbBusReset_ps2Error         ; USB reset / error
jmp    errorHandler                     ; 128us interrupt
jmp    dual1msTimer                     ; 1.024ms interrupt
jmp    dualUsbEndpoint0_ps2Error        ; Endpoint 0 interrupt / error
jmp    dualUsbEndpoint1_ps2Error        ; Endpoint 1 interrupt / error
jmp    errorHandler                     ; Endpoint 2 interrupt
jmp    errorHandler                     ; Reserved
jmp    errorHandler                     ; Capture timer A interrupt Vector
jmp    errorHandler                     ; Capture timer B interrupt Vector
jmp    errorHandler                     ; GPIO interrupt vector
jmp    dualUsbWakeup_ps2Error           ; Wake-up interrupt / error


;********************************************************************
; Error Handler
;
;********************************************************************
    ORG  1Ah

errorHandler: 
    reti                                ; do nothing

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -