#include "usbapp/usb_application_power.h" #include "usb/usb_bridge.h" #include "usb/usb_config.h" #include "usbd_vendor.h" #include "core/csect.h" #include "core/config.h" #include "app/nfm/nfm_base.h" #include "app/led/led.h" #include "drivers/power_management/power_management.h" #define PROTO_REQ_SET_VBUS_POWER_SWITCH 0x1A // включить/выключить питание по линии VBUS #define PROTO_REQ_SET_28_POWER_SWITCH 0x1B // включить/выключить питание по линии 28 вольт #define PROTO_REQ_SET_EXT_POWER_SWITCH 0x1C // включить/выключить питание по линии EXT #define PROTO_REQ_SET_AMP_POWER_SWITCH 0x1E // включить/выключить питание по линии AMP #define PROTO_REQ_GET_28_POWER_VALUE 0x1D // считать значение напряжения линии 28 вольт #define PROTO_REQ_WIDX_AMP1_POWER_MODE 0x0A // включить/выключить питание по линии AMP1 #define PROTO_REQ_WIDX_AMP2_POWER_MODE 0x0B // включить/выключить питание по линии AMP2 #define PROTO_REQ_WIDX_AMP3_POWER_MODE 0x0C // включить/выключить питание по линии AMP3 static int8_t fPowerAppInit(); static int8_t fPowerAppDeInit(); static void fPowerAppReset(); static bool fPowerAppSetup( const tUSBSetupPacket_t * pSetup, bool bFirstStage, bool success ); static size_t fPowerAppControlRx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * tx, size_t idx, size_t bytesRemaining ); static size_t fPowerAppControlTx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * rx, size_t idx, size_t bytesRemaining ); const sUSBAppEntry_Control_t usbapplication_ACM_planarproto_power = { .fUsbInit = fPowerAppInit, .fUsbDeInit = fPowerAppDeInit, .fUsbSetup = fPowerAppSetup, .fUsbCtlEpRx = fPowerAppControlRx, .fUsbCtlEpTx = fPowerAppControlTx, .fResetEvent = fPowerAppReset, }; //----------------------------------------------------- // &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& &&&& static int8_t fPowerAppInit() { return 0; } // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- static int8_t fPowerAppDeInit() { return 0; } // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- static void fPowerAppReset() { } // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- static bool fPowerAppSetup( const tUSBSetupPacket_t * pSetup, bool bFirstStage, bool success ) { switch ( pSetup->bRequest ) { case PROTO_REQ_SET_28_POWER_SWITCH: { return true; } break; case PROTO_REQ_GET_28_POWER_VALUE: { return true; } case PROTO_REQ_SET_VBUS_POWER_SWITCH: { //VBUS(pSetup->wValue); return true; } break; case PROTO_REQ_SET_EXT_POWER_SWITCH: { //EXT_PWR(pSetup->wValue); return true; } break; case PROTO_REQ_SET_AMP_POWER_SWITCH: { // switch(pSetup->wIndex) // { // case PROTO_REQ_WIDX_AMP1_POWER_MODE: // { // AMP_PWR(pSetup->wValue, AMP1); // return true; // } // break; // case PROTO_REQ_WIDX_AMP2_POWER_MODE: // { // AMP_PWR(pSetup->wValue, AMP2); // return true; // } // break; // case PROTO_REQ_WIDX_AMP3_POWER_MODE: // { // AMP_PWR(pSetup->wValue, AMP3); // return true; // } // break; // } } break; } return false; } // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- static size_t fPowerAppControlRx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * rx, size_t idx, size_t bytesRemaining ) { return 0; } // &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- &&&& ---- static size_t fPowerAppControlTx( const tUSBSetupPacket_t * pSetup, sUSBTransfer_t * tx, size_t idx, size_t bytesRemaining ) { // switch ( pSetup->bRequest ) // { // case PROTO_REQ_GET_28_POWER_VALUE: // { // float external_voltage = (float)PMHandle.PM_GetAdcPowerValue()/100; // if( 0 == idx && sizeof(external_voltage) == bytesRemaining ) // { // usb_push_transfer( tx, &external_voltage, sizeof(external_voltage) ); // } // } // break; // } return usb_count_transfer( tx ); }