diff options
Diffstat (limited to 'core/usb/usb_callbacks.c')
-rw-r--r-- | core/usb/usb_callbacks.c | 90 |
1 files changed, 64 insertions, 26 deletions
diff --git a/core/usb/usb_callbacks.c b/core/usb/usb_callbacks.c index 3e881ae..83b39c7 100644 --- a/core/usb/usb_callbacks.c +++ b/core/usb/usb_callbacks.c @@ -2,22 +2,24 @@ #include "usb_callbacks.h" #include "usb_lib.h" -#include "usb_descriptors.h" +#include "descriptors.h" +#include "usb_config.h" +#include "usb.h" ONE_DESCRIPTOR Device_Descriptor = { - (uint8*)usbVcomDescriptor_Device, + (uint8*)&usbVcomDescriptor_Device, sizeof(USB_Descriptor_Device) }; ONE_DESCRIPTOR Config_Descriptor = { - (uint8*)usbVcomDescriptor_Config, - sizeof(USB_Descriptor_Config) + (uint8*)&usbVcomDescriptor_Config, + 0x43//sizeof(USB_Descriptor_Config) }; ONE_DESCRIPTOR String_Descriptor[3] = { - {(uint8*)usbVcomDescriptor_LangID, USB_DESCRIPTOR_STRING_LEN(1)}, - {(uint8*)usbVcomDescriptor_iManufacturer,USB_DESCRIPTOR_STRING_LEN(8)}, - {(uint8*)usbVcomDescriptor_iProduct, USB_DESCRIPTOR_STRING_LEN(8)} + {(uint8*)&usbVcomDescriptor_LangID, USB_DESCRIPTOR_STRING_LEN(1)}, + {(uint8*)&usbVcomDescriptor_iManufacturer,USB_DESCRIPTOR_STRING_LEN(8)}, + {(uint8*)&usbVcomDescriptor_iProduct, USB_DESCRIPTOR_STRING_LEN(8)} }; uint8 last_request = 0; @@ -29,11 +31,13 @@ USB_Line_Coding line_coding = { datatype: 0x08 }; -uint8 vcomBufferTx[VCOM_TX_SIZE]; -uint8 vcomBufferRx[VCOM_RX_SIZE]; +uint8 vcomBufferTx[VCOM_TX_EPSIZE]; +uint8 vcomBufferRx[VCOM_RX_EPSIZE]; uint8 countTx = 0; uint8 countRx = 0; +RESET_STATE reset_state = START; + void vcomDataTxCb(void) { /* do whatever after data has been sent to host */ countTx = 0; @@ -41,14 +45,14 @@ void vcomDataTxCb(void) { void vcomDataRxCb(void) { /* do whatever after data has been received from host */ - countRx = GetEPRxCount(VCOM_RX_ENDP); - PMAToUserBufferCopy(vcomBufferRx,VCOM_RX_ADDR,countRx); - SetEPRxValid(VCOM_RX_ENDP); + /* countRx = GetEPRxCount(VCOM_RX_ENDP); */ +/* PMAToUserBufferCopy(vcomBufferRx,VCOM_RX_ADDR,countRx); */ +/* SetEPRxValid(VCOM_RX_ENDP); */ - countTx = countRx; - UserToPMABufferCopy(vcomBufferRx,VCOM_TX_ADDR,countTx); - SetEPTxCount(VCOM_TX_ENDP,countTx); - SetEPTxValid(VCOM_TX_ENDP); +/* countTx = countRx; */ +/* UserToPMABufferCopy(vcomBufferRx,VCOM_TX_ADDR,countTx); */ +/* SetEPTxCount(VCOM_TX_ENDP,countTx); */ +/* SetEPTxValid(VCOM_TX_ENDP); */ } void vcomManagementCb(void) { @@ -58,12 +62,12 @@ void vcomManagementCb(void) { u8* vcomGetSetLineCoding(uint16 length) { if (length == 0) { - pInformation->Ctrl_Info.Usb_wLength = sizeof(Line_Coding); + pInformation->Ctrl_Info.Usb_wLength = sizeof(USB_Line_Coding); } return (uint8*)&line_coding; } -void vcomSetLineSate(uint16 wValue) { +vcomSetLineState(void) { } void usbInit(void) { @@ -71,7 +75,7 @@ void usbInit(void) { usbPowerOn(); _SetISTR(0); - wInterrupt_Mas = ISR_MSK; + wInterrupt_Mask = ISR_MSK; _SetCNTR(wInterrupt_Mask); usbEnbISR(); @@ -82,7 +86,7 @@ void usbReset(void) { pInformation->Current_Configuration = 0; /* current feature is current bmAttributes */ - pInformation->Current_Feature = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED); + pInformation->Current_Feature = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELF_POWERED); _SetBTABLE(USB_BTABLE_ADDRESS); @@ -90,7 +94,7 @@ void usbReset(void) { _SetEPType(ENDP0, EP_CONTROL); _SetEPTxStatus(ENDP0, EP_TX_STALL); _SetEPRxAddr(ENDP0,VCOM_CTRL_RX_ADDR); - _SetEpTxAddr(ENDP0,VCOM_CTRL_TX_ADDR); + _SetEPTxAddr(ENDP0,VCOM_CTRL_TX_ADDR); Clear_Status_Out(ENDP0); SetEPRxCount(ENDP0, pProperty->MaxPacketSize); @@ -105,14 +109,13 @@ void usbReset(void) { /* setup data endpoint OUT (rx) */ SetEPType (VCOM_RX_ENDP, EP_BULK); SetEPRxAddr (VCOM_RX_ENDP, VCOM_RX_ADDR); - SetEPRxCount (VCOM_RX_ENDP, VCOM_RX_SIZE); + SetEPRxCount (VCOM_RX_ENDP, VCOM_RX_EPSIZE); SetEPTxStatus (VCOM_RX_ENDP, EP_TX_DIS); SetEPRxStatus (VCOM_RX_ENDP, EP_RX_VALID); /* setup data endpoint IN (tx) */ SetEPType (VCOM_TX_ENDP, EP_BULK); SetEPRxAddr (VCOM_TX_ENDP, VCOM_TX_ADDR); - SetEPRxCount (VCOM_TX_ENDP, VCOM_TX_SIZE); SetEPTxStatus (VCOM_TX_ENDP, EP_TX_NAK); SetEPRxStatus (VCOM_TX_ENDP, EP_RX_DIS); @@ -159,14 +162,44 @@ RESULT usbDataSetup(uint8 request) { } RESULT usbNoDataSetup(u8 request) { + uint8 new_signal; + /* we support set com feature but dont handle it */ if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) { + switch (request) { case (SET_COMM_FEATURE): return USB_SUCCESS; case (SET_CONTROL_LINE_STATE): - /* handle the control line status signal (reset?) */ - vcomSetLineState(); + /* to reset the board, pull both dtr and rts low + then pulse dtr by itself */ + new_signal = pInformation->USBwValues.bw.bb0 & (CONTROL_LINE_DTR | CONTROL_LINE_RTS); + switch (reset_state) { + /* no default, covered enum */ + case START: + if (new_signal == 0) { + reset_state = NDTR_NRTS; + } + break; + + case NDTR_NRTS: + if (new_signal == CONTROL_LINE_DTR) { + reset_state = DTR_NRTS; + } else if (new_signal == 0) { + reset_state = NDTR_NRTS; + } else { + reset_state = START; + } + break; + + case DTR_NRTS: + if (new_signal == 0) { + systemHardReset(); + } else { + reset_state = START; + } + break; + } return USB_SUCCESS; } } @@ -193,7 +226,12 @@ u8* usbGetConfigDescriptor(u16 length) { } u8* usbGetStringDescriptor(u16 length) { - return Standard_GetDescriptorData(length, &String_Descriptor); + uint8 wValue0 = pInformation->USBwValue0; + + if (wValue0 > 2) { + return NULL; + } + return Standard_GetDescriptorData(length, &String_Descriptor[wValue0]); } /* internal callbacks to respond to standard requests */ |