📄 sn8_usb_module.lib
字号:
mov a, #imanufacturerString$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_string_Product:
mov a,#iproductString_len
b0mov table_length[0],a
mov a,#iproductString_len_H
b0mov table_length[1],a
mov a, #iproductString$L
b0mov table_index[0],a
mov a, #iproductString$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_string_Serialnumber:
mov a,#iserialNumberString_len
b0mov table_length[0],a
mov a,#iserialNumberString_len_H
b0mov table_length[1],a
mov a, #iserialNumberString$L
b0mov table_index[0],a
mov a, #iserialNumberString$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_string_Configuration:
mov a,#iconfigurationString_len
b0mov table_length[0],a
mov a,#iconfigurationString_len_H
b0mov table_length[1],a
mov a, #iconfigurationString$L
b0mov table_index[0],a
mov a, #iconfigurationString$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_string_Interface:
jmp get_descriptor_90
get_descriptor_30: //Interface descriptor
b0bclr USB_Status.5
cmprs a, #USB_INTERFACE_DESCRIPTOR_TYPE
jmp get_descriptor_40
nop
mov a,#InterfaceDescr_length
b0mov table_length[0],a
mov a,#InterfaceDescr_length_H
b0mov table_length[1],a
mov a, #InterfaceDescr$L
b0mov table_index[0],a
mov a, #InterfaceDescr$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_descriptor_40: //Endpoint descriptor
b0bclr USB_Status.5
cmprs a, #USB_ENDPOINT_DESCRIPTOR_TYPE
jmp get_descriptor_50
mov a, #0x03
and a, wValue_L
b0add PCL, a
jmp stall_ep0
jmp endpoint_01
jmp stall_ep0
jmp stall_ep0
endpoint_01:
mov a,#Endpoint1_Descr_length
b0mov table_length[0],a
mov a,#Endpoint1_Descr_length_H
b0mov table_length[1],a
mov a, #Endpoint1_Descr$L
b0mov table_index[0],a
mov a, #Endpoint1_Descr$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_descriptor_50: // HID CLASS descriptor
b0bclr USB_Status.5
cmprs a, #USB_HID_DESCRIPTOR_TYPE
jmp get_descriptor_60
mov a,#0x01
b0mov PROTOCOL,a
b0mov a, wIndex_L
cmprs a, #0x0
jmp stall_ep0
jmp HID_00
HID_00:
mov a,#HID_Descr_length
b0mov table_length[0],a
mov a,#HID_Descr_length_H
b0mov table_length[1],a
mov a, #HID_Descr$L
b0mov table_index[0],a
mov a, #HID_Descr$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_descriptor_60: // combine HID descriptor in standard descriptor
b0bset USB_Status.5
cmprs a, #USB_HID_REPORT_TYPE
jmp get_descriptor_70
b0mov a, wIndex_L
cmprs a, #0x0 //decide which interface to do
jmp stall_ep0 ;support only one interface
jmp interface00
interface00:
mov a,#ReportDesc_length
b0mov table_length[0],a
mov a,#ReportDesc_length_H
b0mov table_length[1],a
mov a, #ReportDesc$L
b0mov table_index[0],a
mov a, #ReportDesc$M
b0mov table_index[1],a
call table_transmit
jmp get_descriptor_90
get_descriptor_70:
jmp stall_ep0
get_descriptor_90:
jmp control_handler_90
// ==================================================================== //
// Set Descriptor //
// ==================================================================== //
set_descriptor:
jmp Request_Not_Support
;call Request_Not_Support
;jmp control_handler_90
// ==================================================================== //
// Get configuration //
// ==================================================================== //
get_configuration:
mov a,#0x0
CALL EP0_FIFO_WR_addr_set
b0mov a, BSetConfiguration
CALL EP0_FIFO_WR_data
mov a, #0x21
b0mov UE0R, a
jmp control_handler_90
// ==================================================================== //
// Set Configuration //
// ==================================================================== //
set_configuration:
clr Halt0
clr Halt1
b0bts1 bSetAddress
jmp _check_config
b0mov a, wValue_L
b0mov BSetConfiguration, a
mov a, #0x80
b0mov UE1R, a
/*
User can follow the USB SPEC 1.1 to check configuration or un-configuration
status, and set the relative endpoint's function enable or disable.
*/
_valid_config:
mov a,#0x20
b0mov UE0R,a
jmp control_handler_90
_check_config:
b0mov a, BSetConfiguration
cmprs a, wValue_L
jmp stall_ep0
jmp _valid_config
// ==================================================================== //
// Get interface //
// ==================================================================== //
get_interface:
b0bts1 bSetAddress
jmp stall_ep0
mov a, #0x0
CALL EP0_FIFO_WR_addr_set ;clear EP address
b0mov a, wIndex_L
cmprs a, #0x0
jmp stall_ep0
jmp get_interface_0
get_interface_0:
mov a, if_AlternateSet_0
jmp get_interface_next
get_interface_next:
CALL EP0_FIFO_WR_data ;clear fifo data
mov a, #0x21
b0mov UE0R, a
jmp control_handler_90
// ==================================================================== //
// Set interface //
// ==================================================================== //
set_interface:
b0bts1 bSetAddress
jmp stall_ep0
clr Halt0
clr Halt1
b0mov a, wIndex_L
cmprs a, #0x0
jmp stall_ep0
jmp set_interface_0
set_interface_0:
b0mov a, wValue_L
b0mov if_AlternateSet_0,a
jmp set_interface_next
set_interface_next:
mov a,#0x20
b0mov UE0R,a
jmp control_handler_90
;***********************************************************************
; END OF Standard request
;***********************************************************************
;***********************************************************************
; START HID request
;***********************************************************************
// ----- HID rquest ----- //
HID_Request:
b0mov a, bRequest
and a, #0x0f
add PCL, a
jmp Request_Not_Support ; 0x00
jmp get_report ; 0x01
jmp get_idle ; 0x02
jmp get_protocol ; 0x03
jmp Request_Not_Support ; 0x04
jmp Request_Not_Support ; 0x05
jmp Request_Not_Support ; 0x06
jmp Request_Not_Support ; 0x07
jmp Request_Not_Support ; 0x08
jmp set_report ; 0x09
jmp set_idle ; 0x0a
jmp set_protocol ; 0x0b
nop ; 0x0c
nop ; 0x0d
nop ; 0x0e
jmp Request_Not_Support
// ==================================================================== //
// Get Report //
// ==================================================================== //
get_report:
b0mov a, bmRequestType ;double check
cmprs a, #10100001b ;get report
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp Request_Not_Support
b0mov a, wValue_H ;get report type
cmprs a, #GET_REPORT_TYPE_INPUT ;TYPE = INPUT
jmp $+2
jmp get_report_input
;*************************************************************************
;Note!! The feature of get report may not necessary in HID,
; user still can design by add the code here!!
;*************************************************************************
// cmprs a, #GET_REPORT_TYPE_FEATURE ;TYPE = FEATURE
// jmp $+2
// jmp get_report_feature
jmp Request_Not_Support
get_report_input:
/*
Note!!
1. Data move from EP (Interrupt IN) to EP0 FIFO
2. User design
*/
b0mov a, wLength_L
and a, #0x0f
or a, #0x20
b0mov UE0R, a
jmp control_handler_90
/*
get_report_feature:
// Send data output to EP0 FIFO, for EP (Interrupt IN)
mov a, #0x80
b0mov UE0R, a ;clear counter and enable USB
jmp control_handler_90
*/
// ==================================================================== //
// Set Report //
// ==================================================================== //
set_report:
b0mov a, bmRequestType
cmprs a, #00100001b ;get report
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp set_report_interface_01;jmp Request_Not_Support
b0mov a, wValue_H ;get report type
cmprs a, #SET_REPORT_TYPE_OUTPUT ;TYPE = OUTPUT
jmp $+2
jmp set_report_output
cmprs a, #GET_REPORT_TYPE_FEATURE ;TYPE = FEATURE
jmp $+2
jmp set_report_feature
jmp Request_Not_Support
set_report_interface_01:
b0mov a, wValue_H ;get report type
cmprs a, #GET_REPORT_TYPE_FEATURE ;TYPE = FEATURE
jmp Request_Not_Support
jmp set_report_feature
set_report_output:
/*
Read data output from EP0 FIFO, for EP (Interrupt out)
*/
b0bset set_report_flag ;To indicate there comes set report
mov a, #0x20
mov UE0R,a
jmp control_handler_90
set_report_feature:
// Read data output from EP0 FIFO, for EP (Interrupt out)
b0bset set_report_feature_flag
mov a, #0x20
b0mov UE0R, a ;clear counter and enable USB
jmp control_handler_90
// ==================================================================== //
// Get IDLE //
// ==================================================================== //
get_idle:
b0mov a, bmRequestType
cmprs a, #10100001b
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp stall_ep0
jmp get_idle_if_00
get_idle_if_00:
mov a,#0x01
b0mov PROTOCOL,a
mov a, #0X0
CALL EP0_FIFO_WR_addr_set
mov a, IDLE_TIME_IF0_ID ;Get IDLE_TIME
CALL EP0_FIFO_WR_data
mov a, #0x21
b0mov UE0R, a ;1 byte send out
jmp control_handler_90
// ==================================================================== //
// Set IDLE //
// ==================================================================== //
set_idle:
b0mov a, bmRequestType
cmprs a, #00100001b
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp stall_ep0
jmp set_idle_00
set_idle_00:
mov a,#0x01
b0mov PROTOCOL,a
b0mov a, wValue_H
mov IDLE_TIME_IF0_ID, a ;set IDLE_TIME
mov a, #0x20
b0mov UE0R, a ;clr counter
jmp control_handler_90
// ==================================================================== //
// Get PROTOCOL //
// ==================================================================== //
get_protocol:
b0mov a, bmRequestType
cmprs a, #10100001b
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp stall_ep0
jmp get_protocol_00
get_protocol_00:
mov a, #0X0
CALL EP0_FIFO_WR_addr_set
mov a, PROTOCOL ;Get IDLE_TIME
CALL EP0_FIFO_WR_data
mov a, #0x21
b0mov UE0R, a ;1 byte send out
jmp control_handler_90
// ==================================================================== //
// Set PROTOCOL //
// ==================================================================== //
set_protocol:
b0mov a, bmRequestType
cmprs a, #00100001b
jmp Request_Not_Support
b0mov a, wIndex_L
cmprs a, #00h ;interface 00
jmp stall_ep0
jmp set_protocol_00
set_protocol_00:
b0mov a, wValue_L
mov PROTOCOL, a ;set PROTOCOL
mov a, #0x20 ;Send no data
b0mov UE0R, a ;clr counter
jmp control_handler_90
;***********************************************************************
; END OF USB HID request command
;***********************************************************************
// Command not support //
// ----- USB EP0 STALL ----- //
Request_Not_Support:
stall_ep0:
mov a,#01000000b ;STALL function
b0mov UE0R,a
jmp Control_Handler_90
;ret
// ---------------------- //
// USB Descriptor table //
// ---------------------- //
include SN8_USB_Descriptor_Table.lib
// ===================================================================== //
// USB End Points function //
// ===================================================================== //
include SN8_USB_EP1.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -