usb_application_power.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "usbapp/usb_application_power.h"
  2. #include "usb/usb_bridge.h"
  3. #include "usb/usb_config.h"
  4. #include "usbd_vendor.h"
  5. #include "core/csect.h"
  6. #include "core/config.h"
  7. #include "app/nfm/nfm_base.h"
  8. #include "app/led/led.h"
  9. #include "drivers/power_management/power_management.h"
  10. #define PROTO_REQ_SET_VBUS_POWER_SWITCH 0x1A // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè VBUS
  11. #define PROTO_REQ_SET_28_POWER_SWITCH 0x1B // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè 28 âîëüò
  12. #define PROTO_REQ_SET_EXT_POWER_SWITCH 0x1C // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè EXT
  13. #define PROTO_REQ_SET_AMP_POWER_SWITCH 0x1E // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè AMP
  14. #define PROTO_REQ_GET_28_POWER_VALUE 0x1D // ñ÷èòàòü çíà÷åíèå íàïðÿæåíèÿ ëèíèè 28 âîëüò
  15. #define PROTO_REQ_WIDX_AMP1_POWER_MODE 0x0A // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè AMP1
  16. #define PROTO_REQ_WIDX_AMP2_POWER_MODE 0x0B // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè AMP2
  17. #define PROTO_REQ_WIDX_AMP3_POWER_MODE 0x0C // âêëþ÷èòü/âûêëþ÷èòü ïèòàíèå ïî ëèíèè AMP3
  18. static int8_t fPowerAppInit();
  19. static int8_t fPowerAppDeInit();
  20. static void fPowerAppReset();
  21. static bool fPowerAppSetup( const tUSBSetupPacket_t * pSetup, bool bFirstStage, bool success );
  22. static size_t fPowerAppControlRx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * tx, size_t idx, size_t bytesRemaining );
  23. static size_t fPowerAppControlTx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * rx, size_t idx, size_t bytesRemaining );
  24. const sUSBAppEntry_Control_t usbapplication_ACM_planarproto_power = {
  25. .fUsbInit = fPowerAppInit,
  26. .fUsbDeInit = fPowerAppDeInit,
  27. .fUsbSetup = fPowerAppSetup,
  28. .fUsbCtlEpRx = fPowerAppControlRx,
  29. .fUsbCtlEpTx = fPowerAppControlTx,
  30. .fResetEvent = fPowerAppReset,
  31. };
  32. //-----------------------------------------------------
  33. // &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&&
  34. static int8_t fPowerAppInit()
  35. {
  36. return 0;
  37. }
  38. // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ----
  39. static int8_t fPowerAppDeInit()
  40. {
  41. return 0;
  42. }
  43. // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ----
  44. static void fPowerAppReset()
  45. {
  46. }
  47. // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ----
  48. static bool fPowerAppSetup( const tUSBSetupPacket_t * pSetup, bool bFirstStage, bool success )
  49. {
  50. switch ( pSetup->bRequest )
  51. {
  52. case PROTO_REQ_SET_28_POWER_SWITCH:
  53. {
  54. return true;
  55. }
  56. break;
  57. case PROTO_REQ_GET_28_POWER_VALUE:
  58. {
  59. return true;
  60. }
  61. case PROTO_REQ_SET_VBUS_POWER_SWITCH:
  62. {
  63. //VBUS(pSetup->wValue);
  64. return true;
  65. }
  66. break;
  67. case PROTO_REQ_SET_EXT_POWER_SWITCH:
  68. {
  69. //EXT_PWR(pSetup->wValue);
  70. return true;
  71. }
  72. break;
  73. case PROTO_REQ_SET_AMP_POWER_SWITCH:
  74. {
  75. // switch(pSetup->wIndex)
  76. // {
  77. // case PROTO_REQ_WIDX_AMP1_POWER_MODE:
  78. // {
  79. // AMP_PWR(pSetup->wValue, AMP1);
  80. // return true;
  81. // }
  82. // break;
  83. // case PROTO_REQ_WIDX_AMP2_POWER_MODE:
  84. // {
  85. // AMP_PWR(pSetup->wValue, AMP2);
  86. // return true;
  87. // }
  88. // break;
  89. // case PROTO_REQ_WIDX_AMP3_POWER_MODE:
  90. // {
  91. // AMP_PWR(pSetup->wValue, AMP3);
  92. // return true;
  93. // }
  94. // break;
  95. // }
  96. }
  97. break;
  98. }
  99. return false;
  100. }
  101. // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ----
  102. static size_t fPowerAppControlRx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * rx, size_t idx, size_t bytesRemaining )
  103. {
  104. return 0;
  105. }
  106. // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ----
  107. static size_t fPowerAppControlTx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * tx, size_t idx, size_t bytesRemaining )
  108. {
  109. // switch ( pSetup->bRequest )
  110. // {
  111. // case PROTO_REQ_GET_28_POWER_VALUE:
  112. // {
  113. // float external_voltage = (float)PMHandle.PM_GetAdcPowerValue()/100;
  114. // if( 0 == idx && sizeof(external_voltage) == bytesRemaining )
  115. // {
  116. // usb_push_transfer( tx, &external_voltage, sizeof(external_voltage) );
  117. // }
  118. // }
  119. // break;
  120. // }
  121. return usb_count_transfer( tx );
  122. }