Broke some application-specific USB code into separate files within hackrf_usb/. Hoping I can use them as necessary in other projects, or push them into a library eventually.
This commit is contained in:
@ -49,6 +49,8 @@ struct _usb_queue_t {
|
||||
usb_transfer_t* volatile active;
|
||||
};
|
||||
|
||||
#define USB_DECLARE_QUEUE(endpoint_name) \
|
||||
struct _usb_queue_t endpoint_name##_queue;
|
||||
#define USB_DEFINE_QUEUE(endpoint_name, _pool_size) \
|
||||
struct _usb_transfer_t endpoint_name##_transfers[_pool_size]; \
|
||||
struct _usb_queue_t endpoint_name##_queue = { \
|
||||
|
@ -31,6 +31,8 @@ SRC = $(BINARY).c \
|
||||
../common/usb_request.c \
|
||||
../common/usb_standard_request.c \
|
||||
usb_descriptor.c \
|
||||
usb_device.c \
|
||||
usb_endpoint.c \
|
||||
../common/usb_queue.c \
|
||||
../common/fault_handler.c \
|
||||
../common/hackrf_core.c \
|
||||
|
@ -46,6 +46,10 @@
|
||||
#include "usb_descriptor.h"
|
||||
#include "usb_standard_request.h"
|
||||
|
||||
#include "usb_device.h"
|
||||
#include "usb_endpoint.h"
|
||||
#include "usb_api_cpld.h"
|
||||
|
||||
#include "rf_path.h"
|
||||
#include "tuning.h"
|
||||
#include "sgpio_isr.h"
|
||||
@ -74,93 +78,6 @@ typedef struct {
|
||||
|
||||
set_sample_r_params_t set_sample_r_params;
|
||||
|
||||
usb_configuration_t usb_configuration_high_speed = {
|
||||
.number = 1,
|
||||
.speed = USB_SPEED_HIGH,
|
||||
.descriptor = usb_descriptor_configuration_high_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_full_speed = {
|
||||
.number = 1,
|
||||
.speed = USB_SPEED_FULL,
|
||||
.descriptor = usb_descriptor_configuration_full_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_cpld_update_full_speed = {
|
||||
.number = 2,
|
||||
.speed = USB_SPEED_FULL,
|
||||
.descriptor = usb_descriptor_configuration_cpld_update_full_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_cpld_update_high_speed = {
|
||||
.number = 2,
|
||||
.speed = USB_SPEED_HIGH,
|
||||
.descriptor = usb_descriptor_configuration_cpld_update_high_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t* usb_configurations[] = {
|
||||
&usb_configuration_high_speed,
|
||||
&usb_configuration_full_speed,
|
||||
&usb_configuration_cpld_update_full_speed,
|
||||
&usb_configuration_cpld_update_high_speed,
|
||||
0,
|
||||
};
|
||||
|
||||
usb_device_t usb_device = {
|
||||
.descriptor = usb_descriptor_device,
|
||||
.descriptor_strings = usb_descriptor_strings,
|
||||
.qualifier_descriptor = usb_descriptor_device_qualifier,
|
||||
.configurations = &usb_configurations,
|
||||
.configuration = 0,
|
||||
};
|
||||
|
||||
usb_endpoint_t usb_endpoint_control_out;
|
||||
usb_endpoint_t usb_endpoint_control_in;
|
||||
|
||||
usb_endpoint_t usb_endpoint_control_out = {
|
||||
.address = 0x00,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_control_in,
|
||||
.out = &usb_endpoint_control_out,
|
||||
.setup_complete = usb_setup_complete,
|
||||
.transfer_complete = usb_control_out_complete,
|
||||
};
|
||||
USB_DEFINE_QUEUE(usb_endpoint_control_out, 4);
|
||||
|
||||
usb_endpoint_t usb_endpoint_control_in = {
|
||||
.address = 0x80,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_control_in,
|
||||
.out = &usb_endpoint_control_out,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_control_in_complete,
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_control_in, 4);
|
||||
|
||||
// NOTE: Endpoint number for IN and OUT are different. I wish I had some
|
||||
// evidence that having BULK IN and OUT on separate endpoint numbers was
|
||||
// actually a good idea. Seems like everybody does it that way, but why?
|
||||
|
||||
usb_endpoint_t usb_endpoint_bulk_in = {
|
||||
.address = 0x81,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_bulk_in,
|
||||
.out = 0,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_queue_transfer_complete
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_bulk_in, 4);
|
||||
|
||||
usb_endpoint_t usb_endpoint_bulk_out = {
|
||||
.address = 0x02,
|
||||
.device = &usb_device,
|
||||
.in = 0,
|
||||
.out = &usb_endpoint_bulk_out,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_queue_transfer_complete
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_bulk_out, 4);
|
||||
|
||||
void baseband_streaming_enable() {
|
||||
nvic_set_priority(NVIC_SGPIO_IRQ, 0);
|
||||
nvic_enable_irq(NVIC_SGPIO_IRQ);
|
||||
|
67
firmware/hackrf_usb/usb_device.c
Normal file
67
firmware/hackrf_usb/usb_device.c
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone
|
||||
* Copyright 2013 Benjamin Vernoux
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "usb_device.h"
|
||||
|
||||
#include <usb_type.h>
|
||||
|
||||
#include "usb_descriptor.h"
|
||||
|
||||
usb_configuration_t usb_configuration_high_speed = {
|
||||
.number = 1,
|
||||
.speed = USB_SPEED_HIGH,
|
||||
.descriptor = usb_descriptor_configuration_high_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_full_speed = {
|
||||
.number = 1,
|
||||
.speed = USB_SPEED_FULL,
|
||||
.descriptor = usb_descriptor_configuration_full_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_cpld_update_full_speed = {
|
||||
.number = 2,
|
||||
.speed = USB_SPEED_FULL,
|
||||
.descriptor = usb_descriptor_configuration_cpld_update_full_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t usb_configuration_cpld_update_high_speed = {
|
||||
.number = 2,
|
||||
.speed = USB_SPEED_HIGH,
|
||||
.descriptor = usb_descriptor_configuration_cpld_update_high_speed,
|
||||
};
|
||||
|
||||
usb_configuration_t* usb_configurations[] = {
|
||||
&usb_configuration_high_speed,
|
||||
&usb_configuration_full_speed,
|
||||
&usb_configuration_cpld_update_full_speed,
|
||||
&usb_configuration_cpld_update_high_speed,
|
||||
0,
|
||||
};
|
||||
|
||||
usb_device_t usb_device = {
|
||||
.descriptor = usb_descriptor_device,
|
||||
.descriptor_strings = usb_descriptor_strings,
|
||||
.qualifier_descriptor = usb_descriptor_device_qualifier,
|
||||
.configurations = &usb_configurations,
|
||||
.configuration = 0,
|
||||
};
|
30
firmware/hackrf_usb/usb_device.h
Normal file
30
firmware/hackrf_usb/usb_device.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone
|
||||
* Copyright 2013 Benjamin Vernoux
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __USB_DEVICE_H__
|
||||
#define __USB_DEVICE_H__
|
||||
|
||||
#include <usb_type.h>
|
||||
|
||||
extern usb_device_t usb_device;
|
||||
|
||||
#endif /* end of include guard: __USB_DEVICE_H__ */
|
73
firmware/hackrf_usb/usb_endpoint.c
Normal file
73
firmware/hackrf_usb/usb_endpoint.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone
|
||||
* Copyright 2013 Benjamin Vernoux
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "usb_endpoint.h"
|
||||
|
||||
#include <usb_request.h>
|
||||
|
||||
#include "usb_device.h"
|
||||
|
||||
usb_endpoint_t usb_endpoint_control_out = {
|
||||
.address = 0x00,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_control_in,
|
||||
.out = &usb_endpoint_control_out,
|
||||
.setup_complete = usb_setup_complete,
|
||||
.transfer_complete = usb_control_out_complete,
|
||||
};
|
||||
USB_DEFINE_QUEUE(usb_endpoint_control_out, 4);
|
||||
|
||||
usb_endpoint_t usb_endpoint_control_in = {
|
||||
.address = 0x80,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_control_in,
|
||||
.out = &usb_endpoint_control_out,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_control_in_complete,
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_control_in, 4);
|
||||
|
||||
// NOTE: Endpoint number for IN and OUT are different. I wish I had some
|
||||
// evidence that having BULK IN and OUT on separate endpoint numbers was
|
||||
// actually a good idea. Seems like everybody does it that way, but why?
|
||||
|
||||
usb_endpoint_t usb_endpoint_bulk_in = {
|
||||
.address = 0x81,
|
||||
.device = &usb_device,
|
||||
.in = &usb_endpoint_bulk_in,
|
||||
.out = 0,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_queue_transfer_complete
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_bulk_in, 4);
|
||||
|
||||
usb_endpoint_t usb_endpoint_bulk_out = {
|
||||
.address = 0x02,
|
||||
.device = &usb_device,
|
||||
.in = 0,
|
||||
.out = &usb_endpoint_bulk_out,
|
||||
.setup_complete = 0,
|
||||
.transfer_complete = usb_queue_transfer_complete
|
||||
};
|
||||
static USB_DEFINE_QUEUE(usb_endpoint_bulk_out, 4);
|
||||
|
||||
|
41
firmware/hackrf_usb/usb_endpoint.h
Normal file
41
firmware/hackrf_usb/usb_endpoint.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone
|
||||
* Copyright 2013 Benjamin Vernoux
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __USB_ENDPOINT_H__
|
||||
#define __USB_ENDPOINT_H__
|
||||
|
||||
#include <usb_type.h>
|
||||
#include <usb_queue.h>
|
||||
|
||||
extern usb_endpoint_t usb_endpoint_control_out;
|
||||
extern USB_DECLARE_QUEUE(usb_endpoint_control_out);
|
||||
|
||||
extern usb_endpoint_t usb_endpoint_control_in;
|
||||
extern USB_DECLARE_QUEUE(usb_endpoint_control_in);
|
||||
|
||||
extern usb_endpoint_t usb_endpoint_bulk_in;
|
||||
extern USB_DECLARE_QUEUE(usb_endpoint_bulk_in);
|
||||
|
||||
extern usb_endpoint_t usb_endpoint_bulk_out;
|
||||
extern USB_DECLARE_QUEUE(usb_endpoint_bulk_out);
|
||||
|
||||
#endif /* end of include guard: __USB_ENDPOINT_H__ */
|
Reference in New Issue
Block a user