diff --git a/src/sh68f90a.h b/src/sh68f90a.h index c78b56b..711ea05 100644 --- a/src/sh68f90a.h +++ b/src/sh68f90a.h @@ -561,6 +561,32 @@ enum sh68f90a_interrupt { #define _ENUSB (1u<<7) ///< Bit 7 /**@}*/ +/** + * \name Bits from register USBIF1 + * @{ + */ +#define _USBRSTIF (1u<<0) ///< Bit 0 +#define _SUSPIF (1u<<1) ///< Bit 1 +#define _RESMIF (1u<<2) ///< Bit 2 +#define _SOFIF (1u<<3) ///< Bit 3 +#define _SETUPIF (1u<<4) ///< Bit 4 +#define _OW (1u<<5) ///< Bit 5 +#define _OVERIF (1u<<6) ///< Bit 6 +#define _PUPIF (1u<<7) ///< Bit 7 +/**@}*/ + +/** + * \name Bits from register USBIF2 + * @{ + */ +#define _IEP0IF (1u<<0) ///< Bit 0 +#define _IEP1IF (1u<<1) ///< Bit 1 +#define _IEP2IF (1u<<2) ///< Bit 2 +#define _OEP0IF (1u<<4) ///< Bit 4 +#define _OEP1IF (1u<<5) ///< Bit 5 +#define _OEP2IF (1u<<6) ///< Bit 6 +/**@}*/ + /** * \name Bits from register USBIE1 * @{ diff --git a/src/usb.c b/src/usb.c index 7022eb7..769cc8c 100644 --- a/src/usb.c +++ b/src/usb.c @@ -68,12 +68,8 @@ #define STALL_EP0() \ do { IN0_SET_STALL; OUT0_SET_STALL; } while(0) -const uint8_t str_dp_langID[] = { - 0x04, // Length - USB_DESCRIPTOR_TYPE_STRING, // String Type - 0x09, // Language - 0x04 -}; +#define IEP0CNT_CLR { IEP0CNT &= ~0x0f; } +#define IEP0CNT_SET(COUNT) { IEP0CNT_CLR; IEP0CNT |= COUNT; } enum { REPORT_ID_ACPI = 0x01, @@ -318,8 +314,20 @@ usb_descriptor_set_c usb_descriptor_set = { .strings = usb_strings, }; -uint8_t __xdata usb_rx_data[8]; +// interrupt handlers +static void usb_setup_irq(); +static void usb_ep0_out_irq(); +static void usb_ep0_in_irq(); + +// buffer utils +static void setup_ep0_in_xfer(uint8_t *src, uint16_t len); +static void step_ep0_in_xfer(); +static void set_ep0_in_buffer(uint8_t *src, uint8_t len); +static void get_ep0_out_buffer(uint8_t *dest); +static void set_ep1_in_buffer(uint8_t *src, uint8_t len); +static void get_ep1_out_buffer(uint8_t *dest); +// request handlers static void usb_clear_remote_wakeup_handler(__xdata struct usb_req_setup *req); static void usb_clear_endpoint_halt_handler(__xdata struct usb_req_setup *req); static void usb_set_remote_wakeup_handler(__xdata struct usb_req_setup *req); @@ -341,24 +349,18 @@ static void usb_hid_get_idle_handler(__xdata struct usb_req_setup *req); static void usb_hid_set_protocol_handler(__xdata struct usb_req_setup *req); static void usb_hid_get_protocol_handler(__xdata struct usb_req_setup *req); -void SUSPEND_IRQ_Prog(); -void IN0_SetReady(); -void OUT0_IRQ_Prog(); -void IN0_IRQ_Prog(); - -// xfer -static void setup_ep0_in_xfer(uint8_t *src, uint16_t len); -static void step_ep0_in_xfer(); -static void set_ep0_in_buffer(uint8_t *src, uint8_t len); -static void get_ep0_out_buffer(uint8_t *dest); -static void set_ep1_in_buffer(uint8_t *src, uint8_t len); -static void get_ep1_out_buffer(uint8_t *dest); +/** + * 0.5KB of general purpose scratch RAM. + */ +__xdata uint8_t scratch[512]; +uint16_t ep0_xfer_bytes_left; +uint8_t *ep0_xfer_src; // TODO: remove +uint8_t __xdata usb_rx_data[8]; uint8_t __xdata *buffer_addr; __bit device_remote_wakeup_f; uint8_t __xdata configution_value; -uint8_t __xdata usb_rx_data[8]; uint8_t __xdata EP1_IDLE_TIME; uint8_t __xdata EP1_IDLE_COUNT; @@ -383,7 +385,7 @@ void usb_send_report(report_keyboard_t *report) IN1_SET_READY; } -static void usb_request_handler() +static void usb_setup_irq() { EA = 0; get_ep0_out_buffer(usb_rx_data); @@ -394,125 +396,150 @@ static void usb_request_handler() uint8_t type = req->bmRequestType; uint8_t request = req->bRequest; - if (type == (USB_HOST_TO_DEVICE | USB_STANDARD | USB_DEVICE)) { - switch (request) - { - case USB_CLEAR_FEATURE: - usb_clear_remote_wakeup_handler(req); // TODO: check naming & usage - break; - case USB_SET_FEATURE: - usb_set_remote_wakeup_handler(req); // TODO: check naming & usage - break; - case USB_SET_ADDRESS: - usb_set_address_handler(req); - break; - case USB_SET_DESCRIPTOR: - usb_set_descriptor_handler(req); - break; - case USB_SET_CONFIGURATION: - usb_set_configuration_handler(req); - break; - default: - STALL_EP0(); - return; + switch (type) + { + case (USB_HOST_TO_DEVICE | USB_STANDARD | USB_DEVICE): + switch (request) { + case USB_CLEAR_FEATURE: + usb_clear_remote_wakeup_handler(req); // TODO: check naming & usage + break; + + case USB_SET_FEATURE: + usb_set_remote_wakeup_handler(req); // TODO: check naming & usage + break; + + case USB_SET_ADDRESS: + usb_set_address_handler(req); + break; + + case USB_SET_DESCRIPTOR: + usb_set_descriptor_handler(req); + break; + + case USB_SET_CONFIGURATION: + usb_set_configuration_handler(req); + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_DEVICE_TO_HOST | USB_STANDARD | USB_DEVICE)) { - switch (request) - { - case USB_GET_STATUS: - usb_get_device_status_handler(req); - break; - case USB_GET_DESCRIPTOR: - usb_get_descriptor_handler(req); - break; - case USB_GET_CONFIGURATION: - usb_get_configuration_handler(req); - break; - default: - STALL_EP0(); - return; + case (USB_DEVICE_TO_HOST | USB_STANDARD | USB_DEVICE): + switch (request) { + case USB_GET_STATUS: + usb_get_device_status_handler(req); + break; + + case USB_GET_DESCRIPTOR: + usb_get_descriptor_handler(req); + break; + + case USB_GET_CONFIGURATION: + usb_get_configuration_handler(req); + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_HOST_TO_DEVICE | USB_STANDARD | USB_INTERFACE)) { - switch (request) - { - case USB_SET_INTERFACE: - usb_set_interface_handler(req); - break; - default: - STALL_EP0(); - return; + break; + case (USB_HOST_TO_DEVICE | USB_STANDARD | USB_INTERFACE): + switch (request) { + case USB_SET_INTERFACE: + usb_set_interface_handler(req); + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_DEVICE_TO_HOST | USB_STANDARD | USB_INTERFACE)) { - switch (request) - { - case USB_GET_STATUS: - usb_get_interface_status_handler(req); - break; - case USB_GET_DESCRIPTOR: - usb_get_descriptor_handler(req); // TODO: this should be exclusive to the interface - break; - case USB_GET_INTERFACE: - usb_get_interface_handler(req); - break; - default: - STALL_EP0(); - return; + break; + case (USB_DEVICE_TO_HOST | USB_STANDARD | USB_INTERFACE): + switch (request) { + case USB_GET_STATUS: + usb_get_interface_status_handler(req); + break; + + case USB_GET_DESCRIPTOR: + usb_get_descriptor_handler(req); // TODO: this should be exclusive to the interface + break; + + case USB_GET_INTERFACE: + usb_get_interface_handler(req); + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_HOST_TO_DEVICE | USB_STANDARD | USB_ENDPOINT)) { - switch (request) - { - case USB_CLEAR_FEATURE: - usb_clear_endpoint_halt_handler(req); // TODO: check naming and usage - break; - case USB_SET_FEATURE: - usb_set_endpoint_halt_handler(req); // TODO: check naming and usage - break; - default: - STALL_EP0(); - return; + break; + case (USB_HOST_TO_DEVICE | USB_STANDARD | USB_ENDPOINT): + switch (request) { + case USB_CLEAR_FEATURE: + usb_clear_endpoint_halt_handler(req); // TODO: check naming and usage + break; + + case USB_SET_FEATURE: + usb_set_endpoint_halt_handler(req); // TODO: check naming and usage + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_DEVICE_TO_HOST | USB_STANDARD | USB_ENDPOINT)) { - switch (request) - { - case USB_GET_STATUS: - usb_get_endpoint_status_handler(req); // TODO: check naming and usage - break; - default: - STALL_EP0(); - return; + break; + case (USB_DEVICE_TO_HOST | USB_STANDARD | USB_ENDPOINT): + switch (request) { + case USB_GET_STATUS: + usb_get_endpoint_status_handler(req); // TODO: check naming and usage + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_HOST_TO_DEVICE | USB_CLASS | USB_INTERFACE)) { - switch (request) - { - case USB_HID_SET_REPORT: - usb_hid_set_report_handler(req); // TODO: include hid in naming - break; - case USB_HID_SET_IDLE: - usb_hid_set_idle_handler(req); - break; - case USB_HID_SET_PROTOCOL: - usb_hid_set_protocol_handler(req); - break; - default: - STALL_EP0(); - return; + break; + case (USB_HOST_TO_DEVICE | USB_CLASS | USB_INTERFACE): + switch (request) { + case USB_HID_SET_REPORT: + usb_hid_set_report_handler(req); // TODO: include hid in naming + break; + + case USB_HID_SET_IDLE: + usb_hid_set_idle_handler(req); + break; + + case USB_HID_SET_PROTOCOL: + usb_hid_set_protocol_handler(req); + break; + + default: + STALL_EP0(); + return; } - } else if (type == (USB_DEVICE_TO_HOST | USB_CLASS | USB_INTERFACE)) { - switch (request) - { - case USB_HID_GET_REPORT: - usb_hid_get_report_handler(req); // TODO: include hid in naming - break; - case USB_HID_GET_IDLE: - usb_hid_get_idle_handler(req); - break; - case USB_HID_GET_PROTOCOL: - usb_hid_get_protocol_handler(req); - break; - default: - STALL_EP0(); - return; + break; + case (USB_DEVICE_TO_HOST | USB_CLASS | USB_INTERFACE): + switch (request) { + case USB_HID_GET_REPORT: + usb_hid_get_report_handler(req); // TODO: include hid in naming + break; + + case USB_HID_GET_IDLE: + usb_hid_get_idle_handler(req); + break; + + case USB_HID_GET_PROTOCOL: + usb_hid_get_protocol_handler(req); + break; + + default: + STALL_EP0(); + return; } + break; + default: + STALL_EP0(); + return; } } @@ -521,64 +548,57 @@ void usb_interrupt_handler() __interrupt(_INT_USB) uint8_t temp_usbif1 = USBIF1; uint8_t temp_usbif2 = USBIF2; - if (temp_usbif1 != 0x00) { //check USBIF1 flag - if (temp_usbif1 & (1 << 3)) { // SOFIF - USBIF1 &= ~(1 << 3); + if (temp_usbif1 != 0x00) { + if (temp_usbif1 & _SOFIF) { + USBIF1 &= ~_SOFIF; } else { // why is this being cleared and why in this fashion? - USBIF1 &= ~((1 << 4) | (1 << 3)); // Clear SETUPIF & SOF first - USBIF1 &= ~((1 << 6) | (1 << 5)); // SETUP OVERIF & OW + USBIF1 &= ~(_SETUPIF | _SOFIF); // Clear SETUPIF & SOF first + USBIF1 &= ~(_OVERIF | _OW); // SETUP OVERIF & OW - if (temp_usbif1 & (1 << 7)) { // PUPIF - USBIF1 &= ~(1 << 7); + if (temp_usbif1 & _PUPIF) { + USBIF1 &= ~_PUPIF; usb_init(); - } else if (temp_usbif1 & (1 << 4)) { // SETUPIF - USBIF1 &= ~(1 << 4); - usb_request_handler(); - } else if (temp_usbif1 & (1 << 2)) { // RESMIF - USBIF1 &= ~(1 << 2); - } else if (temp_usbif1 & (1 << 1)) { // SUSPIF - USBIF1 &= ~(1 << 1); - SUSPEND_IRQ_Prog(); - } else if (temp_usbif1 & (1 << 0)) { // BUSRSTIF - USBIF1 &= ~(1 << 0); - - // usb_config_ok = 0; - USBCON |= 0x20; // softreset + } else if (temp_usbif1 & _SETUPIF) { + USBIF1 &= ~_SETUPIF; + usb_setup_irq(); + } else if (temp_usbif1 & _RESMIF) { // RESMIF + USBIF1 &= ~_RESMIF; + } else if (temp_usbif1 & _SUSPIF) { // SUSPIF + USBIF1 &= ~_SUSPIF; + } else if (temp_usbif1 & _USBRSTIF) { // BUSRSTIF + USBIF1 &= ~_USBRSTIF; + + USBCON |= _SWRST; // softreset _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); - USBCON &= ~0x20; // clear softreset + USBCON &= ~_SWRST; // clear softreset usb_init(); OUT0_SET_READY; } } } else if (temp_usbif2 != 0x00) { - if (temp_usbif2 & BIT6) { // EP2 OUT Event INT - USBIF2 &= ~BIT6; + if (temp_usbif2 & _OEP2IF) { + USBIF2 &= ~_OEP2IF; OUT2_SET_READY - } else if (temp_usbif2 & BIT5) { // EP1 OUT Event INT - USBIF2 &= ~BIT5; - //////////////////////////// - // OUT1_IRQ_Prog(); - // OUT1_SET_READY - ///////////////////////// - } else if (temp_usbif2 & BIT4) { // EP0 OUT Event INT - USBIF2 &= ~BIT4; - OUT0_IRQ_Prog(); + } else if (temp_usbif2 & _OEP1IF) { + USBIF2 &= ~_OEP1IF; + } else if (temp_usbif2 & _OEP0IF) { + USBIF2 &= ~_OEP0IF; + usb_ep0_out_irq(); OUT0_SET_READY - } else if (temp_usbif2 & BIT2) { // EP2 IN Event INT - USBIF2 &= ~BIT2; - //IN2_IRQ_Prog(); - } else if (temp_usbif2 & BIT1) { // EP1 IN Event INT - USBIF2 &= ~BIT1; - } else if (temp_usbif2 & BIT0) { // EP0 IN Event INT - USBIF2 &= ~BIT0; - IN0_IRQ_Prog(); + } else if (temp_usbif2 & _IEP2IF) { + USBIF2 &= ~_IEP2IF; + } else if (temp_usbif2 & _IEP1IF) { + USBIF2 &= ~_IEP1IF; + } else if (temp_usbif2 & _IEP0IF) { + USBIF2 &= ~_IEP0IF; + usb_ep0_in_irq(); } } } @@ -593,7 +613,8 @@ static void usb_clear_remote_wakeup_handler(__xdata struct usb_req_setup *req) device_remote_wakeup_f = 0; } - IN0_SetReady(); + IEP0CNT_CLR; + IN0_SET_READY; } static void usb_clear_endpoint_halt_handler(__xdata struct usb_req_setup *req) @@ -614,7 +635,8 @@ static void usb_clear_endpoint_halt_handler(__xdata struct usb_req_setup *req) } } - IN0_SetReady(); + IEP0CNT_CLR; + IN0_SET_READY; } static void usb_set_remote_wakeup_handler(__xdata struct usb_req_setup *req) @@ -625,7 +647,8 @@ static void usb_set_remote_wakeup_handler(__xdata struct usb_req_setup *req) device_remote_wakeup_f = 1; } - IN0_SetReady(); + IEP0CNT_CLR; + IN0_SET_READY; } static void usb_set_endpoint_halt_handler(__xdata struct usb_req_setup *req) @@ -645,13 +668,14 @@ static void usb_set_endpoint_halt_handler(__xdata struct usb_req_setup *req) return; } - IN0_SetReady(); + IEP0CNT_CLR; + IN0_SET_READY; } static void usb_set_address_handler(__xdata struct usb_req_setup *req) { ep0_xfer_state = NEW_SETUP_PHASE; - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; OUT0_SET_STALL; IN0_SET_READY; } @@ -665,7 +689,7 @@ static void usb_set_configuration_handler(__xdata struct usb_req_setup *req) if ((req->wValue == 0) || (req->wValue == 1)) { configution_value = req->wValue; // TODO: save config set state - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; } else { STALL_EP0(); @@ -674,7 +698,8 @@ static void usb_set_configuration_handler(__xdata struct usb_req_setup *req) STALL_EP0(); } - IN0_SetReady(); + IEP0CNT_CLR; + IN0_SET_READY; } static void usb_set_interface_handler(__xdata struct usb_req_setup *req) @@ -683,11 +708,11 @@ static void usb_set_interface_handler(__xdata struct usb_req_setup *req) if (req->wValue == 0) { if (req->wIndex == 0) { - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; OUT0_SET_STALL; } else if (req->wIndex == 1) { - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; OUT0_SET_STALL; } else { @@ -709,8 +734,6 @@ static void usb_get_device_status_handler(__xdata struct usb_req_setup *req) if ((req->bmRequestType & 0x1f) == DEVICE_TYPE) { // TODO: replace this regular buffer filling routines - IEP0CNT &= ~0x0f; - IEP0CNT |= 2; buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; if (device_remote_wakeup_f) { @@ -720,6 +743,7 @@ static void usb_get_device_status_handler(__xdata struct usb_req_setup *req) } *buffer_addr = 0; + IEP0CNT_SET(2); IN0_SET_READY; } else { STALL_EP0(); @@ -731,12 +755,12 @@ static void usb_get_interface_status_handler(__xdata struct usb_req_setup *req) if ((req->bmRequestType & 0x1f) == INTERFACE_TYPE) { if ((req->wIndex == 0) || (req->wIndex == 1)) { // TODO: replace this regular buffer filling routines - IEP0CNT &= ~0x0f; - IEP0CNT |= 2; - buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; + *buffer_addr++ = 0; *buffer_addr = 0; + + IEP0CNT_SET(2); IN0_SET_READY; } else { STALL_EP0(); @@ -750,9 +774,6 @@ static void usb_get_endpoint_status_handler(__xdata struct usb_req_setup *req) { if ((req->bmRequestType & 0x1f) == ENDPOINT_TYPE) { // TODO: replace this regular buffer filling routines - IEP0CNT &= ~0x0f; - IEP0CNT |= 2; - if (req->wIndex == 0x80) { buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; *buffer_addr++ = ((EP0CON & 0x02)) >> 1; @@ -772,17 +793,13 @@ static void usb_get_endpoint_status_handler(__xdata struct usb_req_setup *req) return; } + IEP0CNT_SET(2); IN0_SET_READY; } else { STALL_EP0(); } } -/** - * 0.5KB of general purpose scratch RAM. - */ -__xdata uint8_t scratch[512]; - static void usb_get_descriptor_handler(__xdata struct usb_req_setup *req) { uint8_t *__xdata code_pt; // TODO: remove/rename @@ -904,20 +921,20 @@ static void usb_get_descriptor_handler(__xdata struct usb_req_setup *req) static void usb_get_configuration_handler(__xdata struct usb_req_setup *req) { ep0_xfer_state = OUT0_STATUS_PHASE; - IEP0CNT &= ~0x0f; - IEP0CNT = 1; buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; *buffer_addr = configution_value; + + IEP0CNT_SET(1); IN0_SET_READY; } static void usb_get_interface_handler(__xdata struct usb_req_setup *req) { ep0_xfer_state = OUT0_STATUS_PHASE; - IEP0CNT &= ~0x0f; - IEP0CNT = 1; buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; *buffer_addr = 0; + + IEP0CNT_SET(1); IN0_SET_READY; } @@ -951,7 +968,8 @@ static void usb_hid_set_idle_handler(__xdata struct usb_req_setup *req) { // TODO: is this used? EP1_IDLE_TIME = EP1_IDLE_COUNT = req->wValue >> 8; - IEP0CNT &= ~0x0f; + + IEP0CNT_CLR; IN0_SET_READY; } @@ -960,8 +978,8 @@ static void usb_hid_get_idle_handler(__xdata struct usb_req_setup *req) // TODO: replace with regular buffer filling methods buffer_addr = (uint8_t __xdata *)USB_EP0_IN_BUFFER_ADDR; *buffer_addr = EP1_IDLE_TIME; - IEP0CNT &= ~0x0f; - IEP0CNT = 0x01; + + IEP0CNT_SET(1); IN0_SET_READY; } @@ -973,7 +991,7 @@ static void usb_hid_set_protocol_handler(__xdata struct usb_req_setup *req) Protocol_type1 = req->wValue && 0xff; } - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; } @@ -987,25 +1005,20 @@ static void usb_hid_get_protocol_handler(__xdata struct usb_req_setup *req) *buffer_addr = Protocol_type1; } - IEP0CNT &= ~0x0f; - IEP0CNT = 1; + IEP0CNT_SET(1); IN0_SET_READY; } -void SUSPEND_IRQ_Prog() -{ -} - -void OUT0_IRQ_Prog() +void usb_ep0_out_irq() { - if (ep0_xfer_state == OUT0_LED_PHASE) { //scrlk,capslk,numlk LED�� + if (ep0_xfer_state == OUT0_LED_PHASE) { ep0_xfer_state = 0; buffer_addr = (uint8_t __xdata *)USB_EP0_OUT_BUFFER_ADDR; - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; - } else if (ep0_xfer_state == OUT0_Rev_PHASE) { //���scrlk,capslk,numlk LED�� + } else if (ep0_xfer_state == OUT0_Rev_PHASE) { ep0_xfer_state = 0; - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; } else if (ep0_xfer_state == OUT0_KeyMode_PHASE) { CLR_WDT(); @@ -1015,7 +1028,7 @@ void OUT0_IRQ_Prog() if (buffer_addr[0] == 0x05) { switch (buffer_addr[1]) { - case 0x75: // go to ISP Program + case 0x75: isp_jump(); break; @@ -1025,24 +1038,24 @@ void OUT0_IRQ_Prog() } } else { ep0_xfer_state = 0; - IEP0CNT &= ~0x0f; + IEP0CNT_CLR; IN0_SET_READY; } //ep0_xfer_state may be OUT0_STATUS_PHASE or IN0_DATA_PHASE } -void IN0_IRQ_Prog() +void usb_ep0_in_irq() { if (ep0_xfer_state == IN0_DATA_PHASE) { step_ep0_in_xfer(); IN0_SET_READY; - OUT0_SET_READY; //PC in0 may only occur once + OUT0_SET_READY; } else if (ep0_xfer_state == OUT0_STATUS_PHASE) { OUT0_SET_READY; IN0_SET_STALL; - } else { //NEW_SETUP_PHASE + } else { IN0_SET_STALL; OUT0_SET_READY; @@ -1053,15 +1066,6 @@ void IN0_IRQ_Prog() } } -void IN0_SetReady() -{ - IEP0CNT &= ~0x0f; - IN0_SET_READY; -} - -uint16_t ep0_xfer_bytes_left; // init with real value -uint8_t *ep0_xfer_src; - static void setup_ep0_in_xfer(uint8_t *src, uint16_t len) { ep0_xfer_src = src; @@ -1070,30 +1074,29 @@ static void setup_ep0_in_xfer(uint8_t *src, uint16_t len) static void step_ep0_in_xfer() { -#define SET_CNT(COUNT) { IEP0CNT &= ~0x0f; IEP0CNT |= COUNT; } if (ep0_xfer_bytes_left == 0) { ep0_xfer_state = OUT0_STATUS_PHASE; - SET_CNT(0); + IEP0CNT_SET(0); } else if (ep0_xfer_bytes_left > USB_EP0_BUFFER_SIZE) { ep0_xfer_state = IN0_DATA_PHASE; set_ep0_in_buffer(ep0_xfer_src, USB_EP0_BUFFER_SIZE); ep0_xfer_bytes_left -= USB_EP0_BUFFER_SIZE; ep0_xfer_src += USB_EP0_BUFFER_SIZE; - SET_CNT(USB_EP0_BUFFER_SIZE); + IEP0CNT_SET(USB_EP0_BUFFER_SIZE); } else if (ep0_xfer_bytes_left == USB_EP0_BUFFER_SIZE) { ep0_xfer_state = IN0_DATA_PHASE; set_ep0_in_buffer(ep0_xfer_src, USB_EP0_BUFFER_SIZE); ep0_xfer_bytes_left = 0; - SET_CNT(USB_EP0_BUFFER_SIZE); + IEP0CNT_SET(USB_EP0_BUFFER_SIZE); } else { ep0_xfer_state = OUT0_STATUS_PHASE; set_ep0_in_buffer(ep0_xfer_src, ep0_xfer_bytes_left); - SET_CNT(ep0_xfer_bytes_left); + IEP0CNT_SET(ep0_xfer_bytes_left); } }