raspberrypi / pico-playground

BSD 3-Clause "New" or "Revised" License
438 stars 92 forks source link

usb_sound_card.c - line 290 "todo lie thru our teeth for now" #28

Open Bram-Pl opened 1 year ago

Bram-Pl commented 1 year ago

Isochronous data with asynchronous USB transfer type

Line 290 states: todo lie thru our teeth for now in the _as_sync_packet' function. What exactly is meant by this? What does this function do?

Does this mean the asynchronous USB transfer type is not actually providing correct feedback to the USB Host and just spoofing the feedback loop to the host? The function can be seen below. When debugging I noticed that this function is called many times which is what could be expected for something that is used as feedback loop to a USB host device. I just do not comprehend where or when this feedback is returned to the USB host device.

static void _as_sync_packet(struct usb_endpoint *ep) {
    assert(ep->current_transfer);
    DEBUG_PINS_SET(audio_timing, 2);
    DEBUG_PINS_CLR(audio_timing, 2);
    struct usb_buffer *buffer = usb_current_in_packet_buffer(ep);
    assert(buffer->data_max >= 3);
    buffer->data_len = 3;

    // todo lie thru our teeth for now
    uint feedback = (audio_state.freq << 14u) / 1000u;

    buffer->data[0] = feedback;
    buffer->data[1] = feedback >> 8u;
    buffer->data[2] = feedback >> 16u;

    printf("_as_sync_packet function --> data[0]: %d, data[1]: %d, data[2]: %d\n\r");

    // keep on truckin'
    usb_grow_transfer(ep->current_transfer, 1);
    usb_packet_done(ep);
}