fix couple issues with usb firmware

This commit is contained in:
Conor Patrick 2018-07-22 13:41:46 -04:00
parent a54cbd60a1
commit 077be6eab2
16 changed files with 321 additions and 745 deletions

View File

@ -16,6 +16,19 @@ void spi_transfer_complete();
#define EFM32_RW_PIN P1_B2
#define MSG_RDY_INT_PIN P1_B1
#define INPUT_ENDPOINT EP2OUT
#define OUTPUT_ENDPOINT EP3IN
#define INPUT_ENDPOINT_NUM 0x83
#define OUTPUT_ENDPOINT_NUM 0x02
//#define INPUT_ENDPOINT EP1OUT
//#define OUTPUT_ENDPOINT EP1IN
//
//#define INPUT_ENDPOINT_NUM 0x81
//#define OUTPUT_ENDPOINT_NUM 0x01
void delay(int ms);
#endif /* INC_APP_H_ */

View File

@ -57,8 +57,9 @@ extern SI_SEGMENT_VARIABLE(initstruct, const USBD_Init_TypeDef, SI_SEG_CODE);
#endif
#endif // __SILICON_LABS_DESCRIPTORS_H
#if 0
// $[HID Report Descriptors]
extern SI_SEGMENT_VARIABLE(ReportDescriptor0[34], const uint8_t, SI_SEG_CODE);
extern SI_SEGMENT_VARIABLE(ReportDescriptor0[0], const uint8_t, SI_SEG_CODE);
// [HID Report Descriptors]$
#endif

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include "printing.h"
#include "descriptors.h"
#include "app.h"
#define UNUSED(expr) do { (void)(expr); } while (0)
@ -63,22 +64,19 @@ USB_Status_TypeDef USBD_SetupCmdCb(
SI_VARIABLE_SEGMENT_POINTER(setup, USB_Setup_TypeDef, MEM_MODEL_SEG)) {
USB_Status_TypeDef retVal = USB_STATUS_REQ_UNHANDLED;
// USB_Status_TypeDef retVal = USB_STATUS_OK;
// cprints("USBD_SetupCmdCb\r\n");
if ((setup->bmRequestType.Type == USB_SETUP_TYPE_STANDARD)
&& (setup->bmRequestType.Direction == USB_SETUP_DIR_IN)
&& (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)) {
// A HID device must extend the standard GET_DESCRIPTOR command
// with support for HID descriptors.
// cprints("USB_SETUP_TYPE_STANDARD\r\n");
switch (setup->bRequest) {
case GET_DESCRIPTOR:
// cprints("GET_DESCRIPTOR\r\n");
if (setup->wIndex == 0)
{
if ((setup->wValue >> 8) == USB_HID_REPORT_DESCRIPTOR) {
// cprints("1\r\n");
USBD_Write(EP0, ReportDescriptor0,
EFM8_MIN(sizeof(ReportDescriptor0), setup->wLength),
@ -86,7 +84,7 @@ USB_Status_TypeDef USBD_SetupCmdCb(
retVal = USB_STATUS_OK;
} else if ((setup->wValue >> 8) == USB_HID_DESCRIPTOR) {
// cprints("2\r\n");
USBD_Write(EP0, (&configDesc[18]),
EFM8_MIN(USB_HID_DESCSIZE, setup->wLength), false);
retVal = USB_STATUS_OK;
@ -100,12 +98,10 @@ USB_Status_TypeDef USBD_SetupCmdCb(
&& (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)
&& (setup->wIndex == HID_INTERFACE_INDEX))
{
// cprints("USB_SETUP_TYPE_CLASS\r\n");
// Implement the necessary HID class specific commands.
switch (setup->bRequest)
{
case USB_HID_SET_IDLE:
// cprints("USB_HID_SET_IDLE\r\n");
if (((setup->wValue & 0xFF) == 0) // Report ID
&& (setup->wLength == 0)
&& (setup->bmRequestType.Direction != USB_SETUP_DIR_IN))
@ -115,7 +111,6 @@ USB_Status_TypeDef USBD_SetupCmdCb(
break;
case USB_HID_GET_IDLE:
// cprints("USB_HID_GET_IDLE\r\n");
if ((setup->wValue == 0) // Report ID
&& (setup->wLength == 1)
&& (setup->bmRequestType.Direction == USB_SETUP_DIR_IN))
@ -129,10 +124,6 @@ USB_Status_TypeDef USBD_SetupCmdCb(
break;
}
}
else
{
// cprints("nothing\r\n");
}
return retVal;
}
@ -147,11 +138,11 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status,
UNUSED(xferred);
UNUSED(remaining);
if (epAddr == EP2OUT)
if (epAddr == INPUT_ENDPOINT)
{
usb_transfer_complete();
}
else if (epAddr == EP3IN)
else if (epAddr == OUTPUT_ENDPOINT)
{
usb_writeback_complete();
}

View File

@ -14,6 +14,7 @@
#include <string.h>
#include <efm8_usb.h>
#include "descriptors.h"
#include "app.h"
#ifdef __cplusplus
extern "C" {
@ -107,7 +108,7 @@ SI_SEGMENT_VARIABLE(configDesc[],
//Endpoint 2 IN Descriptor
USB_ENDPOINT_DESCSIZE,// bLength
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
0x83,// bEndpointAddress
OUTPUT_ENDPOINT_NUM,// bEndpointAddress
USB_EPTYPE_INTR,// bAttrib
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
0x00,// wMaxPacketSize (MSB)
@ -116,7 +117,7 @@ SI_SEGMENT_VARIABLE(configDesc[],
//Endpoint 3 OUT Descriptor
USB_ENDPOINT_DESCSIZE,// bLength
USB_ENDPOINT_DESCRIPTOR,// bDescriptorType
0x02,// bEndpointAddress
INPUT_ENDPOINT_NUM,// bEndpointAddress
USB_EPTYPE_INTR,// bAttrib
HID_PACKET_SIZE,// wMaxPacketSize (LSB)
0x00,// wMaxPacketSize (MSB)
@ -139,7 +140,7 @@ LANGID_STATIC_CONST_STRING_DESC( langDesc[], LANG_STRING );
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( mfrDesc[], MFR_STRING, MFR_SIZE);
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( prodDesc[], PROD_STRING, PROD_SIZE);
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( serDesc[], SER_STRING, SER_SIZE);
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( cfgDesc[], CFG_STRING, CFG_SIZE);
//UTF16LE_PACKED_STATIC_CONST_STRING_DESC( cfgDesc[], CFG_STRING, CFG_SIZE);
UTF16LE_PACKED_STATIC_CONST_STRING_DESC( int0Desc[], INT0_STRING, INT0_SIZE);
@ -165,7 +166,7 @@ SI_SEGMENT_VARIABLE(initstruct,
deviceDesc, // deviceDescriptor
configDesc,// configDescriptor
myUsbStringTable_USEnglish,// stringDescriptors
sizeof(myUsbStringTable_USEnglish) / sizeof(void *)// numberOfStrings
5// numberOfStrings
};
#ifdef __cplusplus

View File

@ -79,7 +79,7 @@ void usb_write()
{
data uint8_t errors = 0;
USB_TX_COUNT += 64;
while (USB_STATUS_OK != (USBD_Write(EP3IN, writebackbuf, 64, true)))
while (USB_STATUS_OK != (USBD_Write(OUTPUT_ENDPOINT, writebackbuf, 64, true)))
{
delay(2);
if (errors++ > 30)
@ -89,7 +89,7 @@ void usb_write()
}
}
}
extern USBD_Device_TypeDef myUsbDevice;
int main(void) {
data uint8_t k;
@ -102,8 +102,10 @@ int main(void) {
enter_DefaultMode_from_RESET();
eeprom_init();
SCON0_TI = 1;
P2_B0 = 1;
@ -121,6 +123,7 @@ int main(void) {
cprints("hello,world\r\n");
reset = RSTSRC;
cprintx("reset source: ", 1, reset);
if (reset != 0x10)
@ -128,12 +131,6 @@ int main(void) {
RSTSRC = (1<<4);
}
// last_efm32_pin = SPI0FCN0;
// cprintx("spi fifo0 cntrl: ", 1, last_efm32_pin);
//
// last_efm32_pin = SPI0FCN1;
// cprintx("spi fifo1 cntrl: ", 1, last_efm32_pin);
MSG_RDY_INT_PIN = 1;
SIGNAL_WRITE_BSY();
@ -211,7 +208,7 @@ int main(void) {
t1 = millis();
}
// if (!USBD_EpIsBusy(EP2OUT) && !USBD_EpIsBusy(EP3IN) && lastcount==count)
if (!USBD_EpIsBusy(EP2OUT) && lastcount==count)
if (!USBD_EpIsBusy(INPUT_ENDPOINT) && lastcount==count)
{
// cprintd("sched read to ",1,(int)(hidmsgbuf + write_ptr*64));
if (count == BUFFER_SIZE)
@ -220,7 +217,7 @@ int main(void) {
}
else
{
USBD_Read(EP2OUT, hidmsgbuf + write_ptr*64, 64, true);
USBD_Read(INPUT_ENDPOINT, hidmsgbuf + write_ptr*64, 64, true);
}
}

View File

@ -63,6 +63,7 @@ static void int2str_reduce_n(char ** snum, uint32_t copy, uint8_t n)
do
{
copy /= n;
++*snum;
}while(copy);
}
@ -72,8 +73,10 @@ static char xdata __int2str_buf[9];
static void int2str_map_n(char ** snum, uint32_t i, uint8_t n)
{
int c = 0;
do
{
if (*snum <__int2str_buf) break;
*--*snum = __digits[i % n];
i /= n;
}while(i);

View File

@ -5,8 +5,11 @@
*****************************************************************************/
#ifndef NDEBUG
void slab_Assert()
void slab_Assert( const char * file, int line )
{
file = file;
line = line;
while ( 1 );
}
#endif

View File

@ -51,9 +51,9 @@
#ifdef USER_ASSERT
#define SLAB_ASSERT(expr) ((expr) ? ((void)0) : USER_ASSERT( __FILE__, __LINE__ ))
#else
void slab_Assert();
void slab_Assert( const char * file, int line );
//Yes this is smaller than if(!expr){assert}
#define SLAB_ASSERT(expr) if(expr){}else{slab_Assert();}
#define SLAB_ASSERT(expr) if(expr){}else{slab_Assert( __FILE__, __LINE__ );}
#endif
#endif

View File

@ -20,7 +20,7 @@ Known Issues and Limitations:
Target and Tool Chain Information:
---------------------------------
Target: EFM8UB1, EFM8UB2, EFM8UB3, EFM8UB4, C8051F320/1, C8051F326/7, C8051F34x, C8051F38x
Target: EFM8UB1, EFM8UB2, C8051F320/1, C8051F326/7, C8051F34x, C8051F38x
Tool chain: Keil
File List:
@ -51,13 +51,6 @@ Version 1.0.1
USB_PWRSAVE_MODE_FASTWAKE was enabled.
- Improved documentation of USB_PWRSAVE_MODE_FASTWAKE feature.
Version 1.0.2
- Added ability to detect short OUT packet in Isochronous mode and
stuff the buffer with zeroes to keep isochronous stream in sync.
Version 1.0.3
- Added support for EFM8UB3 and EFM8UB4 devices.
-------------------------------------------------------------------------------
End Of File
-------------------------------------------------------------------------------

View File

@ -21,7 +21,6 @@
*
* @section usb_device_contents Contents
*
* @li @ref usb_device_library_revision
* @li @ref usb_device_intro
* @li @ref usb_device_api
* @li @ref usb_device_conf
@ -29,9 +28,6 @@
* @li @ref usb_device_transfers
* @li @ref usb_device_pitfalls
*
* @n @section usb_device_library_revision EFM8 USB Library Revision
* Library Revision: 1.0.3
*
* @n @section usb_device_intro Introduction
*
* The USB device protocol stack provides an API which makes it possible to
@ -112,10 +108,11 @@
*
* @ref USBD_RemoteWakeup() @n
* Used in SUSPENDED state (see @ref USB_Status_TypeDef) to signal resume to
* host. The function will be called automatically by the library if the
* @ref USBD_RemoteWakeupCb() function returns true. The function will
* also check that the host has sent a SET_FEATURE request to enable Remote
* Wakeup before issuing the resume.
* host. It's the applications responsibility to adhere to the USB standard
* which states that a device can not signal resume before it has been
* SUSPENDED for at least 5 ms. The function will also check that the host
* has sent a SET_FEATURE request to enable Remote Wakeup before issuing the
* resume.
*
* @ref USBD_GetUsbState() @n
* Returns the device USB state (see @ref USBD_State_TypeDef). Refer to
@ -263,16 +260,6 @@
* #define SLAB_USB_LANGUAGE USB_LANGID_ENUS
*
* // -----------------------------------------------------------------------------
* // Enable use of UTF-8 strings for string descriptors.
* // If this option is enabled then packed string descriptors that are created
* // with UTF8_PACKED_STATIC_CONST_STRING_DESC() can be UTF-8 encoded and they
* // will be decoded into UCS-2 16-bit wide character format used for USB string
* // descriptors. If this feature is not needed then it can be disabled to save
* // some code memory space.
* // -----------------------------------------------------------------------------
* #define SLAB_USB_UTF8_STRINGS 1
*
* // -----------------------------------------------------------------------------
* // Set the power saving mode
* //
* // SLAB_USB_PWRSAVE_MODE configures when the device will automatically enter
@ -282,17 +269,9 @@
* // USB_PWRSAVE_MODE_ONSUSPEND - Enter USB power-save mode on USB suspend
* // USB_PWRSAVE_MODE_ONVBUSOFF - Enter USB power-save mode when not attached
* // to the USB host.
* // USB_PWRSAVE_MODE_FASTWAKE - Exit USB power-save mode more quickly, but
* // consume more power while in USB power-save
* // mode.
* // While the device is in USB power-save mode
* // (typically during USB suspend), the
* // internal voltage regulator stays in normal
* // power mode instead of entering suspend
* // power mode.
* // This is an advanced feature that may be
* // useful in certain applications that support
* // remote wakeup.
* // USB_PWRSAVE_MODE_FASTWAKE - Exit USB power-save mode more quickly.
* // This is useful for some applications that
* // support remote wakeup.
* // -----------------------------------------------------------------------------
* #define SLAB_USB_PWRSAVE_MODE (USB_PWRSAVE_MODE_ONVBUSOFF \
* | USB_PWRSAVE_MODE_ONSUSPEND)
@ -707,19 +686,14 @@
#endif
#ifndef UNREFERENCED_ARGUMENT
#if defined __C51__
/// Macro for removing unreferenced arguments from compiler warnings
#define UNREFERENCED_ARGUMENT(arg) (0, arg)
#elif defined __ICC8051__
/// Macro for removing unreferenced arguments from compiler warnings
#define UNREFERENCED_ARGUMENT(arg) ((void)arg)
#endif
#endif
/***************************************************************************//**
* @brief Macro for creating USB-compliant UTF-16LE UNICODE string
* descriptor from a C string.
* @details This macro should be used for ASCII strings in which all
* @details This macro should be used for UTF-8 strings in which all
* characters are represented by a single ASCII byte (i.e.
* U.S. English strings).
* The USB Library will expand variables created with this macro
@ -736,71 +710,9 @@
* @param __val
* The value of the string descriptor
******************************************************************************/
#define UTF16LE_PACKED_STATIC_CONST_STRING_DESC(__name, __val, __size) \
#define UTF16LE_PACKED_STATIC_CONST_STRING_DESC(__name, __val) \
SI_SEGMENT_VARIABLE(__name, static const USB_StringDescriptor_TypeDef, SI_SEG_CODE) = \
{ USB_STRING_DESCRIPTOR_UTF16LE_PACKED, __size * 2, USB_STRING_DESCRIPTOR, __val }
/***************************************************************************//**
* @brief Macro for creating USB-compliant UTF-16LE UNICODE string
* descriptor from a UTF-8 string.
* @details This macro should be used for UTF-8 strings in which all
* characters are represented by a valid UTF-8 byte sequence
* of 1-3 bytes per character. The USB library will expand
* variables created with this macro by decoding the UTF-8
* sequence into 16-bit wide UCS-2 characters required for USB
* string descriptors.
* @n@n This example set an array named _manufacturer[]_ to a
* series of symbols: an anchor, a lightning bolt, and a
* fußball as the Manufacturer String:
*
* #define MFR_STRING "⚓⚡⚽"
*
* // This string has 3 Unicode characters so the __len
* // parameter is 3, even though it will take 3 bytes to
* // represent each character
* UTF8_PACKED_STATIC_CONST_STRING_DESC(manufacturer[], 3, \
* MFR_STRING);
* @param __name
* The name of the variable that holds the string descriptor
* @param __len
* Number of Unicode characters (or codepoints) in the string
* @param __val
* The value of the string descriptor
******************************************************************************/
#define UTF8_PACKED_STATIC_CONST_STRING_DESC(__name, __len, __val) \
SI_SEGMENT_VARIABLE(__name, static const USB_StringDescriptor_TypeDef, SI_SEG_CODE) = \
{ USB_STRING_DESCRIPTOR_UTF8, (__len) * 2, USB_STRING_DESCRIPTOR, __val }
/***************************************************************************//**
* @brief Macro for creating USB-compliant UTF-16LE UNICODE string
* descriptor from a UTF-8 string.
* @details This macro should be used for UTF-8 strings in which all
* characters are represented by a valid UTF-8 byte sequence
* of 1-3 bytes per character. The USB library will expand
* variables created with this macro by decoding the UTF-8
* sequence into 16-bit wide UCS-2 characters required for USB
* string descriptors.
* @n@n This example set an array named _manufacturer[]_ to a
* series of symbols: an anchor, a lightning bolt, and a
* fußball as the Manufacturer String:
*
* #define MFR_STRING "⚓⚡⚽"
*
* // This string has 3 Unicode characters so the __len
* // parameter is 3, even though it will take 3 bytes to
* // represent each character
* UTF8_PACKED_STATIC_CONST_STRING_DESC(manufacturer[], 3, \
* MFR_STRING);
* @param __name
* The name of the variable that holds the string descriptor
* @param __len
* Number of Unicode characters (or codepoints) in the string
* @param __val
* The value of the string descriptor
******************************************************************************/
#define UTF8_PACKED_STATIC_CONST_STRING_DESC(__name, __len, __val) \
SI_SEGMENT_VARIABLE(__name, static const USB_StringDescriptor_TypeDef, SI_SEG_CODE) = \
{ USB_STRING_DESCRIPTOR_UTF8, (__len) * 2, USB_STRING_DESCRIPTOR, __val }
{ USB_STRING_DESCRIPTOR_UTF16LE_PACKED, sizeof(__val) * 2, USB_STRING_DESCRIPTOR, __val }
/***************************************************************************//**
* @brief Macro for creating USB-compliant UTF-16LE UNICODE string
@ -867,8 +779,8 @@
* The value of the string descriptor
******************************************************************************/
#define LANGID_STATIC_CONST_STRING_DESC(__name, __val) \
SI_SEGMENT_VARIABLE(__name, static const USB_LangId_StringDescriptor_Typedef, SI_SEG_CODE) = \
{ htole16(((SLAB_USB_NUM_LANGUAGES * 2) + 2) + (USB_STRING_DESCRIPTOR << 8)), __val }
SI_SEGMENT_VARIABLE(__name, static const USB_LangId_StringDescriptor_Typedef, __code) = \
{ (((SLAB_USB_NUM_LANGUAGES * 2) + 2) << 8) + USB_STRING_DESCRIPTOR, __val }
/** @} (end addtogroup efm8_usb_macros Macros) */
@ -897,8 +809,7 @@ typedef enum
USB_STATUS_DEVICE_RESET = -11, ///< Device is/was reset.
USB_STATUS_TIMEOUT = -12, ///< Transfer timeout.
USB_STATUS_DEVICE_REMOVED = -13, ///< Device was removed.
USB_STATUS_EP_RX_BUFFER_OVERRUN = -14, ///< Not enough data in the Rx buffer to hold the
USB_STATUS_DATA_ERROR = -15, ///< OUT packet had CRC or bit-stuffing error
USB_STATUS_EP_RX_BUFFER_OVERRUN = -14 ///< Not enough data in the Rx buffer to hold the
///< last received packet
} USB_Status_TypeDef;
@ -1083,7 +994,7 @@ typedef uint16_t USB_LangId_StringDescriptor_Typedef; ///< The language ID strin
#if (SLAB_USB_NUM_LANGUAGES == 1)
/// @brief USB String Table Structure.
typedef SI_VARIABLE_SEGMENT_POINTER(, USB_StringDescriptor_TypeDef, SI_SEG_GENERIC) USB_StringTable_TypeDef;
typedef USB_StringDescriptor_TypeDef * *USB_StringTable_TypeDef;
#elif (SLAB_USB_NUM_LANGUAGES > 1)
typedef struct
{
@ -1097,9 +1008,9 @@ typedef struct
/// the device.
typedef struct
{
SI_VARIABLE_SEGMENT_POINTER(deviceDescriptor, USB_DeviceDescriptor_TypeDef, SI_SEG_GENERIC); ///< Pointer to the device descriptor
SI_VARIABLE_SEGMENT_POINTER(configDescriptor, USB_ConfigurationDescriptor_TypeDef, SI_SEG_GENERIC); ///< Pointer to the configuration descriptor
SI_VARIABLE_SEGMENT_POINTER(stringDescriptors, USB_StringTable_TypeDef, SI_SEG_GENERIC); ///< Pointer to an array of string descriptor pointers
USB_DeviceDescriptor_TypeDef *deviceDescriptor; ///< Pointer to the device descriptor
uint8_t *configDescriptor; ///< Pointer to the configuration descriptor
USB_StringTable_TypeDef *stringDescriptors; ///< Pointer to an array of string descriptor pointers
uint8_t numberOfStrings; ///< Number of strings in string descriptor array
} USBD_Init_TypeDef;
@ -1107,7 +1018,7 @@ typedef struct
// Endpoint structure
typedef struct
{
SI_VARIABLE_SEGMENT_POINTER(buf, uint8_t, SI_SEG_GENERIC);
uint8_t *buf;
uint16_t remaining;
USBD_EpState_TypeDef state;
union
@ -1171,9 +1082,9 @@ typedef struct
#if SLAB_USB_SUPPORT_ALT_INTERFACES
uint8_t interfaceAltSetting[SLAB_USB_NUM_INTERFACES];
#endif
SI_VARIABLE_SEGMENT_POINTER(deviceDescriptor, USB_DeviceDescriptor_TypeDef, SI_SEG_GENERIC);
SI_VARIABLE_SEGMENT_POINTER(configDescriptor, USB_ConfigurationDescriptor_TypeDef, SI_SEG_GENERIC);
SI_VARIABLE_SEGMENT_POINTER(stringDescriptors, USB_StringTable_TypeDef, SI_SEG_GENERIC);
USB_DeviceDescriptor_TypeDef *deviceDescriptor;
USB_ConfigurationDescriptor_TypeDef *configDescriptor;
USB_StringTable_TypeDef *stringDescriptors;
} USBD_Device_TypeDef;
/// @endcond DO_NOT_INCLUDE_WITH_DOXYGEN
@ -1307,10 +1218,6 @@ USB_Status_TypeDef USBDCH9_SetupCmd(void);
*
* Default setting is '1' and may be overridden by defining in 'usbconfig.h'.
*
* @note The EFM8UB1, EFM8UB3, and EFM8UB4 devices can be configured to ignore
* the voltage on the VBUS pin and to instead use that pin as GPIO. If
* this feature is used, SLAB_USB_BUS_POWERED should be set to '1' even if
* the device is not drawing its power from the VBUS line.
*****************************************************************************/
/**************************************************************************//**
@ -1343,9 +1250,9 @@ USB_Status_TypeDef USBDCH9_SetupCmd(void);
* @brief Enables/disables remote wakeup capability
* @details Remote wakeup allow the USB device to wake the host from suspend.
* When enabled, the library will call @ref USBD_RemoteWakeupCb() to determine
* if the remote wakeup source caused the device to wake up. If it did, the
* library will exit suspend mode and call @ref USBD_RemoteWakeup() to wake
* up the host.
* if the remote wakeup source caused the device to wake up. If it was, the
* library will exit suspend mode and the application should call
* @ref USBD_RemoteWakeup() to wake up the host.
*
* When '1' remote wakeup is enabled
* When '0' remote wakeup is disabled
@ -1673,25 +1580,6 @@ USB_Status_TypeDef USBDCH9_SetupCmd(void);
*
*****************************************************************************/
/**************************************************************************//**
* @def SLAB_USB_UTF8_STRINGS
* @brief
* Enables UTF-8 string decoding for USB string descriptors that are created
* using @ref UTF8_PACKED_STATIC_CONST_STRING_DESC.
*
* @details
* If this option is enabled, USB descriptor strings that are created using
* @ref UTF8_PACKED_STATIC_CONST_STRING_DESC can be encoded as UTF-8 which
* allows for Unicode characters (up to 16-bits wide) to be used for USB
* string descriptors. The UTF-8 strings will be decoded into UCS-2 16-bit
* wide character format required by USB. If this feature is not needed then
* this option can be disabled to save code memory space. If this option is
* disabled, then @ref UTF8_PACKED_STATIC_CONST_STRING_DESC should not be used.
*
* Default setting is '0' and may be overridden by defining in 'usbconfig.h'.
*
*****************************************************************************/
/**************************************************************************//**
* @def SLAB_USB_PWRSAVE_MODE
* @brief Configures the power-saving options supported by the device
@ -1856,10 +1744,6 @@ USB_Status_TypeDef USBDCH9_SetupCmd(void);
#define SLAB_USB_LANGUAGE USB_LANGID_ENUS
#endif
#ifndef SLAB_USB_UTF8_STRINGS
#define SLAB_USB_UTF8_STRINGS 0
#endif
#ifndef SLAB_USB_PWRSAVE_MODE
#define SLAB_USB_PWRSAVE_MODE USB_PWRSAVE_MODE_ONSUSPEND
#endif
@ -1956,7 +1840,7 @@ USBD_State_TypeDef USBD_GetUsbState(void);
* @return
* @ref USB_STATUS_OK on success, else an appropriate error code.
******************************************************************************/
int8_t USBD_Init(SI_VARIABLE_SEGMENT_POINTER(p, const USBD_Init_TypeDef, SI_SEG_GENERIC));
int8_t USBD_Init(const USBD_Init_TypeDef *p);
/***************************************************************************//**
* @brief
@ -1983,7 +1867,7 @@ int8_t USBD_Init(SI_VARIABLE_SEGMENT_POINTER(p, const USBD_Init_TypeDef, SI_SEG_
* @ref USB_STATUS_OK on success, else an appropriate error code.
******************************************************************************/
int8_t USBD_Read(uint8_t epAddr,
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC),
uint8_t *dat,
uint16_t byteCount,
bool callback);
@ -1992,9 +1876,10 @@ int8_t USBD_Read(uint8_t epAddr,
* Perform a remote wakeup signaling sequence.
*
* @note
* This function is typically called by the library if @ref
* USBD_RemoteWakeupCb() returns true, so it does not need to be called by
* application code.
* It is the responsibility of the application to ensure that remote wakeup
* is not attempted before the device has been suspended for at least 5
* miliseconds. This function should not be called from within an interrupt
* handler.
*
* @return
* @ref USB_STATUS_OK on success, else an appropriate error code.
@ -2030,7 +1915,7 @@ void USBD_Run(void);
* @return
* @ref USB_STATUS_OK on success, else an appropriate error code.
******************************************************************************/
int8_t USBD_StallEp(uint8_t epAddr);
int8_t USBD_StallEp(int8_t epAddr);
/***************************************************************************//**
* @brief
@ -2089,7 +1974,7 @@ int8_t USBD_UnStallEp(uint8_t epAddr);
* @ref USB_STATUS_OK on success, else an appropriate error code.
******************************************************************************/
int8_t USBD_Write(uint8_t epAddr,
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC),
uint8_t *dat,
uint16_t byteCount,
bool callback);
@ -2228,8 +2113,8 @@ USB_Status_TypeDef USBD_SetInterfaceCb(uint8_t interface, uint8_t altSetting);
* If remote wakeup is enabled via @ref SLAB_USB_REMOTE_WAKEUP_ENABLED, the
* USB library will query the application after waking from suspend to see if
* the remote wakeup source was the reason for the wakeup. If this function
* returns True, the library will call @ref USBD_RemoteWakeup() to wake up the
* host and exit suspend mode.
* returns True, the library will exit suspend mode and the application should
* call @ref USBD_RemoteWakeup() to wake up the host.
* @return
* True if the remote wakeup source was the reason the device woke from
* suspend, false otherwise.
@ -2311,8 +2196,8 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, \
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
// -------------------- FIFO Access Functions ---------------------------------
void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC));
void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), bool txPacket);
void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, uint8_t *dat);
void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, uint8_t *dat, bool txPacket);
/// @endcond DO_NOT_INCLUDE_WITH_DOXYGEN
// -------------------- Include Files ------------------------------------------

View File

@ -6,9 +6,9 @@
#include "si_toolchain.h"
#include "efm8_usb.h"
#include "assert.h"
//#include "assert.h"
#include <stdint.h>
#define SLAB_ASSERT(x)
// -----------------------------------------------------------------------------
// Global Variables
@ -65,8 +65,8 @@ void USBD_AbortAllTransfers(void)
int8_t USBD_AbortTransfer(uint8_t epAddr)
{
SI_VARIABLE_SEGMENT_POINTER(ep, USBD_Ep_TypeDef, MEM_MODEL_SEG);
int8_t retVal = USB_STATUS_OK;
USBD_Ep_TypeDef MEM_MODEL_SEG *ep;
uint8_t retVal = USB_STATUS_OK;
bool usbIntsEnabled;
USB_SaveSfrPage();
@ -150,7 +150,7 @@ void USBD_Disconnect(void)
bool USBD_EpIsBusy(uint8_t epAddr)
{
SI_VARIABLE_SEGMENT_POINTER(ep, USBD_Ep_TypeDef, MEM_MODEL_SEG);
USBD_Ep_TypeDef MEM_MODEL_SEG *ep;
// Verify this is a valid endpoint address
if (epAddr >= SLAB_USB_NUM_EPS_USED)
@ -174,7 +174,7 @@ USBD_State_TypeDef USBD_GetUsbState(void)
return myUsbDevice.state;
}
int8_t USBD_Init(SI_VARIABLE_SEGMENT_POINTER(p, const USBD_Init_TypeDef, SI_SEG_GENERIC))
int8_t USBD_Init(const USBD_Init_TypeDef *p)
{
uint8_t i;
@ -190,12 +190,12 @@ int8_t USBD_Init(SI_VARIABLE_SEGMENT_POINTER(p, const USBD_Init_TypeDef, SI_SEG_
// Zero out the myUsbDevice struct, then initialize all non-zero members
for (i = 0; i < sizeof(myUsbDevice); i++)
{
*((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, MEM_MODEL_SEG))&myUsbDevice + i) = 0;
*((uint8_t MEM_MODEL_SEG *)&myUsbDevice + i) = 0;
}
// Get the USB descriptors from p
myUsbDevice.deviceDescriptor = p->deviceDescriptor;
myUsbDevice.configDescriptor = p->configDescriptor;
myUsbDevice.configDescriptor = (USB_ConfigurationDescriptor_TypeDef *)p->configDescriptor;
myUsbDevice.stringDescriptors = p->stringDescriptors;
myUsbDevice.numberOfStrings = p->numberOfStrings;
@ -246,12 +246,12 @@ int8_t USBD_Init(SI_VARIABLE_SEGMENT_POINTER(p, const USBD_Init_TypeDef, SI_SEG_
}
int8_t USBD_Read(uint8_t epAddr,
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC),
uint8_t *dat,
uint16_t byteCount,
bool callback)
{
bool usbIntsEnabled;
SI_VARIABLE_SEGMENT_POINTER(ep, USBD_Ep_TypeDef, MEM_MODEL_SEG);
USBD_Ep_TypeDef MEM_MODEL_SEG *ep;
USB_SaveSfrPage();
@ -432,13 +432,8 @@ void USBD_Stop(void)
void USBD_Suspend(void)
{
#if (!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_FASTWAKE))
uint8_t i;
#endif
bool regulatorEnabled, prefetchEnabled;
#if SLAB_USB_REMOTE_WAKEUP_ENABLED
bool remoteWakeup = false;
#endif
USB_SaveSfrPage();
@ -494,8 +489,7 @@ void USBD_Suspend(void)
// wakeup event occurred. If so, exit USBD_Suspend().
if (USB_IsSuspended() == true)
{
remoteWakeup = USBD_RemoteWakeupCb();
if (remoteWakeup == true)
if (USBD_RemoteWakeupCb() == true)
{
break;
}
@ -510,13 +504,8 @@ void USBD_Suspend(void)
break;
}
#endif
#if ((!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF)) || \
(SLAB_USB_BUS_POWERED))
} while (USB_IsSuspended() == true);
#else
} while ((USB_IsSuspended() == true) || (USB_IsVbusOn() == false));
#endif
// Restore the internal regulator
if (regulatorEnabled == true)
{
@ -534,20 +523,6 @@ void USBD_Suspend(void)
USB_SetNormalClock();
#endif
USB_EnableTransceiver();
#if SLAB_USB_REMOTE_WAKEUP_ENABLED
// If the device woke from suspend due to a remote wakeup source, call
// USBD_RemoteWakeup() here to wake up the host.
if (remoteWakeup == true)
{
// Wake up the host
if (USBD_RemoteWakeup() == USB_STATUS_OK)
{
// If the remote wakeup succeeded, transition out of USB suspend state
USBD_SetUsbState(myUsbDevice.savedState);
}
}
#endif
}
USB_RestoreSfrPage();
@ -624,12 +599,12 @@ int8_t USBD_UnStallEp(uint8_t epAddr)
}
int8_t USBD_Write(uint8_t epAddr,
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC),
uint8_t *dat,
uint16_t byteCount,
bool callback)
{
bool usbIntsEnabled;
SI_VARIABLE_SEGMENT_POINTER(ep, USBD_Ep_TypeDef, MEM_MODEL_SEG);
USBD_Ep_TypeDef MEM_MODEL_SEG *ep;
USB_SaveSfrPage();

View File

@ -22,13 +22,14 @@ static USB_Status_TypeDef SetConfiguration(void);
static USB_Status_TypeDef SetFeature(void);
static USB_Status_TypeDef SetInterface(void);
static void USBD_ActivateAllEps(bool forceIdle);
static void EP0_Write(SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), uint16_t numBytes);
static void EP0_Write(uint8_t *dat, uint16_t numBytes);
void SendEp0Stall(void);
// -----------------------------------------------------------------------------
// Global Variables
extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG);
const SI_SEGMENT_VARIABLE(txZero[2], uint8_t, SI_SEG_CODE);
SI_SEGMENT_VARIABLE(txZero[2], uint8_t, SI_SEG_CODE);
// -----------------------------------------------------------------------------
// Static Global Variables
@ -91,6 +92,15 @@ USB_Status_TypeDef USBDCH9_SetupCmd(void)
break;
}
// Reset index to 0 in case one of the above commands modified it
USB_SetIndex(0);
// If the command resulted in an error, send a procedural stall
if (status == USB_STATUS_REQ_ERR)
{
SendEp0Stall();
}
return status;
}
@ -228,7 +238,7 @@ static USB_Status_TypeDef GetConfiguration(void)
{
if (myUsbDevice.state == USBD_STATE_ADDRESSED)
{
EP0_Write((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))txZero, 1);
EP0_Write(txZero, 1);
retVal = USB_STATUS_OK;
}
else if (myUsbDevice.state == USBD_STATE_CONFIGURED)
@ -257,7 +267,7 @@ static USB_Status_TypeDef GetDescriptor(void)
uint8_t index;
uint16_t length = 0;
SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC);
uint8_t *dat;
USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR;
if (*((uint8_t *)&myUsbDevice.setup.bmRequestType) ==
@ -272,7 +282,7 @@ static USB_Status_TypeDef GetDescriptor(void)
{
break;
}
dat = (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.deviceDescriptor;
dat = (uint8_t *)myUsbDevice.deviceDescriptor;
length = myUsbDevice.deviceDescriptor->bLength;
break;
@ -281,14 +291,14 @@ static USB_Status_TypeDef GetDescriptor(void)
{
break;
}
dat = (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.configDescriptor;
dat = (uint8_t *)myUsbDevice.configDescriptor;
length = le16toh(myUsbDevice.configDescriptor->wTotalLength);
break;
case USB_STRING_DESCRIPTOR:
#if (SLAB_USB_NUM_LANGUAGES == 1)
dat = (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.stringDescriptors[index];
dat = (uint8_t *)myUsbDevice.stringDescriptors[index];
// Index 0 is the language string. If SLAB_USB_NUM_LANGUAGES == 1, we
// know the length will be 4 and the format will be UTF16LE.
@ -317,7 +327,7 @@ static USB_Status_TypeDef GetDescriptor(void)
// Index 0 is the language.
if (index == 0)
{
dat = ((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.stringDescriptors->languageArray[0][index]);
dat = ((uint8_t *)myUsbDevice.stringDescriptors->languageArray[0][index]);
length = *((uint8_t *)dat);
myUsbDevice.ep0String.encoding.type = USB_STRING_DESCRIPTOR_UTF16LE;
}
@ -335,7 +345,7 @@ static USB_Status_TypeDef GetDescriptor(void)
}
if ((langSupported == true) && (index < myUsbDevice.numberOfStrings))
{
dat = ((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.stringDescriptors->languageArray[lang][index]);
dat = ((uint8_t *)myUsbDevice.stringDescriptors->languageArray[lang][index]);
length = *(dat + USB_STRING_DESCRIPTOR_LENGTH);
myUsbDevice.ep0String.encoding.type = *(dat + USB_STRING_DESCRIPTOR_ENCODING);
dat += USB_STRING_DESCRIPTOR_LENGTH;
@ -393,10 +403,10 @@ static USB_Status_TypeDef GetInterface(void)
{
#if (SLAB_USB_SUPPORT_ALT_INTERFACES)
// Return the alternate setting for the specified interface
EP0_Write((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))&myUsbDevice.interfaceAltSetting[interface], 1);
EP0_Write(&myUsbDevice.interfaceAltSetting[interface], 1);
#else
// Alternate interfaces are not supported, so return 0x0000.
EP0_Write((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))&txZero, 1);
EP0_Write(&txZero, 1);
#endif
retVal = USB_STATUS_OK;
}
@ -531,7 +541,7 @@ static USB_Status_TypeDef GetStatus(void)
// If the command was valid, send the requested status.
if (retVal == USB_STATUS_OK)
{
EP0_Write((SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))&pStatus, 2);
EP0_Write((uint8_t *)&pStatus, 2);
}
}
@ -858,11 +868,11 @@ static void USBD_ActivateAllEps(bool forceIdle)
* @param numBytes
* Number of bytes to transmit on Endpoint 0
******************************************************************************/
static void EP0_Write(SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), uint16_t numBytes)
static void EP0_Write(uint8_t *dat, uint16_t numBytes)
{
if (myUsbDevice.ep0.state == D_EP_IDLE)
{
myUsbDevice.ep0.buf = dat;
myUsbDevice.ep0.buf = (uint8_t *)dat;
myUsbDevice.ep0.remaining = numBytes;
myUsbDevice.ep0.state = D_EP_TRANSMITTING;
myUsbDevice.ep0.misc.c = 0;

View File

@ -40,16 +40,11 @@ static void USB_WriteFIFO_Code(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat
// -------------------------------
// Generic FIFO access functions
static void USB_ReadFIFO_Generic(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), uint8_t fifoNum);
static void USB_WriteFIFO_Generic(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC));
static void USB_ReadFIFO_Generic(uint8_t numBytes, uint8_t *dat, uint8_t fifoNum);
static void USB_WriteFIFO_Generic(uint8_t numBytes, uint8_t *dat);
#endif // #ifdef SI_GPTR
#if (SLAB_USB_EP3OUT_USED && (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC))
static void memclearXdata(SI_VARIABLE_SEGMENT_POINTER(s, uint8_t, SI_SEG_XDATA),
uint16_t n);
#endif
// -----------------------------------------------------------------------------
// Functions
@ -67,7 +62,7 @@ static void memclearXdata(SI_VARIABLE_SEGMENT_POINTER(s, uint8_t, SI_SEG_XDATA),
// If Isochronous mode is enabled and the max packet size is greater than 255,
// break the FIFO reads up into multiple reads of 255 or less bytes.
// ----------------------------------------------------------------------------
void USB_ReadFIFOIso(uint8_t fifoNum, uint16_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC))
void USB_ReadFIFOIso(uint8_t fifoNum, uint16_t numBytes, uint8_t *dat)
{
uint8_t numBytesRead;
@ -99,7 +94,7 @@ void USB_ReadFIFOIso(uint8_t fifoNum, uint16_t numBytes, SI_VARIABLE_SEGMENT_POI
// If Isochronous mode is enabled and the max packet size is greater than 255,
// break the FIFO writes up into multiple writes of 255 or less bytes.
// ----------------------------------------------------------------------------
void USB_WriteFIFOIso(uint8_t fifoNum, uint16_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC))
void USB_WriteFIFOIso(uint8_t fifoNum, uint16_t numBytes, uint8_t *dat)
{
uint8_t numBytesWrite;
@ -322,6 +317,7 @@ void handleUsbIn3Int(void)
void handleUsbOut1Int(void)
{
uint8_t count;
USB_Status_TypeDef status;
bool xferComplete = false;
@ -361,7 +357,6 @@ void handleUsbOut1Int(void)
myUsbDevice.ep1out.state = D_EP_IDLE;
xferComplete = true;
}
status = USB_STATUS_OK;
USB_EpnClearOutPacketReady();
}
@ -371,7 +366,6 @@ void handleUsbOut1Int(void)
{
myUsbDevice.ep1out.misc.bits.callback = false;
}
USBD_XferCompleteCb(EP1OUT, status, count, myUsbDevice.ep1out.remaining);
}
}
@ -387,6 +381,7 @@ void handleUsbOut1Int(void)
void handleUsbOut2Int(void)
{
uint8_t count;
USB_Status_TypeDef status;
bool xferComplete = false;
@ -451,10 +446,19 @@ void handleUsbOut2Int(void)
* @note This function takes no parameters, but it uses the EP3OUT status
* variables stored in @ref myUsbDevice.ep3out.
******************************************************************************/
#if ((SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR))
void handleUsbOut3Int(void)
{
#if (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)
uint16_t nextIdx;
#if (SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 255)
uint16_t count;
#else
uint8_t count;
#endif // ( SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 255 )
#else
uint8_t count;
#endif // ( SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC )
USB_Status_TypeDef status;
bool xferComplete = false;
@ -474,6 +478,7 @@ void handleUsbOut3Int(void)
myUsbDevice.ep3out.misc.bits.outPacketPending = true;
status = USB_STATUS_EP_ERROR;
}
#if ((SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR))
// Check for overrun of user buffer
else if (myUsbDevice.ep3out.remaining < count)
{
@ -481,11 +486,12 @@ void handleUsbOut3Int(void)
myUsbDevice.ep3out.misc.bits.outPacketPending = true;
status = USB_STATUS_EP_RX_BUFFER_OVERRUN;
}
#endif
else
{
#if ((SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR))
USB_ReadFIFO(3, count, myUsbDevice.ep3out.buf);
myUsbDevice.ep3out.misc.bits.outPacketPending = false;
myUsbDevice.ep3out.remaining -= count;
myUsbDevice.ep3out.buf += count;
@ -494,93 +500,7 @@ void handleUsbOut3Int(void)
myUsbDevice.ep3out.state = D_EP_IDLE;
xferComplete = true;
}
status = USB_STATUS_OK;
USB_EpnClearOutPacketReady();
}
if (myUsbDevice.ep3out.misc.bits.callback == true)
{
if (xferComplete == true)
{
myUsbDevice.ep3out.misc.bits.callback = false;
}
USBD_XferCompleteCb(EP3OUT, status, count, myUsbDevice.ep3out.remaining);
}
}
}
#elif (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)
void handleUsbOut3Int(void)
{
uint16_t nextIdx;
uint16_t numZeroBytesFromCb;
#if (SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 255)
uint16_t count;
#else
uint8_t count;
#endif
USB_Status_TypeDef status = USB_STATUS_OK;
bool xferComplete = false;
USB_SetIndex(3);
if (USB_EpnOutGetSentStall())
{
USB_EpnOutClearSentStall();
}
else if (USB_EpnGetOutPacketReady())
{
count = USB_EpOutGetCount();
// If USBD_Read() has not been called, return an error
if (myUsbDevice.ep3out.state != D_EP_RECEIVING)
{
myUsbDevice.ep3out.misc.bits.outPacketPending = true;
status = USB_STATUS_EP_ERROR;
}
else
{
// DATERR bit set (i.e. CRC/bit-stuffing error)
if (USB_EpnGetDataError()
#ifdef SLAB_USB_ISOC_OUT_MIN_PACKET_SIZE
|| (count < SLAB_USB_ISOC_OUT_MIN_PACKET_SIZE)
#endif
#ifdef SLAB_USB_ISOC_OUT_MAX_PACKET_SIZE
|| (count > SLAB_USB_ISOC_OUT_MAX_PACKET_SIZE)
#endif
)
{
status = USB_STATUS_DATA_ERROR;
}
#ifdef SLAB_USB_ISOC_OUT_PACKETSIZE_MOD2
if ((count % 2) != 0)
{
status = USB_STATUS_DATA_ERROR;
}
#elif defined SLAB_USB_ISOC_OUT_PACKETSIZE_MOD4
if (( count % 4) != 0)
{
status = USB_STATUS_DATA_ERROR;
}
#elif defined SLAB_USB_ISOC_OUT_PACKETSIZE_MOD6
if (count % 6) != 0)
{
status = USB_STATUS_DATA_ERROR;
}
#endif
if (status == USB_STATUS_DATA_ERROR)
{
count = 0;
// Flush FIFO to get rid of bad packet
USB_EpnOutFlush();
myUsbDevice.ep3out.misc.bits.outPacketPending = false;
// Flush clears OPRDY, so no need to call USB_EpnClearOutPacketReady() now
}
else // No data error
{
nextIdx = count + myUsbDevice.ep3outIsoIdx;
// In isochronous mode, a circular buffer is used to hold the data
@ -597,12 +517,12 @@ void handleUsbOut3Int(void)
USB_ReadFIFOIso(3, count, &myUsbDevice.ep3out.buf[myUsbDevice.ep3outIsoIdx]);
myUsbDevice.ep3outIsoIdx = nextIdx;
}
#endif // ( ( SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK ) || ( SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR ) )
myUsbDevice.ep3out.misc.bits.outPacketPending = false;
status = USB_STATUS_OK;
USB_EpnClearOutPacketReady();
}
}
if (myUsbDevice.ep3out.misc.bits.callback == true)
{
if (xferComplete == true)
@ -610,70 +530,18 @@ void handleUsbOut3Int(void)
myUsbDevice.ep3out.misc.bits.callback = false;
}
#if ((SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR))
USBD_XferCompleteCb(EP3OUT, status, count, myUsbDevice.ep3out.remaining);
#elif (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)
// In Isochronous mode, the meaning of the USBD_XferCompleteCb parameters changes:
// xferred is the number of bytes received in the last packet
// remaining is the current index into the circular buffer
numZeroBytesFromCb = USBD_XferCompleteCb(EP3OUT, status, count, myUsbDevice.ep3outIsoIdx);
// If data error occurred, the callback return value specifies how many zero-valued bytes to queue
if (numZeroBytesFromCb && (status == USB_STATUS_DATA_ERROR))
{
uint16_t numZeroBytesToWrite;
SI_SEGMENT_VARIABLE_SEGMENT_POINTER(bufPtr,
uint8_t,
SI_SEG_XDATA,
SI_SEG_DATA);
// Clear status after calling USBD_XferCompleteCb()
status = USB_STATUS_OK;
// Add the specified number of zero-value bytes
nextIdx = numZeroBytesFromCb + myUsbDevice.ep3outIsoIdx;
// Next index is past the end of the buffer (requires two writes)
if (nextIdx > myUsbDevice.ep3out.remaining)
{
// Write up to the end of the buffer
numZeroBytesToWrite = myUsbDevice.ep3out.remaining - myUsbDevice.ep3outIsoIdx;
bufPtr = &myUsbDevice.ep3out.buf[myUsbDevice.ep3outIsoIdx];
memclearXdata(bufPtr, numZeroBytesToWrite);
// Write the rest, starting at beginning of buffer
myUsbDevice.ep3outIsoIdx = nextIdx - myUsbDevice.ep3out.remaining;
numZeroBytesToWrite = myUsbDevice.ep3outIsoIdx;
bufPtr = &myUsbDevice.ep3out.buf[0];
memclearXdata(bufPtr, numZeroBytesToWrite);
}
// Next index is not past the end of the buffer
else
{
bufPtr = &myUsbDevice.ep3out.buf[myUsbDevice.ep3outIsoIdx];
memclearXdata(bufPtr, numZeroBytesFromCb);
myUsbDevice.ep3outIsoIdx = nextIdx;
USBD_XferCompleteCb(EP3OUT, status, count, myUsbDevice.ep3outIsoIdx);
#endif
}
}
}
}
}
/***************************************************************************//**
* @brief Sets all elements in a contiguous array of XDATA to zero
* @param s
* Pointer to the block of memory to fill
* @param n
* Number of bytes to be set to the value
******************************************************************************/
static void memclearXdata(SI_VARIABLE_SEGMENT_POINTER(s, uint8_t, SI_SEG_XDATA),
uint16_t n)
{
while (n)
{
*s++ = 0;
n--;
}
}
#endif // #if ((SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_INTR))
#endif // EP3OUT_USED
/***************************************************************************//**
@ -685,7 +553,7 @@ static void memclearXdata(SI_VARIABLE_SEGMENT_POINTER(s, uint8_t, SI_SEG_XDATA),
* @param dat
* Pointer to buffer to hold data read from the FIFO
******************************************************************************/
void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC))
void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, uint8_t *dat)
{
if (numBytes > 0)
{
@ -699,7 +567,7 @@ void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER
switch (((SI_GEN_PTR_t *)&dat)->gptr.memtype)
{
case SI_GPTR_MTYPE_IDATA:
USB_ReadFIFO_Idata(numBytes, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_IDATA))dat, fifoNum);
USB_ReadFIFO_Idata(numBytes, dat, fifoNum);
break;
// For some compilers, IDATA and DATA are treated the same.
@ -712,7 +580,7 @@ void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER
#endif
case SI_GPTR_MTYPE_XDATA:
USB_ReadFIFO_Xdata(numBytes, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_XDATA))dat, fifoNum);
USB_ReadFIFO_Xdata(numBytes, dat, fifoNum);
break;
// For some compilers, XDATA and PDATA are treated the same.
@ -750,7 +618,7 @@ void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER
* If FALSE, the packet will be stored in the FIFO and the
* transmission must be started at a later time
******************************************************************************/
void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), bool txPacket)
void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, uint8_t *dat, bool txPacket)
{
USB_EnableWriteFIFO(fifoNum);
@ -762,7 +630,7 @@ void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTE
switch (((SI_GEN_PTR_t *)&dat)->gptr.memtype)
{
case SI_GPTR_MTYPE_IDATA:
USB_WriteFIFO_Idata(numBytes, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_IDATA))dat);
USB_WriteFIFO_Idata(numBytes, dat);
break;
// For some compilers, IDATA and DATA are treated the same.
@ -775,7 +643,7 @@ void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTE
#endif
case SI_GPTR_MTYPE_XDATA:
USB_WriteFIFO_Xdata(numBytes, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_XDATA))dat);
USB_WriteFIFO_Xdata(numBytes, dat);
break;
// For some compilers, XDATA and PDATA are treated the same.
@ -788,7 +656,7 @@ void USB_WriteFIFO(uint8_t fifoNum, uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTE
#endif
case SI_GPTR_MTYPE_CODE:
USB_WriteFIFO_Code(numBytes, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_CODE))dat);
USB_WriteFIFO_Code(numBytes, dat);
break;
default:
@ -944,10 +812,10 @@ static void USB_ReadFIFO_Data(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat,
{
while (--numBytes)
{
USB_GetFIFOByte(dat);
USB_GetFIFOByte(*dat);
dat++;
}
USB_GetLastFIFOByte(dat, fifoNum);
USB_GetLastFIFOByte(*dat, fifoNum);
}
/***************************************************************************//**
@ -997,14 +865,14 @@ static void USB_WriteFIFO_Code(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat
* @param fifoNum
* USB FIFO to read
******************************************************************************/
static void USB_ReadFIFO_Generic(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC), uint8_t fifoNum)
static void USB_ReadFIFO_Generic(uint8_t numBytes, uint8_t *dat, uint8_t fifoNum)
{
while (--numBytes)
{
USB_GetFIFOByte(dat);
USB_GetFIFOByte(*dat);
dat++;
}
USB_GetLastFIFOByte(dat, fifoNum);
USB_GetLastFIFOByte(*dat, fifoNum);
}
/***************************************************************************//**
@ -1016,7 +884,7 @@ static void USB_ReadFIFO_Generic(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(d
* @param dat
* Pointer to generic buffer holding data to write to the FIFO
******************************************************************************/
static void USB_WriteFIFO_Generic(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_GENERIC))
static void USB_WriteFIFO_Generic(uint8_t numBytes, uint8_t *dat)
{
while (numBytes--)
{

View File

@ -13,7 +13,7 @@
// Global variables
extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG);
extern SI_SEGMENT_VARIABLE(txZero[2], const uint8_t, SI_SEG_CODE);
extern SI_SEGMENT_VARIABLE(txZero[2], uint8_t, SI_SEG_CODE);
// -----------------------------------------------------------------------------
// Function prototypes
@ -48,12 +48,6 @@ void handleUsbOut3Int(void);
void SendEp0Stall(void);
#if SLAB_USB_UTF8_STRINGS == 1
static uint8_t decodeUtf8toUcs2(
const uint8_t *pUtf8in,
SI_VARIABLE_SEGMENT_POINTER(pUcs2out, uint16_t, MEM_MODEL_SEG));
#endif
// -----------------------------------------------------------------------------
// Functions
@ -218,8 +212,6 @@ void usbIrqHandler(void)
******************************************************************************/
static void handleUsbEp0Int(void)
{
USB_Status_TypeDef retVal = USB_STATUS_REQ_UNHANDLED;
USB_SetIndex(0);
if (USB_Ep0SentStall() || USB_GetSetupEnd())
@ -242,55 +234,32 @@ static void handleUsbEp0Int(void)
// Vendor unique, Class or Standard setup commands override?
#if SLAB_USB_SETUP_CMD_CB
retVal = USBD_SetupCmdCb(&myUsbDevice.setup);
if (retVal == USB_STATUS_REQ_UNHANDLED)
if (USBD_SetupCmdCb(&myUsbDevice.setup) == USB_STATUS_REQ_UNHANDLED)
{
#endif
if (myUsbDevice.setup.bmRequestType.Type == USB_SETUP_TYPE_STANDARD)
{
retVal = USBDCH9_SetupCmd();
USBDCH9_SetupCmd();
}
#if SLAB_USB_SETUP_CMD_CB
}
#endif
// Reset index to 0 in case the call to USBD_SetupCmdCb() or
// USBDCH9_SetupCmd() changed it.
USB_SetIndex(0);
// Put the Enpoint 0 hardware into the correct state here.
if (retVal == USB_STATUS_OK)
{
// If wLength is 0, there is no Data Phase
// Set both the Serviced Out Packet Ready and Data End bits
if (myUsbDevice.setup.wLength == 0)
{
USB_Ep0SetLastOutPacketReady();
}
// If wLength is non-zero, there is a Data Phase.
// Set only the Serviced Out Packet Ready bit.
else
{
USB_Ep0ServicedOutPacketReady();
#if SLAB_USB_SETUP_CMD_CB
// If OUT packet but callback didn't set up a USBD_Read and we are expecting a
// data byte then we need to wait for the read to be setup and NACK packets until
// USBD_Read is called.
if ((myUsbDevice.setup.bmRequestType.Direction == USB_SETUP_DIR_OUT)
&& (myUsbDevice.ep0.state != D_EP_RECEIVING))
{
myUsbDevice.ep0.misc.bits.waitForRead = true;
}
#endif
}
}
// If the setup transaction detected an error, send a stall
else
{
SendEp0Stall();
}
#if SLAB_USB_SETUP_CMD_CB
}
else
{
// If in-packet but callback didn't setup a USBD_Read and we are expecting a data byte then
// we need to wait for the read to be setup and nack packets till USBD_Read is called.
if ((myUsbDevice.setup.bmRequestType.Direction == USB_SETUP_DIR_OUT)
&& (myUsbDevice.ep0.state != D_EP_RECEIVING)
&& (myUsbDevice.setup.wLength)
)
{
myUsbDevice.ep0.misc.bits.waitForRead = true;
}
}
#endif
}
else if (myUsbDevice.ep0.state == D_EP_RECEIVING)
{
@ -312,9 +281,11 @@ static void handleUsbEp0Int(void)
******************************************************************************/
static void USB_ReadFIFOSetup(void)
{
SI_VARIABLE_SEGMENT_POINTER(ptr, uint16_t, MEM_MODEL_SEG) = (SI_VARIABLE_SEGMENT_POINTER(, uint16_t, MEM_MODEL_SEG))&myUsbDevice.setup;
uint16_t MEM_MODEL_SEG *ptr = &myUsbDevice.setup;
USB_ReadFIFO(0, 8, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))ptr);
USB_ReadFIFO(0, 8, (uint8_t *)ptr);
USB_Ep0ServicedOutPacketReady();
// Modify for Endian-ness of the compiler
ptr[1] = le16toh(ptr[1]);
@ -368,11 +339,9 @@ static void handleUsbResetInt(void)
USB_EnableSuspendDetection();
USB_EnableDeviceInts();
// If the device is bus-powered, always put it in the Default state.
// If the device is self-powered and VBUS is present, put the device in the
// Default state. Otherwise, put it in the Attached state.
#if (!SLAB_USB_BUS_POWERED) && \
(!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF))
// If VBUS is preset, put the device in the Default state.
// Otherwise, put it in the Attached state.
#if (!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF))
if (USB_IsVbusOn())
{
USBD_SetUsbState(USBD_STATE_DEFAULT);
@ -437,16 +406,12 @@ static void handleUsbEp0Tx(void)
// Strings can use the USB_STRING_DESCRIPTOR_UTF16LE_PACKED type to pack
// UTF16LE data without the zero's between each character.
// If the current string is of type USB_STRING_DESCRIPTOR_UTF16LE_PACKED,
// unpack it by inserting a zero between each character in the string.
if ((myUsbDevice.ep0String.encoding.type == USB_STRING_DESCRIPTOR_UTF16LE_PACKED)
#if SLAB_USB_UTF8_STRINGS == 1
|| (myUsbDevice.ep0String.encoding.type == USB_STRING_DESCRIPTOR_UTF8)
#endif
)
// unpacket it by inserting a zero between each character in the string.
if (myUsbDevice.ep0String.encoding.type == USB_STRING_DESCRIPTOR_UTF16LE_PACKED)
{
// If ep0String.encoding.init is true, this is the beginning of the string.
// The first two bytes of the string are the bLength and bDescriptorType
// fields. These are not packed like the reset of the string, so write them
// fields. These are no packed like the reset of the string, so write them
// to the FIFO and set ep0String.encoding.init to false.
if (myUsbDevice.ep0String.encoding.init == true)
{
@ -459,36 +424,9 @@ static void handleUsbEp0Tx(void)
// Insert a 0x00 between each character of the string.
for (i = 0; i < count / 2; i++)
{
#if SLAB_USB_UTF8_STRINGS == 1
if (myUsbDevice.ep0String.encoding.type == USB_STRING_DESCRIPTOR_UTF8)
{
SI_SEGMENT_VARIABLE(ucs2, uint16_t, MEM_MODEL_SEG);
uint8_t utf8count;
// decode the utf8 into ucs2 for usb string
utf8count = decodeUtf8toUcs2(myUsbDevice.ep0.buf, &ucs2);
// if consumed utf8 bytes is 0, it means either null byte was
// input or bad utf8 byte sequence. Either way its an error and
// there's not much we can do. So just advance the input string
// by one character and keep going until count is expired.
if (utf8count == 0)
{
utf8count = 1;
}
// adjust to next char in utf8 byte sequence
myUsbDevice.ep0.buf += utf8count;
ucs2 = htole16(ucs2); // usb 16-bit chars are little endian
USB_WriteFIFO(0, 2, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))&ucs2, false);
}
else
#endif
{
USB_WriteFIFO(0, 1, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))myUsbDevice.ep0.buf, false);
USB_WriteFIFO(0, 1, myUsbDevice.ep0.buf, false);
myUsbDevice.ep0.buf++;
USB_WriteFIFO(0, 1, (SI_VARIABLE_SEGMENT_POINTER(, uint8_t, SI_SEG_GENERIC))&txZero, false);
}
USB_WriteFIFO(0, 1, &txZero, false);
}
}
// For any data other than USB_STRING_DESCRIPTOR_UTF16LE_PACKED, just send the
@ -588,98 +526,6 @@ void SendEp0Stall(void)
USB_Ep0SendStall();
}
#if SLAB_USB_UTF8_STRINGS == 1
/***************************************************************************//**
* Decodes UTF-8 to UCS-2 (16-bit) character encoding that is used
* for USB string descriptors.
*
* @param pUtf8in pointer to next character in UTF-8 string
* @param pUcs2out pointer to location for 16-bit character output
*
* Decodes a UTF-8 byte sequence into a single UCS-2 character. This
* will only decode up to 16-bit code point and will not handle the
* 21-bit case (4 bytes input).
*
* For valid cases, the UTF8 character sequence decoded into a 16-bit
* character and stored at the location pointed at by _pUcs2out_.
* The function will then return the number of input bytes that were
* consumed (1, 2, or 3). The caller can use the return value to find
* the start of the next character sequence in a utf-8 string.
*
* If either of the input pointers are NULL, then 0 is returned.
*
* If the first input character is NULL, then the output 16-bit value
* will be set to NULL and the function will return 0.
*
* If any other invalid sequence is detected, then the 16-bit output
* will be set to the equivalent of the question mark character (0x003F)
* and the return code will be 0.
*
* @return count of UTF8 bytes consumed
******************************************************************************/
static uint8_t decodeUtf8toUcs2(
const uint8_t *pUtf8in,
SI_VARIABLE_SEGMENT_POINTER(pUcs2out, uint16_t, MEM_MODEL_SEG))
{
uint8_t ret = 0;
// check the input pointers
if (!pUtf8in || !pUcs2out)
{
return 0;
}
// set default decode to error '?';
*pUcs2out = '?';
// valid cases:
// 0xxxxxxx (7 bits)
// 110xxxxx 10xxxxxx (11 bits)
// 1110xxxx 10xxxxxx 10xxxxxx (16 bits)
// null input
if (pUtf8in[0] == 0)
{
*pUcs2out = 0;
ret = 0;
}
// 7-bit char
else if (pUtf8in[0] < 128)
{
*pUcs2out = pUtf8in[0];
ret = 1;
}
// 11-bit char
else if ((pUtf8in[0] & 0xE0) == 0xC0)
{
if ((pUtf8in[1] & 0xC0) == 0x80)
{
*pUcs2out = ((pUtf8in[0] & 0x1F) << 6) | (pUtf8in[1] & 0x3F);
ret = 2;
}
}
// 16-bit char
else if ((pUtf8in[0] & 0xF0) == 0xE0)
{
if ((pUtf8in[1] & 0xC0) == 0x80)
{
if ((pUtf8in[2] & 0xC0) == 0x80)
{
*pUcs2out = ((pUtf8in[0] & 0x0F) << 12)
| ((pUtf8in[1] & 0x3F) << 6)
| (pUtf8in[2] & 0x3F);
ret = 3;
}
}
}
return ret;
}
#endif // SLAB_USB_UTF8_STRINGS
// This function is called from USBD_Init(). It forces the user project to pull
// this module from the library so that the declared ISR can be seen and
// included. If this is not done then this entire module by never be included

View File

@ -10,6 +10,7 @@
#include "SI_EFM8UB1_Register_Enums.h"
#include <stdint.h>
#include <stdbool.h>
#include "efm8_config.h"
/******************************************************************************/
@ -167,7 +168,7 @@ extern void USB_DisableInts(void);
* @brief Returns state of USB interrupt enabler
* @return TRUE if USB interrupts are enabled, FALSE otherwise.
******************************************************************************/
extern bool USB_GetIntsEnabled(void);
bool USB_GetIntsEnabled(void);
/***************************************************************************//**
* @brief Enables VBUS detection
@ -324,7 +325,9 @@ extern void USB_SuspendTransceiver(void);
do \
{ \
SFRPAGE = PG3_PAGE; \
USB0XCN &= ~(USB0XCN_PHYEN__ENABLED | USB0XCN_Dp__HIGH | USB0XCN_Dn__HIGH);\
USB0XCN &= ~(USB0XCN_PHYEN__ENABLED \
| USB0XCN_Dp__HIGH \
| USB0XCN_Dn__HIGH); \
} while (0)
#endif
@ -503,14 +506,14 @@ extern void USB_UnsuspendRegulator(void);
* @brief Determine if the internal regulator is enabled
* @return TRUE if the internal regulator is enabled, FALSE otherwise
******************************************************************************/
extern bool USB_IsRegulatorEnabled(void);
bool USB_IsRegulatorEnabled(void);
/***************************************************************************//**
* @brief Disable the prefetch engine
* @note This function is implemented as a macro.
******************************************************************************/
#ifdef IS_DOXYGEN
extern void USB_DisablePrefetch(void);
void USB_DisablePrefetch(void);
#else
#define USB_DisablePrefetch() \
do \
@ -525,7 +528,7 @@ extern void USB_DisablePrefetch(void);
* @note This function is implemented as a macro.
******************************************************************************/
#ifdef IS_DOXYGEN
extern void USB_EnablePrefetch(void);
void USB_EnablePrefetch(void);
#else
#define USB_EnablePrefetch() \
do \
@ -539,12 +542,12 @@ extern void USB_EnablePrefetch(void);
* @brief Determine if the prefetch engine is enabled
* @return TRUE if prefetch engine is enabled, FALSE otherwise.
******************************************************************************/
extern bool USB_IsPrefetchEnabled(void);
bool USB_IsPrefetchEnabled(void);
/***************************************************************************//**
* @brief Suspends internal oscillator
******************************************************************************/
extern void USB_SuspendOscillator(void);
void USB_SuspendOscillator(void);
/***************************************************************************//**
* @brief Enables clock recovery in full speed mode
@ -731,8 +734,7 @@ extern void USB_Ep0SetLastOutPacketReady(void);
#ifdef IS_DOXYGEN
extern void USB_Ep0SendStall(void);
#else
#define USB_Ep0SendStall() \
USB_WRITE_BYTE(E0CSR, (E0CSR_SOPRDY__SET | E0CSR_SDSTL__SET))
#define USB_Ep0SendStall() USB_WRITE_BYTE(E0CSR, E0CSR_SDSTL__SET)
#endif
/***************************************************************************//**
@ -964,7 +966,7 @@ extern bool USB_IsOut3IntActive(uint8_t OUT1INT_snapshot);
extern void USB_SetSuspendIntActive(uint8_t CMINT_snapshot);
#else
#define USB_SetSuspendIntActive(CMINT_snapshot) \
((CMINT_snapshot) |= CMINT_SUSINT__SET)
(CMINT_snapshot |= CMINT_SUSINT__SET)
#endif
/***************************************************************************//**
@ -978,7 +980,7 @@ extern void USB_SetSuspendIntActive(uint8_t CMINT_snapshot);
extern void USB_SetEp0IntActive(uint8_t IN1INT_snapshot);
#else
#define USB_SetEp0IntActive(IN1INT_snapshot) \
((IN1INT_snapshot) |= IN1INT_EP0__SET)
(IN1INT_snapshot |= IN1INT_EP0__SET)
#endif
/***************************************************************************//**
@ -992,7 +994,7 @@ extern void USB_SetEp0IntActive(uint8_t IN1INT_snapshot);
extern void USB_SetIn1IntActive(uint8_t IN1INT_snapshot);
#else
#define USB_SetIn1IntActive(IN1INT_snapshot) \
((IN1INT_snapshot) |= IN1INT_IN1__SET)
(IN1INT_snapshot |= IN1INT_IN1__SET)
#endif
/***************************************************************************//**
@ -1006,7 +1008,7 @@ extern void USB_SetIn1IntActive(uint8_t IN1INT_snapshot);
extern void USB_SetIn2IntActive(uint8_t IN1INT_snapshot);
#else
#define USB_SetIn2IntActive(IN1INT_snapshot) \
((IN1INT_snapshot) |= IN1INT_IN2__SET)
(IN1INT_snapshot |= IN1INT_IN2__SET)
#endif
/***************************************************************************//**
@ -1020,7 +1022,7 @@ extern void USB_SetIn2IntActive(uint8_t IN1INT_snapshot);
extern void USB_SetIn3IntActive(uint8_t IN1INT_snapshot);
#else
#define USB_SetIn3IntActive(IN1INT_snapshot) \
((IN1INT_snapshot) |= IN1INT_IN3__SET)
(IN1INT_snapshot |= IN1INT_IN3__SET)
#endif
/***************************************************************************//**
@ -1034,7 +1036,7 @@ extern void USB_SetIn3IntActive(uint8_t IN1INT_snapshot);
extern void USB_SetOut1IntActive(uint8_t OUT1INT_snapshot);
#else
#define USB_SetOut1IntActive(OUT1INT_snapshot) \
((OUT1INT_snapshot) |= OUT1INT_OUT1__SET)
(OUT1INT_snapshot |= OUT1INT_OUT1__SET)
#endif
/***************************************************************************//**
@ -1048,7 +1050,7 @@ extern void USB_SetOut1IntActive(uint8_t OUT1INT_snapshot);
extern void USB_SetOut2IntActive(uint8_t OUT1INT_snapshot);
#else
#define USB_SetOut2IntActive(OUT1INT_snapshot) \
((OUT1INT_snapshot) |= OUT1INT_OUT2__SET)
(OUT1INT_snapshot |= OUT1INT_OUT2__SET)
#endif
/***************************************************************************//**
@ -1062,7 +1064,7 @@ extern void USB_SetOut2IntActive(uint8_t OUT1INT_snapshot);
extern void USB_SetOut3IntActive(uint8_t OUT1INT_snapshot);
#else
#define USB_SetOut3IntActive(OUT1INT_snapshot) \
((OUT1INT_snapshot) |= OUT1INT_OUT3__SET)
(OUT1INT_snapshot |= OUT1INT_OUT3__SET)
#endif
/***************************************************************************//**
@ -1078,7 +1080,7 @@ extern void USB_EnableDeviceInts(void);
(CMIE_SOFE__ENABLED \
| CMIE_RSTINTE__ENABLED \
| CMIE_RSUINTE__ENABLED \
| CMIE_SUSINTE__ENABLED))
| CMIE_SUSINTE__ENABLED));
#endif
/***************************************************************************//**
@ -1088,7 +1090,7 @@ extern void USB_EnableDeviceInts(void);
#ifdef IS_DOXYGEN
extern void USB_EnableSofInt(void);
#else
#define USB_EnableSofInt() USB_SET_BITS(CMIE, CMIE_SOFE__ENABLED)
#define USB_EnableSofInt() USB_SET_BITS(CMIE, CMIE_SOFE__ENABLED);
#endif
/***************************************************************************//**
@ -1098,7 +1100,7 @@ extern void USB_EnableSofInt(void);
#ifdef IS_DOXYGEN
extern void USB_DisableSofInt(void);
#else
#define USB_DisableSofInt() USB_CLEAR_BITS(CMIE, CMIE_SOFE__ENABLED)
#define USB_DisableSofInt() USB_CLEAR_BITS(CMIE, CMIE_SOFE__ENABLED);
#endif
/***************************************************************************//**
@ -1108,7 +1110,7 @@ extern void USB_DisableSofInt(void);
#ifdef IS_DOXYGEN
extern void USB_EnableResetInt(void);
#else
#define USB_EnableResetInt() USB_SET_BITS(CMIE, CMIE_RSTINTE__ENABLED)
#define USB_EnableResetInt() USB_SET_BITS(CMIE, CMIE_RSTINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1118,7 +1120,7 @@ extern void USB_EnableResetInt(void);
#ifdef IS_DOXYGEN
extern void USB_DisableResetInt(void);
#else
#define USB_DisableResetInt() USB_CLEAR_BITS(CMIE, CMIE_RSTINTE__ENABLED)
#define USB_DisableResetInt() USB_CLEAR_BITS(CMIE, CMIE_RSTINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1128,7 +1130,7 @@ extern void USB_DisableResetInt(void);
#ifdef IS_DOXYGEN
extern void USB_EnableResumeInt(void);
#else
#define USB_EnableResumeInt() USB_SET_BITS(CMIE, CMIE_RSUINTE__ENABLED)
#define USB_EnableResumeInt() USB_SET_BITS(CMIE, CMIE_RSUINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1138,7 +1140,7 @@ extern void USB_EnableResumeInt(void);
#ifdef IS_DOXYGEN
extern void USB_DisableResumeInt(void);
#else
#define USB_DisableResumeInt() USB_CLEAR_BITS(CMIE, CMIE_RSUINTE__ENABLED)
#define USB_DisableResumeInt() USB_CLEAR_BITS(CMIE, CMIE_RSUINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1148,7 +1150,7 @@ extern void USB_DisableResumeInt(void);
#ifdef IS_DOXYGEN
extern void USB_EnableSuspendInt(void);
#else
#define USB_EnableSuspendInt() USB_SET_BITS(CMIE, CMIE_SUSINTE__ENABLED)
#define USB_EnableSuspendInt() USB_SET_BITS(CMIE, CMIE_SUSINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1158,7 +1160,7 @@ extern void USB_EnableSuspendInt(void);
#ifdef IS_DOXYGEN
extern void USB_DisableSuspendInt(void);
#else
#define USB_DisableSuspendInt() USB_CLEAR_BITS(CMIE, CMIE_SUSINTE__ENABLED)
#define USB_DisableSuspendInt() USB_CLEAR_BITS(CMIE, CMIE_SUSINTE__ENABLED);
#endif
/***************************************************************************//**
@ -1168,7 +1170,7 @@ extern void USB_DisableSuspendInt(void);
#ifdef IS_DOXYGEN
extern void USB_EnableEp0Int(void);
#else
#define USB_EnableEp0Int() USB_SET_BITS(IN1IE, IN1IE_EP0E__ENABLED)
#define USB_EnableEp0Int() USB_SET_BITS(IN1IE, IN1IE_EP0E__ENABLED);
#endif
/***************************************************************************//**
@ -1178,7 +1180,7 @@ extern void USB_EnableEp0Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableEp0Int(void);
#else
#define USB_DisableEp0Int() USB_CLEAR_BITS(IN1IE, IN1IE_EP0E__ENABLED)
#define USB_DisableEp0Int() USB_CLEAR_BITS(IN1IE, IN1IE_EP0E__ENABLED);
#endif
/***************************************************************************//**
@ -1188,7 +1190,7 @@ extern void USB_DisableEp0Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableIn1Int(void);
#else
#define USB_EnableIn1Int() USB_SET_BITS(IN1IE, IN1IE_IN1E__ENABLED)
#define USB_EnableIn1Int() USB_SET_BITS(IN1IE, IN1IE_IN1E__ENABLED);
#endif
/***************************************************************************//**
@ -1198,7 +1200,7 @@ extern void USB_EnableIn1Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableIn1Int(void);
#else
#define USB_DisableIn1Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN1E__ENABLED)
#define USB_DisableIn1Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN1E__ENABLED);
#endif
/***************************************************************************//**
@ -1208,7 +1210,7 @@ extern void USB_DisableIn1Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableIn2Int(void);
#else
#define USB_EnableIn2Int() USB_SET_BITS(IN1IE, IN1IE_IN2E__ENABLED)
#define USB_EnableIn2Int() USB_SET_BITS(IN1IE, IN1IE_IN2E__ENABLED);
#endif
/***************************************************************************//**
@ -1218,7 +1220,7 @@ extern void USB_EnableIn2Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableIn2Int(void);
#else
#define USB_DisableIn2Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN2E__ENABLED)
#define USB_DisableIn2Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN2E__ENABLED);
#endif
/***************************************************************************//**
@ -1228,7 +1230,7 @@ extern void USB_DisableIn2Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableIn3Int(void);
#else
#define USB_EnableIn3Int() USB_SET_BITS(IN1IE, IN1IE_IN3E__ENABLED)
#define USB_EnableIn3Int() USB_SET_BITS(IN1IE, IN1IE_IN3E__ENABLED);
#endif
/***************************************************************************//**
@ -1238,7 +1240,7 @@ extern void USB_EnableIn3Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableIn3Int(void);
#else
#define USB_DisableIn3Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN3E__ENABLED)
#define USB_DisableIn3Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN3E__ENABLED);
#endif
/***************************************************************************//**
@ -1248,7 +1250,7 @@ extern void USB_DisableIn3Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableOut1Int(void);
#else
#define USB_EnableOut1Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED)
#define USB_EnableOut1Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED);
#endif
/***************************************************************************//**
@ -1258,7 +1260,7 @@ extern void USB_EnableOut1Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableOut1Int(void);
#else
#define USB_DisableOut1Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED)
#define USB_DisableOut1Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED);
#endif
/***************************************************************************//**
@ -1268,7 +1270,7 @@ extern void USB_DisableOut1Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableOut2Int(void);
#else
#define USB_EnableOut2Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED)
#define USB_EnableOut2Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED);
#endif
/***************************************************************************//**
@ -1278,7 +1280,7 @@ extern void USB_EnableOut2Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableOut2Int(void);
#else
#define USB_DisableOut2Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED)
#define USB_DisableOut2Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED);
#endif
/***************************************************************************//**
@ -1288,7 +1290,7 @@ extern void USB_DisableOut2Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableOut3Int(void);
#else
#define USB_EnableOut3Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED)
#define USB_EnableOut3Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED);
#endif
/***************************************************************************//**
@ -1298,7 +1300,7 @@ extern void USB_EnableOut3Int(void);
#ifdef IS_DOXYGEN
extern void USB_DisableOut3Int(void);
#else
#define USB_DisableOut3Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED)
#define USB_DisableOut3Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED);
#endif
/***************************************************************************//**
@ -1308,7 +1310,7 @@ extern void USB_DisableOut3Int(void);
#ifdef IS_DOXYGEN
extern void USB_EnableEp1(void);
#else
#define USB_EnableEp1() USB_SET_BITS(EENABLE, EENABLE_EEN1__ENABLED)
#define USB_EnableEp1() USB_SET_BITS(EENABLE, EENABLE_EEN1__ENABLED);
#endif
/***************************************************************************//**
@ -1318,7 +1320,7 @@ extern void USB_EnableEp1(void);
#ifdef IS_DOXYGEN
extern void USB_DisableEp1(void);
#else
#define USB_DisableEp1() USB_CLEAR_BITS(EENABLE, EENABLE_EEN1__ENABLED)
#define USB_DisableEp1() USB_CLEAR_BITS(EENABLE, EENABLE_EEN1__ENABLED);
#endif
/***************************************************************************//**
@ -1328,7 +1330,7 @@ extern void USB_DisableEp1(void);
#ifdef IS_DOXYGEN
extern void USB_EnableEp2(void);
#else
#define USB_EnableEp2() USB_SET_BITS(EENABLE, EENABLE_EEN2__ENABLED)
#define USB_EnableEp2() USB_SET_BITS(EENABLE, EENABLE_EEN2__ENABLED);
#endif
/***************************************************************************//**
@ -1338,7 +1340,7 @@ extern void USB_EnableEp2(void);
#ifdef IS_DOXYGEN
extern void USB_DisableEp2(void);
#else
#define USB_DisableEp2() USB_CLEAR_BITS(EENABLE, EENABLE_EEN2__ENABLED)
#define USB_DisableEp2() USB_CLEAR_BITS(EENABLE, EENABLE_EEN2__ENABLED);
#endif
/***************************************************************************//**
@ -1348,7 +1350,7 @@ extern void USB_DisableEp2(void);
#ifdef IS_DOXYGEN
extern void USB_EnableEp3(void);
#else
#define USB_EnableEp3() USB_SET_BITS(EENABLE, EENABLE_EEN3__ENABLED)
#define USB_EnableEp3() USB_SET_BITS(EENABLE, EENABLE_EEN3__ENABLED);
#endif
/***************************************************************************//**
@ -1358,7 +1360,7 @@ extern void USB_EnableEp3(void);
#ifdef IS_DOXYGEN
extern void USB_DisableEp3(void);
#else
#define USB_DisableEp3() USB_CLEAR_BITS(EENABLE, EENABLE_EEN3__ENABLED)
#define USB_DisableEp3() USB_CLEAR_BITS(EENABLE, EENABLE_EEN3__ENABLED);
#endif
/***************************************************************************//**
@ -1368,7 +1370,7 @@ extern void USB_DisableEp3(void);
#ifdef IS_DOXYGEN
extern void USB_EpnDirectionOut(void);
#else
#define USB_EpnDirectionOut() USB_CLEAR_BITS(EINCSRH, EINCSRH_DIRSEL__IN)
#define USB_EpnDirectionOut() USB_CLEAR_BITS(EINCSRH, EINCSRH_DIRSEL__IN);
#endif
/***************************************************************************//**
@ -1378,7 +1380,7 @@ extern void USB_EpnDirectionOut(void);
#ifdef IS_DOXYGEN
extern void USB_EpnDirectionIn(void);
#else
#define USB_EpnDirectionIn() USB_SET_BITS(EINCSRH, EINCSRH_DIRSEL__IN)
#define USB_EpnDirectionIn() USB_SET_BITS(EINCSRH, EINCSRH_DIRSEL__IN);
#endif
/***************************************************************************//**
@ -1389,7 +1391,7 @@ extern void USB_EpnDirectionIn(void);
extern void USB_EpnEnableSplitMode(void);
#else
#define USB_EpnEnableSplitMode() \
USB_SET_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED)
USB_SET_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED);
#endif
/***************************************************************************//**
@ -1400,7 +1402,7 @@ extern void USB_EpnEnableSplitMode(void);
extern void USB_EpnDisableSplitMode(void);
#else
#define USB_EpnDisableSplitMode() \
USB_CLEAR_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED)
USB_CLEAR_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED);
#endif
/***************************************************************************//**
@ -1410,7 +1412,7 @@ extern void USB_EpnDisableSplitMode(void);
#ifdef IS_DOXYGEN
extern void USB_EpnInClearDataToggle(void);
#else
#define USB_EpnInClearDataToggle() USB_SET_BITS(EINCSRL, EINCSRL_CLRDT__BMASK)
#define USB_EpnInClearDataToggle() USB_SET_BITS(EINCSRL, EINCSRL_CLRDT__BMASK);
#endif
/***************************************************************************//**
@ -1420,7 +1422,7 @@ extern void USB_EpnInClearDataToggle(void);
#ifdef IS_DOXYGEN
extern void USB_EpnInClearSentStall(void);
#else
#define USB_EpnInClearSentStall() USB_WRITE_BYTE(EINCSRL, 0)
#define USB_EpnInClearSentStall() USB_WRITE_BYTE(EINCSRL, 0);
#endif
/***************************************************************************//**
@ -1430,7 +1432,7 @@ extern void USB_EpnInClearSentStall(void);
#ifdef IS_DOXYGEN
extern void USB_EpnInStall(void);
#else
#define USB_EpnInStall() USB_WRITE_BYTE(EINCSRL, EINCSRL_SDSTL__SET)
#define USB_EpnInStall() USB_WRITE_BYTE(EINCSRL, EINCSRL_SDSTL__SET);
#endif
/***************************************************************************//**
@ -1440,7 +1442,7 @@ extern void USB_EpnInStall(void);
#ifdef IS_DOXYGEN
extern void USB_EpnInEndStall(void);
#else
#define USB_EpnInEndStall() USB_WRITE_BYTE(EINCSRL, 0)
#define USB_EpnInEndStall() USB_WRITE_BYTE(EINCSRL, 0);
#endif
/***************************************************************************//**
@ -1452,7 +1454,7 @@ extern void USB_EpnInEndStall(void);
extern void USB_EpnInEndStallAndClearDataToggle(void);
#else
#define USB_EpnInEndStallAndClearDataToggle() \
USB_WRITE_BYTE(EINCSRL, EINCSRL_CLRDT__BMASK)
USB_WRITE_BYTE(EINCSRL, EINCSRL_CLRDT__BMASK);
#endif
/***************************************************************************//**
@ -1470,7 +1472,7 @@ extern void USB_EpnInFlush(void);
{ \
USB_READ_BYTE(EINCSRL); \
} while (USB0DAT & EINCSRL_FLUSH__SET); \
} while (0)
} while (0);
#endif
/***************************************************************************//**
@ -1480,7 +1482,7 @@ extern void USB_EpnInFlush(void);
#ifdef IS_DOXYGEN
extern void USB_EpnInClearUnderrun(void);
#else
#define USB_EpnInClearUnderrun() USB_CLEAR_BITS(EINCSRL, EINCSRL_UNDRUN__SET)
#define USB_EpnInClearUnderrun() USB_CLEAR_BITS(EINCSRL, EINCSRL_UNDRUN__SET);
#endif
/***************************************************************************//**
@ -1490,7 +1492,7 @@ extern void USB_EpnInClearUnderrun(void);
#ifdef IS_DOXYGEN
extern void USB_EpnSetInPacketReady(void);
#else
#define USB_EpnSetInPacketReady() USB_SET_BITS(EINCSRL, EINCSRL_INPRDY__SET)
#define USB_EpnSetInPacketReady() USB_SET_BITS(EINCSRL, EINCSRL_INPRDY__SET);
#endif
/***************************************************************************//**
@ -1501,7 +1503,7 @@ extern void USB_EpnSetInPacketReady(void);
extern void USB_EpnInEnableDoubleBuffer(void);
#else
#define USB_EpnInEnableDoubleBuffer() \
USB_SET_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED)
USB_SET_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED);
#endif
/***************************************************************************//**
@ -1512,7 +1514,7 @@ extern void USB_EpnInEnableDoubleBuffer(void);
extern void USB_EpnInDisableDoubleBuffer(void);
#else
#define USB_EpnInDisableDoubleBuffer() \
USB_CLEAR_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED)
USB_CLEAR_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED);
#endif
/***************************************************************************//**
@ -1523,7 +1525,7 @@ extern void USB_EpnInDisableDoubleBuffer(void);
extern void USB_EpnInEnableInterruptBulkMode(void);
#else
#define USB_EpnInEnableInterruptBulkMode() \
USB_CLEAR_BITS(EINCSRH, EINCSRH_ISO__ENABLED)
USB_CLEAR_BITS(EINCSRH, EINCSRH_ISO__ENABLED);
#endif
/***************************************************************************//**
@ -1534,7 +1536,7 @@ extern void USB_EpnInEnableInterruptBulkMode(void);
extern void USB_EpnInEnableIsochronousMode(void);
#else
#define USB_EpnInEnableIsochronousMode() \
USB_SET_BITS(EINCSRH, EINCSRH_ISO__ENABLED)
USB_SET_BITS(EINCSRH, EINCSRH_ISO__ENABLED);
#endif
/***************************************************************************//**
@ -1545,7 +1547,7 @@ extern void USB_EpnInEnableIsochronousMode(void);
extern void USB_EpnInEnableForcedDataToggle(void);
#else
#define USB_EpnInEnableForcedDataToggle() \
USB_SET_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE)
USB_SET_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE);
#endif
/***************************************************************************//**
@ -1556,7 +1558,7 @@ extern void USB_EpnInEnableForcedDataToggle(void);
extern void USB_EpnInDisableForcedDataToggle(void);
#else
#define USB_EpnInDisableForcedDataToggle() \
USB_CLEAR_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE)
USB_CLEAR_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE);
#endif
/***************************************************************************//**
@ -1567,7 +1569,7 @@ extern void USB_EpnInDisableForcedDataToggle(void);
extern void USB_EpnOutClearDataToggle(void);
#else
#define USB_EpnOutClearDataToggle() \
USB_SET_BITS(EOUTCSRL, EOUTCSRL_CLRDT__BMASK)
USB_SET_BITS(EOUTCSRL, EOUTCSRL_CLRDT__BMASK);
#endif
/***************************************************************************//**
@ -1578,7 +1580,7 @@ extern void USB_EpnOutClearDataToggle(void);
extern void USB_EpnOutClearSentStall(void);
#else
#define USB_EpnOutClearSentStall() \
USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_STSTL__BMASK)
USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_STSTL__BMASK);
#endif
/***************************************************************************//**
@ -1589,7 +1591,7 @@ extern void USB_EpnOutClearSentStall(void);
extern void USB_EpnOutStall(void);
#else
#define USB_EpnOutStall() \
USB_SET_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET)
USB_SET_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET);
#endif
/***************************************************************************//**
@ -1599,7 +1601,7 @@ extern void USB_EpnOutStall(void);
#ifdef IS_DOXYGEN
extern void USB_EpnOutEndStall(void);
#else
#define USB_EpnOutEndStall() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET)
#define USB_EpnOutEndStall() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET);
#endif
/***************************************************************************//**
@ -1618,7 +1620,7 @@ extern void USB_EpnOutEndStallAndClearDataToggle(void);
while (USB0ADR & USB0ADR_BUSY__SET) {} \
USB0DAT |= EOUTCSRL_CLRDT__BMASK; \
while (USB0ADR & USB0ADR_BUSY__SET) {} \
} while (0)
} while (0);
#endif
/***************************************************************************//**
@ -1636,7 +1638,7 @@ extern void USB_EpnOutFlush(void);
{ \
USB_READ_BYTE(EOUTCSRL); \
} while (USB0DAT & EOUTCSRL_FLUSH__SET); \
} while (0)
} while (0);
#endif
/***************************************************************************//**
@ -1646,7 +1648,7 @@ extern void USB_EpnOutFlush(void);
#ifdef IS_DOXYGEN
extern void USB_EpnOutClearOverrun(void);
#else
#define USB_EpnOutClearOverrun() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OVRUN__SET)
#define USB_EpnOutClearOverrun() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OVRUN__SET);
#endif
/***************************************************************************//**
@ -1657,7 +1659,7 @@ extern void USB_EpnOutClearOverrun(void);
extern void USB_EpnClearOutPacketReady(void);
#else
#define USB_EpnClearOutPacketReady() \
USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OPRDY__SET)
USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OPRDY__SET);
#endif
/***************************************************************************//**
@ -1668,7 +1670,7 @@ extern void USB_EpnClearOutPacketReady(void);
extern void USB_EpnOutEnableDoubleBuffer(void);
#else
#define USB_EpnOutEnableDoubleBuffer() \
USB_SET_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED)
USB_SET_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED);
#endif
/***************************************************************************//**
@ -1679,7 +1681,7 @@ extern void USB_EpnOutEnableDoubleBuffer(void);
extern void USB_EpnOutDisableDoubleBuffer(void);
#else
#define USB_EpnOutDisableDoubleBuffer() \
USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED)
USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED);
#endif
/***************************************************************************//**
@ -1690,7 +1692,7 @@ extern void USB_EpnOutDisableDoubleBuffer(void);
extern void USB_EpnOutEnableInterruptBulkMode(void);
#else
#define USB_EpnOutEnableInterruptBulkMode() \
USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED)
USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED);
#endif
/***************************************************************************//**
@ -1701,7 +1703,7 @@ extern void USB_EpnOutEnableInterruptBulkMode(void);
extern void USB_EpnOutEnableIsochronousMode(void);
#else
#define USB_EpnOutEnableIsochronousMode() \
USB_SET_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED)
USB_SET_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED);
#endif
/***************************************************************************//**
@ -1719,7 +1721,7 @@ extern void USB_EnableReadFIFO(uint8_t fifoNum);
while (USB0ADR & USB0ADR_BUSY__SET) {} \
USB0ADR = (USB0ADR_BUSY__SET \
| USB0ADR_AUTORD__ENABLED \
| (FIFO0 | (fifoNum))); \
| (FIFO0 | fifoNum)); \
} while (0)
#endif
@ -1748,7 +1750,7 @@ extern void USB_GetFIFOByte(uint8_t *readDat);
do \
{ \
while (USB0ADR & USB0ADR_BUSY__SET) {} \
*(readDat) = USB0DAT; \
readDat = USB0DAT; \
} while (0)
#endif
@ -1770,8 +1772,8 @@ extern void USB_GetLastFIFOByte(uint8_t *readDat, uint8_t fifoNum);
do \
{ \
while (USB0ADR & USB0ADR_BUSY__SET) {} \
USB0ADR = (FIFO0 | (fifoNum));\
*(readDat) = USB0DAT; \
USB0ADR = (FIFO0 | fifoNum);\
readDat = USB0DAT; \
} while (0)
#endif
@ -1788,7 +1790,7 @@ extern void USB_EnableWriteFIFO(uint8_t fifoNum);
do \
{ \
while (USB0ADR & USB0ADR_BUSY__SET) {} \
USB0ADR = (FIFO0 | (fifoNum)); \
USB0ADR = (FIFO0 | fifoNum); \
} while (0)
#endif
@ -1817,7 +1819,7 @@ extern void USB_SetFIFOByte(uint8_t writeDat);
do \
{ \
while (USB0ADR & USB0ADR_BUSY__SET) {} \
USB0DAT = (writeDat); \
USB0DAT = writeDat; \
} while (0)
#endif
@ -1850,98 +1852,92 @@ extern void USB_RestoreSfrPage();
* @param epsel
* Endpoint index to target
******************************************************************************/
extern void USB_SetIndex(uint8_t epsel);
void USB_SetIndex(uint8_t epsel);
/***************************************************************************//**
* @brief Reads the USB common interrupt register
* @return Value of CMINT
******************************************************************************/
extern uint8_t USB_GetCommonInts(void);
uint8_t USB_GetCommonInts(void);
/***************************************************************************//**
* @brief Reads the USB in interrupt register
* @return Value of IN1INT
******************************************************************************/
extern uint8_t USB_GetInInts(void);
uint8_t USB_GetInInts(void);
/***************************************************************************//**
* @brief Reads the out interrupt register
* @return Value of OUT1INT
******************************************************************************/
extern uint8_t USB_GetOutInts(void);
uint8_t USB_GetOutInts(void);
/***************************************************************************//**
* @brief Reads the value in INDEX
* @return Value of INDEX
******************************************************************************/
extern uint8_t USB_GetIndex(void);
uint8_t USB_GetIndex(void);
/***************************************************************************//**
* @brief Determines if the USB is currently suspended
* @return TRUE if USB is in suspend mode
******************************************************************************/
extern bool USB_IsSuspended(void);
bool USB_IsSuspended(void);
/***************************************************************************//**
* @brief Gets Setup End state
* @return TRUE when a control transaction end before software has
* set the DATAEND bit.
******************************************************************************/
extern bool USB_GetSetupEnd(void);
bool USB_GetSetupEnd(void);
/***************************************************************************//**
* @brief Determines if STALL was send on Endpoint 0
* @return TRUE after a STALL was sent on Endpoint 0
******************************************************************************/
extern bool USB_Ep0SentStall(void);
bool USB_Ep0SentStall(void);
/***************************************************************************//**
* @brief Determines if Out Packet Ready is set on Endpoint 0
* @return TRUE if Out Packet Ready is set on Endpoint 0
******************************************************************************/
extern bool USB_Ep0InPacketReady(void);
bool USB_Ep0InPacketReady(void);
/***************************************************************************//**
* @brief Determines if In Packet Ready is set on Endpoint 0
* @return TRUE if In Packet Ready is set on Endpoint 0
******************************************************************************/
extern bool USB_Ep0OutPacketReady(void);
bool USB_Ep0OutPacketReady(void);
/***************************************************************************//**
* @brief Gets Endpoint 0 data count
* @return Number of received data bytes in the Endpoint 0 FIFO
******************************************************************************/
extern uint8_t USB_Ep0GetCount(void);
uint8_t USB_Ep0GetCount(void);
/***************************************************************************//**
* @brief Checks if stall was sent on IN Endpoint N
* @return TRUE if stall was sent on IN Endpoint N, FALSE otherwise
******************************************************************************/
extern bool USB_EpnInGetSentStall(void);
bool USB_EpnInGetSentStall(void);
/***************************************************************************//**
* @brief Checks if stall was sent on OUT Endpoint N
* @return TRUE if stall was sent on OUT Endpoint N, FALSE otherwise
******************************************************************************/
extern bool USB_EpnGetInPacketReady(void);
bool USB_EpnGetInPacketReady(void);
/***************************************************************************//**
* @brief Checks if stall was sent on OUT Endpoint N
* @return TRUE if stall was sent on OUT Endpoint N, FALSE otherwise
******************************************************************************/
extern bool USB_EpnOutGetSentStall(void);
bool USB_EpnOutGetSentStall(void);
/***************************************************************************//**
* @brief Gets OutPacketReady on OUT Endpoint N
* @return TRUE if OUTPacketReady is set, FALSE otherwise
******************************************************************************/
extern bool USB_EpnGetOutPacketReady(void);
/***************************************************************************//**
* @brief Gets DataError on OUT Endpoint N
* @return TRUE if Data Error bit is set, FALSE otherwise
******************************************************************************/
extern bool USB_EpnGetDataError(void);
bool USB_EpnGetOutPacketReady(void);
/***************************************************************************//**
* @brief Gets number of bytes in the OUT FIFO
@ -1949,27 +1945,27 @@ extern bool USB_EpnGetDataError(void);
* @return Number of bytes in the FIFO from the last received
* packet
******************************************************************************/
extern uint16_t USB_EpOutGetCount(void);
uint16_t USB_EpOutGetCount(void);
/***************************************************************************//**
* @brief Reads the USB frame number
* @return The frame number on the most recent SOF packet
******************************************************************************/
extern uint16_t USB_GetSofNumber(void);
uint16_t USB_GetSofNumber(void);
/***************************************************************************//**
* @brief Aborts pending IN transactions on the selected endpoint
* @param fifoNum
* Endpoint to abort
******************************************************************************/
extern void USB_AbortInEp(uint8_t fifoNum);
void USB_AbortInEp(uint8_t fifoNum);
/***************************************************************************//**
* @brief Aborts pending OUT transactions on the selected endpoint
* @param fifoNum
* Endpoint to abort
******************************************************************************/
extern void USB_AbortOutEp(uint8_t fifoNum);
void USB_AbortOutEp(uint8_t fifoNum);
/***************************************************************************//**
* @brief Activates the selected endpoint
@ -1984,7 +1980,7 @@ extern void USB_AbortOutEp(uint8_t fifoNum);
* @param isoMode
* Set to 1 if endpoint is in isochronous mode, 0 if it is not
******************************************************************************/
extern void USB_ActivateEp(uint8_t ep,
void USB_ActivateEp(uint8_t ep,
uint16_t packetSize,
bool inDir,
bool splitMode,

View File

@ -18,7 +18,7 @@
/**************************************************************************//**
* @brief Reads a 16-bit indirect USB register value
* @param [in] regAddr
* @param regAddr
* Address of high byte of 16-bit USB indirect register to read
* @return 16-bit register value
*****************************************************************************/
@ -127,12 +127,6 @@ bool USB_EpnGetOutPacketReady(void)
return (bool)(USB0DAT & EOUTCSRL_OPRDY__SET);
}
bool USB_EpnGetDataError(void)
{
USB_READ_BYTE(EOUTCSRL);
return (bool)(USB0DAT & EOUTCSRL_DATERR__SET);
}
uint16_t USB_EpOutGetCount(void)
{
return USB_GetShortRegister(EOUTCNTH);