Skip to content

Update HID classes #6447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions TESTS/usb_device/basic/USBTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#define MAX_EP_SIZE 64
#define MIN_EP_SIZE 8

#define EVENT_READY (1 << 0)

USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking):

USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
USBDevice(phy, vendor_id, product_id, product_release), reset_count(0), suspend_count(0),
resume_count(0), interface_0_alt_set(NONE), interface_1_alt_set(NONE), configuration_set(NONE)
{
Expand All @@ -56,7 +58,8 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
configuration_desc(0);

init();
USBDevice::connect(connect_blocking);
USBDevice::connect();
flags.wait_any(EVENT_READY, osWaitForever, false);

}

Expand Down Expand Up @@ -105,7 +108,10 @@ const char *USBTester::get_iproduct_desc_string()

void USBTester::callback_state_change(DeviceState new_state)
{
if (new_state != Configured) {
if (new_state == Configured) {
flags.set(EVENT_READY);
} else {
flags.clear(EVENT_READY);
configuration_set = NONE;
interface_0_alt_set = NONE;
interface_1_alt_set = NONE;
Expand Down
7 changes: 4 additions & 3 deletions TESTS/usb_device/basic/USBTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "USBDescriptor.h"
#include "USBDevice_Types.h"
#include "EventQueue.h"
#include "EventFlags.h"

#include "USBDevice.h"

Expand All @@ -33,10 +34,9 @@ class USBTester: public USBDevice {
*
* @param vendor_id Your vendor_id
* @param product_id Your product_id
* @param product_release Your preoduct_release
* @param connect_blocking define if the connection must be blocked if USB not plugged in
* @param product_release Your product_release
*/
USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);

~USBTester();

Expand Down Expand Up @@ -107,6 +107,7 @@ class USBTester: public USBDevice {
uint8_t int_out;
uint8_t int_buf[64];
EventQueue *queue;
rtos::EventFlags flags;
volatile uint32_t reset_count;
volatile uint32_t suspend_count;
volatile uint32_t resume_count;
Expand Down
26 changes: 13 additions & 13 deletions TESTS/usb_device/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void control_basic_test()
char str[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
sprintf (str, "%s %d %d", serial.get_serial_desc_string(), vendor_id, product_id);
greentea_send_kv("control_basic_test", str);
// Wait for host before terminating
Expand All @@ -69,7 +69,7 @@ void control_stall_test()
char _value[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
greentea_send_kv("control_stall_test", serial.get_serial_desc_string());
// Wait for host before terminating
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
Expand All @@ -86,7 +86,7 @@ void control_sizes_test()
char _value[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
greentea_send_kv("control_sizes_test", serial.get_serial_desc_string());
// Wait for host before terminating
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
Expand All @@ -103,7 +103,7 @@ void control_stress_test()
char _value[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
greentea_send_kv("control_stress_test", serial.get_serial_desc_string());
// Wait for host before terminating
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
Expand All @@ -123,7 +123,7 @@ void device_reset_test()
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
if (strcmp(_value, "false") != 0) {

USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
serial.clear_reset_count();
greentea_send_kv("device_reset_test", serial.get_serial_desc_string());
while(serial.get_reset_count() == 0);
Expand Down Expand Up @@ -169,7 +169,7 @@ void device_soft_reconnection_test()
const uint32_t reconnect_try_count = 3;

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);

greentea_send_kv("device_soft_reconnection_test", serial.get_serial_desc_string());
// Wait for host before terminating
Expand Down Expand Up @@ -211,7 +211,7 @@ void device_suspend_resume_test()
char _value[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
greentea_send_kv("device_suspend_resume_test", serial.get_serial_desc_string());
printf("[1] suspend_count: %d resume_count: %d\n", serial.get_suspend_count(), serial.get_resume_count());
serial.clear_suspend_count();
Expand All @@ -234,25 +234,25 @@ void repeated_construction_destruction_test()
char _value[128] = {};

{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
}

wait_us(MIN_DISCONNECT_TIME_US);
{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
}

wait_us(MIN_DISCONNECT_TIME_US);
{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
}

wait_us(MIN_DISCONNECT_TIME_US);
{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
// Wait for host before terminating
Expand All @@ -262,7 +262,7 @@ void repeated_construction_destruction_test()

wait_us(MIN_DISCONNECT_TIME_US);
{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
// Wait for host before terminating
Expand All @@ -272,7 +272,7 @@ void repeated_construction_destruction_test()

wait_us(MIN_DISCONNECT_TIME_US);
{
USBTester serial(get_phy(), vendor_id, product_id, product_release, true);
USBTester serial(get_phy(), vendor_id, product_id, product_release);
TEST_ASSERT_EQUAL(true, serial.configured());
greentea_send_kv("repeated_construction_destruction_test", serial.get_serial_desc_string());
// Wait for host before terminating
Expand Down
45 changes: 12 additions & 33 deletions usb/device/USBDevice/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,20 +994,20 @@ bool USBDevice::configured()
return ret;
}

void USBDevice::connect(bool blocking)
void USBDevice::connect()
{
/* Connect device */
lock();

/* Ensure device has been initialized */
init();

/* Connect device */
if (!_connected) {
_phy->connect();
_connected = true;
}
unlock();

if (blocking) {
/* Block if not configured */
while (!configured());
}
unlock();
}

void USBDevice::disconnect()
Expand Down Expand Up @@ -1246,34 +1246,13 @@ USBDevice::USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
_device.state = Powered;
_device.configuration = 0;
_device.suspended = false;
};
}

USBDevice::USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
USBDevice::~USBDevice()
{
this->vendor_id = vendor_id;
this->product_id = product_id;
this->product_release = product_release;

memset(_endpoint_info, 0, sizeof(_endpoint_info));
memset(&_transfer, 0, sizeof(_transfer));
_transfer.user_callback = None;

_setup_ready = false;
_abort_control = false;

_phy = get_usb_phy();
_initialized = false;
_connected = false;
_current_interface = 0;
_current_alternate = 0;
_locked = 0;
_post_process = NULL;

/* Set initial device state */
_device.state = Powered;
_device.configuration = 0;
_device.suspended = false;
};
MBED_ASSERT(!_initialized);
deinit();
}

uint32_t USBDevice::endpoint_max_packet_size(usb_ep_t endpoint)
{
Expand Down
19 changes: 7 additions & 12 deletions usb/device/USBDevice/USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,20 @@ class USBDevice: public USBPhyEvents {
/**
* Instantiate a new USBDevice with the given parameters
*
* This function uses a target's built in USBPhy.
*
* @param phy The USBPhy providing physical USB access
* @param vendor_id The USB vendor ID
* @param product_id The USB product ID
* @param product_release The device release number
*/
USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);

/**
* Instantiate a new USBDevice with the given parameters
* Cleanup this USBDevice
*
* @param phy The USBPhy providing physical USB access
* @param vendor_id The USB vendor ID
* @param product_id The USB product ID
* @param product_release The device release number
* This USBDevice must be uninitialized when the destructor is
* called or the behavior is undefined.
*/
USBDevice(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
virtual ~USBDevice();

/**
* Initialize this instance
Expand All @@ -117,10 +114,8 @@ class USBDevice: public USBPhyEvents {

/**
* Connect a device
*
* @param blocking: block if not configured
*/
void connect(bool blocking = true);
void connect();

/**
* Disconnect a device
Expand Down
Loading