Skip to content

Remove inclusion of mbed.h from USB #9539

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 2 commits into from
Jan 30, 2019
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
3 changes: 2 additions & 1 deletion TESTS/usb_device/basic/USBEndpointTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "stdint.h"
#include "stdlib.h"
#include "USBEndpointTester.h"
#include "mbed_shared_queues.h"
#include "EndpointResolver.h"
Expand Down Expand Up @@ -167,7 +168,7 @@ USBEndpointTester::USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t p
}
MBED_ASSERT(resolver.valid());

queue = mbed_highprio_event_queue();
queue = mbed::mbed_highprio_event_queue();
configuration_desc(0);
init();
USBDevice::connect();
Expand Down
2 changes: 1 addition & 1 deletion TESTS/usb_device/basic/USBEndpointTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class USBEndpointTester: public USBDevice {
};

protected:
EventQueue *queue;
events::EventQueue *queue;
rtos::EventFlags flags;
uint8_t ctrl_buf[2048];

Expand Down
12 changes: 6 additions & 6 deletions TESTS/usb_device/basic/USBTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@


USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
USBDevice(phy, vendor_id, product_id, product_release), interface_0_alt_set(NONE),
interface_1_alt_set(NONE), configuration_set(NONE), reset_count(0),
suspend_count(0), resume_count(0)
USBDevice(phy, vendor_id, product_id, product_release), interface_0_alt_set(NONE),
interface_1_alt_set(NONE), configuration_set(NONE), reset_count(0),
suspend_count(0), resume_count(0)
{

EndpointResolver resolver(endpoint_table());
Expand All @@ -54,7 +54,7 @@ USBTester::USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint1
int_in = resolver.endpoint_in(USB_EP_TYPE_INT, 64);
int_out = resolver.endpoint_out(USB_EP_TYPE_INT, 64);
MBED_ASSERT(resolver.valid());
queue = mbed_highprio_event_queue();
queue = mbed::mbed_highprio_event_queue();

configuration_desc(0);

Expand Down Expand Up @@ -269,14 +269,14 @@ bool USBTester::set_configuration(uint16_t configuration)
bulk_buf, sizeof(bulk_buf), &USBTester::epbulk_out_callback);
// interface 1 alternate 0
success &= setup_iterface(int_in, int_out, MAX_EP_SIZE, USB_EP_TYPE_INT,
int_buf, sizeof(int_buf), &USBTester::epint_out_callback);
int_buf, sizeof(int_buf), &USBTester::epint_out_callback);
} else if (configuration == 2) {
// interface 0 alternate 0
success = setup_iterface(int_in, int_out, MIN_EP_SIZE, USB_EP_TYPE_INT,
int_buf, sizeof(int_buf), &USBTester::epint_out_callback);
// interface 1 alternate 0
success &= setup_iterface(bulk_in, bulk_out, MIN_EP_SIZE, USB_EP_TYPE_BULK,
bulk_buf, sizeof(bulk_buf), &USBTester::epbulk_out_callback);
bulk_buf, sizeof(bulk_buf), &USBTester::epbulk_out_callback);
}
if (success) {
configuration_set = configuration;
Expand Down
32 changes: 25 additions & 7 deletions TESTS/usb_device/basic/USBTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,30 @@ class USBTester: public USBDevice {
const char *get_serial_desc_string();
const char *get_iproduct_desc_string();
const char *get_iinterface_desc_string();
uint32_t get_reset_count() const { return reset_count; }
uint32_t get_suspend_count() const { return suspend_count; }
uint32_t get_resume_count() const { return resume_count; }
void clear_reset_count() { reset_count = 0; }
void clear_suspend_count() { suspend_count = 0; }
void clear_resume_count() { resume_count = 0; }
uint32_t get_reset_count() const
{
return reset_count;
}
uint32_t get_suspend_count() const
{
return suspend_count;
}
uint32_t get_resume_count() const
{
return resume_count;
}
void clear_reset_count()
{
reset_count = 0;
}
void clear_suspend_count()
{
suspend_count = 0;
}
void clear_resume_count()
{
resume_count = 0;
}

private:

Expand Down Expand Up @@ -106,7 +124,7 @@ class USBTester: public USBDevice {
uint8_t int_in;
uint8_t int_out;
uint8_t int_buf[64];
EventQueue *queue;
events::EventQueue *queue;
rtos::EventFlags flags;
volatile uint32_t reset_count;
volatile uint32_t suspend_count;
Expand Down
20 changes: 10 additions & 10 deletions usb/device/USBAudio/USBAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void USBAudio::_init(uint32_t frequency_rx, uint8_t channel_count_rx, uint32_t f
_vol_max = 0x0100;
_vol_res = 0x0004;

_update_vol = callback(stub_volume);
_tx_done = callback(stub_handler);
_rx_done = callback(stub_handler);
_update_vol = mbed::callback(stub_volume);
_tx_done = mbed::callback(stub_handler);
_rx_done = mbed::callback(stub_handler);

_rx_overflow = 0;
_tx_underflow = 0;
Expand Down Expand Up @@ -348,7 +348,7 @@ float USBAudio::get_volume()
return ret;
}

void USBAudio::attach(Callback<void()> &cb)
void USBAudio::attach(mbed::Callback<void()> &cb)
{
lock();

Expand All @@ -360,25 +360,25 @@ void USBAudio::attach(Callback<void()> &cb)
unlock();
}

void USBAudio::attach_tx(Callback<void(AudioEvent)> &cb)
void USBAudio::attach_tx(mbed::Callback<void(AudioEvent)> &cb)
{
lock();

_tx_done = cb;
if (!_tx_done) {
_tx_done = callback(stub_handler);
_tx_done = mbed::callback(stub_handler);
}

unlock();
}

void USBAudio::attach_rx(Callback<void(AudioEvent)> &cb)
void USBAudio::attach_rx(mbed::Callback<void(AudioEvent)> &cb)
{
lock();

_rx_done = cb;
if (!_rx_done) {
_rx_done = callback(stub_handler);
_rx_done = mbed::callback(stub_handler);
}

unlock();
Expand Down Expand Up @@ -498,7 +498,7 @@ void USBAudio::callback_request_xfer_done(const setup_packet_t *setup, bool abor
}

if ((setup->wLength == 1) || (setup->wLength == 2)) {
uint16_t data = (_control_receive[0] << 0) | (_control_receive[1] << 8);
uint16_t data = (_control_receive[0] << 0) | (_control_receive[1] << 8);
data &= ((setup->wLength == 1) ? 0xFF : 0xFFFF);
switch (setup->wValue >> 8) {
case MUTE_CONTROL:
Expand All @@ -516,7 +516,7 @@ void USBAudio::callback_request_xfer_done(const setup_packet_t *setup, bool abor
case REQUEST_SET_CUR:
_vol_cur = data;
_volume = (float)_vol_cur / (float)_vol_max;
_update_vol.call();
_update_vol.call();
break;
default:
break;
Expand Down
18 changes: 9 additions & 9 deletions usb/device/USBAudio/USBAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class USBAudio: protected USBDevice {
* @param product_id Your product_id
* @param product_release Your product_release
*/
USBAudio(bool connect=true, uint32_t frequency_rx = 48000, uint8_t channel_count_rx = 1, uint32_t frequency_tx = 8000, uint8_t channel_count_tx = 1, uint32_t buffer_ms=10, uint16_t vendor_id = 0x7bb8, uint16_t product_id = 0x1111, uint16_t product_release = 0x0100);
USBAudio(bool connect = true, uint32_t frequency_rx = 48000, uint8_t channel_count_rx = 1, uint32_t frequency_tx = 8000, uint8_t channel_count_tx = 1, uint32_t buffer_ms = 10, uint16_t vendor_id = 0x7bb8, uint16_t product_id = 0x1111, uint16_t product_release = 0x0100);

/**
* Fully featured constructor
Expand Down Expand Up @@ -153,7 +153,7 @@ class USBAudio: protected USBDevice {
* @param clear Reset the overflow count back to 0
* @return Number of packets dropped due to overflow
*/
uint32_t read_overflows(bool clear=false);
uint32_t read_overflows(bool clear = false);

/**
* Check if the audio read channel is open
Expand Down Expand Up @@ -196,7 +196,7 @@ class USBAudio: protected USBDevice {
* @return Number of packets that should have been
* sent but weren't due to overflow
*/
uint32_t write_underflows(bool clear=false);
uint32_t write_underflows(bool clear = false);

/**
* Check if the audio write channel is open
Expand All @@ -222,21 +222,21 @@ class USBAudio: protected USBDevice {
* @param cb Callback to attach
*
*/
void attach(Callback<void()> &cb);
void attach(mbed::Callback<void()> &cb);

/** attach a Callback to Tx Done
*
* @param cb Callback to attach
*
*/
void attach_tx(Callback<void(AudioEvent)> &cb);
void attach_tx(mbed::Callback<void(AudioEvent)> &cb);

/** attach a Callback to Rx Done
*
* @param cb Callback to attach
*
*/
void attach_rx(Callback<void(AudioEvent)> &cb);
void attach_rx(mbed::Callback<void(AudioEvent)> &cb);

protected:

Expand Down Expand Up @@ -303,13 +303,13 @@ class USBAudio: protected USBDevice {
uint16_t _vol_res;

// callback to update volume
Callback<void()> _update_vol;
mbed::Callback<void()> _update_vol;

// callback transmit Done
Callback<void(AudioEvent)> _tx_done;
mbed::Callback<void(AudioEvent)> _tx_done;

// callback receive Done
Callback<void(AudioEvent)> _rx_done;
mbed::Callback<void(AudioEvent)> _rx_done;

// Number of times data was dropped due to an overflow
uint32_t _rx_overflow;
Expand Down
4 changes: 2 additions & 2 deletions usb/device/USBDevice/EndpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

#include "mbed.h"
#include "EndpointResolver.h"

static uint32_t logical_to_index(uint32_t logical, bool in_not_out)
Expand Down Expand Up @@ -74,7 +73,8 @@ bool EndpointResolver::valid()
return _valid && (_cost <= _table->resources);
}

void EndpointResolver::reset() {
void EndpointResolver::reset()
{
_cost = 0;
_used = 0;
_valid = true;
Expand Down
2 changes: 0 additions & 2 deletions usb/device/USBDevice/EndpointResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#ifndef ENDPOINT_RESOLVER_H
#define ENDPOINT_RESOLVER_H

#include "mbed.h"

#include "USBPhy.h"

/**
Expand Down
29 changes: 13 additions & 16 deletions usb/device/USBDevice/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

#include "stdint.h"
#include <stdint.h>
#include <string.h>

#include "USBDevice.h"
#include "USBDescriptor.h"
#include "usb_phy_api.h"
#include "mbed_assert.h"

//#define DEBUG

Expand Down Expand Up @@ -62,8 +64,7 @@ bool USBDevice::_request_get_descriptor()
printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(_transfer.setup.wValue));
#endif
switch (DESCRIPTOR_TYPE(_transfer.setup.wValue)) {
case DEVICE_DESCRIPTOR:
{
case DEVICE_DESCRIPTOR: {
if (device_desc() != NULL) {
if ((device_desc()[0] == DEVICE_DESCRIPTOR_LENGTH) \
&& (device_desc()[1] == DEVICE_DESCRIPTOR)) {
Expand All @@ -78,8 +79,7 @@ bool USBDevice::_request_get_descriptor()
}
break;
}
case CONFIGURATION_DESCRIPTOR:
{
case CONFIGURATION_DESCRIPTOR: {
const uint8_t idx = DESCRIPTOR_INDEX(_transfer.setup.wValue);
if (configuration_desc(idx) != NULL) {
if ((configuration_desc(idx)[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
Expand All @@ -89,7 +89,7 @@ bool USBDevice::_request_get_descriptor()
#endif
/* Get wTotalLength */
_transfer.remaining = configuration_desc(idx)[2] \
| (configuration_desc(idx)[3] << 8);
| (configuration_desc(idx)[3] << 8);

_transfer.ptr = (uint8_t *)configuration_desc(idx);
_transfer.direction = Send;
Expand All @@ -98,8 +98,7 @@ bool USBDevice::_request_get_descriptor()
}
break;
}
case STRING_DESCRIPTOR:
{
case STRING_DESCRIPTOR: {
#ifdef DEBUG
printf("str descriptor\r\n");
#endif
Expand Down Expand Up @@ -161,23 +160,20 @@ bool USBDevice::_request_get_descriptor()
}
break;
}
case INTERFACE_DESCRIPTOR:
{
case INTERFACE_DESCRIPTOR: {
#ifdef DEBUG
printf("interface descr\r\n");
#endif
break;
}
case ENDPOINT_DESCRIPTOR:
{
case ENDPOINT_DESCRIPTOR: {
#ifdef DEBUG
printf("endpoint descr\r\n");
#endif
/* TODO: Support is optional, not implemented here */
break;
}
default:
{
default: {
#ifdef DEBUG
printf("ERROR\r\n");
#endif
Expand Down Expand Up @@ -1152,7 +1148,7 @@ void USBDevice::endpoint_stall(usb_ep_t endpoint)
_phy->endpoint_stall(endpoint);

if (info->pending) {
endpoint_abort(endpoint);
endpoint_abort(endpoint);
}

unlock();
Expand Down Expand Up @@ -1587,7 +1583,8 @@ void USBDevice::assert_locked()
MBED_ASSERT(_locked > 0);
}

void USBDevice::_change_state(DeviceState new_state) {
void USBDevice::_change_state(DeviceState new_state)
{
assert_locked();

DeviceState old_state = _device.state;
Expand Down
3 changes: 1 addition & 2 deletions usb/device/USBDevice/USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef USBDEVICE_H
#define USBDEVICE_H

#include "mbed.h"
#include "USBDevice_Types.h"
#include "USBPhy.h"
#include "mbed_critical.h"
Expand Down Expand Up @@ -404,7 +403,7 @@ class USBDevice: public USBPhyEvents {
* @param data Buffer to send or receive if the result is Send or Receive
* @param size Size to transfer if the result is Send or Receive
*/
void complete_request(RequestResult result, uint8_t *data=NULL, uint32_t size=0);
void complete_request(RequestResult result, uint8_t *data = NULL, uint32_t size = 0);

/**
* Called by USBDevice on data stage completion
Expand Down
Loading