void set_keyboard_report(uint64_t rpt) { /* Prevent the interrupt handler from sending the data (which would use * an incomplete buffer). */ hid_ep_data_ready = 0; hid_current_buf = hid_current_buf ? 0 : 1; memcpy_to_usbram((void *) usb_sram_addr(hid_ep_buf[hid_current_buf]), &rpt, sizeof(rpt)); /* Tell the interrupt handler to send the next buffer. */ hid_ep_data_ready = 1; if ((STM32_USB_EP(USB_EP_HID_KEYBOARD) & EP_TX_MASK) == EP_TX_VALID) { /* Endpoint is busy: we sneak in an address change to give us a * chance to send the most updated report. However, there is no * guarantee that this buffer is the one actually sent, so we * keep hid_ep_data_ready = 1, which will send a duplicated * report. */ btable_ep[USB_EP_HID_KEYBOARD].tx_addr = usb_sram_addr(hid_ep_buf[hid_current_buf]); hid_ep_data_ready = 1; } else if (atomic_read_clear(&hid_ep_data_ready)) { /* Endpoint is not busy, and interrupt handler did not just * send our last buffer: swap buffer, enable TX. */ btable_ep[USB_EP_HID_KEYBOARD].tx_addr = usb_sram_addr(hid_ep_buf[hid_current_buf]); STM32_TOGGLE_EP(USB_EP_HID_KEYBOARD, EP_TX_MASK, EP_TX_VALID, 0); } }
static void hid_keyboard_tx(void) { hid_tx(USB_EP_HID_KEYBOARD); if (hid_ep_data_ready) { /* swap buffer, enable TX */ btable_ep[USB_EP_HID_KEYBOARD].tx_addr = usb_sram_addr(hid_ep_buf[hid_current_buf]); STM32_TOGGLE_EP(USB_EP_HID_KEYBOARD, EP_TX_MASK, EP_TX_VALID, 0); } hid_ep_data_ready = 0; }
static void hid_reset(void) { /* HID interrupt endpoint 1 */ btable_ep[USB_EP_HID].tx_addr = usb_sram_addr(hid_ep_buf); btable_ep[USB_EP_HID].tx_count = 8; hid_ep_buf[0] = 0; hid_ep_buf[1] = 0; hid_ep_buf[2] = 0; hid_ep_buf[3] = 0; STM32_USB_EP(USB_EP_HID) = (USB_EP_HID << 0) /*Endpoint Address*/ | (3 << 4) /* TX Valid */ | (3 << 9) /* interrupt EP */ | (0 << 12) /* RX Disabled */; }
static int hid_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx) { if ((ep0_buf_rx[0] == (USB_DIR_IN | USB_RECIP_INTERFACE | (USB_REQ_GET_DESCRIPTOR << 8))) && (ep0_buf_rx[1] == (USB_HID_DT_REPORT << 8))) { /* Setup : HID specific : Get Report descriptor */ memcpy_to_usbram((void *) usb_sram_addr(ep0_buf_tx), report_desc, sizeof(report_desc)); btable_ep[0].tx_count = MIN(ep0_buf_rx[3], sizeof(report_desc)); STM32_TOGGLE_EP(0, EP_TX_RX_MASK, EP_TX_RX_VALID, EP_STATUS_OUT); CPRINTF("RPT %04x[l %04x]\n", STM32_USB_EP(0), ep0_buf_rx[3]); return 0; } return 1; }
void set_keyboard_report(uint64_t rpt) { memcpy_to_usbram((void *) usb_sram_addr(hid_ep_buf), &rpt, sizeof(rpt)); /* enable TX */ STM32_TOGGLE_EP(USB_EP_HID, EP_TX_MASK, EP_TX_VALID, 0); }