- merge: usb_driver.c conflicts fixed

This commit is contained in:
Wiesner András 2024-07-11 08:17:47 +02:00
commit d671bac4af
4 changed files with 103 additions and 83 deletions

View File

@ -38,6 +38,10 @@ void usb_cdc_init(const USB_CdcAssignments *as) {
// initialize buffer // initialize buffer
bfifo_create(&fifo, fifo_mem, USB_CDC_FIFO_MEM_SIZE); bfifo_create(&fifo, fifo_mem, USB_CDC_FIFO_MEM_SIZE);
// initialize an all-0 interrupt
cdcs.interrupt_data = 0;
cdcs.interrupt_pending = true;
// from now on CDC is considered initialized // from now on CDC is considered initialized
cdcs.initialized = true; cdcs.initialized = true;
} }
@ -96,7 +100,10 @@ int usb_cdc_process_and_return(USB_CallbackEvent *cbevt) {
case USB_CBEVT_IN: { case USB_CBEVT_IN: {
if (cbevt->ep == cdcs.ep_assignments.control_ep) { // if notification feeding is requested if (cbevt->ep == cdcs.ep_assignments.control_ep) { // if notification feeding is requested
usbcore_schedule_transmission(cdcs.ep_assignments.control_ep, NULL, 0); // send ZLP if (cdcs.interrupt_pending) {
usbcore_schedule_transmission(cdcs.ep_assignments.control_ep, (const uint8_t *)&(cdcs.interrupt_data), sizeof(uint16_t)); // send ZLP
cdcs.interrupt_pending = false;
}
ret = 0; ret = 0;
} else if (cbevt->ep == cdcs.ep_assignments.data_ep) { // if data are requested } else if (cbevt->ep == cdcs.ep_assignments.data_ep) { // if data are requested
// usbcore_schedule_transmission(cdcs.ep_assignments.data_ep, NULL, 0); // send ZLP // usbcore_schedule_transmission(cdcs.ep_assignments.data_ep, NULL, 0); // send ZLP

View File

@ -50,6 +50,8 @@ typedef struct {
USB_CdcAssignments ep_assignments; // endpoint assignments USB_CdcAssignments ep_assignments; // endpoint assignments
USB_Cdc_LineCodingStruct line_coding; // line coding USB_Cdc_LineCodingStruct line_coding; // line coding
USB_Cdc_ControlLineStateStruct control_line_state; // control line state USB_Cdc_ControlLineStateStruct control_line_state; // control line state
uint16_t interrupt_data; // data sent though the next transfer on the notification element
bool interrupt_pending; // interrupt data is valid and should be send in the next cycle
bool initialized; // CDC is initialized bool initialized; // CDC is initialized
} USB_CdcState; } USB_CdcState;

View File

@ -300,6 +300,10 @@ void usb_eem_ethernet_intercept_cb(EthInterface *intf, const RawPckt *rawPckt) {
} }
void usb_eem_set_intf(EthInterface *intf) { void usb_eem_set_intf(EthInterface *intf) {
if (!eems.initialized) {
return;
}
eems.intf = intf; // store interface eems.intf = intf; // store interface
ethinf_set_intercept_callback(intf, usb_eem_ethernet_intercept_cb); // set intercept callback ethinf_set_intercept_callback(intf, usb_eem_ethernet_intercept_cb); // set intercept callback
} }

View File

@ -169,6 +169,9 @@ void usbdrv_init_global_state() {
#endif #endif
} }
// ---------------
#ifdef USB_HIGH_SPEED #ifdef USB_HIGH_SPEED
__weak void usbdrv_ulpi_init() { __weak void usbdrv_ulpi_init() {
return; return;
@ -240,6 +243,10 @@ void usbdrv_periph_init() {
#endif #endif
#endif #endif
(uint32_t *)(((uint32_t)USBG) + 0x028), // DIEPTXF0
(uint32_t *)(((uint32_t)USBG) + 0x104), // DIEPTXF1
(uint32_t *)(((uint32_t)USBG) + 0x108), // DIEPTXF2
(uint32_t *)(((uint32_t)USBG) + 0x10C), // DIEPTXF3
CLEAR_BIT(USBG->GCCFG, USB_OTG_GCCFG_PWRDWN); // power down the peripheral CLEAR_BIT(USBG->GCCFG, USB_OTG_GCCFG_PWRDWN); // power down the peripheral
@ -752,7 +759,7 @@ uint32_t usbdrv_arm_IN_endpoint(uint8_t ep, const uint8_t *data, uint16_t len) {
// arm OUT endpoint // arm OUT endpoint
uint32_t usbdrv_arm_OUT_endpoint(uint8_t ep, uint8_t size) { uint32_t usbdrv_arm_OUT_endpoint(uint8_t ep, uint8_t size) {
// arm endpoint only if it was not armed before OR if it's the EP0 OUT which is always enabled, but responds NAK after a successful transfer // arm endpoint only if it was not armed before
if (READ_BIT(USBOUTEP[ep].DOEPCTL, USB_OTG_DOEPCTL_EPENA)) { if (READ_BIT(USBOUTEP[ep].DOEPCTL, USB_OTG_DOEPCTL_EPENA)) {
return 0; return 0;
} }