iAP.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*************************************************************/
  2. /** @file: usb_device.h
  3. @brief: USB 从机驱动重写,加入iAP协议
  4. @details:
  5. @author: Bingquan Cai
  6. @date: 2013-10-11,09:34
  7. @note:
  8. */
  9. /*************************************************************/
  10. #ifndef _IAP_H_
  11. #define _IAP_H_
  12. #include "generic/typedef.h"
  13. // #include "string.h"
  14. // #include "usb/usb_slave_api.h"
  15. #define IAP2_LINK_EN 1
  16. #define IAP_USE_USB_HID_EN 1
  17. //USB
  18. #define MAXP_SIZE_INTERRUPT_IN 0x40
  19. //IIC crack
  20. #define AUTHENTICATION_CONTROL_STATUS 0x10
  21. #define SIGNATURE_DATA_LENGTH 0x11
  22. #define SIGNATURE_DATA 0x12
  23. #define CHALLENGE_DATA_LENGTH 0x20
  24. #define CHALLENGE_DATA 0x21
  25. #define ACCESSORY_CERTIFICATE_DATA_LENGTH 0x30
  26. #define ACCESSORY_CERTIFICATE_DATA 0x31
  27. //iAP1 and iAP2 COMMON
  28. #define IAP2_VERSIONS 0x02
  29. #define IAP1_VERSIONS 0x01
  30. #define DEFAULT_SEQUENCE_NUM 0x0
  31. #define EXTRA_SEQUENCE_NUM 0x1
  32. //"Dock speaker"
  33. #define ACCESSORY_NAME 0x44, 0x6f, 0x63, 0x6b, 0x20, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x00
  34. //"IPDLI13"
  35. #define ACCESSORY_MODEL_IDENTIFIER 0x49, 0x50, 0x44, 0x4c, 0x49, 0x31, 0x33, 0x00
  36. //"I want it"
  37. #define ACCESSORY_MANUFACTURER 0x49, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, 0x69, 0x74, 0x00
  38. //"iAP Interface"
  39. #define ACCESSORY_SERIALNUMBER 0x69, 0x41, 0x50, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x00
  40. //< hid
  41. #define HID_PREV_FILE USB_AUDIO_PREFILE
  42. #define HID_NEXT_FILE USB_AUDIO_NEXTFILE
  43. #define HID_PP USB_AUDIO_PP
  44. #define HID_PLAY USB_AUDIO_PLAY
  45. #define HID_PAUSE USB_AUDIO_PAUSE
  46. #define HID_VOL_DOWN USB_AUDIO_VOLDOWN
  47. #define HID_VOL_UP USB_AUDIO_VOLUP
  48. //<iap printf
  49. #include "uart.h"
  50. #define IAP_CHIP_PRINTF
  51. #ifdef IAP_CHIP_PRINTF
  52. #define iAP_deg_str(x) puts(x)
  53. #define iAP_printf printf
  54. #define iAP_printf_buf(x, y) put_buf(x, y)
  55. #define iAP_put_u8hex(x) put_u8hex(x)
  56. #define iAP_put_u16hex(x) put_u16hex(x)
  57. #define iAP_put_u32hex(x) put_u32hex(x)
  58. #else
  59. #define iAP_deg_str(x)
  60. #define iAP_printf(...)
  61. #define iAP_printf_buf(x, y)
  62. #define iAP_put_u8hex(x)
  63. #define iAP_put_u16hex(x)
  64. #define iAP_put_u32hex(x)
  65. #endif
  66. #define _xdata
  67. // #define _data
  68. #define _root
  69. #define _no_init
  70. #define _banked_func
  71. ///variable
  72. typedef enum {
  73. iAP_IDLE = 0,
  74. iAP_INTERRUPT,
  75. iAP_BULK_IN,
  76. iAP_BULE_OUT,
  77. } iAP_STATE;
  78. enum {
  79. NO_MFI_CHIP = 0,
  80. MFI_PROCESS_READY,
  81. MFI_PROCESS_STANDBY,
  82. MFI_PROCESS_PASS,
  83. IAP1_LINK_ERR,
  84. IAP1_LINK_SUCC,
  85. IAP2_LINK_ERR,
  86. IAP2_LINK_SUCC,
  87. };
  88. //extern var
  89. extern u8 chip_online_status;
  90. extern u8 mfi_pass_status;
  91. #define apple_mfi_chip_online_lib() chip_online_status
  92. #define apple_link_disable() mfi_pass_status = MFI_PROCESS_STANDBY
  93. #define apple_link_init() mfi_pass_status = MFI_PROCESS_STANDBY
  94. #define apple_mfi_pass_ready_set_api() mfi_pass_status = MFI_PROCESS_READY
  95. #define apple_hid_key_api(key) iap2_hid_key(key)
  96. ///outside call parameter
  97. extern u8 *iAP_var_pRxBuf ;
  98. extern u8 *iAP_var_pTxBuf ;
  99. extern u16 iAP_var_wLength;
  100. extern u8 iAP_send_pkt_self[0x40] ;
  101. extern u8 iAP_receive_pkt_self[0x40] ;
  102. ///inside call
  103. // void my_code_memcpy(u8 *s1, const u8 *s2, u16 len);
  104. #define my_code_memcpy(x,y,z) memcpy(x,(u8 *)y,z)
  105. // u8 my_memcmp(u8 *s1, const u8 *s2, u8 len);
  106. #define my_code_memcmp(x,y,z) memcmp(x,(u8 *)y,z)
  107. u8 iAP_support(void);
  108. u8 apple_mfi_link(void *hdl);
  109. void apple_mfi_unlink(void);
  110. // #define iAP_host_online() (get_usb_online_status() & BIT(0))
  111. // #define iAP_device_online() (get_usb_online_status() & BIT(1))
  112. #define GET_U16L(x) (u8)(x)
  113. #define GET_U16H(x) (u8)((u16)(x)>>8)
  114. #define SW16(x) (((u16)(x) & 0x00ffU)<<8 | ((u16)(x) & 0xff00U)>>8)
  115. #endif /* _IAP_H_ */