usb: Rework configuration change notification
This commit is contained in:
@ -884,48 +884,16 @@ const usb_request_handlers_t usb_request_handlers = {
|
||||
.reserved = 0,
|
||||
};
|
||||
|
||||
// TODO: Seems like this should live in usb_standard_request.c.
|
||||
bool usb_set_configuration(
|
||||
usb_device_t* const device,
|
||||
const uint_fast8_t configuration_number
|
||||
void usb_configuration_changed(
|
||||
usb_device_t* const device
|
||||
) {
|
||||
const usb_configuration_t* new_configuration = 0;
|
||||
if( configuration_number != 0 ) {
|
||||
|
||||
// Locate requested configuration.
|
||||
if( device->configurations ) {
|
||||
usb_configuration_t** configurations = *(device->configurations);
|
||||
uint32_t i = 0;
|
||||
const usb_speed_t usb_speed_current = usb_speed(device);
|
||||
while( configurations[i] ) {
|
||||
if( (configurations[i]->speed == usb_speed_current) &&
|
||||
(configurations[i]->number == configuration_number) ) {
|
||||
new_configuration = configurations[i];
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Requested configuration not found: request error.
|
||||
if( new_configuration == 0 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( new_configuration != device->configuration ) {
|
||||
// Configuration changed.
|
||||
device->configuration = new_configuration;
|
||||
set_transceiver_mode(transceiver_mode);
|
||||
|
||||
if( device->configuration ) {
|
||||
if( device->configuration->number ) {
|
||||
gpio_set(PORT_LED1_3, PIN_LED1);
|
||||
} else {
|
||||
gpio_clear(PORT_LED1_3, PIN_LED1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
void sgpio_irqhandler() {
|
||||
|
@ -28,13 +28,6 @@
|
||||
|
||||
#include "usb_type.h"
|
||||
|
||||
// TODO: This is a lame move, requiring an extern to be defined to complete
|
||||
// the interface between this API and the application.
|
||||
extern bool usb_set_configuration(
|
||||
usb_device_t* const device,
|
||||
const uint_fast8_t configuration_number
|
||||
);
|
||||
|
||||
void usb_peripheral_reset();
|
||||
|
||||
void usb_device_init(
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "usb_standard_request.h"
|
||||
|
||||
@ -58,10 +59,51 @@ usb_transfer_type_t usb_endpoint_descriptor_transfer_type(
|
||||
return (endpoint_descriptor[3] & 0x3);
|
||||
}
|
||||
|
||||
extern bool usb_set_configuration(
|
||||
void (*usb_configuration_changed_cb)(usb_device_t* const) = NULL;
|
||||
|
||||
void usb_set_configuration_changed_cb(
|
||||
void (*callback)(usb_device_t* const)
|
||||
) {
|
||||
usb_configuration_changed_cb = callback;
|
||||
}
|
||||
|
||||
bool usb_set_configuration(
|
||||
usb_device_t* const device,
|
||||
const uint_fast8_t configuration_number
|
||||
);
|
||||
) {
|
||||
|
||||
const usb_configuration_t* new_configuration = 0;
|
||||
if( configuration_number != 0 ) {
|
||||
|
||||
// Locate requested configuration.
|
||||
if( device->configurations ) {
|
||||
usb_configuration_t** configurations = *(device->configurations);
|
||||
uint32_t i = 0;
|
||||
const usb_speed_t usb_speed_current = usb_speed(device);
|
||||
while( configurations[i] ) {
|
||||
if( (configurations[i]->speed == usb_speed_current) &&
|
||||
(configurations[i]->number == configuration_number) ) {
|
||||
new_configuration = configurations[i];
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Requested configuration not found: request error.
|
||||
if( new_configuration == 0 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( new_configuration != device->configuration ) {
|
||||
// Configuration changed.
|
||||
device->configuration = new_configuration;
|
||||
if (usb_configuration_changed_cb)
|
||||
usb_configuration_changed_cb(device);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static usb_request_status_t usb_send_descriptor(
|
||||
usb_endpoint_t* const endpoint,
|
||||
|
@ -25,6 +25,10 @@
|
||||
#include "usb_type.h"
|
||||
#include "usb_request.h"
|
||||
|
||||
void usb_set_configuration_changed_cb(
|
||||
void (*callback)(usb_device_t* const)
|
||||
);
|
||||
|
||||
usb_request_status_t usb_standard_request(
|
||||
usb_endpoint_t* const endpoint,
|
||||
const usb_transfer_stage_t stage
|
||||
@ -42,4 +46,9 @@ usb_transfer_type_t usb_endpoint_descriptor_transfer_type(
|
||||
const uint8_t* const endpoint_descriptor
|
||||
);
|
||||
|
||||
bool usb_set_configuration(
|
||||
usb_device_t* const device,
|
||||
const uint_fast8_t configuration_number
|
||||
);
|
||||
|
||||
#endif//__USB_STANDARD_REQUEST_H__
|
||||
|
Reference in New Issue
Block a user