?? mouse45b.asm
字號:
;***********************************************************************
; Cypress Semiconductor
; Mouse Demonstration Design Kit Firmware
;
; Features :
; Three button mouse
; Passes Chapter 9 and Hidview Tests
; Includes Suspend/Resume Feature
; Includes Remote Wakeup Feature
;
; This firmware file is for demonstration purposes only.
; Cypress Semiconductor will not assume any liability for its use.
;=======================================================================
; 5/29/98 wmh v4.5b Made another copy of the mouse firmware
; This version is HID Draft4 compliant (Won't work with OSR2.1)
; Differences between HID Draft3 and Draft4 compliance is only in the order
; in which the class and endpoint descriptors are sent to the host.
; Draft3 : Endpoint first then Class
; Draft4 : Class first then Endpoint
; This means that the only differences will be in the ROM lookup table
; and the GetHIDDescriptor request in the USB_EP0_ISR
;=======================================================================
; 03/10/98 lxa v4.5 Modified control_read routines
; control_read and control_read2 did not properly handle the case where
; the total number of data bytes to send was a multiple of 8. In this
; case, the transmission has to send a zero-length data packet to
; terminate the data stage.
;=======================================================================
; 02/03/98 lxa v4.4 Change in USB_EP0_ISR
; GetStringdescriptor sends string report descriptor.
; Added string descriptors in the ROM lookup table.
;=======================================================================
; 01/06/98 lxa v4.3 Added some new routines.
; Added GetIdle, SetIdle and GetReport.
; Added execute2 and control_read2 to be able to send data from
; a RAM buffer.
;=======================================================================
; 01/08/98 wmh v4.2 Remote Wakeup bug Fix
; Wakeup_ISR changed so that we force J state then clear it before
; doing a Force Resume
;=======================================================================
; 12/01/97 wmh v4.1 Exchanged Endpoint and Class Descriptors in the
; ROM lookup table so that Endpoint comes before Class
; Change in GetHIDDescriptor to accomodate this.
;=======================================================================
; 11/11/97 wmh v4.0 Change in main, ReadButtons and One_msec
; Debouncing the buttons + drag solution
;=======================================================================
; 11/7/97 wmh v3.9 Change in main, ReadButtons, CheckHorizontal
; and CheckVertical to solve count loss in movement
;=======================================================================
; 10/13/97 wmh v3.8 Change in USB_EP0_ISR
; SetConfiguration request was changed so as to enable endpoint 1
; GetReport is stalled
; GetReportDescriptor sends HID Report Descriptor
;========================================================================
; 9/26/97 wmh v3.7 small changes
; One_mSec_ISR and Reset have been changed
;========================================================================
; 8/29/97 wmh v3.5 Remote Wake function added
; Remote Wakeup interrupt has been added (Wakeup_ISR)
; The One_mSec_ISR has been changed to accomodate remote wakeup
;========================================================================
; 8/21/97 wmh v2.4.4 control read correction (Endpoint_0 ISR)
; Fixes the case where the host resends a setup packet
;========================================================================
; 7/9/97 wmh v2.4.3 add features
; Turning the LED's off and on has been added to the suspend/Resume
; subroutine in the One_mSec_ISR
;========================================================================
; 7/3/97 wmh v2.4.2 add features
; Suspend/Resume features have been added
; Main work done in the One_mSec_ISR
;========================================================================
; 6/25/97 wmh v2.1 add features
; changes to allow the code to pass chapter 9 and hidview tests have been
; done. That meant major rework of the endpoint zero interrupt service
; routine (USB_EP0_ISR).
;========================================================================
; 5/15/97 gwg v1.1 minor corrections
; I made a couple of changes to the control_read routine. I deleted the
; redundant I/O write to clear the setup bit in the USB_EP0_RX_Status
; before the "control_read_data_stage".
;
; I also removed an unused jmp after the "wait_control_read" loop that
; could never be executed.
;=======================================================
; 4/28/97 gwg v1.0 major rewrite
; The mouse code still needs support for suspend and
; remote wakeup.
;**************** assembler directives *****************
label: XPAGEON
; I/O ports
Port0_Data: equ 00h ; GPIO data port 0
Port1_Data: equ 01h ; GPIO data port 1
Port0_Interrupt: equ 04h ; Interrupt enable for port 0
Port1_Interrupt: equ 05h ; Interrupt enable for port 1
Port0_Pullup: equ 08h ; Pullup resistor control for port 0
Port1_Pullup: equ 09h ; Pullup resistor control for port 1
; USB ports
USB_EP0_TX_Config: equ 10h ; USB EP0 transmit configuration
USB_EP1_TX_Config: equ 11h ; USB EP1 transmit configuration
USB_Device_Address: equ 12h ; USB device address assigned by host
USB_Status_Control: equ 13h ; USB status and control register
USB_EP0_RX_Status: equ 14h ; USB EP0 receive status
; control ports
Global_Interrupt: equ 20h ; Global interrupt enable
Watchdog: equ 21h ; clear watchdog Timer
Cext: equ 22h ; Cext register
Timer: equ 23h ; free-running Timer
; GPIO Isink registers
Port0_Isink: equ 30h
Port0_Isink0: equ 30h
Port0_Isink1: equ 31h
Port0_Isink2: equ 32h
Port0_Isink3: equ 33h
Port0_Isink4: equ 34h
Port0_Isink5: equ 35h
Port0_Isink6: equ 36h
Port0_Isink7: equ 37h
Port1_Isink: equ 38h
Port1_Isink0: equ 38h
Port1_Isink1: equ 39h
Port1_Isink2: equ 3Ah
Port1_Isink3: equ 3Bh
; control port
Status_Control: equ FFh ; Processor Status and Control
;********** Register constants ************************************
; Processor Status and Control
RunBit: equ 1h ; CPU Run bit
SuspendBits: equ 9h ; Run and suspend bits set
PowerOnReset: equ 10h ; Power on reset bit
USBReset: equ 20h ; USB Bus Reset bit
WatchDogReset: equ 40h ; Watchdog Reset bit
; USB Status and Control
BusActivity: equ 1h ; USB bus activity bit
ForceResume: equ 3h ; force resume to host
; interrupt masks
TIMER_ONLY: equ 4h ; one msec timer
ENUMERATE_MASK: equ 0Ch ; one msec timer
; USB EP0 interrupt
RUNTIME_MASK: equ 1Ch ; one msec timer
; USB EP0 interrupt
; USB EP1 interrupt
WAKEUP_MASK: equ 80h ; Cext wakeup interrupt
; USB EP1 transmit configuration
DataToggle: equ 40h ; Data 0/1 bit
; Phototransistor and LED current values
Ptr_Current: equ 07h ; port0 current setting for PTR
LED_Current: equ 0fh ; port1 current setting for LED
; The procedure to set or choose the PTR and LED current values is :
; 1) Program test chip with values shown above.
; 2) Insert into board with typical LED and PTRs.
; 3) Plug into USB computer to activate mouse.
; 4) Using an oscilloscope on the GPIO Port 0 pins, spin
; the mouse wheel. Observe transitions on PTR pins. Signal
; should swing full scale, with ~50% duty cycle when the
; wheel is moving.
; 5) If signal is "High" for > 50% of the time when wheel is
; moving, reduce the LED_Current value and repeat from step
; 1. If the signal is "Low" for > 50% of the time, increase
; the LED_Current value and repeat. (Alternately, Ptr_Current
; could increased / decreased.)
; 6) Settings are proper when duty cycle is approximately 50%
; on all pins.
;========================================================================
; constant declarations
;========================================================================
; from USB Spec v1.0 from page 175
;------------------------------------------------------------------------
; standard request codes
get_status: equ 0
clear_feature: equ 1
set_feature: equ 3
set_address: equ 5
get_descriptor: equ 6
set_descriptor: equ 7
get_configuration: equ 8
set_configuration: equ 9
get_interface: equ 10
set_interface: equ 11
synch_frame: equ 12
; standard descriptor types
device: equ 1
configuration: equ 2
string: equ 3
interface: equ 4
endpoint: equ 5
; standard feature selectors
endpoint_stalled: equ 0 ; recipient endpoint
device_remote_wakeup: equ 1 ; recipient device
;========================================================================
; from HID Class v1.0 Draft #4
;------------------------------------------------------------------------
; class specific descriptor types from section 7.1 Standard Requests
HID: equ 21h
report: equ 22h
physical: equ 23h
; class specific request codes from section 7.2 Class Specific Requests
get_report: equ 1
get_idle: equ 2
get_protocol: equ 3
set_report: equ 9
set_idle: equ 10
set_protocol: equ 11
;========================================================================
; USB packet constants (debug purposes)
;------------------------------------------------------------------------
setup: equ B4h
in: equ 96h
out: equ 87h
data0: equ C3h
data1: equ D2h
ack: equ 4Bh
nak: equ 5Ah
DISABLE_REMOTE_WAKEUP: equ 0 ; bit[1] = 0
ENABLE_REMOTE_WAKEUP: equ 2 ; bit[1] = 1
BOOT_PROTOCOL: equ 0 ; bit[0] = 0
REPORT_PROTOCOL: equ 1 ; bit[0] = 1
;========================================================================
; data variable assignments
;========================================================================
; control endpoint 0 fifo
endpoint_0: equ 70h ; control endpoint
; definitions for SETUP packets
bmRequestType: equ 70h
bRequest: equ 71h
wValue: equ 72h ; default wValue (8-bits)
wValueHi: equ 73h
wIndex: equ 74h ; default wIndex (8-bits)
wIndexHi: equ 75h
wLength: equ 76h ; default wLength (8-bits)
wLengthHi: equ 77h
; interrupt endpoint 1 fifo
endpoint_1: equ 78h
button_position: equ 78h
horiz_position: equ 79h
vert_position: equ 7Ah
;------------------------------------------------------------------------
; data memory variables
; To support the USB specification.
;------------------------------------------------------------------------
interrupt_mask: equ 20h
port_temp: equ 21h
endp0_data_toggle: equ 22h
loop_counter: equ 23h
horiz_state: equ 24h
vert_state: equ 25h
data_start: equ 26h
data_count: equ 27h
endpoint_stall: equ 28h
remote_wakeup_status: equ 29h ; remote wakeup request
; zero is disabled
; two is enabled
configuration_status: equ 2Ah ; configuration status
; zero is unconfigured
; one is configured
;idle_status: equ 2Bh ; support SetIdle and GetIdle
protocol_status: equ 2Ch ; zero is boot protocol
; one is report protocol
suspend_counter: equ 2Dh ; contains number of idle bus msecs
wakeup_counter: equ 2Eh ; used for 10msec count by Wakeup
wakeup_flag: equ 2Fh ; used to indicate wakeup process
disch_counter: equ 30h ; used to discharge the capacitor
report_buffer: equ 31h ; used by GetReport
; order must be buttons,horizontal,vertical
buttons: equ 31h
horizontal: equ 32h
vertical: equ 33h
button_flag: equ 34h
button1_deb: equ 35h ; debouncing register
new_idle_period: equ 36h ; used for idle period(ms)
prev_idle_period: equ 37h ; used to save the previous idle period
idle_period: equ 38h
idle_period_counter: equ 39h
4ms_counter: equ 40h ; used to count 4ms in 1 ms routine
new_idle_flag: equ 41h ; used to signal a new idle period
;*************** interrupt vector table ****************
ORG 00h
jmp Reset ; reset vector
jmp DoNothing_ISR ; 128us interrupt
jmp One_mSec_ISR ; 1024ms interrupt
jmp USB_EP0_ISR ; endpoint 0 interrupt
jmp USB_EP1_ISR ; endpoint 1 interrupt
jmp Reset ; reserved interrupt
jmp DoNothing_ISR ; general purpose I/0 interrupt
jmp Wakeup_ISR ; wakeup or resume interrupt
;************** program listing ************************
ORG 10h
;*******************************************************
; The 128 uSec interrupt is not used by the mouse code.
; If this interrupt occurs, do nothing except re-enable
; interrupts.
; The GPIO interrupts are not used in this version of
; the firmware.
; The Wakeup interupt is not used, either in this version.
DoNothing_ISR:
push A
mov A, [interrupt_mask]
ipret Global_Interrupt
;*******************************************************
; The Wakeup interrupt is used to force the host to
; resume due to a mouse movement or a button press
Wakeup_ISR:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -