Skip to content

Commit

Permalink
testing 2nd interface
Browse files Browse the repository at this point in the history
  • Loading branch information
onlykey committed Sep 25, 2019
1 parent 8676c72 commit 697c4c0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions usb_rawhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,31 @@
#ifdef RAWHID_INTERFACE // defined by usb_dev.h -> usb_desc.h
#if F_CPU >= 20000000


int usb_rawhid_recv(void *buffer, uint32_t timeout)
{
usb_packet_t *rx_packet;
uint32_t begin = millis();
uint8_t useinterface = 0;

while (1) {
if (!usb_configuration) return -1;
rx_packet = usb_rx(RAWHID_RX_ENDPOINT);
if (rx_packet) break;
if (rx_packet) {
useinterface=1;
break;
}
rx_packet = usb_rx(RAWHID_RX_ENDPOINT2);
if (rx_packet) break;
if (rx_packet) {
useinterface=2;
break;
}
if (millis() - begin > timeout || !timeout) return 0;
yield();
}
memcpy(buffer, rx_packet->buf, RAWHID_RX_SIZE);
usb_free(rx_packet);
return RAWHID_RX_SIZE;
return useinterface;
}

int usb_rawhid_available(void)
Expand All @@ -149,18 +157,18 @@ int usb_rawhid_send(const void *buffer, uint32_t timeout)
usb_packet_t *tx_packet;
uint32_t begin = millis();

while (1) {
if (!usb_configuration) return -1;
if (usb_tx_packet_count(RAWHID_TX_ENDPOINT) < TX_PACKET_LIMIT) {
tx_packet = usb_malloc();
if (tx_packet) break;
while (1) {
if (!usb_configuration) return -1;
if (usb_tx_packet_count(RAWHID_TX_ENDPOINT) < TX_PACKET_LIMIT) {
tx_packet = usb_malloc();
if (tx_packet) break;
}
if (millis() - begin > timeout) return 0;
yield();
}
if (millis() - begin > timeout) return 0;
yield();
}
memcpy(tx_packet->buf, buffer, RAWHID_TX_SIZE);
tx_packet->len = RAWHID_TX_SIZE;
usb_tx(RAWHID_TX_ENDPOINT, tx_packet);
memcpy(tx_packet->buf, buffer, RAWHID_TX_SIZE);
tx_packet->len = RAWHID_TX_SIZE;
usb_tx(RAWHID_TX_ENDPOINT, tx_packet);
return RAWHID_TX_SIZE;
}

Expand Down

0 comments on commit 697c4c0

Please sign in to comment.