@@ -57,6 +57,7 @@ extern uint8_t version_string_strlen;
5757
5858/* Allocate aligned buffer on 4bytes for 32bits store */
5959uint8_t spiflash_buffer [W25Q80BV_PAGE_LEN ] __attribute__ ((aligned (4 )));
60+ uint32_t samplerates_buffer [AIRSPY_CONF_NB ];
6061
6162typedef struct {
6263 uint32_t freq_hz ;
@@ -77,17 +78,17 @@ const usb_request_handlers_t usb_request_handlers = {
7778
7879__inline__ void gpio_set (uint32_t gpioport , uint32_t gpios )
7980{
80- GPIO_SET (gpioport ) = gpios ;
81+ GPIO_SET (gpioport ) = gpios ;
8182}
8283
8384__inline__ void gpio_clear (uint32_t gpioport , uint32_t gpios )
8485{
85- GPIO_CLR (gpioport ) = gpios ;
86+ GPIO_CLR (gpioport ) = gpios ;
8687}
8788
8889__inline__ uint32_t gpio_get (uint32_t gpioport , uint32_t gpios )
8990{
90- return (GPIO_PIN (gpioport ) & gpios ) != 0 ;
91+ return (GPIO_PIN (gpioport ) & gpios ) != 0 ;
9192}
9293
9394void usb_streaming_disable (void )
@@ -161,7 +162,7 @@ const usb_transfer_stage_t stage)
161162 {
162163 const uint8_t value = si5351c_read_single (endpoint -> setup .index );
163164 endpoint -> buffer [0 ] = value ;
164- usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
165+ usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
165166 usb_transfer_schedule_ack (endpoint -> out );
166167 return USB_REQUEST_STATUS_OK ;
167168 }
@@ -202,7 +203,7 @@ const usb_transfer_stage_t stage)
202203 {
203204 const uint8_t value = airspy_r820t_read_single (& r820t_conf_rw , endpoint -> setup .index );
204205 endpoint -> buffer [0 ] = value ;
205- usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
206+ usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
206207 usb_transfer_schedule_ack (endpoint -> out );
207208 return USB_REQUEST_STATUS_OK ;
208209 }
@@ -245,7 +246,7 @@ usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
245246 return USB_REQUEST_STATUS_STALL ;
246247 } else
247248 {
248- usb_transfer_schedule_block (endpoint -> out , & spiflash_buffer [0 ], len , NULL , NULL );
249+ usb_transfer_schedule_block (endpoint -> out , & spiflash_buffer [0 ], len , NULL , NULL );
249250 w25q80bv_setup ();
250251 return USB_REQUEST_STATUS_OK ;
251252 }
@@ -308,7 +309,7 @@ usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
308309 spiflash_buffer [i ] = u8_addr_pt [i ];
309310 }
310311 }
311- usb_transfer_schedule_block (endpoint -> in , & spiflash_buffer [0 ], len , NULL , NULL );
312+ usb_transfer_schedule_block (endpoint -> in , & spiflash_buffer [0 ], len , NULL , NULL );
312313 return USB_REQUEST_STATUS_OK ;
313314 }
314315 } else if (stage == USB_TRANSFER_STAGE_DATA )
@@ -402,7 +403,7 @@ const usb_transfer_stage_t stage)
402403 {
403404 if (endpoint -> setup .index > (AIRSPY_SAMPLERATE_END - 1 ))
404405 {
405- return USB_REQUEST_STATUS_STALL ;
406+ return USB_REQUEST_STATUS_STALL ;
406407 }else
407408 {
408409 sample_rate_conf_no = endpoint -> setup .index ;
@@ -541,18 +542,18 @@ usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
541542{
542543 if ( stage == USB_TRANSFER_STAGE_SETUP )
543544 {
544- if (endpoint -> setup .index == 0x04 )
545- {
546- usb_transfer_schedule_block (endpoint -> in , & usb_descriptor_CompatIDDescriptor , endpoint -> setup .length , NULL , NULL );
547- usb_transfer_schedule_ack (endpoint -> out );
548- return USB_REQUEST_STATUS_OK ;
549- }
550- if (endpoint -> setup .index == 0x05 )
551- {
552- usb_transfer_schedule_block (endpoint -> in , & usb_descriptor_ExtProps , endpoint -> setup .length , NULL , NULL );
553- usb_transfer_schedule_ack (endpoint -> out );
554- return USB_REQUEST_STATUS_OK ;
555- }
545+ if (endpoint -> setup .index == 0x04 )
546+ {
547+ usb_transfer_schedule_block (endpoint -> in , & usb_descriptor_CompatIDDescriptor , endpoint -> setup .length , NULL , NULL );
548+ usb_transfer_schedule_ack (endpoint -> out );
549+ return USB_REQUEST_STATUS_OK ;
550+ }
551+ if (endpoint -> setup .index == 0x05 )
552+ {
553+ usb_transfer_schedule_block (endpoint -> in , & usb_descriptor_ExtProps , endpoint -> setup .length , NULL , NULL );
554+ usb_transfer_schedule_ack (endpoint -> out );
555+ return USB_REQUEST_STATUS_OK ;
556+ }
556557 return USB_REQUEST_STATUS_STALL ;
557558 }
558559 return USB_REQUEST_STATUS_OK ;
@@ -643,7 +644,7 @@ const usb_transfer_stage_t stage)
643644 value = gpio_get (port_num , pin_num );
644645 }
645646 endpoint -> buffer [0 ] = value ;
646- usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
647+ usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
647648 usb_transfer_schedule_ack (endpoint -> out );
648649 return USB_REQUEST_STATUS_OK ;
649650 }
@@ -719,7 +720,7 @@ const usb_transfer_stage_t stage)
719720 value = 0 ;
720721 }
721722 endpoint -> buffer [0 ] = value ;
722- usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
723+ usb_transfer_schedule_block (endpoint -> in , & endpoint -> buffer , 1 , NULL , NULL );
723724 usb_transfer_schedule_ack (endpoint -> out );
724725 return USB_REQUEST_STATUS_OK ;
725726 }
@@ -729,6 +730,45 @@ const usb_transfer_stage_t stage)
729730 }
730731}
731732
733+ usb_request_status_t usb_vendor_request_get_samplerates_command (
734+ usb_endpoint_t * const endpoint , const usb_transfer_stage_t stage )
735+ {
736+ int i ;
737+ uint16_t nb_samplerate ;
738+ uint32_t schedule_block_len ;
739+
740+ if (stage == USB_TRANSFER_STAGE_SETUP )
741+ {
742+ nb_samplerate = endpoint -> setup .index ;
743+
744+ if (nb_samplerate > AIRSPY_CONF_NB )
745+ {
746+ nb_samplerate = AIRSPY_CONF_NB ;
747+ }
748+
749+ if (nb_samplerate == 0 )
750+ {
751+ /* Return the number of samplerates available */
752+ samplerates_buffer [0 ] = AIRSPY_CONF_NB ;
753+ usb_transfer_schedule_block (endpoint -> in , & samplerates_buffer [0 ], 4 , NULL , NULL );
754+ } else
755+ {
756+ /* Return each samplerate available */
757+ for (i = 0 ; i < nb_samplerate ; i ++ )
758+ {
759+ samplerates_buffer [i ] = airspy_m0_conf [i ].r820t_if_freq * 2 ; /* samplerate = IF_freq * 2 */
760+ }
761+ schedule_block_len = nb_samplerate * sizeof (uint32_t );
762+ usb_transfer_schedule_block (endpoint -> in , & samplerates_buffer [0 ], schedule_block_len , NULL , NULL );
763+ }
764+ usb_transfer_schedule_ack (endpoint -> out );
765+ return USB_REQUEST_STATUS_OK ;
766+ } else
767+ {
768+ return USB_REQUEST_STATUS_OK ;
769+ }
770+ }
771+
732772/* ID 1 to X corresponds to user endpoint->setup.request */
733773usb_request_handler_fn vendor_request_handler [AIRSPY_CMD_MAX + 1 ];
734774
@@ -782,6 +822,8 @@ void airspy_usb_req_init(void)
782822
783823 vendor_request_handler [AIRSPY_GPIODIR_WRITE ] = usb_vendor_request_gpiodir_write_command ;
784824 vendor_request_handler [AIRSPY_GPIODIR_READ ] = usb_vendor_request_gpiodir_read_command ;
825+
826+ vendor_request_handler [AIRSPY_GET_SAMPLERATES ] = usb_vendor_request_get_samplerates_command ;
785827}
786828
787829usb_request_status_t usb_vendor_request (usb_endpoint_t * const endpoint , const usb_transfer_stage_t stage )
@@ -799,11 +841,11 @@ usb_request_status_t usb_vendor_request(usb_endpoint_t* const endpoint, const us
799841 {
800842 if ( stage == USB_TRANSFER_STAGE_SETUP )
801843 {
802- status = USB_REQUEST_STATUS_STALL ;
803- } else
804- {
805- status = USB_REQUEST_STATUS_OK ;
806- }
844+ status = USB_REQUEST_STATUS_STALL ;
845+ } else
846+ {
847+ status = USB_REQUEST_STATUS_OK ;
848+ }
807849 }
808850 return status ;
809851}
0 commit comments