ql_usb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. #ifndef QL_USB_H
  13. #define QL_USB_H
  14. #include "ql_api_common.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*===========================================================================
  19. * Macro Definition
  20. ===========================================================================*/
  21. #define USB_MSC_DEVICE_MAX 2 //USB Mass Storage功能最大支持映射2个存储器
  22. #define USB_MSC_DEVICE_TYPE 4
  23. #define USB_DETECT_TIME_MIN 0
  24. #define USB_DETECT_TIME_MAX 100000000
  25. #define USB_CHARGING_ONFF_TIME_MIN 0
  26. #define USB_CHARGING_ONFF_TIME_MAX 100000
  27. #define QUEC_USBAT_INTF_NUM 2 //usb at口
  28. #define QUEC_USBDAIG_INTF_NUM 3 //usb diag口
  29. #define QUEC_USBDBHOST_INTF_NUM 4 //debug host口
  30. #define QUEC_USBCPLOG_INTF_NUM 5 //cp log口
  31. #define QUEC_USBAPLOG_INTF_NUM 6 //已废弃不使用
  32. #define QUEC_USBMODEM_INTF_NUM 7 //usb modem口
  33. #define QUEC_USBNMEA_INTF_NUM 8 //usb nmea口
  34. #define QUEC_USBATEXT_INTF_NUM 9 //已废弃不使用
  35. #define QUEC_UAC_CTRL_INTF_NUM 10 //UAC 控制接口
  36. #define QUEC_UAC_RX_INTF_NUM 11 //UAC 接收数据接口
  37. #define QUEC_UAC_TX_INTF_NUM 12 //UAC 发送数据接口
  38. #define QUEC_USBPRINTER_INTF_NUM 13 //usb打印机
  39. #define QUEC_USBPRINTER_INTF_MTP 14 //usb mtp
  40. #define USB_FUNC_ITEM_MAX 10
  41. /*===========================================================================
  42. * Enum
  43. ===========================================================================*/
  44. typedef enum
  45. {
  46. QL_USB_SUCCESS = QL_SUCCESS, /* operating is successful */
  47. QL_USB_INVALID_PARAM = (QL_COMPONENT_BSP_USB << 16) | 1000, /* invalid input param */
  48. QL_USB_SYS_ERROR = (QL_COMPONENT_BSP_USB << 16) | 1001, /* system error */
  49. QL_USB_DETECT_SAVE_NV_ERR = (QL_COMPONENT_BSP_USB << 16) | 1002, /* save detect time to NV failed */
  50. QL_USB_NO_SPACE = (QL_COMPONENT_BSP_USB << 16) | 1003, /* no space to store data */
  51. QL_USB_NOT_SUPPORT = (QL_COMPONENT_BSP_USB << 16) | 1004, /* current operation not support */
  52. }ql_errcode_usb_e;
  53. typedef enum
  54. {
  55. QL_USB_HOTPLUG_OUT = 0, //USB in plug out state
  56. QL_USB_HOTPLUG_IN = 1, //USB was inserted but not enum
  57. QL_USB_HOTPLUG_IN_ENUMED =2 //USB insert and enum done
  58. }QL_USB_HOTPLUG_E;
  59. typedef enum
  60. {
  61. QL_USB_DET_MIN = 0,
  62. QL_USB_DET_CHARGER = 0, //usb will be enabled and disabled by VBUS high level and low level
  63. QL_USB_DET_AON = 1, //usb will be enabled always, and won't be disabled
  64. QL_USB_DET_NO_VBUS = 2, //usb will be enabled and disabled by GPIO, the GPIO function not support now, so it is same as QL_USB_DET_AON now
  65. QL_USB_DET_MAX,
  66. }QL_USB_DET_E;
  67. /*
  68. 1. QL_USB_ENUM_MASS_STORAGE用于将模块的SD卡/内置flash/外置6线flash映射到电脑,用于传输文件,由于占用RAM空间较大,开启此模式后,默认会删除USB Modem口
  69. 2. usb nmea口默认不开启,用户可使用宏CONFIG_QUEC_PROJECT_FEATURE_USB_NMEA_AT开启,也可在quec_usb_serial_create函数中打开COM6的枚举,占用200k ram
  70. 3. usb modem口默认开启,用户可使用宏CONFIG_QUEC_PROJECT_FEATURE_USB_MODEM_AT关闭,也可在quec_usb_serial_create函数中关闭COM6的枚举,占用200k ram
  71. 4. usb at口默认开启,用户可在可在quec_usb_serial_create函数中关闭COM0的枚举,占用200k ram
  72. */
  73. typedef enum
  74. {
  75. QL_USB_ENUM_NONE = -1, //NO USB port will be enumerated
  76. QL_USB_ENUM_USBNET_COM, //usbnet(rndis/ecm), USB_AT(ttyUSB0), USB_DIAG, USB_DebugHost, USB_AP_LOG, USB_CP_LOG, USB_MODEM(ttyUSB5)
  77. QL_USB_ENUM_USBNET_COM_UAC, //not support in 8850, only support in 8910
  78. QL_USB_ENUM_USBNET_COM_PRINTER, //not support in 8850, only support in 8910
  79. QL_USB_ENUM_ACM_ONLY, //not support in 8850, only support in 8910
  80. QL_USB_ENUM_MASS_STORAGE, ////usbnet(rndis/ecm), USB_AT(ttyUSB0), USB_DIAG, USB_MOS, USB_AP_LOG, USB_CP_LOG, USB_MSC(用于将模块的SD等存储映射到电脑,用于传输文件)
  81. QL_USB_ENUM_MAX, //invalid
  82. }QL_USB_ENMU_MODE_E;
  83. typedef enum
  84. {
  85. QL_USB_NV_TYPE_ENUM_MODE = 0,
  86. QL_USB_NV_TYPE_MSC = 1,
  87. QL_USB_NV_TYPE_MAX,
  88. }QL_USB_NV_TYPE_E;
  89. /*
  90. 1. 选择映射模块的哪些存储器到PC端, 最大支持映射2个存储器; 例如需要映射sd卡和外部
  91. 6线flash,可以用 (QL_USB_MSC_SDCARD | QL_USB_MSC_EFS)
  92. 2. 注意: 映射模块外部flash时,外部flash使用的文件系统需要是模块自带的,
  93. 内核需要用ql_fopen这些API去控制与PC之间的文件传输
  94. */
  95. typedef enum
  96. {
  97. QL_USB_MSC_DEFAULT = 0, //默认设备,默认映射SD卡和内置flash
  98. QL_USB_MSC_SDCARD = 0x01, //模块的SD卡
  99. QL_USB_MSC_UFS = 0x2, //模块的内置flash
  100. QL_USB_MSC_EFS = 0x4, //模块的外置6线flash
  101. QL_USB_MSC_EXNSFFS = 0x8 //模块的外置4线flash
  102. }QL_USB_MSC_E;
  103. /*===========================================================================
  104. * STRUCT
  105. ===========================================================================*/
  106. typedef struct
  107. {
  108. QL_USB_DET_E det_mode;
  109. uint det_pin; //not used now, but will used feature
  110. uint reserve[2]; //reserved for futher using
  111. }ql_usb_detmdoe_t; //this structure will be writed to NV
  112. typedef struct
  113. {
  114. uint32_t usb_detect_time;
  115. uint32_t charging_on_time;
  116. uint32_t charging_off_time;
  117. ql_usb_detmdoe_t usb_det_mode;
  118. } ql_usb_setting_s;
  119. typedef struct
  120. {
  121. int msc_device; //需要映射到PC的存储器,参考枚举QL_USB_MSC_E;多个存储之间用'|'连接,最大支持映射2个存储器
  122. }ql_usb_msc_cfg_t;
  123. typedef struct
  124. {
  125. uint8 enum_mode;
  126. ql_usb_msc_cfg_t msc_cfg;
  127. }ql_usb_nv_t;
  128. /*===========================================================================
  129. * function
  130. ===========================================================================*/
  131. /*****************************************************************
  132. !!!!! don't block the callback , as is run in interrupt !!!!!!
  133. * Function: ql_usb_hotplug_cb
  134. *
  135. * Description: the defination of usb hotplug callback
  136. *
  137. * Parameters:
  138. * state Indicates whether the USB action is unplugged or inserted
  139. * ctx not used now
  140. *
  141. * Return:
  142. * 0
  143. *****************************************************************/
  144. typedef int(*ql_usb_hotplug_cb)(QL_USB_HOTPLUG_E state, void *ctx); //
  145. /*****************************************************************
  146. *
  147. * Function: ql_usb_bind_hotplug_cb
  148. *
  149. * Description: bind usb hotplug callback to kernel
  150. *
  151. * Attention:
  152. 1. the callback will be run in interrupt, so it is forbidden to block the callback;
  153. 2. it is forbidden to call Audio start/stop/close, file write/read,CFW(releated to RPC)in interrupt;
  154. 3. it is forbidden to enter critical in interrupt
  155. 4. it is suggested for users to perform simple operations , or send event(no timeout) to inform your task in interrupt
  156. * Parameters:
  157. * hotplug_callback [in]callback
  158. *
  159. * Return:
  160. * 0
  161. *****************************************************************/
  162. ql_errcode_usb_e ql_usb_bind_hotplug_cb(ql_usb_hotplug_cb hotplug_callback);
  163. /*****************************************************************
  164. * Function: ql_usb_get_hotplug_state
  165. *
  166. * Description: get the usb hotplug state
  167. *
  168. * Parameters:
  169. * hotplug_callback [in]callback
  170. *
  171. * Return:
  172. * QL_USB_HOTPLUG_OUT : USB is not insrrted
  173. * QL_USB_HOTPLUG_IN : USB is inserted
  174. *****************************************************************/
  175. QL_USB_HOTPLUG_E ql_usb_get_hotplug_state(void);
  176. /*****************************************************************
  177. * Function: ql_usb_set_detmode
  178. *
  179. * Description: set usb detect mode
  180. *
  181. * Parameters:
  182. * usb_mode [in] detected mode, take effect after reset
  183. *
  184. * Return:
  185. * 0: success
  186. * others: ql_errcode_usb_e
  187. *****************************************************************/
  188. ql_errcode_usb_e ql_usb_set_detmode(ql_usb_detmdoe_t *usb_mode);
  189. /*****************************************************************
  190. * Function: ql_usb_get_detmode
  191. *
  192. * Description: get the usb detect mode
  193. *
  194. * Parameters:
  195. * ql_usb_detmdoe_t [out]usb detect mode
  196. *
  197. * Return:
  198. * 0: success
  199. * others: ql_errcode_usb_e
  200. *****************************************************************/
  201. ql_errcode_usb_e ql_usb_get_detmode(ql_usb_detmdoe_t *mode);
  202. /*****************************************************************
  203. * Function: ql_set_usb_detect_max_time
  204. *
  205. * Description: Set the maximum time to detect the connection of
  206. * USB DP/DM data line after USB insertion
  207. * 设置USB插入后最大的检测时间,如果过了这个时间,还没有
  208. * 检测到DP/DM线上有数据返回,则关闭检测,省电
  209. *
  210. * Parameters:
  211. * ms [in] the maximum detect time to set
  212. *
  213. * Return:
  214. * 0 success
  215. * other ql_errcode_usb_e
  216. *
  217. *****************************************************************/
  218. ql_errcode_usb_e ql_set_usb_detect_max_time(uint32_t ms);
  219. /*****************************************************************
  220. * Function: ql_get_usb_detect_max_time
  221. *
  222. * Description: get the maximum USB detection time set
  223. *
  224. * Parameters:
  225. * ms [out] the maximum detect time
  226. *
  227. * Return:
  228. * 0 success
  229. * other ql_errcode_usb_e
  230. *
  231. *****************************************************************/
  232. ql_errcode_usb_e ql_get_usb_detect_max_time(uint32_t *ms);
  233. /*****************************************************************
  234. * Function: ql_usb_get_enum_mode
  235. *
  236. * Description: to get the usb enumeration mode
  237. *
  238. * Return:
  239. * QL_USB_ENMU_MODE_E
  240. *
  241. *****************************************************************/
  242. QL_USB_ENMU_MODE_E ql_usb_get_enum_mode(void);
  243. /*****************************************************************
  244. * Function: ql_usb_set_enum_mode
  245. *
  246. * Description: to set the enumeration mode of usb port.For UAC or
  247. usb printer mode, the USB nmea PORT will not be enumerated
  248. *
  249. * Parameters:
  250. * mode [in] see it in QL_USB_ENMU_MODE_E for detail
  251. *
  252. * Return:
  253. * 0 success
  254. * other ql_errcode_usb_e
  255. *****************************************************************/
  256. ql_errcode_usb_e ql_usb_set_enum_mode(QL_USB_ENMU_MODE_E mode);
  257. #ifdef CONFIG_QUEC_PROJECT_FEATURE_USB_MASS_STORAGE
  258. /*****************************************************************
  259. * Function: ql_usb_msc_config_set
  260. *
  261. * Description: to set the configration of usb mass storage, need to set
  262. the enum mode to usb mass storage by ql_usb_get_enum_mode firstly;
  263. Restart to take effect
  264. * Parameters:
  265. * msc_device [in]see it in QL_USB_MSC_E for detail, to set the mapping storage device
  266. *
  267. * Return:
  268. * 0 success
  269. * other ql_errcode_usb_e
  270. *****************************************************************/
  271. ql_errcode_usb_e ql_usb_msc_config_set(ql_usb_msc_cfg_t *msc_cfg);
  272. /*****************************************************************
  273. * Function: ql_usb_msc_config_get
  274. *
  275. * Description: to get the configration of usb mass storage
  276. *
  277. * Parameters:
  278. * msc_cfg [out]the space for getting the configration
  279. *
  280. * Return:
  281. * 0 success
  282. * other ql_errcode_usb_e
  283. *****************************************************************/
  284. ql_errcode_usb_e ql_usb_msc_config_get(ql_usb_msc_cfg_t *msc_cfg);
  285. #endif
  286. #ifdef __cplusplus
  287. } /*"C" */
  288. #endif
  289. #endif /* QL_USB_H */