luat_usb_app_air105.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "luat_base.h"
  22. #include "luat_malloc.h"
  23. #include "luat_msgbus.h"
  24. #include "app_interface.h"
  25. #define LUAT_LOG_TAG "luat.usbapp"
  26. #include "luat_log.h"
  27. extern void *luat_spi_get_sdhc_ctrl(void);
  28. int32_t luat_usb_app_vhid_cb(void *pData, void *pParam);
  29. void luat_usb_app_set_vid_pid(uint8_t usb_id, uint16_t vid, uint16_t pid)
  30. {
  31. Core_USBSetID(usb_id, vid, pid);
  32. }
  33. void luat_usb_app_set_hid_mode(uint8_t usb_id, uint8_t hid_mode, uint8_t buff_size)
  34. {
  35. Core_USBSetHIDMode(usb_id, hid_mode, buff_size);
  36. }
  37. //打开luatos内置usb device config,实现虚拟MSC,HID和串口的复合设备功能,串口收发见luat_uart
  38. void luat_usb_app_start(uint8_t usb_id)
  39. {
  40. Core_USBDefaultDeviceStart(usb_id);
  41. Core_VHIDInit(usb_id, luat_usb_app_vhid_cb);
  42. }
  43. void luat_usb_app_stop(uint8_t usb_id)
  44. {
  45. USB_StackStop(usb_id);
  46. USB_StackClearSetup(usb_id);
  47. }
  48. void luat_usb_app_vhid_tx(uint8_t usb_id, uint8_t *data, uint32_t len)
  49. {
  50. Core_VHIDSendRawData(usb_id, data, len);
  51. }
  52. uint32_t luat_usb_app_vhid_rx(uint8_t usb_id, uint8_t *data, uint32_t len)
  53. {
  54. return Core_VHIDRxBufferRead(usb_id, data, len);
  55. }
  56. void luat_usb_app_vhid_upload(uint8_t usb_id, uint8_t *key_data, uint32_t len)
  57. {
  58. Core_VHIDUploadData(usb_id, key_data, len);
  59. }
  60. void luat_usb_app_vhid_cancel_upload(uint8_t usb_id)
  61. {
  62. Core_VHIDUploadStop(usb_id);
  63. }
  64. void luat_usb_udisk_attach_sdhc(uint8_t usb_id)
  65. {
  66. Core_UDiskAttachSDHC(usb_id, luat_spi_get_sdhc_ctrl());
  67. }
  68. void luat_usb_udisk_detach_sdhc(uint8_t usb_id)
  69. {
  70. Core_UDiskDetachSDHC(usb_id, NULL);
  71. }