Update USB licenses and format code

Update USB licenses from MIT to Apache 2 and run astyle on the code.
feature-hal-spec-usb-device
Russ Butler 2018-02-26 09:32:14 -06:00
parent 61a575af23
commit 14b0c313ed
4 changed files with 285 additions and 347 deletions

View File

@ -1,19 +1,17 @@
/* Copyright (c) 2010-2011 mbed.org, MIT License /* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software * Licensed under the Apache License, Version 2.0 (the "License");
* and associated documentation files (the "Software"), to deal in the Software without * you may not use this file except in compliance with the License.
* restriction, including without limitation the rights to use, copy, modify, merge, publish, * You may obtain a copy of the License at
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or * http://www.apache.org/licenses/LICENSE-2.0
* substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * Unless required by applicable law or agreed to in writing, software
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * distributed under the License is distributed on an "AS IS" BASIS,
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * See the License for the specific language governing permissions and
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * limitations under the License.
*/ */
/* Standard descriptor types */ /* Standard descriptor types */

View File

@ -1,19 +1,17 @@
/* Copyright (c) 2010-2011 mbed.org, MIT License /* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software * Licensed under the Apache License, Version 2.0 (the "License");
* and associated documentation files (the "Software"), to deal in the Software without * you may not use this file except in compliance with the License.
* restriction, including without limitation the rights to use, copy, modify, merge, publish, * You may obtain a copy of the License at
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or * http://www.apache.org/licenses/LICENSE-2.0
* substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * Unless required by applicable law or agreed to in writing, software
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * distributed under the License is distributed on an "AS IS" BASIS,
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * See the License for the specific language governing permissions and
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * limitations under the License.
*/ */
#include "stdint.h" #include "stdint.h"
@ -46,14 +44,11 @@ bool USBDevice::requestGetDescriptor(void)
#ifdef DEBUG #ifdef DEBUG
printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(transfer.setup.wValue)); printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(transfer.setup.wValue));
#endif #endif
switch (DESCRIPTOR_TYPE(transfer.setup.wValue)) switch (DESCRIPTOR_TYPE(transfer.setup.wValue)) {
{
case DEVICE_DESCRIPTOR: case DEVICE_DESCRIPTOR:
if (deviceDesc() != NULL) if (deviceDesc() != NULL) {
{
if ((deviceDesc()[0] == DEVICE_DESCRIPTOR_LENGTH) \ if ((deviceDesc()[0] == DEVICE_DESCRIPTOR_LENGTH) \
&& (deviceDesc()[1] == DEVICE_DESCRIPTOR)) && (deviceDesc()[1] == DEVICE_DESCRIPTOR)) {
{
#ifdef DEBUG #ifdef DEBUG
printf("device descr\r\n"); printf("device descr\r\n");
#endif #endif
@ -65,11 +60,9 @@ bool USBDevice::requestGetDescriptor(void)
} }
break; break;
case CONFIGURATION_DESCRIPTOR: case CONFIGURATION_DESCRIPTOR:
if (configurationDesc() != NULL) if (configurationDesc() != NULL) {
{
if ((configurationDesc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \ if ((configurationDesc()[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
&& (configurationDesc()[1] == CONFIGURATION_DESCRIPTOR)) && (configurationDesc()[1] == CONFIGURATION_DESCRIPTOR)) {
{
#ifdef DEBUG #ifdef DEBUG
printf("conf descr request\r\n"); printf("conf descr request\r\n");
#endif #endif
@ -87,8 +80,7 @@ bool USBDevice::requestGetDescriptor(void)
#ifdef DEBUG #ifdef DEBUG
printf("str descriptor\r\n"); printf("str descriptor\r\n");
#endif #endif
switch (DESCRIPTOR_INDEX(transfer.setup.wValue)) switch (DESCRIPTOR_INDEX(transfer.setup.wValue)) {
{
case STRING_OFFSET_LANGID: case STRING_OFFSET_LANGID:
#ifdef DEBUG #ifdef DEBUG
printf("1\r\n"); printf("1\r\n");
@ -185,8 +177,7 @@ bool USBDevice::controlOut(void)
uint32_t packetSize; uint32_t packetSize;
/* Check we should be transferring data OUT */ /* Check we should be transferring data OUT */
if (transfer.direction != HOST_TO_DEVICE) if (transfer.direction != HOST_TO_DEVICE) {
{
/* for other platforms, count on the HAL to handle this case */ /* for other platforms, count on the HAL to handle this case */
return false; return false;
} }
@ -195,8 +186,7 @@ bool USBDevice::controlOut(void)
packetSize = EP0getReadResult(buffer); packetSize = EP0getReadResult(buffer);
/* Check if transfer size is valid */ /* Check if transfer size is valid */
if (packetSize > transfer.remaining) if (packetSize > transfer.remaining) {
{
/* Too big */ /* Too big */
return false; return false;
} }
@ -206,20 +196,16 @@ bool USBDevice::controlOut(void)
transfer.remaining -= packetSize; transfer.remaining -= packetSize;
/* Check if transfer has completed */ /* Check if transfer has completed */
if (transfer.remaining == 0) if (transfer.remaining == 0) {
{
/* Transfer completed */ /* Transfer completed */
if (transfer.notify) if (transfer.notify) {
{
/* Notify class layer. */ /* Notify class layer. */
USBCallback_requestCompleted(buffer, packetSize); USBCallback_requestCompleted(buffer, packetSize);
transfer.notify = false; transfer.notify = false;
} }
/* Status stage */ /* Status stage */
EP0write(NULL, 0); EP0write(NULL, 0);
} } else {
else
{
EP0read(); EP0read();
} }
@ -233,18 +219,15 @@ bool USBDevice::controlIn(void)
/* Check if transfer has completed (status stage transactions */ /* Check if transfer has completed (status stage transactions */
/* also have transfer.remaining == 0) */ /* also have transfer.remaining == 0) */
if (transfer.remaining == 0) if (transfer.remaining == 0) {
{ if (transfer.zlp) {
if (transfer.zlp)
{
/* Send zero length packet */ /* Send zero length packet */
EP0write(NULL, 0); EP0write(NULL, 0);
transfer.zlp = false; transfer.zlp = false;
} }
/* Transfer completed */ /* Transfer completed */
if (transfer.notify) if (transfer.notify) {
{
/* Notify class layer. */ /* Notify class layer. */
USBCallback_requestCompleted(NULL, 0); USBCallback_requestCompleted(NULL, 0);
transfer.notify = false; transfer.notify = false;
@ -258,15 +241,13 @@ bool USBDevice::controlIn(void)
} }
/* Check we should be transferring data IN */ /* Check we should be transferring data IN */
if (transfer.direction != DEVICE_TO_HOST) if (transfer.direction != DEVICE_TO_HOST) {
{
return false; return false;
} }
packetSize = transfer.remaining; packetSize = transfer.remaining;
if (packetSize > MAX_PACKET_SIZE_EP0) if (packetSize > MAX_PACKET_SIZE_EP0) {
{
packetSize = MAX_PACKET_SIZE_EP0; packetSize = MAX_PACKET_SIZE_EP0;
} }
@ -285,12 +266,9 @@ bool USBDevice::requestSetAddress(void)
/* Set the device address */ /* Set the device address */
setAddress(transfer.setup.wValue); setAddress(transfer.setup.wValue);
if (transfer.setup.wValue == 0) if (transfer.setup.wValue == 0) {
{
device.state = DEFAULT; device.state = DEFAULT;
} } else {
else
{
device.state = ADDRESS; device.state = ADDRESS;
} }
@ -302,22 +280,16 @@ bool USBDevice::requestSetConfiguration(void)
device.configuration = transfer.setup.wValue; device.configuration = transfer.setup.wValue;
/* Set the device configuration */ /* Set the device configuration */
if (device.configuration == 0) if (device.configuration == 0) {
{
/* Not configured */ /* Not configured */
unconfigureDevice(); unconfigureDevice();
device.state = ADDRESS; device.state = ADDRESS;
} } else {
else if (USBCallback_setConfiguration(device.configuration)) {
{
if (USBCallback_setConfiguration(device.configuration))
{
/* Valid configuration */ /* Valid configuration */
configureDevice(); configureDevice();
device.state = CONFIGURED; device.state = CONFIGURED;
} } else {
else
{
return false; return false;
} }
} }
@ -338,8 +310,7 @@ bool USBDevice::requestGetInterface(void)
{ {
/* Return the selected alternate setting for an interface */ /* Return the selected alternate setting for an interface */
if (device.state != CONFIGURED) if (device.state != CONFIGURED) {
{
return false; return false;
} }
@ -354,8 +325,7 @@ bool USBDevice::requestGetInterface(void)
bool USBDevice::requestSetInterface(void) bool USBDevice::requestSetInterface(void)
{ {
bool success = false; bool success = false;
if(USBCallback_setInterface(transfer.setup.wIndex, transfer.setup.wValue)) if (USBCallback_setInterface(transfer.setup.wIndex, transfer.setup.wValue)) {
{
success = true; success = true;
currentInterface = transfer.setup.wIndex; currentInterface = transfer.setup.wIndex;
currentAlternate = transfer.setup.wValue; currentAlternate = transfer.setup.wValue;
@ -367,23 +337,19 @@ bool USBDevice::requestSetFeature()
{ {
bool success = false; bool success = false;
if (device.state != CONFIGURED) if (device.state != CONFIGURED) {
{
/* Endpoint or interface must be zero */ /* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0) if (transfer.setup.wIndex != 0) {
{
return false; return false;
} }
} }
switch (transfer.setup.bmRequestType.Recipient) switch (transfer.setup.bmRequestType.Recipient) {
{
case DEVICE_RECIPIENT: case DEVICE_RECIPIENT:
/* TODO: Remote wakeup feature not supported */ /* TODO: Remote wakeup feature not supported */
break; break;
case ENDPOINT_RECIPIENT: case ENDPOINT_RECIPIENT:
if (transfer.setup.wValue == ENDPOINT_HALT) if (transfer.setup.wValue == ENDPOINT_HALT) {
{
/* TODO: We should check that the endpoint number is valid */ /* TODO: We should check that the endpoint number is valid */
stallEndpoint( stallEndpoint(
WINDEX_TO_PHYSICAL(transfer.setup.wIndex)); WINDEX_TO_PHYSICAL(transfer.setup.wIndex));
@ -401,24 +367,20 @@ bool USBDevice::requestClearFeature()
{ {
bool success = false; bool success = false;
if (device.state != CONFIGURED) if (device.state != CONFIGURED) {
{
/* Endpoint or interface must be zero */ /* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0) if (transfer.setup.wIndex != 0) {
{
return false; return false;
} }
} }
switch (transfer.setup.bmRequestType.Recipient) switch (transfer.setup.bmRequestType.Recipient) {
{
case DEVICE_RECIPIENT: case DEVICE_RECIPIENT:
/* TODO: Remote wakeup feature not supported */ /* TODO: Remote wakeup feature not supported */
break; break;
case ENDPOINT_RECIPIENT: case ENDPOINT_RECIPIENT:
/* TODO: We should check that the endpoint number is valid */ /* TODO: We should check that the endpoint number is valid */
if (transfer.setup.wValue == ENDPOINT_HALT) if (transfer.setup.wValue == ENDPOINT_HALT) {
{
unstallEndpoint(WINDEX_TO_PHYSICAL(transfer.setup.wIndex)); unstallEndpoint(WINDEX_TO_PHYSICAL(transfer.setup.wIndex));
success = true; success = true;
} }
@ -435,17 +397,14 @@ bool USBDevice::requestGetStatus(void)
static uint16_t status; static uint16_t status;
bool success = false; bool success = false;
if (device.state != CONFIGURED) if (device.state != CONFIGURED) {
{
/* Endpoint or interface must be zero */ /* Endpoint or interface must be zero */
if (transfer.setup.wIndex != 0) if (transfer.setup.wIndex != 0) {
{
return false; return false;
} }
} }
switch (transfer.setup.bmRequestType.Recipient) switch (transfer.setup.bmRequestType.Recipient) {
{
case DEVICE_RECIPIENT: case DEVICE_RECIPIENT:
/* TODO: Currently only supports self powered devices */ /* TODO: Currently only supports self powered devices */
status = DEVICE_STATUS_SELF_POWERED; status = DEVICE_STATUS_SELF_POWERED;
@ -458,12 +417,9 @@ bool USBDevice::requestGetStatus(void)
case ENDPOINT_RECIPIENT: case ENDPOINT_RECIPIENT:
/* TODO: We should check that the endpoint number is valid */ /* TODO: We should check that the endpoint number is valid */
if (getEndpointStallState( if (getEndpointStallState(
WINDEX_TO_PHYSICAL(transfer.setup.wIndex))) WINDEX_TO_PHYSICAL(transfer.setup.wIndex))) {
{
status = ENDPOINT_STATUS_HALT; status = ENDPOINT_STATUS_HALT;
} } else {
else
{
status = 0; status = 0;
} }
success = true; success = true;
@ -472,8 +428,7 @@ bool USBDevice::requestGetStatus(void)
break; break;
} }
if (success) if (success) {
{
/* Send the status */ /* Send the status */
transfer.ptr = (uint8_t *)&status; /* Assumes little endian */ transfer.ptr = (uint8_t *)&status; /* Assumes little endian */
transfer.remaining = sizeof(status); transfer.remaining = sizeof(status);
@ -488,10 +443,8 @@ bool USBDevice::requestSetup(void)
bool success = false; bool success = false;
/* Process standard requests */ /* Process standard requests */
if ((transfer.setup.bmRequestType.Type == STANDARD_TYPE)) if ((transfer.setup.bmRequestType.Type == STANDARD_TYPE)) {
{ switch (transfer.setup.bRequest) {
switch (transfer.setup.bRequest)
{
case GET_STATUS: case GET_STATUS:
success = requestGetStatus(); success = requestGetStatus();
break; break;
@ -561,11 +514,9 @@ bool USBDevice::controlSetup(void)
/* Class / vendor specific */ /* Class / vendor specific */
success = USBCallback_request(); success = USBCallback_request();
if (!success) if (!success) {
{
/* Standard requests */ /* Standard requests */
if (!requestSetup()) if (!requestSetup()) {
{
#ifdef DEBUG #ifdef DEBUG
printf("fail!!!!\r\n"); printf("fail!!!!\r\n");
#endif #endif
@ -574,62 +525,47 @@ bool USBDevice::controlSetup(void)
} }
/* Check transfer size and direction */ /* Check transfer size and direction */
if (transfer.setup.wLength>0) if (transfer.setup.wLength > 0) {
{
if (transfer.setup.bmRequestType.dataTransferDirection \ if (transfer.setup.bmRequestType.dataTransferDirection \
== DEVICE_TO_HOST) == DEVICE_TO_HOST) {
{
/* IN data stage is required */ /* IN data stage is required */
if (transfer.direction != DEVICE_TO_HOST) if (transfer.direction != DEVICE_TO_HOST) {
{
return false; return false;
} }
/* Transfer must be less than or equal to the size */ /* Transfer must be less than or equal to the size */
/* requested by the host */ /* requested by the host */
if (transfer.remaining > transfer.setup.wLength) if (transfer.remaining > transfer.setup.wLength) {
{
transfer.remaining = transfer.setup.wLength; transfer.remaining = transfer.setup.wLength;
} }
} } else {
else
{
/* OUT data stage is required */ /* OUT data stage is required */
if (transfer.direction != HOST_TO_DEVICE) if (transfer.direction != HOST_TO_DEVICE) {
{
return false; return false;
} }
/* Transfer must be equal to the size requested by the host */ /* Transfer must be equal to the size requested by the host */
if (transfer.remaining != transfer.setup.wLength) if (transfer.remaining != transfer.setup.wLength) {
{
return false; return false;
} }
} }
} } else {
else
{
/* No data stage; transfer size must be zero */ /* No data stage; transfer size must be zero */
if (transfer.remaining != 0) if (transfer.remaining != 0) {
{
return false; return false;
} }
} }
/* Data or status stage if applicable */ /* Data or status stage if applicable */
if (transfer.setup.wLength>0) if (transfer.setup.wLength > 0) {
{
if (transfer.setup.bmRequestType.dataTransferDirection \ if (transfer.setup.bmRequestType.dataTransferDirection \
== DEVICE_TO_HOST) == DEVICE_TO_HOST) {
{
/* Check if we'll need to send a zero length packet at */ /* Check if we'll need to send a zero length packet at */
/* the end of this transfer */ /* the end of this transfer */
if (transfer.setup.wLength > transfer.remaining) if (transfer.setup.wLength > transfer.remaining) {
{
/* Device wishes to transfer less than host requested */ /* Device wishes to transfer less than host requested */
if ((transfer.remaining % MAX_PACKET_SIZE_EP0) == 0) if ((transfer.remaining % MAX_PACKET_SIZE_EP0) == 0) {
{
/* Transfer is a multiple of EP0 max packet size */ /* Transfer is a multiple of EP0 max packet size */
transfer.zlp = true; transfer.zlp = true;
} }
@ -637,15 +573,11 @@ bool USBDevice::controlSetup(void)
/* IN stage */ /* IN stage */
controlIn(); controlIn();
} } else {
else
{
/* OUT stage */ /* OUT stage */
EP0read(); EP0read();
} }
} } else {
else
{
/* Status stage */ /* Status stage */
EP0write(NULL, 0); EP0write(NULL, 0);
} }
@ -666,8 +598,7 @@ void USBDevice::busReset(void)
void USBDevice::EP0setupCallback(void) void USBDevice::EP0setupCallback(void)
{ {
/* Endpoint 0 setup event */ /* Endpoint 0 setup event */
if (!controlSetup()) if (!controlSetup()) {
{
/* Protocol stall */ /* Protocol stall */
EP0stall(); EP0stall();
} }
@ -678,8 +609,7 @@ void USBDevice::EP0setupCallback(void)
void USBDevice::EP0out(void) void USBDevice::EP0out(void)
{ {
/* Endpoint 0 OUT data event */ /* Endpoint 0 OUT data event */
if (!controlOut()) if (!controlOut()) {
{
/* Protocol stall; this will stall both endpoints */ /* Protocol stall; this will stall both endpoints */
EP0stall(); EP0stall();
} }
@ -691,8 +621,7 @@ void USBDevice::EP0in(void)
printf("EP0IN\r\n"); printf("EP0IN\r\n");
#endif #endif
/* Endpoint 0 IN data event */ /* Endpoint 0 IN data event */
if (!controlIn()) if (!controlIn()) {
{
/* Protocol stall; this will stall both endpoints */ /* Protocol stall; this will stall both endpoints */
EP0stall(); EP0stall();
} }
@ -749,15 +678,13 @@ uint8_t * USBDevice::findDescriptor(uint8_t descriptorType)
uint16_t wTotalLength; uint16_t wTotalLength;
uint8_t *ptr; uint8_t *ptr;
if (configurationDesc() == NULL) if (configurationDesc() == NULL) {
{
return NULL; return NULL;
} }
/* Check this is a configuration descriptor */ /* Check this is a configuration descriptor */
if ((configurationDesc()[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \ if ((configurationDesc()[0] != CONFIGURATION_DESCRIPTOR_LENGTH) \
|| (configurationDesc()[1] != CONFIGURATION_DESCRIPTOR)) || (configurationDesc()[1] != CONFIGURATION_DESCRIPTOR)) {
{
return NULL; return NULL;
} }
@ -774,8 +701,7 @@ uint8_t * USBDevice::findDescriptor(uint8_t descriptorType)
ptr = &(((uint8_t *)configurationDesc())[CONFIGURATION_DESCRIPTOR_LENGTH]); ptr = &(((uint8_t *)configurationDesc())[CONFIGURATION_DESCRIPTOR_LENGTH]);
do { do {
if (ptr[1] /* bDescriptorType */ == descriptorType) if (ptr[1] /* bDescriptorType */ == descriptorType) {
{
/* Found */ /* Found */
return ptr; return ptr;
} }
@ -798,7 +724,8 @@ void USBDevice::suspendStateChanged(unsigned int suspended)
} }
USBDevice::USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release){ USBDevice::USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
{
VENDOR_ID = vendor_id; VENDOR_ID = vendor_id;
PRODUCT_ID = product_id; PRODUCT_ID = product_id;
PRODUCT_RELEASE = product_release; PRODUCT_RELEASE = product_release;
@ -820,8 +747,7 @@ bool USBDevice::write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_
{ {
EP_STATUS result; EP_STATUS result;
if (size > maxSize) if (size > maxSize) {
{
return false; return false;
} }
@ -833,8 +759,7 @@ bool USBDevice::write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_
/* Send report */ /* Send report */
result = endpointWrite(endpoint, buffer, size); result = endpointWrite(endpoint, buffer, size);
if (result != EP_PENDING) if (result != EP_PENDING) {
{
return false; return false;
} }
@ -851,8 +776,7 @@ bool USBDevice::writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint3
{ {
EP_STATUS result; EP_STATUS result;
if (size > maxSize) if (size > maxSize) {
{
return false; return false;
} }
@ -863,8 +787,7 @@ bool USBDevice::writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint3
/* Send report */ /* Send report */
result = endpointWrite(endpoint, buffer, size); result = endpointWrite(endpoint, buffer, size);
if (result != EP_PENDING) if (result != EP_PENDING) {
{
return false; return false;
} }
@ -907,7 +830,8 @@ bool USBDevice::readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, u
const uint8_t * USBDevice::deviceDesc() { const uint8_t *USBDevice::deviceDesc()
{
uint8_t deviceDescriptorTemp[] = { uint8_t deviceDescriptorTemp[] = {
DEVICE_DESCRIPTOR_LENGTH, /* bLength */ DEVICE_DESCRIPTOR_LENGTH, /* bLength */
DEVICE_DESCRIPTOR, /* bDescriptorType */ DEVICE_DESCRIPTOR, /* bDescriptorType */
@ -933,7 +857,8 @@ const uint8_t * USBDevice::deviceDesc() {
return deviceDescriptor; return deviceDescriptor;
} }
const uint8_t * USBDevice::stringLangidDesc() { const uint8_t *USBDevice::stringLangidDesc()
{
static const uint8_t stringLangidDescriptor[] = { static const uint8_t stringLangidDescriptor[] = {
0x04, /*bLength*/ 0x04, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
@ -942,7 +867,8 @@ const uint8_t * USBDevice::stringLangidDesc() {
return (uint8_t *)stringLangidDescriptor; return (uint8_t *)stringLangidDescriptor;
} }
const uint8_t * USBDevice::stringImanufacturerDesc() { const uint8_t *USBDevice::stringImanufacturerDesc()
{
static const uint8_t stringImanufacturerDescriptor[] = { static const uint8_t stringImanufacturerDescriptor[] = {
0x12, /*bLength*/ 0x12, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
@ -951,7 +877,8 @@ const uint8_t * USBDevice::stringImanufacturerDesc() {
return stringImanufacturerDescriptor; return stringImanufacturerDescriptor;
} }
const uint8_t * USBDevice::stringIserialDesc() { const uint8_t *USBDevice::stringIserialDesc()
{
static const uint8_t stringIserialDescriptor[] = { static const uint8_t stringIserialDescriptor[] = {
0x16, /*bLength*/ 0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
@ -960,7 +887,8 @@ const uint8_t * USBDevice::stringIserialDesc() {
return stringIserialDescriptor; return stringIserialDescriptor;
} }
const uint8_t * USBDevice::stringIConfigurationDesc() { const uint8_t *USBDevice::stringIConfigurationDesc()
{
static const uint8_t stringIconfigurationDescriptor[] = { static const uint8_t stringIconfigurationDescriptor[] = {
0x06, /*bLength*/ 0x06, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
@ -969,7 +897,8 @@ const uint8_t * USBDevice::stringIConfigurationDesc() {
return stringIconfigurationDescriptor; return stringIconfigurationDescriptor;
} }
const uint8_t * USBDevice::stringIinterfaceDesc() { const uint8_t *USBDevice::stringIinterfaceDesc()
{
static const uint8_t stringIinterfaceDescriptor[] = { static const uint8_t stringIinterfaceDescriptor[] = {
0x08, /*bLength*/ 0x08, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
@ -978,7 +907,8 @@ const uint8_t * USBDevice::stringIinterfaceDesc() {
return stringIinterfaceDescriptor; return stringIinterfaceDescriptor;
} }
const uint8_t * USBDevice::stringIproductDesc() { const uint8_t *USBDevice::stringIproductDesc()
{
static const uint8_t stringIproductDescriptor[] = { static const uint8_t stringIproductDescriptor[] = {
0x16, /*bLength*/ 0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ STRING_DESCRIPTOR, /*bDescriptorType 0x03*/

View File

@ -1,19 +1,17 @@
/* Copyright (c) 2010-2011 mbed.org, MIT License /* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software * Licensed under the Apache License, Version 2.0 (the "License");
* and associated documentation files (the "Software"), to deal in the Software without * you may not use this file except in compliance with the License.
* restriction, including without limitation the rights to use, copy, modify, merge, publish, * You may obtain a copy of the License at
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or * http://www.apache.org/licenses/LICENSE-2.0
* substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * Unless required by applicable law or agreed to in writing, software
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * distributed under the License is distributed on an "AS IS" BASIS,
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * See the License for the specific language governing permissions and
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * limitations under the License.
*/ */
#ifndef USBDEVICE_H #ifndef USBDEVICE_H
@ -23,8 +21,7 @@
#include "USBDevice_Types.h" #include "USBDevice_Types.h"
#include "USBHAL.h" #include "USBHAL.h"
class USBDevice: public USBHAL class USBDevice: public USBHAL {
{
public: public:
USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release); USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
@ -133,7 +130,10 @@ public:
* *
* @returns true if class handles this request * @returns true if class handles this request
*/ */
virtual bool USBCallback_request() { return false; }; virtual bool USBCallback_request()
{
return false;
};
/* /*
* Called by USBDevice on Endpoint0 request completion * Called by USBDevice on Endpoint0 request completion
@ -153,7 +153,10 @@ public:
* *
* @param configuration Number of the configuration * @param configuration Number of the configuration
*/ */
virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; }; virtual bool USBCallback_setConfiguration(uint8_t configuration)
{
return false;
};
/* /*
* Called by USBDevice layer. Set interface/alternate of the device. * Called by USBDevice layer. Set interface/alternate of the device.
@ -162,7 +165,10 @@ public:
* @param alternate Number of the alternate to be configured * @param alternate Number of the alternate to be configured
* @returns true if class handles this request * @returns true if class handles this request
*/ */
virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; }; virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate)
{
return false;
};
/* /*
* Get device descriptor. * Get device descriptor.
@ -176,7 +182,10 @@ public:
* *
* @returns pointer to the configuration descriptor * @returns pointer to the configuration descriptor
*/ */
virtual const uint8_t * configurationDesc(){return NULL;}; virtual const uint8_t *configurationDesc()
{
return NULL;
};
/* /*
* Get string lang id descriptor * Get string lang id descriptor
@ -225,7 +234,10 @@ public:
* *
* @returns length of the report descriptor * @returns length of the report descriptor
*/ */
virtual uint16_t reportDescLength() { return 0; }; virtual uint16_t reportDescLength()
{
return 0;
};

View File

@ -1,19 +1,17 @@
/* Copyright (c) 2010-2011 mbed.org, MIT License /* mbed Microcontroller Library
* Copyright (c) 2018-2018 ARM Limited
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software * Licensed under the Apache License, Version 2.0 (the "License");
* and associated documentation files (the "Software"), to deal in the Software without * you may not use this file except in compliance with the License.
* restriction, including without limitation the rights to use, copy, modify, merge, publish, * You may obtain a copy of the License at
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or * http://www.apache.org/licenses/LICENSE-2.0
* substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * Unless required by applicable law or agreed to in writing, software
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * distributed under the License is distributed on an "AS IS" BASIS,
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * See the License for the specific language governing permissions and
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * limitations under the License.
*/ */
#ifndef USBDEVICE_TYPES_H #ifndef USBDEVICE_TYPES_H