📄 hidtherm.asm
字号:
; interrupt happens every time a host sends an
; OUT on endpoint 2. A report is sent from the
; host, so this routine gathers the report and
; processes it.
;
;*******************************************************
Endpoint2:
push A
; check to see if we ACK'd the last OUT token
iord ep2_mode
and A, EP_ACK
jz endpoint2_set_response
; check if we received the packet OK
iord ep2_count
and A, DATA_VALID
jz endpoint2_set_response
; check the data toggle
iord ep2_count
and A, DATA_TOGGLE
cmp A, [ep2_data_toggle]
jnz endpoint2_set_response
; the ACK bit is sticky, so we have to clear it in firmware
mov A, NAK_OUT
iowr ep2_mode
; change data toggle
mov A, 80h
xor [ep2_data_toggle], A
; read the endpoint2 buffer - byte 0 to determine how to set the
; LED. 1 - on, 0 - off. Note that this codes ignores the byte count
; because it doesn't really matter in our case.
mov A, [ep2_dmabuff0]
and A, 01h
jz ready_led_off
ready_led_on:
mov A, ~40h
iowr port1
mov [led_status], A
jmp endpoint2_set_response
ready_led_off:
mov A, FFh
iowr port1
mov [led_status], A
; set the next response to and IN token
endpoint2_set_response:
mov A, [ep2_stall] ; if endpoint is set to stall, then set
cmp A, FFh ; mode to stall
jnz endpoint2_ack
mov A, STALL_IN_OUT ; set endpoint to stall (if stall flag is set)
iowr ep2_mode
jmp endpoint2_done
endpoint2_ack:
mov A, ACK_OUT
iowr ep2_mode
endpoint2_done:
pop A
reti
;**********************************************************
;
; Routine: spi_temp_write
; Purpose: Writes a single byte to the SPI temp sensor
; Parameters: temp_addr - register address
; temp_data - byte to write to register.
;
;**********************************************************
Spi_temp_write:
; raise slave select line
mov A, TEMP_SO | TEMP_SI | TEMP_SCK | EE_CS | RF_IN | TEMP_CS
iowr port0
; write address byte
mov A, [temp_addr]
iowr spi_data ; write address
wait_wreg_byte: ; wait for transfer to finish
iord spi_control
and A, TCMP
jz wait_wreg_byte
; clear the TCMP (transfer complete) bit
mov A, MODE0
iowr spi_control
; write data byte
mov A, [temp_data]
iowr spi_data ; write data
wait_wtdata_byte: ; wait for transfer to finish
iord spi_control
and A, TCMP
jz wait_wtdata_byte
; clear the TCMP (transfer complete) bit
mov A, MODE0
iowr spi_control
; lower slave select line
mov A, TEMP_SO | TEMP_SI | TEMP_SCK | EE_CS | RF_IN
iowr port0
ret
;**********************************************************
;
; Routine: spi_temp_read
; Purpose: Reads a single byte from the SPI temp sensor
; Parameters: temp_addr - register address
; temp_data - byte read from register.
;
;**********************************************************
Spi_temp_read:
; raise slave select line
mov A, TEMP_SO | TEMP_SI | TEMP_SCK | EE_CS | RF_IN | TEMP_CS
iowr port0
; write address byte
mov A, [temp_addr]
iowr spi_data ; write address
wait_rreg_byte: ; wait for transfer to finish
iord spi_control
and A, TCMP
jz wait_rreg_byte
; clear the TCMP (transfer complete) bit
mov A, MODE0
iowr spi_control
; read data address byte
iowr spi_data ; write dummy data (value doesn't matter)
wait_rtdata_byte: ; wait for transfer to finish
iord spi_control
and A, TCMP
jz wait_rtdata_byte
iord spi_data
mov [temp_data], A
; clear the TCMP (transfer complete) bit
mov A, MODE0
iowr spi_control
; lower slave select line
mov A, TEMP_SO | TEMP_SI | TEMP_SCK | EE_CS | RF_IN
iowr port0
ret
;**********************************************************
; USB OPERATION JUMP TABLES
;**********************************************************
XPAGEOFF
ORG 600h
; bmRequestTypes commented out are not used for this device,
; but may be used for your device. They are kept here as
; an example of how to use this jumptable.
bmRequestType_jumptable:
jmp h2d_std_device ; 00
jmp h2d_std_interface ; 01
jmp h2d_std_endpoint ; 02
jmp request_not_supported ; h2d_std_other 03
jmp request_not_supported ; h2d_class_device 04
jmp h2d_class_interface ; 05
jmp request_not_supported ; h2d_class_endpoint 06
jmp request_not_supported ; h2d_class_other 07
jmp request_not_supported ; h2d_vendor_device 08
jmp request_not_supported ; h2d_vendor_interface 09
jmp request_not_supported ; h2d_vendor_endpoint 0A
jmp request_not_supported ; h2d_vendor_other 0B
jmp request_not_supported ; 0C
jmp request_not_supported ; 0D
jmp request_not_supported ; 0E
jmp request_not_supported ; 0F
jmp d2h_std_device ; 10
jmp d2h_std_interface ; 11
jmp d2h_std_endpoint ; 12
jmp request_not_supported ; d2h_std_other 13
jmp request_not_supported ; d2h_class_device 14
jmp request_not_supported ; d2h_class_interface 15
jmp request_not_supported ; d2h_class_endpoint 16
jmp request_not_supported ; d2h_class_other 17
jmp request_not_supported ; d2h_vendor_device 18
jmp request_not_supported ; d2h_vendor_interface 19
jmp request_not_supported ; d2h_vendor_endpoint 1A
jmp request_not_supported ; d2h_vendor_other 1B
jmp request_not_supported ; 1C
jmp request_not_supported ; 1D
jmp request_not_supported ; 1E
jmp request_not_supported ; 1F
h2d_std_device_jumptable:
jmp request_not_supported ; 00
jmp request_not_supported ; clear_device_feature 01
jmp request_not_supported ; 02
jmp request_not_supported ; set_device_feature 03
jmp request_not_supported ; 04
jmp set_device_address ; set_device_address 05
jmp request_not_supported ; 06
jmp request_not_supported ; set_device_descriptor 07
jmp request_not_supported ; 08
jmp set_device_configuration; set_device_configuration 09
h2d_std_interface_jumptable:
jmp request_not_supported ; 00
jmp request_not_supported ; clear_interface_feature 01
jmp request_not_supported ; 02
jmp request_not_supported ; set_interface_feature 03
jmp request_not_supported ; 04
jmp request_not_supported ; 05
jmp request_not_supported ; 06
jmp request_not_supported ; 07
jmp request_not_supported ; 08
jmp request_not_supported ; 09
jmp request_not_supported ; 0A
jmp set_interface_interface ; set_interface_interface 0B
h2d_std_endpoint_jumptable:
jmp request_not_supported ; 00
jmp clear_endpoint_feature ; clear_endpoint_feature 01
jmp request_not_supported ; 02
jmp set_endpoint_feature ; set_endpoint_feature 03
h2d_class_interface_jumptable:
jmp request_not_supported ; set_report 09
jmp request_not_supported ; set_interface_idle ; 0A
jmp request_not_supported ; set_interface_protocol ; 0B
d2h_std_device_jumptable:
jmp get_device_status ; get_device_status 00
jmp request_not_supported ; 01
jmp request_not_supported ; 02
jmp request_not_supported ; 03
jmp request_not_supported ; 04
jmp request_not_supported ; 05
jmp get_device_descriptor ; get_device_descriptor 06
jmp request_not_supported ; 07
jmp get_device_configuration; get_device_configuration 08
d2h_std_interface_jumptable:
jmp get_interface_status ; get_interface_status 00
jmp request_not_supported ; 01
jmp request_not_supported ; 02
jmp request_not_supported ; 03
jmp request_not_supported ; 04
jmp request_not_supported ; 05
jmp get_interface_hid ; get_interface_hid 06
jmp request_not_supported ; 07
jmp request_not_supported ; 08
jmp request_not_supported ; 09
jmp get_interface_interface ; get_interface_interface 0A
ep0_in_jumptable:
jmp request_not_supported
jmp control_read_data_stage
jmp control_write_status_stage
jmp no_data_control_status_stage
ep0_out_jumptable:
jmp request_not_supported
jmp control_read_status_stage
jmp control_write_data_stage
jmp no_data_control_error
get_device_descriptor_jumptable:
jmp request_not_supported
jmp send_device_descriptor
jmp send_configuration_descriptor
jmp send_string_descriptor
jmp send_interface_descriptor
jmp send_endpoint_descriptor
string_jumptable:
jmp language_string
jmp manufacturer_string
jmp product_string
jmp request_not_supported ; serial number string
jmp request_not_supported ; configuration string
;*********************************************************
; DESCRIPTOR TABLES
;*********************************************************
XPAGEOFF
ORG 800h
control_read_table:
; Device Descriptor Table
device_desc_table:
db DEVICE_DESC_SIZE ; bLength (18 bytes)
db DEVICE ; bDescriptorType (device descriptor)
db 10h, 1 ; bcdUSB (ver 1.1)
db 0 ; bDeviceClass (each interface specifies class info)
db 0 ; bDeviceSubClass (not specified)
db 0 ; bDeviceProtocol (not specified)
db 8 ; bMaxPacketSize0 (8 bytes)
db B4h, 04h ; idVendor (Cypress vendor ID)
db 16h, 03h ; idProduct (0x0316)
db 0, 3 ; bcdDevice (3.00)
db 1 ; iManufacturer ("Cypress")
db 2 ; iProduct ("USB Thermometer V3.00")
db 0 ; iSerialNumber (not supported)
db 1 ; bNumConfigurations (1)
; Configuration Descriptor Table
config_desc_table:
db CONFIG_DESC_SIZE ; bLength (9 bytes)
db CONFIGURATION ; bDescriptorType (CONFIGURATION)
db config_desc_table_end - config_desc_table, 0 ; wTotalLength
db 1 ; bNumInterfaces (1)
db 1 ; bConfigurationValue (1)
db 0 ; iConfiguration (not supported)
db BUS_POWERED ; bmAttributes (bus powered)
db 100/2 ; MaxPower (100mA)
interface_desc_table:
db INTERFACE_DESC_SIZE ; bLength (9 bytes)
db INTERFACE ; bDescriptorType (INTERFACE)
db 0 ; bInterfaceNumber (0)
db 0 ; bAlternateSetting (0)
db 2 ; bNumEndpoints (1)
db HID_CLASS ; bInterfaceClass ( HID Class )
db 0 ; bInterfaceSubClass ( not specified)
db 0 ; bInterfaceProtocol ( not specified)
db 0 ; iInterface ( interface string index, not supported)
hid_desc_table:
db HID_DESC_SIZE ; bLength (9 bytes)
db HID ; bDescriptorType (HID)
db 10h, 1 ; bcdHID (1.10)
db 0 ; bCountryCode (US)
db 1 ; bNumDescriptors (1)
db HID_REPORT ; bDescriptorType (HID report)
db hid_report_desc_table_end - hid_report_desc_table , 0 ; wDescriptorLength ( in bytes )
endpoint1_desc_table:
db ENDPOINT_DESC_SIZE ; bLength (7 bytes)
db ENDPOINT ; bDescriptorType (ENDPOINT)
db EP_IN | 1 ; bEndpointAddress (IN endpoint, endpoint 1)
db EP_INT ; bmAttributes (interrupt)
db REPORT_PACKET_SIZE, 0 ; wMaxPacketSize (determinted by HID report inputs)
db 32 ; bInterval (32ms)
endpoint2_desc_table:
db ENDPOINT_DESC_SIZE ; bLength (7 bytes)
db ENDPOINT ; bDescriptorType (ENDPOINT)
db EP_OUT | 2 ; bEndpointAddress (OUT endpoint, endpoint 2)
db EP_INT ; bmAttributes (interrupt)
db 1, 0 ; wMaxPacketSize (determined by HID report output(s))
db 32 ; bInterval (32ms)
config_desc_table_end:
; HID report descriptor table (71 bytes)
hid_report_desc_table:
db hrVUPAGE, 00h, FFh ; vendor defined usage page
db hrUSAGE, 1 ; vendor defined usage #1
db hrCOLLECTION, hrcAPPLICATION ; collection (application)
; button report
db hrUPAGE, hruBUTTON ; usage page (button)
db hrUMIN, 1 ; usage min (1 button)
db hrUMAX, 1 ; usage max (1 button)
db hrLMIN, 0 ; logical min (0)
db hrLMAX, 1 ; logical max (1)
db hrRCOUNT, 1 ; report count (1 report)
db hrRSIZE, 1 ; report size (1 bit)
db hrINPUT, hrDATA | hrVARIABLE | hrABSOLUTE ; input (data, variable, absolute)
db hrRCOUNT, 1 ; report count (1 report)
db hrRSIZE, 7 ; report size (7 bits)
db hrINPUT, hrCONSTANT | hrVARIABLE | hrABSOLUTE ; input (constant, variable, absolute)
; thermometer report
db hrUPAGE, hruGDESKTOP ; usage page (generic desktop)
db hrUSAGE, hrgdVNO ; usage (Vno: non-oriented vector)
db hrLMINex, DAh, 00h ; logical min (218K = -55C)
db hrLMAXex, 89h, 01h ; logical max (393K = 120C)
db hrUNITS, 01h, 00h, 01h, 00h ; units (SI linear: Kelvin)
db hrUEXPS, 0 ; units exponent (0)
db hrRCOUNT, 1 ; report count (1 report)
db hrRSIZE, 16 ; report size (16 bits)
db hrINPUT, hrDATA | hrVARIABLE | hrABSOLUTE ; input (data, variable, absolute)
; LED setting
db hrUPAGE, hruLED ; usage page (LED)
db hrUSAGE, hrlREADY ; usage (ready)
db hrLMIN, 0 ; logical min (0)
db hrLMAX, 1 ; logical max (1)
db hrRCOUNT, 1 ; report count (1 report)
db hrRSIZE, 1 ; report size (1 bit)
db hrOUTPUT, hrDATA | hrARRAY | hrABSOLUTE ; output (data, array, absolute)
db hrRCOUNT, 1 ; report count (1 report)
db hrRSIZE, 7 ; report size (7 bits)
db hrOUTPUT, hrCONSTANT | hrARRAY | hrABSOLUTE ; output (constant, array, absolute)
db hrENDCOLLECT ; end collection
hid_report_desc_table_end:
device_status_table:
db 01h, 00h ; remote wakeup disabled, bus powered
device_configured_table:
db 01h ; device in configured state
device_unconfigured_table:
db 00h ; device in unconfigured state
endpoint_nostall_table:
db 00h, 00h ; endpoint not stalled
endpoint_stall_table:
db 01h, 00h ; endpoint stalled
interface_status_table:
db 00h, 00h ; default response
interface_alternate_table:
db 00h ; only valid alternate setting
ilanguage_string: ; Language String
db ilanguage_string_end - ilanguage_string ; Length
db STRING ; Type (3=string)
db 9 ; Language: English
db 4 ; Sub-language: US
ilanguage_string_end:
imanufacturer_string: ; Manufacturer String
db imanufacturer_string_end - imanufacturer_string ; Length
db STRING ; Type (3=string)
dsu "Cypress"
imanufacturer_string_end:
iproduct_string: ; Product String
db iproduct_string_end - iproduct_string ; Length
db STRING ; Type (3=string)
dsu "USB Thermometer V3.00"
iproduct_string_end:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -