/* Execute a request and store result to the DAP_queue Parameters: queue - DAP queue, reqbuf = buffer with DAP request, len = of the request buffer, retbuf = buffer to peek on the result of the DAP operation Return Value: TRUE - Success, FALSE - Error  */
BOOL DAP_queue_execute_buf(DAP_queue *queue, const uint8_t *reqbuf, int len, uint8_t **retbuf)
/* Execute a request and store result to the DAP_queue Parameters: queue - DAP queue, reqbuf = buffer with DAP request, len = of the request buffer, retbuf = buffer to peek on the result of the DAP operation Return Value: TRUE - Success, FALSE - Error  */
BOOL DAP_queue_execute_buf(DAP_queue *queue, const uint8_t *reqbuf, int len, uint8_t **retbuf)
{
    uint32_t rsize;
    if (queue->free_count > 0) {
        if (DAP_activity_blink(reqbuf)) {
            main_blink_hid_led(MAIN_LED_FLASH);
        }
        if (len > DAP_PACKET_SIZE) {
            len = DAP_PACKET_SIZE;
        }
        queue->free_count--;
        memcpy(queue->USB_Request[queue->recv_idx], reqbuf, len);
        rsize = DAP_ExecuteCommand(reqbuf, queue->USB_Request[queue->recv_idx]);
        queue->resp_size[queue->recv_idx] = rsize & 0xFFFF;
        *retbuf = queue->USB_Request[queue->recv_idx];
        queue->recv_idx = (queue->recv_idx + 1) % DAP_PACKET_COUNT;
        queue->send_count++;
        return (__TRUE);
    }
    return (__FALSE);
}