Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Sets the baud rate of a compatible USB device
- ; Inputs:
- ; ix: Serial device struct
- ; hl: pointer for setup code
- ; Returns:
- ; hl: Error or SRL_SUCCESS
- set_rate_ct:
- ld a,(hl) ; total number of packets
- inc hl
- ld b,a
- .loop:
- push bc,hl
- ld bc,0
- push bc ; transferred
- ld bc,50
- push bc ; num retries
- ex de,hl
- ld bc,sizeof setuppkt
- add hl,bc
- ld bc,(hl)
- push bc ; data
- push de ; setup
- ld bc,0
- push bc ; ep addr
- ld bc,(xsrl_device.dev)
- push bc ; device
- call usb_GetDeviceEndpoint
- pop bc,bc
- push hl ; endpoint
- call usb_ControlTransfer
- pop bc,bc,bc,bc,bc,de,bc
- ld a,l ; returned error code
- or a,a
- jq nz,.error ; something went wrong
- ld hl,sizeof setuppkt + 3
- add hl,de ; next setup packet
- djnz .loop
- ld l,SRL_SUCCESS
- ret
- .error:
- ld l,SRL_ERROR_USB_FAILED
- ret
- default_cdc_setup:
- db 1 ; number of packets to transfer
- setuppkt $21,$20,$0000,$0000,$0007 ; set baud rate
- dl .linecoding ; line coding
- .linecoding:
- db $80,$25,0,0,0,0,8
- ch340_setup:
- db 7 ; number of packets to transfer
- setuppkt $61,$A1,$C29C,$B2B9,$0000 ; serial init
- dl 0 ; data
- setuppkt $61,$A4,$00DF,$0000,$0000 ; modem on
- dl 0 ; data
- setuppkt $61,$A4,$009F,$0000,$0000 ; modem call
- dl 0 ; data
- setuppkt $61,$9A,$2727,$0000,$0000 ; control lines
- dl 0 ; data
- setuppkt $61,$9A,$1312,$B282,$0000 ; baud factor
- dl 0 ; data
- setuppkt $61,$9A,$0f2c,$0008,$0000 ; baud offset
- dl 0 ; data
- setuppkt $61,$9A,$2518,$00c3,$0000 ; baud low
- dl 0 ; data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement