pdiusb.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef PDIUSB_H_
  2. #define PDIUSB_H_
  3. #include <stdint.h>
  4. enum pdiusb_ep_index {
  5. PDIUSB_EP_CTLOUT,
  6. PDIUSB_EP_CTLIN,
  7. PDIUSB_EP_EP1OUT,
  8. PDIUSB_EP_EP1IN,
  9. PDIUSB_EP_EP2OUT,
  10. PDIUSB_EP_EP2IN,
  11. PDIUSB_EP_COUNT,
  12. };
  13. #define PDIUSB_EPIDX_OUT(ep_index) ((ep_index) & 0xFEu)
  14. #define PDIUSB_EPIDX_IN(ep_index) ((ep_index) | 0x01u)
  15. /* PDIUSBD12 commands */
  16. #define PDIUSB_CMD_ADDREN 0xD0u /* 8bit command data */
  17. #define PDIUSB_AEN 0x80u
  18. #define PDIUSB_ADDR 0x7Fu
  19. #define PDIUSB_CMD_ENDPEN 0xD8u /* 8bit command data */
  20. #define PDIUSB_GENISOEN 0x01u
  21. #define PDIUSB_CMD_SETMODE 0xF3u /* 16bit command data */
  22. #define PDIUSB_MODE_NOLAZYCLK 0x0002u
  23. #define PDIUSB_MODE_CLKARUN 0x0004u
  24. #define PDIUSB_MODE_IRQM 0x0008u
  25. #define PDIUSB_MODE_SOFTCONN 0x0010u
  26. #define PDIUSB_MODE_EPCFG 0x00C0u
  27. #define PDIUSB_MODE_EPNONISO 0x0000u
  28. #define PDIUSB_MODE_EPISOOUT 0x0040u
  29. #define PDIUSB_MODE_EPISOIN 0x0080u
  30. #define PDIUSB_MODE_EPISOBI 0x00C0u
  31. #define PDIUSB_MODE_CLKDIV 0x0F00u
  32. #define PDIUSB_MODE_CLKDIV_SHIFT 8u
  33. #define PDIUSB_MODE_STO 0x4000u
  34. #define PDIUSB_MODE_SOFIRQ 0x8000u
  35. #define PDIUSB_CMD_DMA 0xFBu /* 8bit command data */
  36. #define PDIUSB_DMA_BURST 0x03u
  37. #define PDIUSB_DMAB_1CYC 0x00u
  38. #define PDIUSB_DMAB_4CYC 0x01u
  39. #define PDIUSB_DMAB_8CYC 0x02u
  40. #define PDIUSB_DMAB_16CYC 0x03u
  41. #define PDIUSB_DMAEN 0x04u
  42. #define PDIUSB_DMADIRWR 0x08u
  43. #define PDIUSB_DMAAUTOREL 0x10u
  44. #define PDIUSB_DMASOFIRQ 0x20u
  45. #define PDIUSB_EP4IRQEN 0x40u
  46. #define PDIUSB_EP5IRQEN 0x80u
  47. #define PDIUSB_CMD_IRQSTAT 0xF4u /* 16bit command data */
  48. #define PDIUSB_IST_MASK 0x01FFu
  49. #define PDIUSB_IST_EP(ep) (1u << (0u + (ep)))
  50. #define PDIUSB_IST_BUSRST (1u << 6u)
  51. #define PDIUSB_IST_SUSPCHG (1u << 7u)
  52. #define PDIUSB_IST_DMAEOT (1u << 8u)
  53. #define PDIUSB_CMD_SELEP(ep) ((uint8_t)(0x00u + (ep))) /* 8bit command data */
  54. #define PDIUSB_SELEPR_FULL 0x01u
  55. #define PDIUSB_SELEPR_STALL 0x02u
  56. #define PDIUSB_CMD_GEPSTAT(ep) ((uint8_t)(0x80u + (ep))) /* 8bit command data */
  57. #define PDIUSB_GEPSTAT_SETUP 0x04u
  58. #define PDIUSB_GEPSTAT_B0FULL 0x20u
  59. #define PDIUSB_GEPSTAT_B1FULL 0x40u
  60. #define PDIUSB_GEPSTAT_STALL 0x80u
  61. #define PDIUSB_CMD_SEPSTAT(ep) ((uint8_t)(0x80u + (ep))) /* 8bit command data */
  62. #define PDIUSB_SEPSTAT_STALL 0x01u
  63. #define PDIUSB_CMD_TRSTAT(ep) ((uint8_t)(0x40u + (ep))) /* 8bit command data */
  64. #define PDIUSB_TRSTAT_TRANSOK 0x01u /* TX/RX success */
  65. #define PDIUSB_TRSTAT_ERR 0x1Eu /* Error code */
  66. #define PDIUSB_TRERR_NOERR 0x00u /* No error */
  67. #define PDIUSB_TRERR_PIDENC 0x02u /* PID encoding error */
  68. #define PDIUSB_TRERR_PIDUNK 0x04u /* PID unknown; encoding is valid */
  69. #define PDIUSB_TRERR_UNEXP 0x06u /* Packet is not of the type expected */
  70. #define PDIUSB_TRERR_TCRC 0x08u /* Token CRC error */
  71. #define PDIUSB_TRERR_DCRC 0x0Au /* Data CRC error */
  72. #define PDIUSB_TRERR_TOUT 0x0Cu /* Time Out error */
  73. #define PDIUSB_TRERR_31337 0x0Eu /* Never happens */
  74. #define PDIUSB_TRERR_UEOP 0x10u /* Unexpected End-Of-Packet */
  75. #define PDIUSB_TRERR_NAK 0x12u /* Sent or received NAK */
  76. #define PDIUSB_TRERR_SSTALL 0x14u /* Sent Stall, a token was RXed, but the EP was stalled */
  77. #define PDIUSB_TRERR_OFLOW 0x16u /* RX buffer overflow error */
  78. #define PDIUSB_TRERR_BITST 0x1Au /* Bitstuff error */
  79. #define PDIUSB_TRERR_WDPID 0x1Eu /* Wrong DATA PID */
  80. #define PDIUSB_TRSTAT_SETUP 0x20u /* Last packet had SETUP token */
  81. #define PDIUSB_TRSTAT_D1PID 0x40u /* Last packet had DATA1 PID */
  82. #define PDIUSB_TRSTAT_PSTATNRD 0x80u /* Previous status not read */
  83. #define PDIUSB_CMD_RWBUF 0xF0u /* 8bit command data */
  84. #define PDIUSB_CMD_CLRBUF 0xF2u /* 0bit command data */
  85. #define PDIUSB_CMD_VALBUF 0xFAu /* 0bit command data */
  86. #define PDIUSB_CMD_ACKSETUP 0xF1u /* 0bit command data */
  87. #define PDIUSB_CMD_RESUME 0xF6u /* 0bit command data */
  88. #define PDIUSB_CMD_CURFRNUM 0xF5u /* 16bit command data */
  89. #define PDIUSB_CMD_GETCHIPID 0xFDu /* 16bit command data */
  90. #define PDIUSB_CHIPID 0x1012u /* Magic ChipID value */
  91. /* CLKOUT speed divisors */
  92. #define PDIUSB_CLKOUT_48MHZ 0u /* 48.00000000000 MHz */
  93. #define PDIUSB_CLKOUT_24MHZ 1u /* 24.00000000000 MHz */
  94. #define PDIUSB_CLKOUT_16MHZ 2u /* 16.00000000000 MHz */
  95. #define PDIUSB_CLKOUT_12MHZ 3u /* 12.00000000000 MHz */
  96. #define PDIUSB_CLKOUT_9p6MHZ 4u /* 9.60000000000 MHz */
  97. #define PDIUSB_CLKOUT_8MHZ 5u /* 8.00000000000 MHz */
  98. #define PDIUSB_CLKOUT_6p9MHZ 6u /* 6.85714285714 MHz */
  99. #define PDIUSB_CLKOUT_6MHZ 7u /* 6.00000000000 MHz */
  100. #define PDIUSB_CLKOUT_5p3MHZ 8u /* 5.33333333333 MHz */
  101. #define PDIUSB_CLKOUT_4p8MHZ 9u /* 4.80000000000 MHz */
  102. #define PDIUSB_CLKOUT_4p4MHZ 10u /* 4.36363636364 MHz */
  103. #define PDIUSB_CLKOUT_4MHZ 11u /* 4.00000000000 MHz */
  104. #define PDIUSB_CLKOUT_3p7MHZ 12u /* 3.69230769231 MHz */
  105. #define PDIUSB_CLKOUT_3p4MHZ 13u /* 3.42857142857 MHz */
  106. #define PDIUSB_CLKOUT_3p2MHZ 14u /* 3.20000000000 MHz */
  107. #define PDIUSB_CLKOUT_3MHZ 15u /* 3.00000000000 MHz */
  108. uint8_t pdiusb_configure_clkout(void);
  109. uint8_t pdiusb_init(void);
  110. void pdiusb_exit(void);
  111. #endif /* PDIUSB_H_ */