Advertisement
tr1p1ea

Untitled

Oct 31st, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. ; Sets the baud rate of a compatible USB device
  2. ; Inputs:
  3. ; ix: Serial device struct
  4. ; hl: pointer for setup code
  5. ; Returns:
  6. ; hl: Error or SRL_SUCCESS
  7. set_rate_ct:
  8. ld a,(hl) ; total number of packets
  9. inc hl
  10. ld b,a
  11. .loop:
  12. push bc,hl
  13. ld bc,0
  14. push bc ; transferred
  15. ld bc,50
  16. push bc ; num retries
  17. ex de,hl
  18. ld bc,sizeof setuppkt
  19. add hl,bc
  20. ld bc,(hl)
  21. push bc ; data
  22. push de ; setup
  23. ld bc,0
  24. push bc ; ep addr
  25. ld bc,(xsrl_device.dev)
  26. push bc ; device
  27. call usb_GetDeviceEndpoint
  28. pop bc,bc
  29. push hl ; endpoint
  30. call usb_ControlTransfer
  31. pop bc,bc,bc,bc,bc,de,bc
  32. ld a,l ; returned error code
  33. or a,a
  34. jq nz,.error ; something went wrong
  35. ld hl,sizeof setuppkt + 3
  36. add hl,de ; next setup packet
  37. djnz .loop
  38. ld l,SRL_SUCCESS
  39. ret
  40. .error:
  41. ld l,SRL_ERROR_USB_FAILED
  42. ret
  43.  
  44. default_cdc_setup:
  45. db 1 ; number of packets to transfer
  46. setuppkt $21,$20,$0000,$0000,$0007 ; set baud rate
  47. dl .linecoding ; line coding
  48. .linecoding:
  49. db $80,$25,0,0,0,0,8
  50.  
  51. ch340_setup:
  52. db 7 ; number of packets to transfer
  53. setuppkt $61,$A1,$C29C,$B2B9,$0000 ; serial init
  54. dl 0 ; data
  55. setuppkt $61,$A4,$00DF,$0000,$0000 ; modem on
  56. dl 0 ; data
  57. setuppkt $61,$A4,$009F,$0000,$0000 ; modem call
  58. dl 0 ; data
  59. setuppkt $61,$9A,$2727,$0000,$0000 ; control lines
  60. dl 0 ; data
  61. setuppkt $61,$9A,$1312,$B282,$0000 ; baud factor
  62. dl 0 ; data
  63. setuppkt $61,$9A,$0f2c,$0008,$0000 ; baud offset
  64. dl 0 ; data
  65. setuppkt $61,$9A,$2518,$00c3,$0000 ; baud low
  66. dl 0 ; data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement