usb: Rework configuration change notification
This commit is contained in:
@ -884,48 +884,16 @@ const usb_request_handlers_t usb_request_handlers = {
|
|||||||
.reserved = 0,
|
.reserved = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Seems like this should live in usb_standard_request.c.
|
void usb_configuration_changed(
|
||||||
bool usb_set_configuration(
|
usb_device_t* const device
|
||||||
usb_device_t* const device,
|
|
||||||
const uint_fast8_t configuration_number
|
|
||||||
) {
|
) {
|
||||||
const usb_configuration_t* new_configuration = 0;
|
set_transceiver_mode(transceiver_mode);
|
||||||
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 ) {
|
if( device->configuration->number ) {
|
||||||
// Configuration changed.
|
gpio_set(PORT_LED1_3, PIN_LED1);
|
||||||
device->configuration = new_configuration;
|
} else {
|
||||||
set_transceiver_mode(transceiver_mode);
|
gpio_clear(PORT_LED1_3, PIN_LED1);
|
||||||
|
|
||||||
if( device->configuration ) {
|
|
||||||
gpio_set(PORT_LED1_3, PIN_LED1);
|
|
||||||
} else {
|
|
||||||
gpio_clear(PORT_LED1_3, PIN_LED1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void sgpio_irqhandler() {
|
void sgpio_irqhandler() {
|
||||||
|
@ -28,13 +28,6 @@
|
|||||||
|
|
||||||
#include "usb_type.h"
|
#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_peripheral_reset();
|
||||||
|
|
||||||
void usb_device_init(
|
void usb_device_init(
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "usb_standard_request.h"
|
#include "usb_standard_request.h"
|
||||||
|
|
||||||
@ -58,10 +59,51 @@ usb_transfer_type_t usb_endpoint_descriptor_transfer_type(
|
|||||||
return (endpoint_descriptor[3] & 0x3);
|
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,
|
usb_device_t* const device,
|
||||||
const uint_fast8_t configuration_number
|
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(
|
static usb_request_status_t usb_send_descriptor(
|
||||||
usb_endpoint_t* const endpoint,
|
usb_endpoint_t* const endpoint,
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
#include "usb_type.h"
|
#include "usb_type.h"
|
||||||
#include "usb_request.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_request_status_t usb_standard_request(
|
||||||
usb_endpoint_t* const endpoint,
|
usb_endpoint_t* const endpoint,
|
||||||
const usb_transfer_stage_t stage
|
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
|
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__
|
#endif//__USB_STANDARD_REQUEST_H__
|
||||||
|
Reference in New Issue
Block a user