From 86aa5ec657ebdf026b63ee60d5699db5f7601c72 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Wed, 12 Sep 2018 21:25:40 -0400 Subject: [PATCH] move to targets/ --- Makefile | 16 +- lib/efm8_assert/assert.c | 15 - lib/efm8_assert/assert.h | 60 - lib/efm8_usb/Readme.txt | 56 - lib/efm8_usb/inc/efm8_usb.h | 2210 ----------------- lib/efm8_usb/src/efm8_usbd.c | 755 ------ lib/efm8_usb/src/efm8_usbdch9.c | 880 ------- lib/efm8_usb/src/efm8_usbdep.c | 896 ------- lib/efm8_usb/src/efm8_usbdint.c | 533 ---- lib/efm8ub1/peripheralDrivers/inc/usb_0.h | 2087 ---------------- lib/efm8ub1/peripheralDrivers/src/usb_0.c | 232 -- targets/efm32boot/.cproject | 10 +- targets/efm32boot/.project | 4 +- {nrf52840 => targets/nrf52840}/Makefile | 0 {nrf52840 => targets/nrf52840}/app_config.h | 0 .../nrf52840}/blinky_gcc_nrf52.ld | 0 {nrf52840 => targets/nrf52840}/crypto.c | 0 {nrf52840 => targets/nrf52840}/device.c | 0 {nrf52840 => targets/nrf52840}/list.py | 0 {nrf52840 => targets/nrf52840}/main.c | 0 {nrf52840 => targets/nrf52840}/pyserial.py | 0 {nrf52840 => targets/nrf52840}/retarget.c | 0 {nrf52840 => targets/nrf52840}/sdk_config.h | 0 {nrf52840 => targets/nrf52840}/usb.c | 0 {nrf52840 => targets/nrf52840}/usb.h | 0 {nrf52840 => targets/nrf52840}/usbhid.c | 0 26 files changed, 15 insertions(+), 7739 deletions(-) delete mode 100644 lib/efm8_assert/assert.c delete mode 100644 lib/efm8_assert/assert.h delete mode 100644 lib/efm8_usb/Readme.txt delete mode 100644 lib/efm8_usb/inc/efm8_usb.h delete mode 100644 lib/efm8_usb/src/efm8_usbd.c delete mode 100644 lib/efm8_usb/src/efm8_usbdch9.c delete mode 100644 lib/efm8_usb/src/efm8_usbdep.c delete mode 100644 lib/efm8_usb/src/efm8_usbdint.c delete mode 100644 lib/efm8ub1/peripheralDrivers/inc/usb_0.h delete mode 100644 lib/efm8ub1/peripheralDrivers/src/usb_0.c rename {nrf52840 => targets/nrf52840}/Makefile (100%) rename {nrf52840 => targets/nrf52840}/app_config.h (100%) rename {nrf52840 => targets/nrf52840}/blinky_gcc_nrf52.ld (100%) rename {nrf52840 => targets/nrf52840}/crypto.c (100%) rename {nrf52840 => targets/nrf52840}/device.c (100%) rename {nrf52840 => targets/nrf52840}/list.py (100%) rename {nrf52840 => targets/nrf52840}/main.c (100%) rename {nrf52840 => targets/nrf52840}/pyserial.py (100%) rename {nrf52840 => targets/nrf52840}/retarget.c (100%) rename {nrf52840 => targets/nrf52840}/sdk_config.h (100%) rename {nrf52840 => targets/nrf52840}/usb.c (100%) rename {nrf52840 => targets/nrf52840}/usb.h (100%) rename {nrf52840 => targets/nrf52840}/usbhid.c (100%) diff --git a/Makefile b/Makefile index c9c3459..7655ccf 100644 --- a/Makefile +++ b/Makefile @@ -32,24 +32,24 @@ cbor: test: testgcm efm8prog: - cd '.\efm8\Keil 8051 v9.53 - Debug' && $(MAKE) all + cd './targets/efm8\Keil 8051 v9.53 - Debug' && $(MAKE) all flashefm8.exe -part EFM8UB10F8G -sn 440105518 -erase - flashefm8.exe -part EFM8UB10F8G -sn 440105518 -upload '.\efm8\Keil 8051 v9.53 - Debug\efm8.hex' + flashefm8.exe -part EFM8UB10F8G -sn 440105518 -upload './targets/efm8/Keil 8051 v9.53 - Debug/efm8.hex' efm32com: - cd '.\efm32\GNU ARM v7.2.1 - Debug' && $(MAKE) all + cd './targets/efm32/GNU ARM v7.2.1 - Debug' && $(MAKE) all efm32prog: - cd '.\efm32\GNU ARM v7.2.1 - Debug' && $(MAKE) all - commander flash '.\efm32\GNU ARM v7.2.1 - Debug\EFM32.hex' $(EFM32_DEBUGGER) -p "0x1E7FC:0x00000000:4" + cd './targets/efm32/GNU ARM v7.2.1 - Debug' && $(MAKE) all + commander flash './targets/efm32/GNU ARM v7.2.1 - Debug/EFM32.hex' $(EFM32_DEBUGGER) -p "0x1E7FC:0x00000000:4" efm32read: - cd '.\efm32\GNU ARM v7.2.1 - Debug' && $(MAKE) all + cd './targets/efm32/GNU ARM v7.2.1 - Debug' && $(MAKE) all commander swo read $(EFM32_DEBUGGER) efm32bootprog: - cd '.\efm32boot\GNU ARM v7.2.1 - Debug' && $(MAKE) all - commander flash '.\efm32boot\GNU ARM v7.2.1 - Debug\efm32boot.hex' $(EFM32_DEBUGGER) --masserase + cd './targets/efm32boot/GNU ARM v7.2.1 - Debug' && $(MAKE) all + commander flash './efm32boot/GNU ARM v7.2.1 - Debug/efm32boot.hex' $(EFM32_DEBUGGER) --masserase $(name): $(obj) $(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS) diff --git a/lib/efm8_assert/assert.c b/lib/efm8_assert/assert.c deleted file mode 100644 index e96edfd..0000000 --- a/lib/efm8_assert/assert.c +++ /dev/null @@ -1,15 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#ifndef NDEBUG -void slab_Assert( const char * file, int line ) -{ - file = file; - line = line; - - while ( 1 ); -} -#endif diff --git a/lib/efm8_assert/assert.h b/lib/efm8_assert/assert.h deleted file mode 100644 index d99ef84..0000000 --- a/lib/efm8_assert/assert.h +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2014 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#ifndef __ASSERT_H__ - -#include "efm8_config.h" - -/**************************************************************************//** - * @addtogroup efm8_assert - * @{ - * - * @brief Runtime assert for EFM8 - * - * This module contains a runtime assert macro. It can be compiled out by setting - * the NDEBUG flag. - * - *****************************************************************************/ - - -/**************************************************************************//** - * @def NDEBUG - * @brief Controls if the asserts are present. - * - * Asserts are removed if this symbol is defined - * - *****************************************************************************/ - -/**************************************************************************//** - * @def USER_ASSERT - * @brief User implemented assert function. - * - * When asserts are enabled the default handler can be be replaced with a user defined - * function of the form 'void userAssertName( const char * file, int line )' by setting - * the value of USER_ASSERT to the userAssertName. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_ASSERT(expr) - * @brief default implementation of assert_failed. - * - * This function can be replaced by a user defined assert function by setting the USER_ASSERT flag - *****************************************************************************/ - -#ifdef NDEBUG - #define SLAB_ASSERT(expr) -#else - #ifdef USER_ASSERT - #define SLAB_ASSERT(expr) ((expr) ? ((void)0) : USER_ASSERT( __FILE__, __LINE__ )) - #else - 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( __FILE__, __LINE__ );} - #endif -#endif - -#endif //!__ASSERT_H__ diff --git a/lib/efm8_usb/Readme.txt b/lib/efm8_usb/Readme.txt deleted file mode 100644 index 059e38b..0000000 --- a/lib/efm8_usb/Readme.txt +++ /dev/null @@ -1,56 +0,0 @@ -------------------------------------------------------------------------------- - Readme.txt -------------------------------------------------------------------------------- - -Copyright 2014 Silicon Laboratories, Inc. -http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - -Program Description: -------------------- - -This is the generic EFM8 USB Firmware Library. Please see the EFM8 Libraries -Documentation for more information (/doc/EFM8/software/Lib/index.html). - -Known Issues and Limitations: ----------------------------- - -1) The library does not reset its Data Toggle after receiving a SET_INTERFACE - request. - -Target and Tool Chain Information: ---------------------------------- - -Target: EFM8UB1, EFM8UB2, C8051F320/1, C8051F326/7, C8051F34x, C8051F38x -Tool chain: Keil - -File List: ---------- - -/inc/efm8_usb.h -/src/efm8_usbd.c -/src/efm8_usbdch9.c -/src/efm8_usbdep.c -/src/efm8_usbdint.c - -Release Information: -------------------- - -Version 1.0.0 - - Initial release. - -Version 1.0.1 - - Fixed bug in logic of remote wakeup feature where the device would - attempt to wake the host before enabling its USB transceiver. - - Fixed bug where the device would stall the Data Phase instead of the - Setup Phase when sending a procedural stall on Endpoint 0. - - Fixed bug where a bus-powered device would look at VBUS after a USB Reset - to determine if it should enter the Default or Attached State. VBUS is - always present on a bus-powered device, so it should automatically enter - the Default State. - - Removed code that generated a compiler warning when - USB_PWRSAVE_MODE_FASTWAKE was enabled. - - Improved documentation of USB_PWRSAVE_MODE_FASTWAKE feature. - -------------------------------------------------------------------------------- - End Of File -------------------------------------------------------------------------------- diff --git a/lib/efm8_usb/inc/efm8_usb.h b/lib/efm8_usb/inc/efm8_usb.h deleted file mode 100644 index 2581ce3..0000000 --- a/lib/efm8_usb/inc/efm8_usb.h +++ /dev/null @@ -1,2210 +0,0 @@ -/***************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - ******************************************************************************/ - -#ifndef __SILICON_LABS_EFM8_USB_H__ -#define __SILICON_LABS_EFM8_USB_H__ - -#include "si_toolchain.h" -#include "usbconfig.h" -#include -#include -#include -#include - -/***************************************************************************//** - * @addtogroup Efm8_usb - * @brief USB Device Protocol Stack for EFM8 devices - * @{ - * - * @section usb_device_contents Contents - * - * @li @ref usb_device_intro - * @li @ref usb_device_api - * @li @ref usb_device_conf - * @li @ref usb_device_powersave - * @li @ref usb_device_transfers - * @li @ref usb_device_pitfalls - * - * @n @section usb_device_intro Introduction - * - * The USB device protocol stack provides an API which makes it possible to - * create USB devices with a minimum of effort. The device stack supports Control, - * Bulk, Interrupt, and Isochronous transfers. - * - * The stack is highly configurable to suit various needs and includes - * demonstration projects to get you started fast. - * - * We recommend that you read through this documentation, then proceed to build - * and test a few example projects before you start designing your own device. - * - * @n @section usb_library_architecture_diagram Library Architecture Diagram - * - * @image html USB_Library_Architecture.png - * - * @n @section usb_device_api The EFM8 USB Library API - * - * This section contains brief descriptions of the functions in the API. You will - * find detailed information on input and output parameters and return values by - * clicking on the hyper-linked function names. It is also a good idea to study - * the code in the USB demonstration projects. - * - * Your application code must include one header file: @em efm8_usb.h. - * - * All functions defined in the API can be called from within interrupt handlers. - * - * @subsection usb_device_api_functions API Functions - * - * @ref USBD_Init() @n - * This function is called to register your device and all its properties with - * the device stack. The application must fill in a @ref USBD_Init_TypeDef - * structure prior to calling. When this function has been called your device - * is ready to be enumerated by the USB host. - * - * @ref USBD_Read(), @ref USBD_Write() @n - * These functions initiate data transfers. - * @n @htmlonly USBD_Read() @endhtmlonly initiate a transfer of data @em - * from host @em to device (an @em OUT transfer in USB terminology). - * @n @htmlonly USBD_Write() @endhtmlonly initiate a transfer of data @em from - * device @em to host (an @em IN transfer). - * - * When the USB host actually performs the transfer, your application will be - * notified by means of a call to the @ref USBD_XferCompleteCb() callback - * function (optionally). Refer to @ref TransferCallback for details of the - * callback functionality. - * - * @ref USBD_AbortTransfer(), @ref USBD_AbortAllTransfers() @n - * These functions terminate transfers that are initiated with @htmlonly - * USBD_Read() or USBD_Write() @endhtmlonly but that have not completed yet. - * These functions will deactivate the transfer setup to make the USB device - * endpoint hardware ready for new (and potentially) different transfers. - * - * @ref USBD_Connect(), @ref USBD_Disconnect() @n - * These functions turn the data-line (D+ or D-) pull-up on or off. They can - * be used to force re-enumeration. It's good practice to delay at least one - * second between @htmlonly USBD_Disconnect() and USBD_Connect() @endhtmlonly - * to allow the USB host to unload the currently active device driver. - * - * @ref USBD_EpIsBusy() @n - * Checks if an endpoint is busy. - * - * @ref USBD_StallEp(), @ref USBD_UnStallEp() @n - * These functions stall or un-stall an endpoint. This functionality may not - * be needed by your application. They may be useful when implementing some - * USB classes, e.g. a mass storage devices use them extensively. - * - * @ref USBD_Stop() @n - * Removes the data-line (D+ or D-) pull-up and disables the USB block. The - * application should call @htmlonly USBD_Init() after calling - * USBD_Stop() @endhtmlonly to restart USB operation. - * - * @ref USBD_Suspend() @n - * Puts the device in its low-power suspend mode. This function will not exit - * until a wakeup event (resume signaling, VBUS attachment/removal, or remote - * wakeup source interrupt) occurs. The USB Library can be configured to - * automatically call this function by configuring @ref SLAB_USB_PWRSAVE_MODE. - * - * @ref USBD_RemoteWakeup() @n - * Used in SUSPENDED state (see @ref USB_Status_TypeDef) to signal resume to - * 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 - * Figure 9-1. "Device State Diagram" in the USB revision 2.0 specification. - * - * @ref USBD_Run() @n - * When @ref SLAB_USB_POLLED_MODE is set to 1, the USB interrupt is disabled - * and the application must periodically call @htmlonly USBD_Run() - * @endhtmlonly to handle USB events. - * - * @n @subsection usb_device_api_callback Callback Functions - * - * @subsubsection usb_device_api_mandatory_callbacks Mandatory Callback Functions - * - * @n @anchor TransferCallback - * @ref USBD_XferCompleteCb() is called each time a packet is sent or - * received. It is called with three parameters, the status of the transfer, - * the number of bytes transferred and the number of bytes remaining. The - * transfer complete callback can be enabled or disabled by setting the - * callback parameters of @ref USBD_Write() and @ref USBD_Read() to - * true or false. - * @note This callback is called from within the USB interrupt handler if - * @ref SLAB_USB_POLLED_MODE is set to 1. Otherwise, it is called from - * @ref USBD_Run(). - * - * @n - * @subsubsection usb_device_api_optional_callbacks Optional Callback Functions - * - * @n These callbacks are all optional, and it is up to the application - * programmer to decide if the application needs the functionality they - * provide. Each callback is enabled or disabled by setting a constant in - * usbconfig.h. - * @note These callbacks are called from within the USB interrupt handler if - * @ref SLAB_USB_POLLED_MODE is set to 1. Otherwise, they are called - * from @ref USBD_Run(). - * - * @n USBD_ResetCb() is called each time reset signaling is sensed on the USB - * wire. - * - * @n USBD_SofCb() is called with the frame number as a parameter on each SOF - * interrupt. - * - * @n USBD_DeviceStateChangeCb() is called whenever the device state changes. - * Some uses of this include detecting that a USB suspend has been issued - * in order to reduce current consumption or calling USBD_Read() after - * entering the Configured state. The USB HID keyboard example - * project has a good example on how to use this callback. - * - * @n USBD_IsSelfPoweredCb() is called by the device stack when host - * queries the device with a GET_STATUS command to check if the device is - * currently self-powered or bus-powered. This feature is only applicable on - * self-powered devices which can also operate when only bus power is - * available. - * - * @n USBD_SetupCmdCb() is called each time a setup command is received from - * the host. Use this callback to override or extend the default handling of - * standard setup commands, and to implement class- or vendor-specific setup - * commands. The USB HID keyboard example project has a good example of how - * to use this callback. - * - * @n @section usb_device_conf Configuring the Library - * - * Your application must provide a header file named @em usbconfig.h. This file - * must contain the following \#define's. See @ref usb_config for - * documentation of these constants.@n @n - * @code - * // ----------------------------------------------------------------------------- - * // Specify bus- or self-powered - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_BUS_POWERED 0 - * - * // ----------------------------------------------------------------------------- - * // Specify USB speed - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_FULL_SPEED 1 - * - * // ----------------------------------------------------------------------------- - * // Enable or disable the clock recovery - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_CLOCK_RECOVERY_ENABLED 1 - * - * // ----------------------------------------------------------------------------- - * // Enable or disable remote wakeup - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_REMOTE_WAKEUP_ENABLED 0 - * - * // ----------------------------------------------------------------------------- - * // Specify number of interfaces and whether any interfaces support alternate - * // settings - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_NUM_INTERFACES 1 - * #define SLAB_USB_SUPPORT_ALT_INTERFACES 0 - * - * // ----------------------------------------------------------------------------- - * // Enable or disable each endpoint - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_EP1IN_USED 1 - * #define SLAB_USB_EP1OUT_USED 0 - * #define SLAB_USB_EP2IN_USED 0 - * #define SLAB_USB_EP2OUT_USED 0 - * #define SLAB_USB_EP3IN_USED 0 - * #define SLAB_USB_EP3OUT_USED 0 - * - * // ----------------------------------------------------------------------------- - * // Specify the maximum packet size for each endpoint - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_EP1IN_MAX_PACKET_SIZE 64 - * #define SLAB_USB_EP1OUT_MAX_PACKET_SIZE 0 - * #define SLAB_USB_EP2IN_MAX_PACKET_SIZE 0 - * #define SLAB_USB_EP2OUT_MAX_PACKET_SIZE 0 - * #define SLAB_USB_EP3IN_MAX_PACKET_SIZE 0 - * #define SLAB_USB_EP3OUT_MAX_PACKET_SIZE 0 - * - * // ----------------------------------------------------------------------------- - * // Specify transfer type of each endpoint - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_EP1IN_TRANSFER_TYPE USB_EPTYPE_INTR - * #define SLAB_USB_EP1OUT_TRANSFER_TYPE USB_EPTYPE_BULK - * #define SLAB_USB_EP2IN_TRANSFER_TYPE USB_EPTYPE_INTR - * #define SLAB_USB_EP2OUT_TRANSFER_TYPE USB_EPTYPE_BULK - * #define SLAB_USB_EP3IN_TRANSFER_TYPE USB_EPTYPE_ISOC - * #define SLAB_USB_EP3OUT_TRANSFER_TYPE USB_EPTYPE_ISOC - * - * // ----------------------------------------------------------------------------- - * // Enable or disable callback functions - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_RESET_CB 1 - * #define SLAB_USB_SOF_CB 1 - * #define SLAB_USB_STATE_CHANGE_CB 1 - * #define SLAB_USB_IS_SELF_POWERED_CB 1 - * #define SLAB_USB_SETUP_CMD_CB 1 - * #define SLAB_USB_HANDLER_CB 0 - * - * // ----------------------------------------------------------------------------- - * // Specify number of languages supported by string descriptors - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_NUM_LANGUAGES 1 - * - * // ----------------------------------------------------------------------------- - * // If only one descriptor language is supported, specify that language here. - * // If multiple descriptor languages are supported, this value is ignored and - * // the supported languages must listed in the - * // myUsbStringTableLanguageIDsDescriptor structure. - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_LANGUAGE USB_LANGID_ENUS - * - * // ----------------------------------------------------------------------------- - * // Set the power saving mode - * // - * // SLAB_USB_PWRSAVE_MODE configures when the device will automatically enter - * // the USB power-save mode. It is a bitmask constant with bit values: - * // - * // USB_PWRSAVE_MODE_OFF - No energy saving mode selected - * // 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. - * // This is useful for some applications that - * // support remote wakeup. - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_PWRSAVE_MODE (USB_PWRSAVE_MODE_ONVBUSOFF \ - * | USB_PWRSAVE_MODE_ONSUSPEND) - * - * // ----------------------------------------------------------------------------- - * // Enable or disable polled mode - * // - * // When enabled, the application must call USBD_Run() periodically to process - * // USB events. - * // When disabled, USB events will be handled automatically by an interrupt - * // handler. - * // ----------------------------------------------------------------------------- - * #define SLAB_USB_POLLED_MODE 0 - * @endcode - * - * @n @section usb_device_powersave Energy-saving options - * - * The device stack provides built-in energy saving options.These options - * are configured by setting flags in @ref SLAB_USB_PWRSAVE_MODE in @em - * usbconfig.h. These flags are bitmasks and can be or'd together.@n@n - * - * Energy-Saving Option Flags: - * - * @ref USB_PWRSAVE_MODE_OFF@n The device will not automatically enter its - * low-power suspned mode after detecting a USB suspend. The application - * firmware may still call @ref USBD_Suspend() to manually enter suspend mode. - * - * @ref USB_PWRSAVE_MODE_ONSUSPEND@n Enter a low-power suspend mode - * when a USB suspend is detected. When resume signaling is detected, - * the stack will exit the low-power mode. - * - * @ref USB_PWRSAVE_MODE_ONVBUSOFF@n Enter the low-power suspend - * mode any time the device detects that VBUS is not present. When VBUS is - * attached, the stack will exit the low-power mode. The USB Specification - * does not define the state of the device when VBUS is not present, but it - * may be desirable for some applications to enter suspend mode when in this - * undefined state. - * - * @ref USB_PWRSAVE_MODE_FASTWAKE@n Keep the internal regulator at - * its normal operating state while in the low-power suspend state. This - * allows the device to wake from suspend more quickly than it would from its - * suspend state. This option can be useful in applications that support - * remote wakeup and need to exit suspend in time to recognize some external - * signal (i.e. a byte received on the UART). The device will still consume - * low enough power to meet the USB Suspend Current Specification, but it will - * be slightly higher than it would otherwise be. - * - * The USB HID Keyboard device example project demonstrates some of these - * energy-saving options. - * - * Example: - * Leave all energy saving to the stack, the device enters low-power mode on - * suspend and when detached from host. @n - * In usbconfig.h: - * @code - * #define SLAB_USB_PWRSAVE_MODE (USB_PWRSAVE_MODE_ONSUSPEND | USB_PWRSAVE_MODE_ONVBUSOFF) - * @endcode - * - * @n @section usb_device_transfers Transfer Operation - * - * @subsection usb_device_transfers_overview Overview - * - * A USB transfer consists of one or more packets. For an IN transfer, the - * packets are sent from the device to the host. For an OUT transfer, the - * packets are sent from the host to the device. @ref USBD_Write() initiates - * an IN transfer, while @ref USBD_Read() initiates an OUT transfer. - * - * @subsection usb_device_transfers_types Transfer Types - * - * There are four USB transfer types: @ref usb_device_transfer_types_control, - * @ref usb_device_transfer_types_bulk, @ref usb_device_transfer_types_interrupt, - * and @ref usb_device_transfer_types_isochronous. - * - * @subsubsection usb_device_transfer_types_control Control - * - * Control transfers are used to send configuration and status - * information, and also to send vendor-defined data. The USB Library only - * supports control transfers on Endpoint 0. @n @n - * The application firmware can handle control requests by looking at the - * contents of the setup packet in @ref USBD_SetupCmdCb(). If the application - * supports a particular request, it can call @ref USBD_Read() or @ref - * USBD_Write() with epAddr set to EP0 and return @ref - * USB_STATUS_OK. If it does not need to handle the request, it should return - * @ref USB_STATUS_REQ_UNHANDLED. This will notify the library that it should - * try to handle the setup command. The library will automatically service - * Standard (i.e. Chapter 9) requests, so @ref USBD_SetupCmdCb() should return - * @ref USB_STATUS_REQ_UNHANDLED unless it is a class- or vendor-specific - * request. If neither the library nor the application supports a setup - * request, the library will issue a stall. - * - * @subsubsection usb_device_transfer_types_bulk Bulk - * - * Bulk transfers are used to send large, non-periodic data. Examples include - * sending a file to a Mass Storage Device or a print-job to a printer. A bulk - * transfer may consist of one or more packets. - * - * Endpoints are configured for bulk mode in usbconfig.h. As an - * example: @code - * #define SLAB_USB_EP1OUT_TRANSFER_TYPE USB_EPTYPE_BULK@endcode - * configures Endpout 1 OUT transfers for bulk mode. - * - * The @ref byteCount parameter of @ref USBD_Write() and @ref USBD_Read() - * configures the maximum length for a given bulk transfer. The transfer will - * complete when the device sends or receives either: - * 1. A packet less than its maximum packet size - * 2. Exactly the number of bytes specified in @ref byteCount - * Note that @ref USBD_XferCompleteCb() will be called for each packet sent or - * received for the duration of a transfer. - * - * @subsubsection usb_device_transfer_types_interrupt Interrupt - * - * Interrupt transfers are used to send low-bandwidth, hight-latency data at - * a non-periodic rate. Examples include input devices, such as mice, - * keyboards, and joysticks. An interrupt transfer may consist of one or more - * packets. - * - * Endpoints are configured for interrupt mode in usbconfig.h. As an - * example: @code - * #define SLAB_USB_EP1OUT_TRANSFER_TYPE USB_EPTYPE_INTR@endcode - * configures Endpout 1 OUT transfers for interrupt mode. - * - * Interrupt transfers work identically to bulk transfer in the USB Library. - * Refer to @ref usb_device_transfer_types_bulk for more information. - * - * @subsubsection usb_device_transfer_types_isochronous Isochronous - * - * Isochronous transfers are used to send periodic, continuous data. Automatic - * error-checking is not included with isochronous transfers as it is with all - * other transfer types. Examples include streaming audio and video. As - * isochronous data is sent at a continuous rate, it typically consists of - * one IN and/or OUT packet per frame. - * - * Endpoint 3 is the only endpoint in the USB Library that supports - * isochronous transfers. Endpoints are configured for isochronous mode in - * usbconfig.h. As an example: @code - * #define SLAB_USB_EP3OUT_TRANSFER_TYPE USB_EPTYPE_ISOC@endcode - * configures Endpout 3 OUT transfers for isochronous mode. - * - * The library works differently for isochronous transfers. The application - * must define a circular buffer to hold isochronous data. When calling - * USBD_Read() or USBD_Write(), dat is the first address of this - * buffer and byteCount is its length. The library will read from or - * write to this buffer as soon as the host issues a request, so it is the - * responsibility of the application firmware to ensure that this buffer is - * fed or consumed at the correct rate to prevent an underrun/overrun - * condition. - * - * The parameters of @ref USBD_XferCompleteCb() take on a different meaning in - * isochronous mode. For OUT transfers, xferred is the number of - * bute received in the last packet and remaining is the current - * index into the circular buffer. For IN transfers, xferred is - * ignored, remaining is the current index into the circular buffer, - * and the return value is the number of bytes to transmit in the next - * packet. - * - * @n @section usb_device_pitfalls Pitfalls - * - * @subsection usb_device_pitfalls_nonreentrancy Non-Reentrancy - * - * Due to the non-reentrant architecture of the 8051, it is recommended - * that all calls to a particular API function be made from functions of the - * same interrupt priority (main loop, low priority, or high priority). - * - * The interrupt priority of the USB callback functions is determined by the - * constant @ref SLAB_USB_POLLED_MODE. When 0, the callbacks are called from - * the USB Interrupt Handler. When 1, the callbacks are called from - * USBD_Run(), which is typically called from the main loop. - * If an API function must be called from functions of differing interrupt - * priorities, there are a number of ways to ensure that the calls are made - * safely: - * - * 1. Disable the interrupt source of the higher-priority function before - * making the call. Restore the interrupt enable setting after the call - * returns: - * - * (Assuming @htmlonly USBD_Write() is called from main() and - * USBD_XferCompleteCb() @endhtmlonly, the call from main() should - * disable and restore the USB interrupt): - * @code - * bool usbIntsEnabled = USB_GetIntsEnabled(); - * - * USB_DisableInts(); - * - * USBD_Write(EP1IN, myBuf, 1, true); - * - * if (usbIntsEnabled) - * { - * USB_EnableInts(); - * } - * @endcode - * - * 2. Add the compiler-specific reentrant keyword to the function - * definition(s) in efm8_usbd.c: - * @code - * int8_t USBD_AbortTransfer(uint8_t epAddr) reentrant - * @endcode - * and to the function prototype definition(s) in efm8_usb.h: - * @code - * int8_t USBD_AbortTransfer(uint8_t epAddr) reentrant; - * @endcode - * Using the reentrant keyword may require the application to provide - * a heap for local variable allocation. Additionally, it will reduce - * the performance and increase the code size of the modified function. - * 3. Make a copy of the function(s) and rename it. Call the original - * function in once context, and the renamed version in another. - * - * @subsection usb_device_pitfalls_buffer_allocation Buffer Allocation - * - * Dynamically allocated buffers passed to @ref USBD_Write() and @ref - * USBD_Read() must not be freed until the transfer completes. - * - ******************************************************************************/ - -/***************************************************************************//** - * @addtogroup efm8_usb_constants Constants - * @{ - ******************************************************************************/ - -// ----------------------------------------------------------------------------- -// Global Constants - -// SETUP request, direction of data stage -#define USB_SETUP_DIR_OUT 0 ///< Setup request data stage OUT direction value. -#define USB_SETUP_DIR_IN 1 ///< Setup request data stage IN direction value. -#define USB_SETUP_DIR_MASK 0x80 ///< Setup request data stage direction mask. -#define USB_SETUP_DIR_D2H 0x80 ///< Setup request data stage IN direction mask. -#define USB_SETUP_DIR_H2D 0x00 ///< Setup request data stage OUT direction mask. - -// SETUP request type -#define USB_SETUP_TYPE_STANDARD 0 ///< Standard setup request value. -#define USB_SETUP_TYPE_CLASS 1 ///< Class setup request value. -#define USB_SETUP_TYPE_VENDOR 2 ///< Vendor setup request value. -#define USB_SETUP_TYPE_STANDARD_MASK 0x00 ///< Standard setup request mask. -#define USB_SETUP_TYPE_CLASS_MASK 0x20 ///< Class setup request mask. -#define USB_SETUP_TYPE_VENDOR_MASK 0x40 ///< Vendor setup request mask. - -// SETUP request recipient -#define USB_SETUP_RECIPIENT_DEVICE 0 ///< Setup request device recipient value. -#define USB_SETUP_RECIPIENT_INTERFACE 1 ///< Setup request interface recipient value. -#define USB_SETUP_RECIPIENT_ENDPOINT 2 ///< Setup request endpoint recipient value. -#define USB_SETUP_RECIPIENT_OTHER 3 ///< Setup request other recipient value. - -// bmRequestType bitmasks -#define USB_BMREQUESTTYPE_RECIPIENT 0x1F ///< Recipient is bmRequestType[4:0] -#define USB_BMREQUESTTYPE_TYPE 0x60 ///< Type is bmRequestType[6:5] -#define USB_BMREQUESTTYPE_DIRECTION 0x80 ///< Recipient is bmRequestType[7] - -// SETUP standard request codes for Full Speed devices -#define GET_STATUS 0 ///< Standard setup request GET_STATUS. -#define CLEAR_FEATURE 1 ///< Standard setup request CLEAR_FEATURE. -#define SET_FEATURE 3 ///< Standard setup request SET_FEATURE. -#define SET_ADDRESS 5 ///< Standard setup request SET_ADDRESS. -#define GET_DESCRIPTOR 6 ///< Standard setup request GET_DESCRIPTOR. -#define SET_DESCRIPTOR 7 ///< Standard setup request SET_DESCRIPTOR. -#define GET_CONFIGURATION 8 ///< Standard setup request GET_CONFIGURATION. -#define SET_CONFIGURATION 9 ///< Standard setup request SET_CONFIGURATION. -#define GET_INTERFACE 10 ///< Standard setup request GET_INTERFACE. -#define SET_INTERFACE 11 ///< Standard setup request SET_INTERFACE. -#define SYNCH_FRAME 12 ///< Standard setup request SYNCH_FRAME. - -// SETUP class request codes -#define USB_HID_GET_REPORT 0x01 ///< HID class setup request GET_REPORT. -#define USB_HID_GET_IDLE 0x02 ///< HID class setup request GET_IDLE. -#define USB_HID_SET_REPORT 0x09 ///< HID class setup request SET_REPORT. -#define USB_HID_SET_IDLE 0x0A ///< HID class setup request SET_IDLE. -#define USB_HID_SET_PROTOCOL 0x0B ///< HID class setup request SET_PROTOCOL. -#define USB_CDC_SETLINECODING 0x20 ///< CDC class setup request SET_LINE_CODING. -#define USB_CDC_GETLINECODING 0x21 ///< CDC class setup request GET_LINE_CODING. -#define USB_CDC_SETCTRLLINESTATE 0x22 ///< CDC class setup request SET_CONTROL_LINE_STATE. -#define USB_MSD_BOTRESET 0xFF ///< MSD class setup request Bulk only transfer reset. -#define USB_MSD_GETMAXLUN 0xFE ///< MSD class setup request Get Max LUN. - -// SETUP command GET/SET_DESCRIPTOR descriptor types -#define USB_DEVICE_DESCRIPTOR 1 ///< DEVICE descriptor value. -#define USB_CONFIG_DESCRIPTOR 2 ///< CONFIGURATION descriptor value. -#define USB_STRING_DESCRIPTOR 3 ///< STRING descriptor value. -#define USB_INTERFACE_DESCRIPTOR 4 ///< INTERFACE descriptor value. -#define USB_ENDPOINT_DESCRIPTOR 5 ///< ENDPOINT descriptor value. -#define USB_DEVICE_QUALIFIER_DESCRIPTOR 6 ///< DEVICE_QUALIFIER descriptor value. -#define USB_OTHER_SPEED_CONFIG_DESCRIPTOR 7 ///< OTHER_SPEED_CONFIGURATION descriptor value. -#define USB_INTERFACE_POWER_DESCRIPTOR 8 ///< INTERFACE_POWER descriptor value. -#define USB_HUB_DESCRIPTOR 0x29 ///< HUB descriptor value. -#define USB_HID_DESCRIPTOR 0x21 ///< HID descriptor value. -#define USB_HID_REPORT_DESCRIPTOR 0x22 ///< HID REPORT descriptor value. -#define USB_CS_INTERFACE_DESCRIPTOR 0x24 ///< Audio Class-specific Descriptor Type. - -#define USB_DEVICE_DESCSIZE 18 ///< Device descriptor size. -#define USB_CONFIG_DESCSIZE 9 ///< Configuration descriptor size. -#define USB_INTERFACE_DESCSIZE 9 ///< Interface descriptor size. -#define USB_ENDPOINT_DESCSIZE 7 ///< Endpoint descriptor size. -#define USB_DEVICE_QUALIFIER_DESCSIZE 10 ///< Device qualifier descriptor size. -#define USB_OTHER_SPEED_CONFIG_DESCSIZE 9 ///< Device other speed configuration descriptor size. -#define USB_HID_DESCSIZE 9 ///< HID descriptor size. -#define USB_CDC_HEADER_FND_DESCSIZE 5 ///< CDC Header functional descriptor size. -#define USB_CDC_CALLMNG_FND_DESCSIZE 5 ///< CDC Call Management functional descriptor size. -#define USB_CDC_ACM_FND_DESCSIZE 4 ///< CDC Abstract Control Management functional descriptor size. - -// String descriptor locations -#define USB_STRING_DESCRIPTOR_ENCODING 0 ///< Denotes whether string descriptor is UTF-8 or binary -#define USB_STRING_DESCRIPTOR_LENGTH 1 ///< Length of string descriptor -#define USB_STRING_DESCRIPTOR_TYPE 2 ///< Type of string descriptor (USB_STRING_DESCRIPTOR) -#define USB_STRING_DESCRIPTOR_NAME 3 ///< The string encoded as per USB_STRING_DESCRIPTOR_PACKED - -// String descriptor encoding types -#define USB_STRING_DESCRIPTOR_UTF16LE 0 ///< The string is in UTF-16LE encoding -#define USB_STRING_DESCRIPTOR_UTF16LE_PACKED 1 ///< The string is in packed UTF-16LE encoding (the 0x00 - /// characters between ASCII characters are omitted) -#define USB_STRING_DESCRIPTOR_UTF8 2 ///< The string is in UTF-8 encoding - -// Misc. USB definitions -#define USB_FULL_EP0_SIZE 64 ///< The size of endpoint 0 at full speed. -#define USB_FULL_INT_BULK_MAX_EP_SIZE 64 ///< The max size of any full speed bulk/interrupt endpoint. -#define USB_FULL_ISOC_MAX_EP_SIZE 1023 ///< The max size of any full speed isochronous endpoint. -#define USB_LOW_EP0_SIZE 8 ///< The size of endpoint 0 at low speed. -#define USB_LOW_INT_BULK_MAX_EP_SIZE 8 ///< The max size of any low speed bulk/interrupt endpoint. -#define USB_LOW_ISOC_MAX_EP_SIZE 0 ///< The max size of any low speed isochronous endpoint. -#define USB_EPTYPE_CTRL 0 ///< Endpoint type control. -#define USB_EPTYPE_ISOC 1 ///< Endpoint type isochronous. -#define USB_EPTYPE_BULK 2 ///< Endpoint type bulk. -#define USB_EPTYPE_INTR 3 ///< Endpoint type interrupt. -#define USB_EP_DIR_IN 0x80 ///< Endpoint IN direction mask. -#define USB_EP_DIR_OUT 0x00 ///< Endponit OUT direction mask. -#define USB_SETUP_PKT_SIZE 8 ///< Setup request packet size. -#define USB_EPNUM_MASK 0x0F ///< Endpoint number mask. -#define USB_LANGID_ENUS 0x0409 ///< English-United States language id. -#define USB_LANGID_NOBO 0x0414 ///< Norwegian-Bokmal language id. -#define USB_MAX_DEVICE_ADDRESS 127 ///< Maximum allowable device address. -#define MAX_USB_EP_NUM 15 ///< Limit imposed by the USB standard -#define USB_VENDOR_ID_SILICON_LABS 0x10C4 ///< Silicon Labs VID - -#define CONFIG_DESC_BM_REMOTEWAKEUP 0x20 ///< Configuration descriptor attribute macro. -#define CONFIG_DESC_BM_SELFPOWERED 0x40 ///< Configuration descriptor attribute macro. -#define CONFIG_DESC_BM_RESERVED_D7 0x80 ///< Configuration descriptor attribute macro. -#define CONFIG_DESC_BM_TRANSFERTYPE 0x03 ///< Configuration descriptor transfer type bitmask. -#define CONFIG_DESC_MAXPOWER_mA(x) (((x)+1)/2) ///< Configuration descriptor power macro. - -#define DEVICE_IS_SELFPOWERED 0x0001 ///< Standard request GET_STATUS bitmask. -#define REMOTE_WAKEUP_ENABLED 0x0002 ///< Standard request GET_STATUS bitmask. -#define USB_FEATURE_ENDPOINT_HALT 0 ///< Standard request CLEAR/SET_FEATURE bitmask. -#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 ///< Standard request CLEAR/SET_FEATURE bitmask. - -#define HUB_FEATURE_PORT_RESET 4 ///< HUB class request CLEAR/SET_PORT_FEATURE feature selector. -#define HUB_FEATURE_PORT_POWER 8 ///< HUB class request CLEAR/SET_PORT_FEATURE feature selector. -#define HUB_FEATURE_C_PORT_CONNECTION 16 ///< HUB class request CLEAR/SET_PORT_FEATURE feature selector. -#define HUB_FEATURE_C_PORT_RESET 20 ///< HUB class request CLEAR/SET_PORT_FEATURE feature selector. -#define HUB_FEATURE_PORT_INDICATOR 22 ///< HUB class request CLEAR/SET_PORT_FEATURE feature selector. - -#define USB_CLASS_CDC 2 ///< CDC device/interface class code. -#define USB_CLASS_CDC_DATA 0x0A ///< CDC Data interface class code. -#define USB_CLASS_CDC_ACM 2 ///< CDC Abstract Control Model interface subclass code. -#define USB_CLASS_CDC_HFN 0 ///< CDC class Header Functional Descriptor subtype. -#define USB_CLASS_CDC_CMNGFN 1 ///< CDC class Call Management Functional Descriptor subtype. -#define USB_CLASS_CDC_ACMFN 2 ///< CDC class Abstract Control Management Functional Descriptor subtype. -#define USB_CLASS_CDC_UNIONFN 6 ///< CDC class Union Functional Descriptor subtype. - -#define USB_CLASS_HID 3 ///< HID device/interface class code. -#define USB_CLASS_HID_KEYBOARD 1 ///< HID keyboard interface protocol code. -#define USB_CLASS_HID_MOUSE 2 ///< HID mouse interface protocol code. - -#define USB_CLASS_HUB 9 ///< HUB device/interface class code. - -#define USB_CLASS_MSD 8 ///< MSD device/interface class code. -#define USB_CLASS_MSD_BOT_TRANSPORT 0x50 ///< MSD Bulk Only Transport protocol. -#define USB_CLASS_MSD_SCSI_CMDSET 6 ///< MSD Subclass SCSI transparent command set. -#define USB_CLASS_MSD_CSW_CMDPASSED 0 ///< MSD BOT Command status wrapper command passed code. -#define USB_CLASS_MSD_CSW_CMDFAILED 1 ///< MSD BOT Command status wrapper command failed code. -#define USB_CLASS_MSD_CSW_PHASEERROR 2 ///< MSD BOT Command status wrapper cmd phase error code. - -#define USB_CLASS_VENDOR_SPECIFIC 0xFF ///< Vendor Specific class -#define USB_SUBCLASS_VENDOR_SPECIFIC 0xFF ///< Vendor Specific sub-class - -/// @brief USB power save modes -#define USB_PWRSAVE_MODE_OFF 0 ///< No energy saving option selected. -#define USB_PWRSAVE_MODE_ONSUSPEND 1 ///< Enter USB power-save mode on suspend. -#define USB_PWRSAVE_MODE_ONVBUSOFF 2 ///< Enter USB power-save mode when not attached to the USB host. -#define USB_PWRSAVE_MODE_FASTWAKE 4 ///< Exit USB power-save mode more quickly. This is useful for - ///< some applications that support remote wakeup. - -/// @brief Endpoint 0 packet size -#if SLAB_USB_FULL_SPEED -#define USB_EP0_SIZE USB_FULL_EP0_SIZE -#else -#define USB_EP0_SIZE USB_LOW_EP0_SIZE -#endif // SLABS_USB_FULL_SPEED - -/// @brief Total number of USB endpoints used by the device -#define SLAB_USB_NUM_EPS_USED (SLAB_USB_EP1IN_USED \ - + SLAB_USB_EP1OUT_USED \ - + SLAB_USB_EP2IN_USED \ - + SLAB_USB_EP2OUT_USED \ - + SLAB_USB_EP3IN_USED \ - + SLAB_USB_EP3OUT_USED \ - + 1) -/** @} (end addtogroup efm8_usb_constants Constants) */ - -/***************************************************************************//** - * @addtogroup efm8_usb_macros Macros - * @{ - ******************************************************************************/ - -// ----------------------------------------------------------------------------- -// Global Macros - -/// Macro for getting minimum value. -#ifndef EFM8_MIN -#define EFM8_MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - -/// Macro for getting maximum value. -#ifndef EFM8_MAX -#define EFM8_MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - -#ifndef UNREFERENCED_ARGUMENT -/// Macro for removing unreferenced arguments from compiler warnings -#define UNREFERENCED_ARGUMENT(arg) (0, arg) -#endif - -/***************************************************************************//** - * @brief Macro for creating USB-compliant UTF-16LE UNICODE string - * descriptor from a C string. - * @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 - * by inserting a 0x00 between each character. This allows the - * string to be stored in a "packed", or compressed, format. - * @n@n This example sends "Silicon Labs" as the Manufacturer String: - * - * #define MFR_STRING "Silicon Labs" - * - * UTF16LE_PACKED_STATIC_CONST_STRING_DESC(manufacturer[], \ - * MFR_STRING); - * @param __name - * The name of the variable that holds the string descriptor - * @param __val - * The value of the string descriptor - ******************************************************************************/ -#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, sizeof(__val) * 2, USB_STRING_DESCRIPTOR, __val } - -/***************************************************************************//** - * @brief Macro for creating USB-compliant UTF-16LE UNICODE string - * descriptor from a C array initializer. - * @details This macro should be used for converting an array initializer - * into a string descriptor. Unlike @ref - * UTF16LE_PACKED_STATIC_CONST_STRING_DESC(), the library will not - * attempt to unpack variables created with this macro, so the - * array will be sent exactly as it is defined. - * @n@n This example sends "Mouse" as the Product String: - * - * #define PROD_STRING 'M',0,'o',0,'u',0,'s',0,'e',0 - * - * ARRAY_STATIC_CONST_STRING_DESC(product[], \ - * 10, \ - * PROD_STRING); - * @param __name - * The name of the variable that holds the string descriptor - * @param __len - * Number of characters (including nulls) in the string to send - * @param __val - * The array initializer. - ******************************************************************************/ -#define ARRAY_STATIC_CONST_STRING_DESC(__name, __len, __val) \ - SI_SEGMENT_VARIABLE(__name, static const USB_StringDescriptor_TypeDef, SI_SEG_CODE) = \ - { USB_STRING_DESCRIPTOR_UTF16LE, __len + 2, USB_STRING_DESCRIPTOR, __val } - -/***************************************************************************//** - * @brief Macro for creating USB-compliant UTF-16LE UNICODE string - * descriptor from a UTF-16 C string. - * @details This macro should be used for strings which are already - * represented in UTF-16. This is an advanced option that should - * only be used for some foreign languages. - * @param __name - * The name of the variable that holds the string descriptor - * @param __val - * The value of the string descriptor - ******************************************************************************/ -#define UTF16LE_STATIC_CONST_STRING_DESC(__name, __val) \ - SI_SEGMENT_VARIABLE(__name, static const USB_StringDescriptor_TypeDef, SI_SEG_CODE) = \ - { USB_STRING_DESCRIPTOR_UTF16LE, sizeof(__val) + 2, USB_STRING_DESCRIPTOR, __val } - -/***************************************************************************//** - * @brief Macro for creating Language ID's String Descriptor (String - * Descriptor 0) - * @details This macro should be used to create the Language ID String - * Descriptor. - * @n@n This example USB device only support U.S. English: - * - * #define LANG_STRING htole16(SLAB_USB_LANGUAGE) - * - * LANGID_STATIC_CONST_STRING_DESC(langDesc[], LANG_STRING); - * - * This example USB device support Norwegian U.S. English: - * - * #define LANG_STRING htole16(USB_LANGID_NOBO), \ - * htole16(USB_LANGID_ENUS) - * - * LANGID_STATIC_CONST_STRING_DESC(langDesc[], LANG_STRING); - * - * @param __name - * The name of the variable that holds the string descriptor - * @param __val - * The value of the string descriptor - ******************************************************************************/ -#define LANGID_STATIC_CONST_STRING_DESC(__name, __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) */ - -/***************************************************************************//** - * @addtogroup efm8_usb_typedefs Typedefs - * @{ - ******************************************************************************/ - -// ----------------------------------------------------------------------------- -// Typedefs - -/// @brief USB transfer status enumerator. -typedef enum -{ - USB_STATUS_OK = 0, ///< No errors detected. - USB_STATUS_REQ_ERR = -1, ///< Setup request error. - USB_STATUS_EP_BUSY = -2, ///< Endpoint is busy. - USB_STATUS_REQ_UNHANDLED = -3, ///< Setup request not handled. - USB_STATUS_ILLEGAL = -4, ///< Illegal operation attempted. - USB_STATUS_EP_STALLED = -5, ///< Endpoint is stalled. - USB_STATUS_EP_ABORTED = -6, ///< Endpoint transfer was aborted. - USB_STATUS_EP_ERROR = -7, ///< Endpoint transfer error. - USB_STATUS_EP_NAK = -8, ///< Endpoint NAK'ed transfer request. - USB_STATUS_DEVICE_UNCONFIGURED = -9, ///< Device is unconfigured. - USB_STATUS_DEVICE_SUSPENDED = -10, ///< Device is suspended. - 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 - ///< last received packet -} USB_Status_TypeDef; - -/// @brief USB device state enumerator. -typedef enum -{ - USBD_STATE_NONE = 0, ///< Device state is undefined/unknown. - USBD_STATE_ATTACHED = 1, ///< Device state is ATTACHED. - USBD_STATE_POWERED = 2, ///< Device state is POWERED. - USBD_STATE_DEFAULT = 3, ///< Device state is DEFAULT. - USBD_STATE_ADDRESSED = 4, ///< Device state is ADDRESSED. - USBD_STATE_SUSPENDED = 5, ///< Device state is SUSPENDED. - USBD_STATE_CONFIGURED = 6, ///< Device state is CONFIGURED. - USBD_STATE_LASTMARKER = 7, ///< Device state enum end marker. -} USBD_State_TypeDef; - -/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN -/// @brief Endpoint states -typedef enum -{ - D_EP_DISABLED = 0, ///< Endpoint is disabled - D_EP_IDLE = 1, ///< Endpoint is idle - D_EP_TRANSMITTING = 2, ///< Endpoint is transmitting data - D_EP_RECEIVING = 3, ///< Endpoint is receiving data - D_EP_STATUS = 4, ///< Endpoint is in status stage - D_EP_STALL = 5, ///< Endpoint is stalling - D_EP_HALT = 6, ///< Endpoint is halted - D_EP_LASTMARKER = 7 ///< End of EpState enum -} USBD_EpState_TypeDef; -/// @endcond DO_NOT_INCLUDE_WITH_DOXYGEN - -/// @brief Endpoint access address -typedef enum -{ - EP0, -#if (SLAB_USB_EP1IN_USED) - EP1IN, -#endif -#if (SLAB_USB_EP2IN_USED) - EP2IN, -#endif -#if (SLAB_USB_EP3IN_USED) - EP3IN, -#endif -#if (SLAB_USB_EP1OUT_USED) - EP1OUT, -#endif -#if (SLAB_USB_EP2OUT_USED) - EP2OUT, -#endif -#if (SLAB_USB_EP3OUT_USED) - EP3OUT, -#endif -}USB_EP_Index_TypeDef; - -/// @brief USB Setup type. -typedef struct -{ - struct - { - uint8_t Recipient : 5; ///< Request recipient (device, interface, endpoint, other) - uint8_t Type : 2; ///< Request type (standard, class or vendor). - uint8_t Direction : 1; ///< Transfer direction of SETUP data phase. - } bmRequestType; - - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; -} USB_Setup_TypeDef; - -/// @brief USB Setup Union type. -typedef union -{ - USB_Setup_TypeDef setup; - uint8_t c[8]; - uint16_t i[4]; -} USB_Setup_UnionDef; - -/// @brief USB Device Descriptor. -typedef struct -{ - uint8_t bLength; ///< Size of this descriptor in bytes - uint8_t bDescriptorType; ///< Constant DEVICE Descriptor Type - uint16_t bcdUSB; ///< USB Specification Release Number in BCD - uint8_t bDeviceClass; ///< Class code (assigned by the USB-IF) - uint8_t bDeviceSubClass; ///< Subclass code (assigned by the USB-IF) - uint8_t bDeviceProtocol; ///< Protocol code (assigned by the USB-IF) - uint8_t bMaxPacketSize0; ///< Maximum packet size for endpoint zero - uint16_t idVendor; ///< Vendor ID (assigned by the USB-IF) - uint16_t idProduct; ///< Product ID (assigned by the manufacturer) - uint16_t bcdDevice; ///< Device release number in binary-coded decimal - uint8_t iManufacturer; ///< Index of string descriptor describing manufacturer - uint8_t iProduct; ///< Index of string descriptor describing product - uint8_t iSerialNumber; ///< Index of string descriptor describing the serial number - uint8_t bNumConfigurations; ///< Number of possible configurations -} USB_DeviceDescriptor_TypeDef; - - -/// @brief USB Configuration Descriptor. -typedef struct -{ - uint8_t bLength; ///< Size of this descriptor in bytes - uint8_t bDescriptorType; ///< Constant CONFIGURATION Descriptor Type - uint16_t wTotalLength; ///< Total length of data returned for this - ///< configuration. Includes the combined length of all - ///< descriptors (configuration, interface, endpoint, - ///< and class- or vendor-specific) returned for this - ///< configuration. - uint8_t bNumInterfaces; ///< Number of interfaces supported by this - ///< configuration - uint8_t bConfigurationValue; ///< Value to use as an argument to the - ///< SetConfiguration request to select this - ///< configuration. - uint8_t iConfiguration; ///< Index of string descriptor describing this - ///< configuration. - uint8_t bmAttributes; ///< Configuration characteristics. - ///< @n D7: Reserved (set to one) - ///< @n D6: Self-powered - ///< @n D5: Remote Wakeup - ///< @n D4...0: Reserved (reset to zero) - uint8_t bMaxPower; ///< Maximum power consumption of the USB device, unit - ///< is 2mA per LSB -} USB_ConfigurationDescriptor_TypeDef; - - -/// @brief USB Interface Descriptor. -typedef struct -{ - uint8_t bLength; ///< Size of this descriptor in bytes. - uint8_t bDescriptorType; ///< Constant INTERFACE Descriptor Type. - uint8_t bInterfaceNumber; ///< Number of this interface. Zero-based value - ///< identifying the index in the array of concurrent - ///< interfaces supported by this configuration. - uint8_t bAlternateSetting; ///< Value used to select this alternate setting for - ///< the interface identified in the prior field. - uint8_t bNumEndpoints; ///< Number of endpoints used by this interface - ///< (excluding endpoint zero). If this value is zero, - ///< this interface only uses the Default Control Pipe. - uint8_t bInterfaceClass; ///< Class code (assigned by the USB-IF). A value - ///< of zero is reserved for future standardization. If - ///< this field is set to FFH, the interface class is - ///< vendor-specific. All other values are reserved for - ///< assignment by the USB-IF. - uint8_t bInterfaceSubClass; ///< Subclass code (assigned by the USB-IF). These codes - ///< are qualified by the value of the bInterfaceClass - ///< field. If the bInterfaceClass field is reset to - ///< zero, this field must also be reset to zero. If - ///< the bInterfaceClass field is not set to FFH, all - ///< values are reserved for assignment by the USB-IF. - uint8_t bInterfaceProtocol; ///< Protocol code (assigned by the USB). These codes - ///< are qualified by the value of the bInterfaceClass - ///< and the bInterfaceSubClass fields. If an interface - ///< supports class-specific requests, this code - ///< identifies the protocols that the device uses as - ///< defined by the specification of the device class. - ///< If this field is reset to zero, the device does - ///< not use a class-specific protocol on this - ///< interface. If this field is set to FFH, the device - ///< uses a vendor-specific protocol for this interface - uint8_t iInterface; ///< Index of string descriptor describing this - ///< interface. -} USB_InterfaceDescriptor_TypeDef; - - -/// @brief USB Endpoint Descriptor. -typedef struct -{ - uint8_t bLength; ///< Size of this descriptor in bytes - uint8_t bDescriptorType; ///< Constant ENDPOINT Descriptor Type - uint8_t bEndpointAddress; ///< The address of the endpoint - uint8_t bmAttributes; ///< This field describes the endpoint attributes - uint16_t wMaxPacketSize; ///< Maximum packet size for the endpoint - uint8_t bInterval; ///< Interval for polling EP for data transfers -} USB_EndpointDescriptor_TypeDef; - -/// @brief USB String Descriptor. -typedef uint8_t USB_StringDescriptor_TypeDef; ///< The string descriptor - -/// @brief USB Language ID String Descriptor. -typedef uint16_t USB_LangId_StringDescriptor_Typedef; ///< The language ID string descriptor - -#if (SLAB_USB_NUM_LANGUAGES == 1) -/// @brief USB String Table Structure. -typedef USB_StringDescriptor_TypeDef * *USB_StringTable_TypeDef; -#elif (SLAB_USB_NUM_LANGUAGES > 1) -typedef struct -{ - uint16_t *languageIDs; - USB_StringDescriptor_TypeDef * * *languageArray; -} USB_StringTable_TypeDef; -#endif // ( SLAB_USB_NUM_LANGUAGES == 1 ) - -/// @brief USB Device stack initialization structure. -/// @details This structure is passed to @ref USBD_Init() when starting up -/// the device. -typedef struct -{ - 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; - -/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN -// Endpoint structure -typedef struct -{ - uint8_t *buf; - uint16_t remaining; - USBD_EpState_TypeDef state; - union - { - struct - { - uint8_t callback : 1; - uint8_t outPacketPending : 1; - uint8_t inPacketPending : 1; - uint8_t waitForRead : 1; - } bits; - uint8_t c; - } misc; -} USBD_Ep_TypeDef; - -// USB Device structure -typedef struct -{ - uint8_t configurationValue; -#if SLAB_USB_REMOTE_WAKEUP_ENABLED - uint8_t remoteWakeupEnabled; -#endif - uint8_t numberOfStrings; - USBD_State_TypeDef state; - USBD_State_TypeDef savedState; - USB_Setup_TypeDef setup; - union - { - struct - { - uint8_t type : 7; - uint8_t init : 1; - } encoding; - uint8_t c; - } ep0String; - USBD_Ep_TypeDef ep0; -#if SLAB_USB_EP1IN_USED - USBD_Ep_TypeDef ep1in; -#endif -#if SLAB_USB_EP2IN_USED - USBD_Ep_TypeDef ep2in; -#endif -#if SLAB_USB_EP3IN_USED - USBD_Ep_TypeDef ep3in; -#endif -#if SLAB_USB_EP1OUT_USED - USBD_Ep_TypeDef ep1out; -#endif -#if SLAB_USB_EP2OUT_USED - USBD_Ep_TypeDef ep2out; -#endif -#if SLAB_USB_EP3OUT_USED - USBD_Ep_TypeDef ep3out; -#endif -#if ((SLAB_USB_EP3IN_USED) && (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC)) - uint16_t ep3inIsoIdx; -#endif -#if ((SLAB_USB_EP3OUT_USED) && (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)) - uint16_t ep3outIsoIdx; -#endif -#if SLAB_USB_SUPPORT_ALT_INTERFACES - uint8_t interfaceAltSetting[SLAB_USB_NUM_INTERFACES]; -#endif - USB_DeviceDescriptor_TypeDef *deviceDescriptor; - USB_ConfigurationDescriptor_TypeDef *configDescriptor; - USB_StringTable_TypeDef *stringDescriptors; -} USBD_Device_TypeDef; -/// @endcond DO_NOT_INCLUDE_WITH_DOXYGEN - -/** @} (end addtogroup efm8_usb_typedefs Typedefs) */ - -/***************************************************************************//** - * @addtogroup efm8_usb_constants Constants - * @{ - ******************************************************************************/ - -// ----------------------------------------------------------------------------- -// Compiler-specific memory segment definitions - -#ifndef MEM_MODEL_SEG - -// ----------------------------------------------------------------------------- -// Memory Model-Specific Location -// -// MEM_MODEL_SEG is the default memory segment used for a given -// memory model. Some variables use this symbol in order to reduce the amount -// of code space and number of cycles it takes to access them. -// The user can override this value by defining it in his usbconfig.h file. -// For example: -// -// #define MEM_MODEL_LOC SI_SEG_XDATA -// -// will place these variables in XRAM regardless of the memory model used to -// build the project. -// ----------------------------------------------------------------------------- - -#if (defined SDCC) || (defined __SDCC) - -#if (__SDCC_MODEL_SMALL) -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif defined __SDCC_MODEL_MEDIUM -#define MEM_MODEL_SEG SI_SEG_PDATA -#elif (defined __SDCC_MODEL_LARGE) || (defined __SDCC_MODEL_HUGE) -#define MEM_MODEL_SEG SI_SEG_XDATA -#else -#error "Illegal memory model setting." -#endif - -#elif defined __RC51__ - -#if (__MEMORY_MODEL__ == 0) // TINY -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (__MEMORY_MODEL__ == 1) // SMALL -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (__MEMORY_MODEL__ == 2) // COMPACT -#define MEM_MODEL_SEG SI_SEG_PDATA -#elif (__MEMORY_MODEL__ == 3) // LARGE -#define MEM_MODEL_SEG SI_SEG_XDATA -#elif (__MEMORY_MODEL__ == 4) // HUGE -#define MEM_MODEL_SEG SI_SEG_PDATA -#else -#error "Illegal memory model setting." -#endif - -#elif defined __C51__ - -#if (__MODEL__ == 0) // SMALL -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (__MODEL__ == 1) // COMPACT -#define MEM_MODEL_SEG SI_SEG_PDATA -#elif (__MODEL__ == 2) // LARGE -#define MEM_MODEL_SEG SI_SEG_XDATA -#else -#error "Illegal memory model setting." -#endif - -#elif defined _CC51 - -#if (_MODEL == 's') // SMALL -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (_MODEL == 'a') // AUXPAGE -#define MEM_MODEL_SEG SI_SEG_PDATA -#elif (_MODEL == 'l') // LARGE -#define MEM_MODEL_SEG SI_SEG_XDATA -#elif (_MODEL == 'r') // REENTRANT -#define MEM_MODEL_SEG SI_SEG_XDATA -#else -#error "Illegal memory model setting." -#endif - -#elif defined __ICC8051__ -#if (__DATA_MODEL__ == 0) // TINY -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (__DATA_MODEL__ == 1) // SMALL -#define MEM_MODEL_SEG SI_SEG_IDATA -#elif (__DATA_MODEL__ == 2) // LARGE -#define MEM_MODEL_SEG SI_SEG_XDATA -#elif (__DATA_MODEL__ == 3) // GENERIC -#define MEM_MODEL_SEG SI_SEG_XDATA -#elif (__DATA_MODEL__ == 4) // FAR -#define MEM_MODEL_SEG SI_SEG_XDATA -#else -#error "Illegal memory model setting." -#endif - -#endif -#endif // #ifndef MEM_MODEL_SEG - -/** @} (end addtogroup efm8_usb_constants Constants) */ - -/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN -void USBD_SetUsbState(USBD_State_TypeDef newState); -USB_Status_TypeDef USBDCH9_SetupCmd(void); -/// @endcond DO_NOT_INCLUDE_WITH_DOXYGEN - -// ----------------------------------------------------------------------------- -// Library Configuration Definitions - -/**************************************************************************//** - * @addtogroup efm8_usb_config Library Configuration - * @{ - * - * @details Library configuration constants read from usbconfig.h. - * - * This library will look for configuration constants in **usbconfig.h**. - * This file is provided/written by the user and should be - * located in a directory that is part of the include path. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_BUS_POWERED - * @brief Configures the USB device for bus-powered or self-powered mode. - * @details - * When '1' the USB device is bus-powered. - * When '0' the USB device is self-powered. - * - * Default setting is '1' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_FULL_SPEED - * @brief Configures the USB device for full-speed or low-speed operation. - * @details - * When '1' the USB device is full-speed - * When '0' the USB device is low-speed - * - * Default setting is '1' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_CLOCK_RECOVERY_ENABLED - * @brief Enables/disables the USB Clock Recovery - * @details USB Clock Recovery uses the incoming USB dat stream to adjust the - * internal oscillator. This allows the internal oscillator to meet the - * requirements for USB clock tolerance. - * - * When '1' the USB clock recovery is enabled - * When '0' the USB clock recovery is disabled - * - * Default setting is '1' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_REMOTE_WAKEUP_ENABLED - * @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 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 - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_NUM_INTERFACES - * @brief The number of interfaces available in the configuration - * @details - * Default setting is '1' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_SUPPORT_ALT_INTERFACES - * @brief Enables/disables alternate interface settings - * @details If any of the interfaces support alternate settings, this should be - * set to '1'. Upon receiveing a SET_INTERFACE request, the library will call - * @ref USBD_SetInterfaceCb(), which should return @ref USB_STATUS_OK if the - * alternate setting is valid or @ref USB_STATUS_REQ_ERR if it is not. - * - * When '1' alternate inteface settings are supported - * When '0' alternate interface settings are not supported, and the library will - * respond to any SET_INTERFACE request with a procedural stall - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1IN_USED - * @brief Enables/disables Endpoint 1 IN - * @details - * When '1' Endpoint 1 IN is enabled - * When '0' Endpoint 1 IN is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1OUT_USED - * @brief Enables/disables Endpoint 1 OUT - * @details - * When '1' Endpoint 1 OUT is enabled - * When '0' Endpoint 1 OUT is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2IN_USED - * @brief Enables/disables Endpoint 2 IN - * @details - * When '1' Endpoint 2 IN is enabled - * When '0' Endpoint 2 IN is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2OUT_USED - * @brief Enables/disables Endpoint 2 OUT - * @details - * When '1' Endpoint 2 OUT is enabled - * When '0' Endpoint 2 OUT is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3IN_USED - * @brief Enables/disables Endpoint 3 IN - * @details - * When '1' Endpoint 3 IN is enabled - * When '0' Endpoint 3 IN is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3OUT_USED - * @brief Enables/disables Endpoint 3 OUT - * @details - * When '1' Endpoint 3 OUT is enabled - * When '0' Endpoint 3 OUT is disabled - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1IN_MAX_PACKET_SIZE - * @brief The maximum packet size that can be received on Endpoint 1 IN - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1OUT_MAX_PACKET_SIZE - * @brief The maximum packet size that can be transmitted on Endpoint 1 OUT - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2IN_MAX_PACKET_SIZE - * @brief The maximum packet size that can be received on Endpoint 2 IN - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2OUT_MAX_PACKET_SIZE - * @brief The maximum packet size that can be transmitted on Endpoint 2 OUT - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3IN_MAX_PACKET_SIZE - * @brief The maximum packet size that can be received on Endpoint 3 IN - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3OUT_MAX_PACKET_SIZE - * @brief The maximum packet size that can be transmitted on Endpoint 3 OUT - * @details - * Default setting is '64' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1IN_TRANSFER_TYPE - * @brief Transfer type on Endpoint 1 IN - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP1OUT_TRANSFER_TYPE - * @brief Transfer type on Endpoint 1 OUT - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2IN_TRANSFER_TYPE - * @brief Transfer type on Endpoint 2 IN - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP2OUT_TRANSFER_TYPE - * @brief Transfer type on Endpoint 2 OUT - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3IN_TRANSFER_TYPE - * @brief Transfer type on Endpoint 3 IN - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * USB_EPTYPE_ISOC - Isochronous - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_EP3OUT_TRANSFER_TYPE - * @brief Transfer type on Endpoint 3 OUT - * @details - * May take one of the following values: - * USB_EPTYPE_INTR - Interrupt - * USB_EPTYPE_BULK - Bulk - * USB_EPTYPE_ISOC - Isochronous - * - * Default setting is @ref USB_EPTYPE_INTR and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_RESET_CB - * @brief Enables/disables the USB Reset callback function - * @details - * When '1' @ref USBD_ResetCb() is called upon reception of a USB Reset - * When '0' @ref USBD_ResetCb() is not called upon reception of a USB Reset - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_SOF_CB - * @brief Enables/disables the USB Start-Of-Frame callback function - * @details - * When '1' @ref USBD_SofCb() is called upon reception of a Start-of-Frame - * packet - * When '0' @ref USBD_SofCb() is not called upon reception of a Start-of-Frame - * packet - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_STATE_CHANGE_CB - * @brief Enables/disables the USB State Change callback function - * @details - * When '1' @ref USBD_DeviceStateChangeCb() is called when the USB device state - * changes - * When '0' @ref USBD_DeviceStateChangeCb() is not called when the USB device - * state changes - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_IS_SELF_POWERED_CB - * @brief Enables/disables the USB Self-Powered callback function - * @details - * When '1' @ref USBD_IsSelfPoweredCb() is called upon reception of a - * GET_STATUS (Self-Powered) request - * When '0' @ref USBD_IsSelfPoweredCb() is not called upon reception of a - * GET_STATUS (Self-Powered) request - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_SETUP_CMD_CB - * @brief Enables/disables the USB Setup Command callback function - * @details - * When '1' @ref USBD_SetupCmdCb() is called upon reception of a Setup Request - * When '0' @ref USBD_SetupCmdCb() is not called upon reception of a Setup - * Request - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_HANDLER_CB - * @brief Enables/disables the USB Handler Entry and Exit callback functions - * @details - * When '1' @ref USBD_EnterHandler() will be called before the USB handler - * executes and @ref USBD_ExitHandler() will be called after the USB handler - * completes - * When '0' @ref USBD_EnterHandler() and @ref USBD_ExitHandler() will not be - * called - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_NUM_LANGUAGES - * @brief Number of languages supported by the USB string descriptors - * @details - * Default setting is '1' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_LANGUAGE - * @brief - * Defines the language of the USB string descriptors when - * @ref SLAB_USB_NUM_LANGUAGES is '1'. - * - * @details - * When @ref SLAB_USB_NUM_LANGUAGES is greater than '1', the supported languages - * must be defined in a separate table, and a structure of type - * @ref USB_StringDescriptor_TypeDef must be defined for each supported - * language - * - * Default setting is @ref USB_LANGID_ENUS and may be overridden by defining in - * 'usbconfig.h'. - * - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_PWRSAVE_MODE - * @brief Configures the power-saving options supported by the device - * - * @details - * Default setting is @ref USB_PWRSAVE_MODE_ONSUSPEND and may be overridden by - * defining in 'usbconfig.h'. - * - * SLAB_USB_PWRSAVE_MODE configures when the device will automatically enter - * the USB power-save mode. It is a bitmask constant with bit values: - * - * @ref USB_PWRSAVE_MODE_OFF - No energy saving option selected - * @ref USB_PWRSAVE_MODE_ONSUSPEND - Enter USB power-save mode on USB suspend - * @ref USB_PWRSAVE_MODE_ONVBUSOFF - Enter USB power-save mode when not - * attached to the USB host. - * @ref USB_PWRSAVE_MODE_FASTWAKE - Exit USB power-save mode more quickly. - * This is useful for some applications that - * support remote wakeup. - *****************************************************************************/ - -/**************************************************************************//** - * @def SLAB_USB_POLLED_MODE - * @brief Enables/disables USB library polled mode - * @details - * When '1' the library will run in polled mode - * When '0' the library will run in interrupt mode - * - * Default setting is '0' and may be overridden by defining in 'usbconfig.h'. - * - *****************************************************************************/ - -/** @} (end addtogroup efm8_usb_config Library Configuration) */ - -// Set default USB library configurations if the value is not configured in -// usbconfig.h - -#ifndef SLAB_USB_BUS_POWERED -#define SLAB_USB_BUS_POWERED 1 -#endif - -#ifndef SLAB_USB_FULL_SPEED -#define SLAB_USB_FULL_SPEED 1 -#endif - -#ifndef SLAB_USB_CLOCK_RECOVERY_ENABLED -#define SLAB_USB_CLOCK_RECOVERY_ENABLED 1 -#endif - -#ifndef SLAB_USB_REMOTE_WAKEUP_ENABLED -#define SLAB_USB_REMOTE_WAKEUP_ENABLED 0 -#endif - -#ifndef SLAB_USB_NUM_INTERFACES -#define SLAB_USB_NUM_INTERFACES 1 -#endif - -#ifndef SLAB_USB_SUPPORT_ALT_INTERFACES -#define SLAB_USB_SUPPORT_ALT_INTERFACES 0 -#endif - -#ifndef SLAB_USB_EP1IN_USED -#define SLAB_USB_EP1IN_USED 0 -#endif - -#ifndef SLAB_USB_EP1OUT_USED -#define SLAB_USB_EP1OUT_USED 0 -#endif - -#ifndef SLAB_USB_EP2IN_USED -#define SLAB_USB_EP2IN_USED 0 -#endif - -#ifndef SLAB_USB_EP2OUT_USED -#define SLAB_USB_EP2OUT_USED 0 -#endif - -#ifndef SLAB_USB_EP3IN_USED -#define SLAB_USB_EP3IN_USED 0 -#endif - -#ifndef SLAB_USB_EP3OUT_USED -#define SLAB_USB_EP3OUT_USED 0 -#endif - -#ifndef SLAB_USB_EP1IN_MAX_PACKET_SIZE -#define SLAB_USB_EP1IN_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP1OUT_MAX_PACKET_SIZE -#define SLAB_USB_EP1OUT_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP2IN_MAX_PACKET_SIZE -#define SLAB_USB_EP2IN_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP2OUT_MAX_PACKET_SIZE -#define SLAB_USB_EP2OUT_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP3IN_MAX_PACKET_SIZE -#define SLAB_USB_EP3IN_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP3OUT_MAX_PACKET_SIZE -#define SLAB_USB_EP3OUT_MAX_PACKET_SIZE 64 -#endif - -#ifndef SLAB_USB_EP1IN_TRANSFER_TYPE -#define SLAB_USB_EP1IN_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_EP1OUT_TRANSFER_TYPE -#define SLAB_USB_EP1OUT_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_EP2IN_TRANSFER_TYPE -#define SLAB_USB_EP2IN_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_EP2OUT_TRANSFER_TYPE -#define SLAB_USB_EP2OUT_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_EP3IN_TRANSFER_TYPE -#define SLAB_USB_EP3IN_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_EP3OUT_TRANSFER_TYPE -#define SLAB_USB_EP3OUT_TRANSFER_TYPE USB_EPTYPE_INTR -#endif - -#ifndef SLAB_USB_RESET_CB -#define SLAB_USB_RESET_CB 0 -#endif - -#ifndef SLAB_USB_SOF_CB -#define SLAB_USB_SOF_CB 0 -#endif - -#ifndef SLAB_USB_STATE_CHANGE_CB -#define SLAB_USB_STATE_CHANGE_CB 0 -#endif - -#ifndef SLAB_USB_IS_SELF_POWERED_CB -#define SLAB_USB_IS_SELF_POWERED_CB 0 -#endif - -#ifndef SLAB_USB_SETUP_CMD_CB -#define SLAB_USB_SETUP_CMD_CB 0 -#endif - -#ifndef SLAB_USB_HANDLER_CB -#define SLAB_USB_HANDLER_CB 0 -#endif - -#ifndef SLAB_USB_NUM_LANGUAGES -#define SLAB_USB_NUM_LANGUAGES 1 -#endif - -#ifndef SLAB_USB_LANGUAGE -#define SLAB_USB_LANGUAGE USB_LANGID_ENUS -#endif - -#ifndef SLAB_USB_PWRSAVE_MODE -#define SLAB_USB_PWRSAVE_MODE USB_PWRSAVE_MODE_ONSUSPEND -#endif - -#ifndef SLAB_USB_POLLED_MODE -#define SLAB_USB_POLLED_MODE 0 -#endif - -#if SLAB_USB_POLLED_MODE -void usbIrqHandler(void); -#endif - -/***************************************************************************//** - * @addtogroup efm8_api API Functions - * @{ - ******************************************************************************/ - -/***************************************************************************//** - * @brief - * Abort all pending transfers. - * - * @details - * Aborts transfers for all endpoints currently in use. Pending - * transfers on the default endpoint (EP0) are not aborted. - ******************************************************************************/ -void USBD_AbortAllTransfers(void); - -/***************************************************************************//** - * @brief - * Abort a pending transfer on a specific endpoint. - * - * @param epAddr - * The address of the endpoint to abort. - * @return - * @ref USB_STATUS_OK is the transfer aborted, @ref USB_STATUS_ILLEGAL - * otherwise - ******************************************************************************/ -int8_t USBD_AbortTransfer(uint8_t epAddr); - -/***************************************************************************//** - * @brief - * Start USB device operation. - * - * @details - * Device operation is started by connecting a pull-up resistor on the - * appropriate USB data line. - ******************************************************************************/ -void USBD_Connect(void); - -/***************************************************************************//** - * @brief - * Stop USB device operation. - * - * @details - * Device operation is stopped by disconnecting the pull-up resistor from the - * appropriate USB data line. Often referred to as a "soft" disconnect. - ******************************************************************************/ -void USBD_Disconnect(void); - -/***************************************************************************//** - * @brief - * Check if an endpoint is busy doing a transfer. - * - * @param epAddr - * The address of the endpoint to check. - * - * @return - * True if endpoint is busy, false otherwise. - ******************************************************************************/ -bool USBD_EpIsBusy(uint8_t epAddr); - -/***************************************************************************//** - * @brief - * Get current USB device state. - * - * @return - * Device USB state. See @ref USBD_State_TypeDef. - ******************************************************************************/ -USBD_State_TypeDef USBD_GetUsbState(void); - -/***************************************************************************//** - * @brief - * Initializes USB device hardware and internal protocol stack data structures, - * then connects the data-line (D+ or D-) pullup resistor to signal host that - * enumeration can begin. - * - * @note - * You may later use @ref USBD_Disconnect() and @ref USBD_Connect() to force - * reenumeration. - * - * @param p - * Pointer to device initialization struct. See @ref USBD_Init_TypeDef. - * - * @return - * @ref USB_STATUS_OK on success, else an appropriate error code. - ******************************************************************************/ -int8_t USBD_Init(const USBD_Init_TypeDef *p); - -/***************************************************************************//** - * @brief - * Start a read (OUT) transfer on an endpoint. - * - * @note - * If it is possible that the host will send more data than your device - * expects, round buffer size up to the next multiple of maxpacket size. - * - * @param epAddr - * Endpoint address. - * - * @param dat - * Pointer to transfer data buffer. - * - * @param byteCount - * Transfer length. - * - * @param callback - * Boolean to determine if USB_XferCompleteCb should be called for this - * transfer. - * - * @return - * @ref USB_STATUS_OK on success, else an appropriate error code. - ******************************************************************************/ -int8_t USBD_Read(uint8_t epAddr, - uint8_t *dat, - uint16_t byteCount, - bool callback); - -/***************************************************************************//** - * @brief - * Perform a remote wakeup signaling sequence. - * - * @note - * 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. - ******************************************************************************/ -int8_t USBD_RemoteWakeup(void); - -/***************************************************************************//** - * @brief - * Processes USB events when the library is configured for polled mode - * - * @details - * The USB library can be configured for interrupt (SLAB_USB_POLLED_MODE == 0) - * or polled (SLAB_USB_POLLED_MODE == 1) mode. - * - * When in interrupt mode, the USB interrupt handler will trigger - * when a USB event occurs. Callback functions will be called as needed. - * - * When in polled mode, the application must call USBD_Run() periodically to - * check for and process USB events. This may be useful in complex systems or - * when using an RTOS to perform all USB processing in the main loop instead - * of in the interrupt context. - * - ******************************************************************************/ -void USBD_Run(void); - -/***************************************************************************//** - * @brief - * Set an endpoint in the stalled (halted) state. - * - * @param epAddr - * The address of the endpoint to stall. - * - * @return - * @ref USB_STATUS_OK on success, else an appropriate error code. - ******************************************************************************/ -int8_t USBD_StallEp(int8_t epAddr); - -/***************************************************************************//** - * @brief - * Stop USB device stack operation. - * - * @details - * The data-line pullup resistor is turned off, USB interrupts are disabled, - * and finally the USB pins are disabled. - ******************************************************************************/ -void USBD_Stop(void); - -/***************************************************************************//** - * @brief - * Enters USB suspend mode - * - * @details - * Disables USB transceiver, VDD Monitor, and prefetch engine. Suspends the - * internal regulator and internal oscillator. - * This function will not exit until the device recognizes resume signaling, - * VBUS attachment/removal, or a remote wakeup source interrupt. - * Before exiting, restores the states of the USB transceiver, - * VDD Monitor, prefetch engine, and internal regulator. - ******************************************************************************/ -void USBD_Suspend(void); - -/***************************************************************************//** - * @brief - * Reset stall state on a stalled (halted) endpoint. - * - * @param epAddr - * The address of the endpoint to un-stall. - * - * @return - * @ref USB_STATUS_OK on success, else an appropriate error code. - ******************************************************************************/ -int8_t USBD_UnStallEp(uint8_t epAddr); - -/***************************************************************************//** - * @brief - * Start a write (IN) transfer on an endpoint. - * - * @param epAddr - * Endpoint address. - * - * @param dat - * Pointer to transfer data buffer. This buffer must be WORD (4 byte) aligned. - * - * @param byteCount - * Transfer length. - * - * @param callback - * Boolean to determine if USB_XferCompleteCb should be called for this - * transfer. - * - * @return - * @ref USB_STATUS_OK on success, else an appropriate error code. - ******************************************************************************/ -int8_t USBD_Write(uint8_t epAddr, - uint8_t *dat, - uint16_t byteCount, - bool callback); - -/** @} (end addtogroup efm8_api API Functions) */ - -/***************************************************************************//** - * @addtogroup efm8_callbacks Callback Functions - * @{ - ******************************************************************************/ - -/***************************************************************************//** - * @brief - * USB Handler Entry callback function. - * @details - * Some systems may wish to be in a low-power state when between USB events. - * This low-power state may configure the system clock to a very low - * frequency. In order to reduce the execution time of the USB handler, this - * function is called before the handler executes to allow the system to switch - * to a higher clock source. When all USB processing is complete, - * @ref USBD_ExitHandler() will be called to allow the system to return - * to the low-power state. - * This callback function is optionally enabled by setting - * @ref SLAB_USB_HANDLER_CB to 1. - ******************************************************************************/ -void USBD_EnterHandler(void); - -/***************************************************************************//** - * @brief - * USB Handler Exit callback function. - * @details - * Some systems may wish to be in a low-power state when between USB events. - * This low-power state may configure the system clock to a very low - * frequency. This function is called after all USB processing is finished - * to allow a system that was previously configured by - * @ref USBD_EnterHandler() for high power to return to a low power state. - * This callback function is optionally enabled by setting - * @ref SLAB_USB_HANDLER_CB to 1. - ******************************************************************************/ -void USBD_ExitHandler(void); - -/***************************************************************************//** - * @brief - * USB Reset callback function. - * @details - * Called whenever USB reset signaling is detected on the USB port. - ******************************************************************************/ -void USBD_ResetCb(void); - -/***************************************************************************//** - * @brief - * USB Start Of Frame (SOF) interrupt callback function. - * - * @details - * Called at each SOF interrupt (if enabled), - * - * @param sofNr - * Current frame number. The value rolls over to 0 after 16383 (0x3FFF). - ******************************************************************************/ -void USBD_SofCb(uint16_t sofNr); - -/***************************************************************************//** - * @brief - * USB State change callback function. - * - * @details - * Called whenever the USB state of the device changes - * - * @param oldState - * The device USB state just left. See @ref USBD_State_TypeDef. - * - * @param newState - * New (the current) USB device state. See @ref USBD_State_TypeDef. - ******************************************************************************/ -void USBD_DeviceStateChangeCb(USBD_State_TypeDef oldState, - USBD_State_TypeDef newState); - -/***************************************************************************//** - * @brief - * USB power mode callback function. - * - * @details - * Called whenever the device stack needs to know if the device is currently - * self- or bus-powered. Typically when host has issued a @ref GET_STATUS - * setup command. - * - * @return - * True if self-powered, false otherwise. - ******************************************************************************/ -bool USBD_IsSelfPoweredCb(void); - -/***************************************************************************//** - * @brief - * USB setup request callback function. - * - * @details - * Called on each setup request received from host. This gives the system a - * possibility to extend or override standard requests, and to implement class - * or vendor specific requests. Return @ref USB_STATUS_OK if the request is - * handled, return @ref USB_STATUS_REQ_ERR if it is an illegal request or - * return @ref USB_STATUS_REQ_UNHANDLED to pass the request on to the default - * request handler. - * - * @param setup - * Pointer to a USB setup packet. See @ref USB_Setup_TypeDef. - * - * @return - * An appropriate status/error code. See @ref USB_Status_TypeDef. - ******************************************************************************/ -USB_Status_TypeDef USBD_SetupCmdCb(SI_VARIABLE_SEGMENT_POINTER(setup, - USB_Setup_TypeDef, - MEM_MODEL_SEG)); - -/***************************************************************************//** - * @brief - * USB set interface callback function. - * - * @details - * Called each time the SET_INTERFACE request is made. - * - * @param interface - * Number of the interface to set. - * - * @param altSetting - * Alternate setting for the interface - * - * @return - * @ref USB_STATUS_OK if the alternate interface is valid and can be set, - * @ref USB_STATUS_REQ_ERR otherwise - ******************************************************************************/ -USB_Status_TypeDef USBD_SetInterfaceCb(uint8_t interface, uint8_t altSetting); - -/***************************************************************************//** - * @brief - * Queries the application to see if a remote wakeup occurred. - * @details - * 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 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. - * - ******************************************************************************/ -bool USBD_RemoteWakeupCb(void); - -/***************************************************************************//** - * @brief - * Delays 10 - 15 ms while resume signaling is active during a remote - * wakeup event - * - ******************************************************************************/ -void USBD_RemoteWakeupDelay(void); - -/***************************************************************************//** - * @brief - * Processes USB events when the library is configured for polled mode - * - * @ details - * The USB library can be configured for interrupt - * (@ref SLAB_USB_POLLED_MODE == 0) or polled (@ref SLAB_USB_POLLED_MODE == 1) - * mode. - * - * When in interrupt mode, the USB interrupt handler will trigger - * when a USB event occurs. Callback functions will be called as needed. - * - * When in polled mode, the application must call USBD_Run() periodically to - * check for and process USB events. This may be useful in complex systems or - * when using an RTOS to perform all USB processing in the main loop instead - * of in the interrupt context. - * - ******************************************************************************/ -void USBD_Run(void); - -/***************************************************************************//** - * @brief - * USB transfer complete callback function. - * - * @details - * Called each time a packet is sent on an IN endpoint or received on an - * OUT endpoint. - * - * @param epAddr - * Endpoint on which the transfer occurred - * - * @param status - * Status of the endpoint - * - * @param xferred - * For bulk, interrupt, and control transfers: - * Number of bytes transferred since the last USBD_Write() or USBD_Read() - * call. - * For isochronous IN transfers: - * This parameter is not used - * For isochronous OUT transfers: - * the number of bytes received in the last packet - * - * @param remaining - * For bulk, interrupt, and control transfers: - * Number of bytes left to send or receive on the endpoint - * For isochronous transfers: - * The current index into the circular buffer holding isochronous data - * - * @return - * For bulk, interrupt, and control transfers: - * '0' - * For isochronous IN transfers: - * the number of bytes to transmit in the next packet - * For isochronous OUT ransfers: - * '0' - ******************************************************************************/ -uint16_t USBD_XferCompleteCb(uint8_t epAddr, \ - USB_Status_TypeDef status, \ - uint16_t xferred, \ - uint16_t remaining); - -/** @} (end addtogroup efm8_callbacks Callback Functions) */ - -/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN -// -------------------- FIFO Access Functions --------------------------------- -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 ------------------------------------------ - - // Error if peripheral driver not in use - #include "usb_0.h" - -/** @} (end addtogroup Efm8_usb) */ - -#endif // __SILICON_LABS_EFM8_USB_H__ diff --git a/lib/efm8_usb/src/efm8_usbd.c b/lib/efm8_usb/src/efm8_usbd.c deleted file mode 100644 index 24e2d8d..0000000 --- a/lib/efm8_usb/src/efm8_usbd.c +++ /dev/null @@ -1,755 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#include "si_toolchain.h" -#include "efm8_usb.h" -//#include "assert.h" -#include -#define SLAB_ASSERT(x) -// ----------------------------------------------------------------------------- -// Global Variables - -/// Tracks the state of the USB device and endpoints and contains pointers -/// to all descriptors. -SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG); - -// ----------------------------------------------------------------------------- -// Macros - -/// Returns the requested endpoint object of type USBD_Ep_TypeDef -/// This macro does not check that epAddr is valid, so the calling function -/// should verify epAddr before using the macro. -#define GetEp(epAddr) (&myUsbDevice.ep0 + epAddr) - - -#if SLAB_USB_POLLED_MODE -#define DISABLE_USB_INTS {} -#define ENABLE_USB_INTS {} - -#else -/// Saves the current state of the USB Interrupt Enable to a variable called -/// usbIntsEnabled, then disables USB interrupts. -#define DISABLE_USB_INTS { usbIntsEnabled = USB_GetIntsEnabled(); USB_DisableInts(); } - -/// Sets the USB Interrupt Enable bit to the value of usbIntsEnabled. -/// @ref DISABLE_USB_INTS must be used before this macro is used. -#define ENABLE_USB_INTS { if (usbIntsEnabled) {USB_EnableInts(); } } -#endif // SLAB_USB_POLLED_MODE - -// Function in efm8_usbdint.c to force load the module for libraries -extern void forceModuleLoad_usbint(void); - -// ----------------------------------------------------------------------------- -// USB API Functions - -void USBD_AbortAllTransfers(void) -{ - uint8_t i; - bool usbIntsEnabled; - - USB_SaveSfrPage(); - DISABLE_USB_INTS; - - // Call USBD_AbortTransfer() for each endpoint - for (i = 1; i < SLAB_USB_NUM_EPS_USED; i++) - { - USBD_AbortTransfer(i); - } - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); -} - -int8_t USBD_AbortTransfer(uint8_t epAddr) -{ - USBD_Ep_TypeDef MEM_MODEL_SEG *ep; - uint8_t retVal = USB_STATUS_OK; - bool usbIntsEnabled; - - USB_SaveSfrPage(); - - // Verify this is a valid endpoint address and is not Endpoint 0. - if ((epAddr == EP0) || (epAddr >= SLAB_USB_NUM_EPS_USED)) - { - SLAB_ASSERT(false); - retVal = USB_STATUS_ILLEGAL; - } - else - { - DISABLE_USB_INTS; - ep = GetEp(epAddr); - - // If the state of the endpoint is already idle, there is not need to abort - // a transfer - if (ep->state != D_EP_IDLE) - { - switch (epAddr) - { - #if SLAB_USB_EP1IN_USED - case EP1IN: - USB_AbortInEp(1); - break; - #endif - #if SLAB_USB_EP2IN_USED - case EP2IN: - USB_AbortInEp(2); - break; - #endif - #if SLAB_USB_EP3IN_USED - case EP3IN: - USB_AbortInEp(3); - break; - #endif - #if SLAB_USB_EP1OUT_USED - case EP1OUT: - USB_AbortOutEp(1); - break; - #endif - #if SLAB_USB_EP2OUT_USED - case EP2OUT: - USB_AbortOutEp(2); - break; - #endif - #if SLAB_USB_EP3OUT_USED - case EP3OUT: - USB_AbortOutEp(3); - break; - #endif - } - - // Set the endpoint state to idle and clear out endpoint state variables - ep->state = D_EP_IDLE; - ep->misc.c = 0; - } - } - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); - - return retVal; -} - -void USBD_Connect(void) -{ - USB_SaveSfrPage(); - myUsbDevice.ep0.state = D_EP_IDLE; - USB_EnablePullUpResistor(); - USB_EnableTransceiver(); - USB_RestoreSfrPage(); -} - -void USBD_Disconnect(void) -{ - USB_SaveSfrPage(); - USB_DisablePullUpResistor(); - USB_RestoreSfrPage(); -} - -bool USBD_EpIsBusy(uint8_t epAddr) -{ - USBD_Ep_TypeDef MEM_MODEL_SEG *ep; - - // Verify this is a valid endpoint address - if (epAddr >= SLAB_USB_NUM_EPS_USED) - { - SLAB_ASSERT(false); - return true; - } - - ep = GetEp(epAddr); - - if (ep->state == D_EP_IDLE) - { - return false; - } - - return true; -} - -USBD_State_TypeDef USBD_GetUsbState(void) -{ - return myUsbDevice.state; -} - -int8_t USBD_Init(const USBD_Init_TypeDef *p) -{ - uint8_t i; - - USB_SaveSfrPage(); - USB_DisableInts(); - - // This forces the liner to bring in the contents efm8_usbdint - // It is place here since all users MUST call this function - // for the library to work properly - forceModuleLoad_usbint(); - - - // Zero out the myUsbDevice struct, then initialize all non-zero members - for (i = 0; i < sizeof(myUsbDevice); i++) - { - *((uint8_t MEM_MODEL_SEG *)&myUsbDevice + i) = 0; - } - - // Get the USB descriptors from p - myUsbDevice.deviceDescriptor = p->deviceDescriptor; - myUsbDevice.configDescriptor = (USB_ConfigurationDescriptor_TypeDef *)p->configDescriptor; - myUsbDevice.stringDescriptors = p->stringDescriptors; - myUsbDevice.numberOfStrings = p->numberOfStrings; - - // Enable USB clock -#if SLAB_USB_FULL_SPEED - USB_SetClockIntOsc(); - USB_SelectFullSpeed(); -#else - USB_SetClockIntOscDiv8(); - USB_SelectLowSpeed(); -#endif // SLAB_USB_FULL_SPEED - - // Enable or disable VBUS detection -#if SLAB_USB_BUS_POWERED - USB_VbusDetectDisable(); -#else - USB_VbusDetectEnable(); -#endif - - USB_ForceReset(); - USB_EnableDeviceInts(); - USBD_Connect(); - - // If VBUS is present, the state should be Default. - // Otherwise, it is Attached. -#if SLAB_USB_BUS_POWERED - myUsbDevice.state = USBD_STATE_DEFAULT; -#else - if (USB_IsVbusOn()) - { - myUsbDevice.state = USBD_STATE_DEFAULT; - } - else - { - myUsbDevice.state = USBD_STATE_ATTACHED; - } -#endif - - // Only enable USB interrupts when not in polled mode -#if (SLAB_USB_POLLED_MODE == 0) - USB_EnableInts(); -#endif - - USB_RestoreSfrPage(); - USB_DisableInhibit(); - - return USB_STATUS_OK; -} - -int8_t USBD_Read(uint8_t epAddr, - uint8_t *dat, - uint16_t byteCount, - bool callback) -{ - bool usbIntsEnabled; - USBD_Ep_TypeDef MEM_MODEL_SEG *ep; - - USB_SaveSfrPage(); - - // Verify the endpoint address is valid. - switch (epAddr) - { - case EP0: -#if SLAB_USB_EP1OUT_USED - case EP1OUT: -#endif -#if SLAB_USB_EP2OUT_USED - case EP2OUT: -#endif -#if SLAB_USB_EP3OUT_USED - case EP3OUT: -#endif - break; -#if SLAB_USB_EP1IN_USED - case EP1IN: -#endif -#if SLAB_USB_EP2IN_USED - case EP2IN: -#endif -#if SLAB_USB_EP3IN_USED - case EP3IN: -#endif - default: - SLAB_ASSERT(false); - return USB_STATUS_ILLEGAL; - } - - // If the device has not been configured, we cannot start a transfer. - if ((epAddr != EP0) && (myUsbDevice.state != USBD_STATE_CONFIGURED)) - { - return USB_STATUS_DEVICE_UNCONFIGURED; - } - - ep = GetEp(epAddr); - - // If the endpoint is not idle, we cannot start a new transfer. - // Return the appropriate error code. - if (ep->state != D_EP_IDLE) - { - if (ep->state == D_EP_STALL) - { - return USB_STATUS_EP_STALLED; - } - else - { - return USB_STATUS_EP_BUSY; - } - } - - DISABLE_USB_INTS; - - ep->buf = dat; - ep->remaining = byteCount; - ep->state = D_EP_RECEIVING; - ep->misc.bits.callback = callback; - ep->misc.bits.waitForRead = false; - - // If isochronous, set the buffer index to 0 -#if ((SLAB_USB_EP3OUT_USED) && (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)) - if (epAddr == EP3OUT) - { - myUsbDevice.ep3outIsoIdx = 0; - } -#endif - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); - - return USB_STATUS_OK; -} - -#if SLAB_USB_REMOTE_WAKEUP_ENABLED -int8_t USBD_RemoteWakeup(void) -{ - // The device must be suspended and Remote Wakeup must have been previously - // configured with a SET_FEATURE (Remote Wakeup) command. - if ((myUsbDevice.state != USBD_STATE_SUSPENDED) || - (myUsbDevice.remoteWakeupEnabled == false)) - { - return USB_STATUS_ILLEGAL; - } - - USB_ForceResume(); - USBD_RemoteWakeupDelay(); // Application will provide the delay between - // starting and stopping the resume signal. - USB_ClearResume(); - - return USB_STATUS_OK; -} -#endif // SLAB_USB_REMOTE_WAKEUP_ENABLED - -#if SLAB_USB_POLLED_MODE -void USBD_Run(void) -{ - usbIrqHandler(); -} -#endif // SLAB_USB_POLLED_MODE - -int8_t USBD_StallEp(uint8_t epAddr) -{ - bool usbIntsEnabled; - - USB_SaveSfrPage(); - - // Verify the endpoint address is valid and not Endpoint 0. - if ((epAddr == EP0) || (epAddr >= SLAB_USB_NUM_EPS_USED)) - { - SLAB_ASSERT(false); - return USB_STATUS_ILLEGAL; - } - - DISABLE_USB_INTS; - - // Halt the appropriate endpoint by sending a stall and setting the endpoint - // state to Halted (D_EP_HALT). - switch (epAddr) - { -#if SLAB_USB_EP1IN_USED - case (EP1IN): - myUsbDevice.ep1in.state = D_EP_HALT; - USB_SetIndex(1); - USB_EpnInStall(); - break; -#endif -#if SLAB_USB_EP2IN_USED - case (EP2IN): - myUsbDevice.ep2in.state = D_EP_HALT; - USB_SetIndex(2); - USB_EpnInStall(); - break; -#endif -#if SLAB_USB_EP3IN_USED - case (EP3IN): - myUsbDevice.ep3in.state = D_EP_HALT; - USB_SetIndex(3); - USB_EpnInStall(); - break; -#endif -#if SLAB_USB_EP1OUT_USED - case (EP1OUT): - myUsbDevice.ep1out.state = D_EP_HALT; - USB_SetIndex(1); - USB_EpnOutStall(); - break; -#endif -#if SLAB_USB_EP2OUT_USED - case (EP2OUT): - myUsbDevice.ep2out.state = D_EP_HALT; - USB_SetIndex(2); - USB_EpnOutStall(); - break; -#endif -#if SLAB_USB_EP3OUT_USED - case (EP3OUT): - myUsbDevice.ep3out.state = D_EP_HALT; - USB_SetIndex(3); - USB_EpnOutStall(); - break; -#endif - } - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); - - return USB_STATUS_OK; -} - -void USBD_Stop(void) -{ - USB_DisableInts(); - USBD_Disconnect(); - USBD_SetUsbState(USBD_STATE_NONE); -} - -void USBD_Suspend(void) -{ - uint8_t i; - bool regulatorEnabled, prefetchEnabled; - - USB_SaveSfrPage(); - - // If the USB_PWRSAVE_MODE_ONVBUSOFF is enabled, we can enter suspend if VBUS - // is not present even if the USB has not detected a suspend event. -#if ((!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF)) || \ - (SLAB_USB_BUS_POWERED)) - if (USB_IsSuspended() == true) -#else - if ((USB_IsSuspended() == true) || (USB_IsVbusOn() == false)) -#endif - { - USB_SuspendTransceiver(); - -#if SLAB_USB_FULL_SPEED - USB_SetSuspendClock(); -#endif - - // Get the state of the prefetch engine enable bit and disable the prefetch - // engine - prefetchEnabled = USB_IsPrefetchEnabled(); - USB_DisablePrefetch(); - - // Get the state of the internal regulator before suspending it. - if (USB_IsRegulatorEnabled() == true) - { - regulatorEnabled = true; - -#if (SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_FASTWAKE) - USB_SuspendRegulatorFastWake(); -#else - USB_SuspendRegulator(); - - // Wait at least 12 clock instructions before halting the internal oscillator - for (i = 0; i < 3; i++) - { - } -#endif - } - else - { - regulatorEnabled = false; - } - - do - { - USB_SuspendOscillator(); - - // When we arrive here, the device has waked from suspend mode. - -#if SLAB_USB_REMOTE_WAKEUP_ENABLED - // If remote wakeup is enabled, query the application if the remote - // wakeup event occurred. If so, exit USBD_Suspend(). - if (USB_IsSuspended() == true) - { - if (USBD_RemoteWakeupCb() == true) - { - break; - } - } -#endif -#if ((!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF)) && \ - (SLAB_USB_BUS_POWERED == 0)) - // If the USB_PWRSAVE_MODE_ONVBUSOFF mode is disabled, VBUS has been - // removed, so exit USBD_Suspend(). - if (USB_IsVbusOn() == false) - { - break; - } -#endif - } while (USB_IsSuspended() == true); - - // Restore the internal regulator - if (regulatorEnabled == true) - { - USB_UnsuspendRegulator(); - } - - // Restore the prefetch engine - if (prefetchEnabled == true) - { - USB_EnablePrefetch(); - } - -#if SLAB_USB_FULL_SPEED - // Restore the clock - USB_SetNormalClock(); -#endif - USB_EnableTransceiver(); - } - - USB_RestoreSfrPage(); -} - -int8_t USBD_UnStallEp(uint8_t epAddr) -{ - bool usbIntsEnabled; - - USB_SaveSfrPage(); - - // Verify the endpoint address is valid and not Endpoint 0. - if ((epAddr == EP0) || (epAddr >= SLAB_USB_NUM_EPS_USED)) - { - SLAB_ASSERT(false); - return USB_STATUS_ILLEGAL; - } - else - { - DISABLE_USB_INTS; - - // End the stall condition and set the endpoint state to idle. - switch (epAddr) - { -#if SLAB_USB_EP1IN_USED - case (EP1IN): - myUsbDevice.ep1in.state = D_EP_IDLE; - USB_SetIndex(1); - USB_EpnInEndStall(); - break; -#endif -#if SLAB_USB_EP2IN_USED - case (EP2IN): - myUsbDevice.ep2in.state = D_EP_IDLE; - USB_SetIndex(2); - USB_EpnInEndStall(); - break; -#endif -#if SLAB_USB_EP3IN_USED - case (EP3IN): - myUsbDevice.ep3in.state = D_EP_IDLE; - USB_SetIndex(3); - USB_EpnInEndStall(); - break; -#endif -#if SLAB_USB_EP1OUT_USED - case (EP1OUT): - myUsbDevice.ep1out.state = D_EP_IDLE; - USB_SetIndex(1); - USB_EpnOutEndStall(); - break; -#endif -#if SLAB_USB_EP2OUT_USED - case (EP2OUT): - myUsbDevice.ep2out.state = D_EP_IDLE; - USB_SetIndex(2); - USB_EpnOutEndStall(); - break; -#endif -#if SLAB_USB_EP3OUT_USED - case (EP3OUT): - myUsbDevice.ep3out.state = D_EP_IDLE; - USB_SetIndex(3); - USB_EpnOutEndStall(); - break; -#endif - } - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); - } - - return USB_STATUS_OK; -} - -int8_t USBD_Write(uint8_t epAddr, - uint8_t *dat, - uint16_t byteCount, - bool callback) -{ - bool usbIntsEnabled; - USBD_Ep_TypeDef MEM_MODEL_SEG *ep; - - USB_SaveSfrPage(); - - // Verify the endpoint address is valid. - switch (epAddr) - { - case EP0: -#if SLAB_USB_EP1IN_USED - case EP1IN: -#endif -#if SLAB_USB_EP2IN_USED - case EP2IN: -#endif -#if SLAB_USB_EP3IN_USED - case EP3IN: -#endif - break; -#if SLAB_USB_EP1OUT_USED - case EP1OUT: -#endif -#if SLAB_USB_EP2OUT_USED - case EP2OUT: -#endif -#if SLAB_USB_EP3OUT_USED - case EP3OUT: -#endif - default: - SLAB_ASSERT(false); - return USB_STATUS_ILLEGAL; - } - - // If the device is not configured and it is not Endpoint 0, we cannot begin - // a transfer. - if ((epAddr != EP0) && (myUsbDevice.state != USBD_STATE_CONFIGURED)) - { - return USB_STATUS_DEVICE_UNCONFIGURED; - } - - ep = GetEp(epAddr); - - // If the endpoint is not idle, we cannot start a new transfer. - // Return the appropriate error code. - if (ep->state != D_EP_IDLE) - { - if (ep->state == D_EP_STALL) - { - return USB_STATUS_EP_STALLED; - } - else - { - return USB_STATUS_EP_BUSY; - } - } - - DISABLE_USB_INTS; - - ep->buf = dat; - ep->remaining = byteCount; - ep->state = D_EP_TRANSMITTING; - ep->misc.bits.callback = callback; - - switch (epAddr) - { - // For Endpoint 0, set the inPacketPending flag to true. The USB handler - // will see this on the next SOF and begin the transfer. - case (EP0): - myUsbDevice.ep0.misc.bits.inPacketPending = true; - break; - - // For data endpoints, we will call USB_WriteFIFO here to reduce latency - // between the call to USBD_Write() and the first packet being sent. -#if SLAB_USB_EP1IN_USED - case (EP1IN): - USB_WriteFIFO(1, - (byteCount > SLAB_USB_EP1IN_MAX_PACKET_SIZE) ? SLAB_USB_EP1IN_MAX_PACKET_SIZE : byteCount, - myUsbDevice.ep1in.buf, - true); - break; -#endif // SLAB_USB_EP1IN_USED -#if SLAB_USB_EP2IN_USED - case (EP2IN): - USB_WriteFIFO(2, - (byteCount > SLAB_USB_EP2IN_MAX_PACKET_SIZE) ? SLAB_USB_EP2IN_MAX_PACKET_SIZE : byteCount, - myUsbDevice.ep2in.buf, - true); - break; -#endif // SLAB_USB_EP2IN_USED -#if SLAB_USB_EP3IN_USED - case (EP3IN): -#if ((SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_INTR)) - USB_WriteFIFO(3, - (byteCount > SLAB_USB_EP3IN_MAX_PACKET_SIZE) ? SLAB_USB_EP3IN_MAX_PACKET_SIZE : byteCount, - myUsbDevice.ep3in.buf, - true); -#elif (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC) - myUsbDevice.ep3in.misc.bits.inPacketPending = true; - myUsbDevice.ep3inIsoIdx = 0; -#endif - break; -#endif // SLAB_USB_EP3IN_USED - } - - ENABLE_USB_INTS; - USB_RestoreSfrPage(); - - return USB_STATUS_OK; -} - -// ----------------------------------------------------------------------------- -// UtilityFunctions - -void USBD_SetUsbState(USBD_State_TypeDef newState) -{ -#if (SLAB_USB_SUPPORT_ALT_INTERFACES) - uint8_t i; -#endif - USBD_State_TypeDef currentState; - - currentState = myUsbDevice.state; - - // If the device is un-configuring, disable the data endpoints and clear out - // alternate interface settings - if ((currentState >= USBD_STATE_SUSPENDED) - && (newState < USBD_STATE_SUSPENDED)) - { - USBD_AbortAllTransfers(); - -#if (SLAB_USB_SUPPORT_ALT_INTERFACES) - for (i = 0; i < SLAB_USB_NUM_INTERFACES; i++) - { - myUsbDevice.interfaceAltSetting[i] = 0; - } -#endif - } - if (newState == USBD_STATE_SUSPENDED) - { - myUsbDevice.savedState = currentState; - } - - myUsbDevice.state = newState; - -#if SLAB_USB_STATE_CHANGE_CB - if (currentState != newState) - { - USBD_DeviceStateChangeCb(currentState, newState); - } -#endif -} diff --git a/lib/efm8_usb/src/efm8_usbdch9.c b/lib/efm8_usb/src/efm8_usbdch9.c deleted file mode 100644 index c0afa23..0000000 --- a/lib/efm8_usb/src/efm8_usbdch9.c +++ /dev/null @@ -1,880 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#include "si_toolchain.h" -#include "efm8_usb.h" -#include -#include - -// ----------------------------------------------------------------------------- -// Function Prototypes - -static USB_Status_TypeDef ClearFeature(void); -static USB_Status_TypeDef GetConfiguration(void); -static USB_Status_TypeDef GetDescriptor(void); -static USB_Status_TypeDef GetInterface(void); -static USB_Status_TypeDef GetStatus(void); -static USB_Status_TypeDef SetAddress(void); -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(uint8_t *dat, uint16_t numBytes); -void SendEp0Stall(void); - -// ----------------------------------------------------------------------------- -// Global Variables - -extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG); -SI_SEGMENT_VARIABLE(txZero[2], uint8_t, SI_SEG_CODE); - -// ----------------------------------------------------------------------------- -// Static Global Variables - -static uint16_t pStatus; - -// ----------------------------------------------------------------------------- -// Chapter 9 Functions - -/***************************************************************************//** - * @brief Processes Standard Request (Chapter 9 Command) - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -USB_Status_TypeDef USBDCH9_SetupCmd(void) -{ - USB_Status_TypeDef status = USB_STATUS_OK; - - switch (myUsbDevice.setup.bRequest) - { - case GET_STATUS: - status = GetStatus(); - break; - - case CLEAR_FEATURE: - status = ClearFeature(); - break; - - case SET_FEATURE: - status = SetFeature(); - break; - - case SET_ADDRESS: - status = SetAddress(); - break; - - case GET_DESCRIPTOR: - status = GetDescriptor(); - break; - - case GET_CONFIGURATION: - status = GetConfiguration(); - break; - - case SET_CONFIGURATION: - status = SetConfiguration(); - break; - - case GET_INTERFACE: - status = GetInterface(); - break; - - case SET_INTERFACE: - status = SetInterface(); - break; - - default: - status = USB_STATUS_REQ_ERR; - 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; -} - -/***************************************************************************//** - * @brief Clears the requested feature - * @details Supports CLEAR_FEATURE for Remote Wakeup and Endpoint Halt - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef ClearFeature(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if (myUsbDevice.setup.wLength == 0) - { - switch (myUsbDevice.setup.bmRequestType.Recipient) - { - #if SLAB_USB_REMOTE_WAKEUP_ENABLED - case USB_SETUP_RECIPIENT_DEVICE: - if ((myUsbDevice.setup.wIndex == 0) - && (myUsbDevice.setup.wValue == USB_FEATURE_DEVICE_REMOTE_WAKEUP) - && (myUsbDevice.state >= USBD_STATE_ADDRESSED)) - { - // Remote wakeup feature clear - myUsbDevice.remoteWakeupEnabled = false; - retVal = USB_STATUS_OK; - } - break; - #endif // SLAB_USB_REMOTE_WAKEUP_ENABLED - case USB_SETUP_RECIPIENT_ENDPOINT: - if (myUsbDevice.setup.wValue == USB_FEATURE_ENDPOINT_HALT) - { - // Device does not support halting endpoint 0, but do not return - // an error as this is a valid request - if (((myUsbDevice.setup.wIndex & ~USB_EP_DIR_IN) == 0) - && (myUsbDevice.state >= USBD_STATE_ADDRESSED)) - { - retVal = USB_STATUS_OK; - } - else if (((myUsbDevice.setup.wIndex & ~USB_SETUP_DIR_D2H) < SLAB_USB_NUM_EPS_USED) - && (myUsbDevice.state == USBD_STATE_CONFIGURED)) - { - retVal = USB_STATUS_OK; - USB_SetIndex((myUsbDevice.setup.wIndex & 0xFF) & ~USB_SETUP_DIR_D2H); - -#if (SLAB_USB_EP1IN_USED || SLAB_USB_EP2IN_USED || SLAB_USB_EP3IN_USED) - if ((myUsbDevice.setup.wIndex & 0xFF) & USB_EP_DIR_IN) - { - USB_EpnInEndStallAndClearDataToggle(); - } -#endif -#if (SLAB_USB_EP1OUT_USED || SLAB_USB_EP2OUT_USED || SLAB_USB_EP3OUT_USED) - if (((myUsbDevice.setup.wIndex & 0xFF) & USB_EP_DIR_IN) == 0) - { - USB_EpnOutEndStallAndClearDataToggle(); - } -#endif - - switch (myUsbDevice.setup.wIndex & 0xFF) - { -#if SLAB_USB_EP1OUT_USED - case (USB_EP_DIR_OUT | 1): - if (myUsbDevice.ep1out.state != D_EP_RECEIVING) - { - myUsbDevice.ep1out.state = D_EP_IDLE; - } - break; -#endif -#if SLAB_USB_EP2OUT_USED - case (USB_EP_DIR_OUT | 2): - if (myUsbDevice.ep2out.state != D_EP_RECEIVING) - { - myUsbDevice.ep2out.state = D_EP_IDLE; - } - break; -#endif -#if SLAB_USB_EP3OUT_USED - case (USB_EP_DIR_OUT | 3): - if (myUsbDevice.ep3out.state != D_EP_RECEIVING) - { - myUsbDevice.ep3out.state = D_EP_IDLE; - } - break; -#endif -#if SLAB_USB_EP1IN_USED - case (USB_EP_DIR_IN | 1): - if (myUsbDevice.ep1in.state != D_EP_TRANSMITTING) - { - myUsbDevice.ep1in.state = D_EP_IDLE; - } - break; -#endif -#if SLAB_USB_EP2IN_USED - case (USB_EP_DIR_IN | 2): - if (myUsbDevice.ep2in.state != D_EP_TRANSMITTING) - { - myUsbDevice.ep2in.state = D_EP_IDLE; - } - break; -#endif -#if SLAB_USB_EP3IN_USED - case (USB_EP_DIR_IN | 3): - if (myUsbDevice.ep3in.state != D_EP_TRANSMITTING) - { - myUsbDevice.ep3in.state = D_EP_IDLE; - } - break; -#endif - } - } - } - } - } - return retVal; -} - -/***************************************************************************//** - * @brief Gets the current configuration value - * @details Zero means the device is not configured, a non-zero value - * is the configuration value of the configured device. - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef GetConfiguration(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if ((myUsbDevice.setup.wIndex == 0) - && (myUsbDevice.setup.wValue == 0) - && (myUsbDevice.setup.wLength == 1) - && (myUsbDevice.setup.bmRequestType.Direction == USB_SETUP_DIR_IN) - && (myUsbDevice.setup.bmRequestType.Recipient == USB_SETUP_RECIPIENT_DEVICE)) - { - if (myUsbDevice.state == USBD_STATE_ADDRESSED) - { - EP0_Write(txZero, 1); - retVal = USB_STATUS_OK; - } - else if (myUsbDevice.state == USBD_STATE_CONFIGURED) - { - EP0_Write(&myUsbDevice.configurationValue, 1); - retVal = USB_STATUS_OK; - } - } - return retVal; -} - -/***************************************************************************//** - * @brief Sends the requested USB Descriptor - * @details Supports single or multiple languages (configured by - * @ref SLAB_USB_NUM_LANGUAGES). - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef GetDescriptor(void) -{ -#if (SLAB_USB_NUM_LANGUAGES > 1) - bool langSupported; - uint8_t lang; -#endif - - uint8_t index; - uint16_t length = 0; - uint8_t *dat; - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if (*((uint8_t *)&myUsbDevice.setup.bmRequestType) == - (USB_SETUP_DIR_D2H | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_DEVICE)) - { - index = myUsbDevice.setup.wValue & 0xFF; - - switch (myUsbDevice.setup.wValue >> 8) - { - case USB_DEVICE_DESCRIPTOR: - if (index != 0) - { - break; - } - dat = (uint8_t *)myUsbDevice.deviceDescriptor; - length = myUsbDevice.deviceDescriptor->bLength; - break; - - case USB_CONFIG_DESCRIPTOR: - if (index != 0) - { - break; - } - dat = (uint8_t *)myUsbDevice.configDescriptor; - length = le16toh(myUsbDevice.configDescriptor->wTotalLength); - break; - - case USB_STRING_DESCRIPTOR: - #if (SLAB_USB_NUM_LANGUAGES == 1) - - 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. - if (index == 0) - { - length = 4; - myUsbDevice.ep0String.encoding.type = USB_STRING_DESCRIPTOR_UTF16LE; - } - // Otherwise, verify the language is correct (either the value set as - // SLAB_USB_LANGUAGE in usbconfig.h, or 0). - else if ((myUsbDevice.setup.wIndex == 0) || (myUsbDevice.setup.wIndex == SLAB_USB_LANGUAGE)) - { - // Verify the index is valid - if (index < myUsbDevice.numberOfStrings) - { - length = *(dat + USB_STRING_DESCRIPTOR_LENGTH); - myUsbDevice.ep0String.encoding.type = *(dat + USB_STRING_DESCRIPTOR_ENCODING); - dat += USB_STRING_DESCRIPTOR_LENGTH; - myUsbDevice.ep0String.encoding.init = true; - } - } - #elif (SLAB_USB_NUM_LANGUAGES > 1) - - langSupported = false; - - // Index 0 is the language. - if (index == 0) - { - dat = ((uint8_t *)myUsbDevice.stringDescriptors->languageArray[0][index]); - length = *((uint8_t *)dat); - myUsbDevice.ep0String.encoding.type = USB_STRING_DESCRIPTOR_UTF16LE; - } - else - { - // Otherwise, verify the language is one of the supported languages or 0. - for (lang = 0; lang < SLAB_USB_NUM_LANGUAGES; lang++) - { - if ((myUsbDevice.stringDescriptors->languageIDs[lang] == myUsbDevice.setup.wIndex) - || (myUsbDevice.stringDescriptors->languageIDs[lang] == 0)) - { - langSupported = true; - break; - } - } - if ((langSupported == true) && (index < myUsbDevice.numberOfStrings)) - { - 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; - - if (myUsbDevice.ep0String.encoding.type == USB_STRING_DESCRIPTOR_UTF16LE_PACKED) - { - myUsbDevice.ep0String.encoding.init = true; - } - else - { - myUsbDevice.ep0String.encoding.init = false; - } - } - } - #endif // ( SLAB_USB_NUM_LANGUAGES == 1 ) - } - - // If there is a descriptor to send, get the proper length, then call - // EP0_Write() to send. - if (length) - { - if (length > myUsbDevice.setup.wLength) - { - length = myUsbDevice.setup.wLength; - } - - EP0_Write(dat, length); - - retVal = USB_STATUS_OK; - } - } - - return retVal; -} - -/***************************************************************************//** - * @brief Sends the current interface alternate setting - * @details Sends 0x0000 if alternate interfaces are not supported. - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef GetInterface(void) -{ - uint16_t interface = myUsbDevice.setup.wIndex; - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if ((interface < SLAB_USB_NUM_INTERFACES) - && (myUsbDevice.setup.wLength == 1) - && (myUsbDevice.setup.wValue == 0) - && (*((uint8_t *)&myUsbDevice.setup.bmRequestType) == - (USB_SETUP_DIR_D2H | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_INTERFACE))) - { - if (myUsbDevice.state == USBD_STATE_CONFIGURED) - { -#if (SLAB_USB_SUPPORT_ALT_INTERFACES) - // Return the alternate setting for the specified interface - EP0_Write(&myUsbDevice.interfaceAltSetting[interface], 1); -#else - // Alternate interfaces are not supported, so return 0x0000. - EP0_Write(&txZero, 1); -#endif - retVal = USB_STATUS_OK; - } - } - return retVal; -} - -/***************************************************************************//** - * @brief Sends the requested Remote Wakeup, Self-Powered, or - * Endpoint Status - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef GetStatus(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if ((myUsbDevice.setup.wLength == 2) - && (myUsbDevice.setup.wValue == 0) - && (myUsbDevice.setup.bmRequestType.Direction == USB_SETUP_DIR_IN) - && (myUsbDevice.state >= USBD_STATE_ADDRESSED)) - { - pStatus = htole16(0); // Default return value is 0x0000 - - switch (myUsbDevice.setup.bmRequestType.Recipient) - { - case USB_SETUP_RECIPIENT_DEVICE: - if (myUsbDevice.setup.wIndex == 0) - { - #if SLAB_USB_REMOTE_WAKEUP_ENABLED - // Remote wakeup feature status - if (myUsbDevice.remoteWakeupEnabled) - { - pStatus |= htole16(REMOTE_WAKEUP_ENABLED); - } - #endif // SLAB_USB_REMOTE_WAKEUP_ENABLED - - #if SLAB_USB_IS_SELF_POWERED_CB - // Current self/bus power status - if (USBD_IsSelfPoweredCb()) - { - pStatus |= htole16(DEVICE_IS_SELFPOWERED); - } - #elif (SLAB_USB_BUS_POWERED == 0) - pStatus |= htole16(DEVICE_IS_SELFPOWERED); - #endif // SLAB_USB_IS_SELF_POWERED_CB - - retVal = USB_STATUS_OK; - } - break; - - case USB_SETUP_RECIPIENT_INTERFACE: - if (myUsbDevice.setup.wIndex < SLAB_USB_NUM_INTERFACES) - { - retVal = USB_STATUS_OK; - } - break; - - - case USB_SETUP_RECIPIENT_ENDPOINT: - // Device does not support halting endpoint 0, but do not give - // an error as this is a valid request - if (((myUsbDevice.setup.wIndex & ~USB_EP_DIR_IN) == 0) - && (myUsbDevice.state == USBD_STATE_ADDRESSED)) - { - retVal = USB_STATUS_OK; - } - else if (myUsbDevice.state == USBD_STATE_CONFIGURED) - { - switch (myUsbDevice.setup.wIndex & 0xFF) - { - #if SLAB_USB_EP1OUT_USED - case (USB_EP_DIR_OUT | 1): - if (myUsbDevice.ep1out.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - #if SLAB_USB_EP2OUT_USED - case (USB_EP_DIR_OUT | 2): - if (myUsbDevice.ep2out.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - #if SLAB_USB_EP3OUT_USED - case (USB_EP_DIR_OUT | 3): - if (myUsbDevice.ep3out.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - #if SLAB_USB_EP1IN_USED - case (USB_EP_DIR_IN | 1): - if (myUsbDevice.ep1in.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - #if SLAB_USB_EP2IN_USED - case (USB_EP_DIR_IN | 2): - if (myUsbDevice.ep2in.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - #if SLAB_USB_EP3IN_USED - case (USB_EP_DIR_IN | 3): - if (myUsbDevice.ep3in.state == D_EP_HALT) - { - pStatus = htole16(1); - } - retVal = USB_STATUS_OK; - break; - #endif - } - } - break; - } - - // If the command was valid, send the requested status. - if (retVal == USB_STATUS_OK) - { - EP0_Write((uint8_t *)&pStatus, 2); - } - } - - return retVal; -} - -/***************************************************************************//** - * @brief Sets the Address - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef SetAddress(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if ((myUsbDevice.setup.wValue < 128) - && (myUsbDevice.setup.wLength == 0) - && (myUsbDevice.setup.bmRequestType.Recipient == USB_SETUP_RECIPIENT_DEVICE) - && (myUsbDevice.setup.wIndex == 0)) - { - // If the device is in the Default state and the address is non-zero, put - // the device in the Addressed state. - if (myUsbDevice.state == USBD_STATE_DEFAULT) - { - if (myUsbDevice.setup.wValue != 0) - { - USBD_SetUsbState(USBD_STATE_ADDRESSED); - } - retVal = USB_STATUS_OK; - } - // If the device is already addressed and the address is zero, put the - // device in the Default state. - else if (myUsbDevice.state == USBD_STATE_ADDRESSED) - { - if (myUsbDevice.setup.wValue == 0) - { - USBD_SetUsbState(USBD_STATE_DEFAULT); - } - retVal = USB_STATUS_OK; - } - - // Set the new address if the request was valid. - if (retVal == USB_STATUS_OK) - { - USB_SetAddress(myUsbDevice.setup.wValue); - } - } - - return retVal; -} - -/***************************************************************************//** - * @brief Sets the Configuration - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef SetConfiguration(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if (((myUsbDevice.setup.wValue >> 8) == 0) - && (myUsbDevice.setup.bmRequestType.Recipient == USB_SETUP_RECIPIENT_DEVICE) - && (myUsbDevice.setup.wLength == 0) - && (myUsbDevice.setup.wIndex == 0)) - { - // If the device is in the Addressed state and a valid Configuration value - // was sent, enter the Configured state. - if (myUsbDevice.state == USBD_STATE_ADDRESSED) - { - if ((myUsbDevice.setup.wValue == 0) - || (myUsbDevice.setup.wValue == myUsbDevice.configDescriptor->bConfigurationValue)) - { - myUsbDevice.configurationValue = myUsbDevice.setup.wValue; - if (myUsbDevice.setup.wValue == myUsbDevice.configDescriptor->bConfigurationValue) - { - USBD_ActivateAllEps(true); - USBD_SetUsbState(USBD_STATE_CONFIGURED); - } - retVal = USB_STATUS_OK; - } - } - // If the device is in the Configured state and Configuration zero is sent, - // abort all transfer and enter the Addressed state. - else if (myUsbDevice.state == USBD_STATE_CONFIGURED) - { - if ((myUsbDevice.setup.wValue == 0) - || (myUsbDevice.setup.wValue == myUsbDevice.configDescriptor->bConfigurationValue)) - { - myUsbDevice.configurationValue = myUsbDevice.setup.wValue; - if (myUsbDevice.setup.wValue == 0) - { - USBD_SetUsbState(USBD_STATE_ADDRESSED); - USBD_AbortAllTransfers(); - } - else - { - // Reenable device endpoints, will reset data toggles - USBD_ActivateAllEps(false); - } - retVal = USB_STATUS_OK; - } - } - } - - return retVal; -} - -/***************************************************************************//** - * @brief Sets the Remote Wakeup or Endpoint Halt Feature - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef SetFeature(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - - if (myUsbDevice.setup.wLength == 0) - { - switch (myUsbDevice.setup.bmRequestType.Recipient) - { - #if SLAB_USB_REMOTE_WAKEUP_ENABLED - case USB_SETUP_RECIPIENT_DEVICE: - if ((myUsbDevice.setup.wIndex == 0) // ITF no. 0 - && (myUsbDevice.setup.wValue == USB_FEATURE_DEVICE_REMOTE_WAKEUP) - && (myUsbDevice.state == USBD_STATE_CONFIGURED)) - { - myUsbDevice.remoteWakeupEnabled = true; - retVal = USB_STATUS_OK; - } - break; - #endif // SLAB_USB_REMOTE_WAKEUP_ENABLED - case USB_SETUP_RECIPIENT_ENDPOINT: - // Device does not support halting endpoint 0, but do not return - // an error as this is a valid request - if (((myUsbDevice.setup.wIndex & ~USB_EP_DIR_IN) == 0) - && (myUsbDevice.state >= USBD_STATE_ADDRESSED)) - { - retVal = USB_STATUS_OK; - } - else if ((((myUsbDevice.setup.wIndex) & ~USB_SETUP_DIR_D2H) < SLAB_USB_NUM_EPS_USED) - && (myUsbDevice.setup.wValue == USB_FEATURE_ENDPOINT_HALT) - && (myUsbDevice.state == USBD_STATE_CONFIGURED)) - { - retVal = USB_STATUS_OK; - USB_SetIndex((myUsbDevice.setup.wIndex & 0xFF) & ~USB_SETUP_DIR_D2H); - - // Enable Stalls on the specified endpoint. -#if (SLAB_USB_EP1IN_USED || SLAB_USB_EP2IN_USED || SLAB_USB_EP3IN_USED) - if ((myUsbDevice.setup.wIndex & 0xFF) & USB_EP_DIR_IN) - { - USB_EpnInStall(); - } -#endif -#if (SLAB_USB_EP1OUT_USED || SLAB_USB_EP2OUT_USED || SLAB_USB_EP3OUT_USED) - if (((myUsbDevice.setup.wIndex & 0xFF) & USB_EP_DIR_IN) == 0) - { - USB_EpnOutStall(); - } -#endif - - // Put the specified endpoint in the Halted state. - switch (myUsbDevice.setup.wIndex & 0xFF) - { - #if SLAB_USB_EP1OUT_USED - case (USB_EP_DIR_OUT | 1): - myUsbDevice.ep1out.state = D_EP_HALT; - break; - #endif - #if SLAB_USB_EP2OUT_USED - case (USB_EP_DIR_OUT | 2): - myUsbDevice.ep2out.state = D_EP_HALT; - break; - #endif - #if SLAB_USB_EP3OUT_USED - case (USB_EP_DIR_OUT | 3): - myUsbDevice.ep3out.state = D_EP_HALT; - break; - #endif - #if SLAB_USB_EP1IN_USED - case (USB_EP_DIR_IN | 1): - myUsbDevice.ep1in.state = D_EP_HALT; - break; - #endif - #if SLAB_USB_EP2IN_USED - case (USB_EP_DIR_IN | 2): - myUsbDevice.ep2in.state = D_EP_HALT; - break; - #endif - #if SLAB_USB_EP3IN_USED - case (USB_EP_DIR_IN | 3): - myUsbDevice.ep3in.state = D_EP_HALT; - break; - #endif - } - } - } - } - - return retVal; -} - -/***************************************************************************//** - * @brief Sets the Interface and Alternate Interface (if supported) - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static USB_Status_TypeDef SetInterface(void) -{ - USB_Status_TypeDef retVal = USB_STATUS_REQ_ERR; - uint8_t interface = (uint8_t)myUsbDevice.setup.wIndex; - uint8_t altSetting = (uint8_t)myUsbDevice.setup.wValue; - - if ((interface < SLAB_USB_NUM_INTERFACES) - && (myUsbDevice.state == USBD_STATE_CONFIGURED) - && (myUsbDevice.setup.wLength == 0) -#if (SLAB_USB_SUPPORT_ALT_INTERFACES == 0) - && (altSetting == 0) -#endif - && (myUsbDevice.setup.bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)) - { -#if (SLAB_USB_SUPPORT_ALT_INTERFACES) - if (USBD_SetInterfaceCb(interface, altSetting) == USB_STATUS_OK) - { - myUsbDevice.interfaceAltSetting[interface] = altSetting; - retVal = USB_STATUS_OK; - } -#else -#if (SLAB_USB_NUM_INTERFACES == 1) - // Reset data toggles on EP's - USBD_ActivateAllEps(false); -#endif // ( SLAB_USB_NUM_INTERFACES == 1 ) - retVal = USB_STATUS_OK; -#endif // ( SLAB_USB_SUPPORT_ALT_INTERFACES ) - } - - return retVal; -} - -// ----------------------------------------------------------------------------- -// Utility Functions - -/***************************************************************************//** - * @brief Enables all endpoints for data transfers - * @return Status of request (type @ref USB_Status_TypeDef) - * @note This function takes no parameters, but it uses the setup command - * stored in @ref myUsbDevice.setup. - ******************************************************************************/ -static void USBD_ActivateAllEps(bool forceIdle) -{ - if (forceIdle == true) - { -#if SLAB_USB_EP1IN_USED - myUsbDevice.ep1in.state = D_EP_IDLE; -#endif -#if SLAB_USB_EP2IN_USED - myUsbDevice.ep2in.state = D_EP_IDLE; -#endif -#if SLAB_USB_EP3IN_USED - myUsbDevice.ep3in.state = D_EP_IDLE; -#endif -#if SLAB_USB_EP1OUT_USED - myUsbDevice.ep1out.state = D_EP_IDLE; -#endif -#if SLAB_USB_EP2OUT_USED - myUsbDevice.ep2out.state = D_EP_IDLE; -#endif -#if SLAB_USB_EP3OUT_USED - myUsbDevice.ep3out.state = D_EP_IDLE; -#endif - } - -#if SLAB_USB_EP1IN_USED - USB_ActivateEp(1, // ep - SLAB_USB_EP1IN_MAX_PACKET_SIZE, // packetSize - 1, // inDir - SLAB_USB_EP1OUT_USED, // splitMode - 0); // isoMod -#endif // SLAB_USB_EP1IN_USED -#if SLAB_USB_EP2IN_USED - USB_ActivateEp(2, // ep - SLAB_USB_EP2IN_MAX_PACKET_SIZE, // packetSize - 1, // inDir - SLAB_USB_EP2OUT_USED, // splitMode - 0); // isoMod -#endif // SLAB_USB_EP2IN_USED -#if SLAB_USB_EP3IN_USED - USB_ActivateEp(3, // ep - SLAB_USB_EP3IN_MAX_PACKET_SIZE, // packetSize - 1, // inDir - SLAB_USB_EP3OUT_USED, // splitMode - (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC)); // isoMod -#endif // SLAB_USB_EP3IN_USED -#if SLAB_USB_EP1OUT_USED - USB_ActivateEp(1, // ep - SLAB_USB_EP1OUT_MAX_PACKET_SIZE, // packetSize - 0, // inDir - SLAB_USB_EP1IN_USED, // splitMode - 0); // isoMod -#endif // SLAB_USB_EP1OUT_USED -#if SLAB_USB_EP2OUT_USED - USB_ActivateEp(2, // ep - SLAB_USB_EP2OUT_MAX_PACKET_SIZE, // packetSize - 0, // inDir - SLAB_USB_EP2IN_USED, // splitMode - 0); // isoMod -#endif // SLAB_USB_EP2OUT_USED -#if SLAB_USB_EP3OUT_USED - USB_ActivateEp(3, // ep - SLAB_USB_EP3OUT_MAX_PACKET_SIZE, // packetSize - 0, // inDir - SLAB_USB_EP3IN_USED, // splitMode - (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC)); // isoMod -#endif // SLAB_USB_EP1OUT_USED -} - -/***************************************************************************//** - * @brief Sets up an Endpoint 0 Write - * @param dat - * Data to transmit on Endpoint 0 - * @param numBytes - * Number of bytes to transmit on Endpoint 0 - ******************************************************************************/ -static void EP0_Write(uint8_t *dat, uint16_t numBytes) -{ - if (myUsbDevice.ep0.state == D_EP_IDLE) - { - myUsbDevice.ep0.buf = (uint8_t *)dat; - myUsbDevice.ep0.remaining = numBytes; - myUsbDevice.ep0.state = D_EP_TRANSMITTING; - myUsbDevice.ep0.misc.c = 0; - } -} diff --git a/lib/efm8_usb/src/efm8_usbdep.c b/lib/efm8_usb/src/efm8_usbdep.c deleted file mode 100644 index ec8721a..0000000 --- a/lib/efm8_usb/src/efm8_usbdep.c +++ /dev/null @@ -1,896 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#include "si_toolchain.h" -#include "efm8_usb.h" -#include -#include - -extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG); - -// ----------------------------------------------------------------------------- -// Function Prototypes - -// ------------------------------- -// Memory-specific FIFO access functions -#ifdef SI_GPTR - -static void USB_ReadFIFO_Idata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_IDATA), uint8_t fifoNum); -static void USB_WriteFIFO_Idata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_IDATA)); - -static void USB_ReadFIFO_Xdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_XDATA), uint8_t fifoNum); -static void USB_WriteFIFO_Xdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_XDATA)); - -#if SI_GPTR_MTYPE_PDATA != SI_GPTR_MTYPE_XDATA -static void USB_ReadFIFO_Pdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_PDATA), uint8_t fifoNum); -static void USB_WriteFIFO_Pdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_PDATA)); -#endif - -#if SI_GPTR_MTYPE_DATA != SI_GPTR_MTYPE_IDATA -static void USB_ReadFIFO_Data(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_DATA), uint8_t fifoNum); -static void USB_WriteFIFO_Data(uint8_t numBytes, uint8_t SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_DATA)); -#endif - -static void USB_WriteFIFO_Code(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_CODE)); - -#else - -// ------------------------------- -// Generic FIFO access functions -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 - -// ----------------------------------------------------------------------------- -// Functions - -/***************************************************************************//** - * @brief Reads Isochronous data from the Endpoint FIFO - * @param fifoNum - * USB Endpoint FIFO to read - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to buffer to hold data read from the FIFO - ******************************************************************************/ -#if (SLAB_USB_EP3OUT_USED && (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC) && (SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 255)) -// ---------------------------------------------------------------------------- -// 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, uint8_t *dat) -{ - uint8_t numBytesRead; - - // USB_ReadFIFO() accepts a maximum of 255 bytes. If the number of bytes to - // send is greated than 255, call USB_ReadFIFO() multiple times. - while (numBytes > 0) - { - numBytesRead = (numBytes > 255) ? 255 : numBytes; - USB_ReadFIFO(fifoNum, numBytesRead, dat); - numBytes -= numBytesRead; - dat += numBytesRead; - } -} -#else -#define USB_ReadFIFOIso(a, b, c) USB_ReadFIFO(a, b, c) -#endif - -/***************************************************************************//** - * @brief Writes Isochronous data to the Endpoint FIFO - * @param fifoNum - * USB Endpoint FIFO to write - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to buffer hoding data to write to the FIFO - ******************************************************************************/ -#if (SLAB_USB_EP3IN_USED && (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC) && (SLAB_USB_EP3IN_MAX_PACKET_SIZE > 255)) -// ---------------------------------------------------------------------------- -// 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, uint8_t *dat) -{ - uint8_t numBytesWrite; - - // USB_WriteFIFO() accepts a maximum of 255 bytes. If the number of bytes to - // send is greated than 255, call USB_WriteFIFO() multiple times. - while (numBytes > 0) - { - numBytesWrite = (numBytes > 255) ? 255 : numBytes; - numBytes -= numBytesWrite; - USB_WriteFIFO(fifoNum, numBytesWrite, dat, (numBytes == 0)); - dat += numBytesWrite; - } -} -#else -#define USB_WriteFIFOIso(a, b, c) USB_WriteFIFO(a, b, c, true) -#endif - -#if SLAB_USB_EP1IN_USED -/***************************************************************************//** - * @brief Handle Endpoint 1 IN transfer interrupt - * @note This function takes no parameters, but it uses the EP1IN status - * variables stored in @ref myUsbDevice.ep1in. - ******************************************************************************/ -void handleUsbIn1Int(void) -{ - uint8_t xferred; - bool callback; - - USB_SetIndex(1); - - if (USB_EpnInGetSentStall()) - { - USB_EpnInClearSentStall(); - } - else if (myUsbDevice.ep1in.state == D_EP_TRANSMITTING) - { - xferred = (myUsbDevice.ep1in.remaining > SLAB_USB_EP1IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP1IN_MAX_PACKET_SIZE : myUsbDevice.ep1in.remaining; - myUsbDevice.ep1in.remaining -= xferred; - myUsbDevice.ep1in.buf += xferred; - - callback = myUsbDevice.ep1in.misc.bits.callback; - - // Load more data - if (myUsbDevice.ep1in.remaining > 0) - { - USB_WriteFIFO(1, - (myUsbDevice.ep1in.remaining > SLAB_USB_EP1IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP1IN_MAX_PACKET_SIZE - : myUsbDevice.ep1in.remaining, - myUsbDevice.ep1in.buf, - true); - } - else - { - myUsbDevice.ep1in.misc.bits.callback = false; - myUsbDevice.ep1in.state = D_EP_IDLE; - } - - if (callback == true) - { - USBD_XferCompleteCb(EP1IN, USB_STATUS_OK, xferred, myUsbDevice.ep1in.remaining); - } - - } -} -#endif // SLAB_USB_EP1IN_USED - -#if SLAB_USB_EP2IN_USED -/***************************************************************************//** - * @brief Handle Endpoint 2 IN transfer interrupt - * @note This function takes no parameters, but it uses the EP2IN status - * variables stored in @ref myUsbDevice.ep2in. - ******************************************************************************/ -void handleUsbIn2Int(void) -{ - uint8_t xferred; - bool callback; - - USB_SetIndex(2); - - if (USB_EpnInGetSentStall()) - { - USB_EpnInClearSentStall(); - } - else if (myUsbDevice.ep2in.state == D_EP_TRANSMITTING) - { - xferred = (myUsbDevice.ep2in.remaining > SLAB_USB_EP2IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP2IN_MAX_PACKET_SIZE : myUsbDevice.ep2in.remaining; - myUsbDevice.ep2in.remaining -= xferred; - myUsbDevice.ep2in.buf += xferred; - - callback = myUsbDevice.ep2in.misc.bits.callback; - - // Load more data - if (myUsbDevice.ep2in.remaining > 0) - { - USB_WriteFIFO(2, - (myUsbDevice.ep2in.remaining > SLAB_USB_EP2IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP2IN_MAX_PACKET_SIZE - : myUsbDevice.ep2in.remaining, - myUsbDevice.ep2in.buf, - true); - } - else - { - myUsbDevice.ep2in.misc.bits.callback = false; - myUsbDevice.ep2in.state = D_EP_IDLE; - } - - if (callback == true) - { - USBD_XferCompleteCb(EP2IN, USB_STATUS_OK, xferred, myUsbDevice.ep2in.remaining); - } - - } -} -#endif // SLAB_USB_EP2IN_USED - -#if SLAB_USB_EP3IN_USED -/***************************************************************************//** - * @brief Handle Endpoint 3 IN transfer interrupt - * @details Endpoint 3 IN is the only IN endpoint that supports isochronous - * transfers. - * @note This function takes no parameters, but it uses the EP3IN status - * variables stored in @ref myUsbDevice.ep3in. - ******************************************************************************/ -void handleUsbIn3Int(void) -{ -#if SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - uint16_t xferred, nextIdx; -#else - uint8_t xferred; - bool callback; -#endif - - USB_SetIndex(3); - - if (USB_EpnInGetSentStall()) - { - USB_EpnInClearSentStall(); - } - else if (myUsbDevice.ep3in.state == D_EP_TRANSMITTING) - { -#if ((SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_INTR)) - xferred = (myUsbDevice.ep3in.remaining > SLAB_USB_EP3IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP3IN_MAX_PACKET_SIZE : myUsbDevice.ep3in.remaining; - myUsbDevice.ep3in.remaining -= xferred; - myUsbDevice.ep3in.buf += xferred; -#endif - -#if ((SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_INTR)) - - callback = myUsbDevice.ep3in.misc.bits.callback; - -#elif (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC) - if (myUsbDevice.ep3in.misc.bits.callback == true) - { - // In Isochronous mode, the meaning of the USBD_XferCompleteCb parameters changes: - // xferred is ignored - // remaining is the current index into the circular buffer - // the return value is the number of bytes to transmit in the next packet - xferred = USBD_XferCompleteCb(EP3IN, USB_STATUS_OK, 0, myUsbDevice.ep3inIsoIdx); - if (xferred == 0) - { - myUsbDevice.ep3in.misc.bits.inPacketPending = true; - return; - } - } -#endif - // Load more data -#if ((SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_BULK) || (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_INTR)) - if (myUsbDevice.ep3in.remaining > 0) - { - USB_WriteFIFO(3, - (myUsbDevice.ep3in.remaining > SLAB_USB_EP3IN_MAX_PACKET_SIZE) - ? SLAB_USB_EP3IN_MAX_PACKET_SIZE - : myUsbDevice.ep3in.remaining, - myUsbDevice.ep3in.buf, - true); - } - else - { - myUsbDevice.ep3in.misc.bits.callback = false; - myUsbDevice.ep3in.state = D_EP_IDLE; - } - - if (callback == true) - { - USBD_XferCompleteCb(EP3IN, USB_STATUS_OK, xferred, myUsbDevice.ep3in.remaining); - } -#elif (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC) - nextIdx = xferred + myUsbDevice.ep3inIsoIdx; - myUsbDevice.ep3in.misc.bits.inPacketPending = false; - - // Check if the next index is past the end of the circular buffer. - // If so, break the write up into two calls to USB_WriteFIFOIso() - if (nextIdx > myUsbDevice.ep3in.remaining) - { - USB_WriteFIFOIso(3, myUsbDevice.ep3in.remaining - myUsbDevice.ep3inIsoIdx, &myUsbDevice.ep3in.buf[myUsbDevice.ep3inIsoIdx]); - myUsbDevice.ep3inIsoIdx = nextIdx - myUsbDevice.ep3in.remaining; - USB_WriteFIFOIso(3, myUsbDevice.ep3inIsoIdx, myUsbDevice.ep3in.buf); - } - else - { - USB_WriteFIFOIso(3, xferred, &myUsbDevice.ep3in.buf[myUsbDevice.ep3inIsoIdx]); - myUsbDevice.ep3inIsoIdx = nextIdx; - } -#endif // ( ( SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_BULK ) || ( SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_INTR ) ) - } -} -#endif // SLAB_USB_EP3IN_USED - -#if SLAB_USB_EP1OUT_USED -/***************************************************************************//** - * @brief Handle Endpoint 1 OUT transfer interrupt - * @note This function takes no parameters, but it uses the EP1OUT status - * variables stored in @ref myUsbDevice.ep1out. - ******************************************************************************/ -void handleUsbOut1Int(void) -{ - uint8_t count; - - USB_Status_TypeDef status; - bool xferComplete = false; - - USB_SetIndex(1); - - if (USB_EpnOutGetSentStall()) - { - USB_EpnOutClearSentStall(); - } - else if (USB_EpnGetOutPacketReady()) - { - count = USB_EpOutGetCount(); - - // If USBD_Read() has not been called, return an error - if (myUsbDevice.ep1out.state != D_EP_RECEIVING) - { - myUsbDevice.ep1out.misc.bits.outPacketPending = true; - status = USB_STATUS_EP_ERROR; - } - // Check for overrun of user buffer - else if (myUsbDevice.ep1out.remaining < count) - { - myUsbDevice.ep1out.state = D_EP_IDLE; - myUsbDevice.ep1out.misc.bits.outPacketPending = true; - status = USB_STATUS_EP_RX_BUFFER_OVERRUN; - } - else - { - USB_ReadFIFO(1, count, myUsbDevice.ep1out.buf); - - myUsbDevice.ep1out.misc.bits.outPacketPending = false; - myUsbDevice.ep1out.remaining -= count; - myUsbDevice.ep1out.buf += count; - - if ((myUsbDevice.ep1out.remaining == 0) || (count != SLAB_USB_EP1OUT_MAX_PACKET_SIZE)) - { - myUsbDevice.ep1out.state = D_EP_IDLE; - xferComplete = true; - } - status = USB_STATUS_OK; - USB_EpnClearOutPacketReady(); - } - if (myUsbDevice.ep1out.misc.bits.callback == true) - { - if (xferComplete == true) - { - myUsbDevice.ep1out.misc.bits.callback = false; - } - USBD_XferCompleteCb(EP1OUT, status, count, myUsbDevice.ep1out.remaining); - } - } -} -#endif // EP1OUT_USED - -#if SLAB_USB_EP2OUT_USED -/***************************************************************************//** - * @brief Handle Endpoint 2 OUT transfer interrupt - * @note This function takes no parameters, but it uses the EP2OUT status - * variables stored in @ref myUsbDevice.ep2out. - ******************************************************************************/ -void handleUsbOut2Int(void) -{ - uint8_t count; - - USB_Status_TypeDef status; - bool xferComplete = false; - - USB_SetIndex(2); - - if (USB_EpnOutGetSentStall()) - { - USB_EpnOutClearSentStall(); - } - else if (USB_EpnGetOutPacketReady()) - { - count = USB_EpOutGetCount(); - - // If USBD_Read() has not been called, return an error - if (myUsbDevice.ep2out.state != D_EP_RECEIVING) - { - myUsbDevice.ep2out.misc.bits.outPacketPending = true; - status = USB_STATUS_EP_ERROR; - } - // Check for overrun of user buffer - else if (myUsbDevice.ep2out.remaining < count) - { - myUsbDevice.ep2out.state = D_EP_IDLE; - myUsbDevice.ep2out.misc.bits.outPacketPending = true; - status = USB_STATUS_EP_RX_BUFFER_OVERRUN; - } - else - { - USB_ReadFIFO(2, count, myUsbDevice.ep2out.buf); - - myUsbDevice.ep2out.misc.bits.outPacketPending = false; - myUsbDevice.ep2out.remaining -= count; - myUsbDevice.ep2out.buf += count; - - if ((myUsbDevice.ep2out.remaining == 0) || (count != SLAB_USB_EP2OUT_MAX_PACKET_SIZE)) - { - myUsbDevice.ep2out.state = D_EP_IDLE; - xferComplete = true; - } - - status = USB_STATUS_OK; - USB_EpnClearOutPacketReady(); - } - if (myUsbDevice.ep2out.misc.bits.callback == true) - { - if (xferComplete == true) - { - myUsbDevice.ep2out.misc.bits.callback = false; - } - - USBD_XferCompleteCb(EP2OUT, status, count, myUsbDevice.ep2out.remaining); - } - } -} -#endif // EP2OUT_USED - -#if SLAB_USB_EP3OUT_USED -/***************************************************************************//** - * @brief Handle Endpoint 3 OUT transfer interrupt - * @details Endpoint 3 OUT is the only OUT endpoint that supports - * isochronous transfers. - * @note This function takes no parameters, but it uses the EP3OUT status - * variables stored in @ref myUsbDevice.ep3out. - ******************************************************************************/ -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; - - 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; - } -#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) - { - myUsbDevice.ep3out.state = D_EP_IDLE; - 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.remaining -= count; - myUsbDevice.ep3out.buf += count; - - if ((myUsbDevice.ep3out.remaining == 0) || (count != SLAB_USB_EP3OUT_MAX_PACKET_SIZE)) - { - myUsbDevice.ep3out.state = D_EP_IDLE; - xferComplete = true; - } -#elif (SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC) - nextIdx = count + myUsbDevice.ep3outIsoIdx; - - // In isochronous mode, a circular buffer is used to hold the data - // If the next index into the circular buffer passes the end of the - // buffer, make two calls to USB_ReadFIFOIso() - if (nextIdx > myUsbDevice.ep3out.remaining) - { - USB_ReadFIFOIso(3, myUsbDevice.ep3out.remaining - myUsbDevice.ep3outIsoIdx, &myUsbDevice.ep3out.buf[myUsbDevice.ep3outIsoIdx]); - myUsbDevice.ep3outIsoIdx = nextIdx - myUsbDevice.ep3out.remaining; - USB_ReadFIFOIso(3, myUsbDevice.ep3outIsoIdx, myUsbDevice.ep3out.buf); - } - else - { - 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) - { - 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 - USBD_XferCompleteCb(EP3OUT, status, count, myUsbDevice.ep3outIsoIdx); -#endif - } - } -} -#endif // EP3OUT_USED - -/***************************************************************************//** - * @brief Reads data from the USB FIFO - * @param fifoNum - * USB Endpoint FIFO to read - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to buffer to hold data read from the FIFO - ******************************************************************************/ -void USB_ReadFIFO(uint8_t fifoNum, uint8_t numBytes, uint8_t *dat) -{ - if (numBytes > 0) - { - USB_EnableReadFIFO(fifoNum); - - // Convert generic pointer to memory-specific pointer and call the - // the corresponding memory-specific function, if possible. - // The memory-specific functions are much faster than the generic functions. -#ifdef SI_GPTR - - switch (((SI_GEN_PTR_t *)&dat)->gptr.memtype) - { - case SI_GPTR_MTYPE_IDATA: - USB_ReadFIFO_Idata(numBytes, dat, fifoNum); - break; - - // For some compilers, IDATA and DATA are treated the same. - // Only call the USB_ReadFIFO_Data() if the compiler differentiates - // between DATA and IDATA. -#if (SI_GPTR_MTYPE_DATA != SI_GPTR_MTYPE_IDATA) - case SI_GPTR_MTYPE_DATA: - USB_ReadFIFO_Data(numBytes, dat, fifoNum); - break; -#endif - - case SI_GPTR_MTYPE_XDATA: - USB_ReadFIFO_Xdata(numBytes, dat, fifoNum); - break; - - // For some compilers, XDATA and PDATA are treated the same. - // Only call the USB_ReadFIFO_Pdata() if the compiler differentiates - // between XDATA and PDATA. -#if (SI_GPTR_MTYPE_PDATA != SI_GPTR_MTYPE_XDATA) - case SI_GPTR_MTYPE_PDATA: - USB_ReadFIFO_Pdata(numBytes, dat, fifoNum); - break; -#endif - - default: - break; - } - -#else - USB_ReadFIFO_Generic(numBytes, dat, fifoNum); -#endif // #ifdef SI_GPTR - - USB_DisableReadFIFO(fifoNum); - } -} - -/***************************************************************************//** - * @brief Writes data to the USB FIFO - * @param fifoNum - * USB Endpoint FIFO to write - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to buffer hoding data to write to the FIFO - * @param txPacket - * If TRUE, the packet will be sent immediately after loading the - * FIFO - * 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, uint8_t *dat, bool txPacket) -{ - USB_EnableWriteFIFO(fifoNum); - - // Convert generic pointer to memory-specific pointer and call the - // the corresponding memory-specific function, if possible. - // The memory-specific functions are much faster than the generic functions. -#ifdef SI_GPTR - - switch (((SI_GEN_PTR_t *)&dat)->gptr.memtype) - { - case SI_GPTR_MTYPE_IDATA: - USB_WriteFIFO_Idata(numBytes, dat); - break; - - // For some compilers, IDATA and DATA are treated the same. - // Only call the USB_WriteFIFO_Data() if the compiler differentiates between - // DATA and IDATA. -#if (SI_GPTR_MTYPE_DATA != SI_GPTR_MTYPE_IDATA) - case SI_GPTR_MTYPE_DATA: - USB_WriteFIFO_Data(numBytes, dat); - break; -#endif - - case SI_GPTR_MTYPE_XDATA: - USB_WriteFIFO_Xdata(numBytes, dat); - break; - - // For some compilers, XDATA and PDATA are treated the same. - // Only call the USB_WriteFIFO_Pdata() if the compiler differentiates - // between XDATA and PDATA. -#if (SI_GPTR_MTYPE_PDATA != SI_GPTR_MTYPE_XDATA) - case SI_GPTR_MTYPE_PDATA: - USB_WriteFIFO_Pdata(numBytes, dat); - break; -#endif - - case SI_GPTR_MTYPE_CODE: - USB_WriteFIFO_Code(numBytes, dat); - break; - - default: - break; - } - -#else - USB_WriteFIFO_Generic(numBytes, dat); -#endif // #ifdef SI_GPTR - - USB_DisableWriteFIFO(fifoNum); - - if ((txPacket == true) && (fifoNum > 0)) - { - USB_SetIndex(fifoNum); - USB_EpnSetInPacketReady(); - } -} - -// ----------------------------------------------------------------------------- -// Memory-Specific FIFO Access Functions -// -// Memory-specific functions are much faster (more than 2x) than generic -// generic functions, so we will use memory-specific functions if possible. -// ----------------------------------------------------------------------------- - -#ifdef SI_GPTR -/***************************************************************************//** - * @brief Reads data from the USB FIFO to a buffer in IRAM - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to IDATA buffer to hold data read from the FIFO - * @param fifoNum - * USB FIFO to read - ******************************************************************************/ -static void USB_ReadFIFO_Idata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_IDATA), uint8_t fifoNum) -{ - while (--numBytes) - { - USB_GetFIFOByte(dat); - dat++; - } - USB_GetLastFIFOByte(dat, fifoNum); -} - -/***************************************************************************//** - * @brief Writes data held in IRAM to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to IDATA buffer holding data to write to the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Idata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_IDATA)) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} - -/***************************************************************************//** - * @brief Reads data from the USB FIFO to a buffer in XRAM - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to XDATA buffer to hold data read from the FIFO - * @param fifoNum - * USB FIFO to read - ******************************************************************************/ -static void USB_ReadFIFO_Xdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_XDATA), uint8_t fifoNum) -{ - while (--numBytes) - { - USB_GetFIFOByte(dat); - dat++; - } - USB_GetLastFIFOByte(dat, fifoNum); -} - -/***************************************************************************//** - * @brief Writes data held in XRAM to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to XDATA buffer holding data to write to the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Xdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_XDATA)) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} - -#if SI_GPTR_MTYPE_PDATA != SI_GPTR_MTYPE_XDATA -/***************************************************************************//** - * @brief Reads data from the USB FIFO to a buffer in paged XRAM - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to PDATA buffer to hold data read from the FIFO - * @param fifoNum - * USB FIFO to read - ******************************************************************************/ -static void USB_ReadFIFO_Pdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_PDATA), uint8_t fifoNum) -{ - while (--numBytes) - { - USB_GetFIFOByte(dat); - dat++; - } - USB_GetLastFIFOByte(dat, fifoNum); -} - -/***************************************************************************//** - * @brief Writes data held in paged XRAM to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to PDATA buffer holding data to write to the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Pdata(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_PDATA)) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} - -#endif - -#if SI_GPTR_MTYPE_DATA != SI_GPTR_MTYPE_IDATA -/***************************************************************************//** - * @brief Reads data from the USB FIFO to a buffer in DRAM - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to DATA buffer to hold data read from the FIFO - * @param fifoNum - * USB FIFO to read - ******************************************************************************/ -static void USB_ReadFIFO_Data(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_DATA), uint8_t fifoNum) -{ - while (--numBytes) - { - USB_GetFIFOByte(*dat); - dat++; - } - USB_GetLastFIFOByte(*dat, fifoNum); -} - -/***************************************************************************//** - * @brief Writes data held in DRAM to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to DATA buffer to hold data read from the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Data(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_DATA)) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} -#endif - -/***************************************************************************//** - * @brief Writes data held in code space to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to CODE buffer holding data to write to the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Code(uint8_t numBytes, SI_VARIABLE_SEGMENT_POINTER(dat, uint8_t, SI_SEG_CODE)) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} - -#else -/***************************************************************************//** - * @brief Reads data from the USB FIFO to a buffer in generic memory space - * @param numBytes - * Number of bytes to read from the FIFO - * @param dat - * Pointer to generic buffer to hold data read from the FIFO - * @param fifoNum - * USB FIFO to read - ******************************************************************************/ -static void USB_ReadFIFO_Generic(uint8_t numBytes, uint8_t *dat, uint8_t fifoNum) -{ - while (--numBytes) - { - USB_GetFIFOByte(*dat); - dat++; - } - USB_GetLastFIFOByte(*dat, fifoNum); -} - -/***************************************************************************//** - * @brief Writes data held in generic memory space to the USB FIFO - * @details The FIFO to write must be set before calling the function with - * @ref USB_EnableWriteFIFO(). - * @param numBytes - * Number of bytes to write to the FIFO - * @param dat - * Pointer to generic buffer holding data to write to the FIFO - ******************************************************************************/ -static void USB_WriteFIFO_Generic(uint8_t numBytes, uint8_t *dat) -{ - while (numBytes--) - { - USB_SetFIFOByte(*dat); - dat++; - } -} - -#endif // #ifdef SI_GPTR diff --git a/lib/efm8_usb/src/efm8_usbdint.c b/lib/efm8_usb/src/efm8_usbdint.c deleted file mode 100644 index f00c9ed..0000000 --- a/lib/efm8_usb/src/efm8_usbdint.c +++ /dev/null @@ -1,533 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#include "si_toolchain.h" -#include "efm8_usb.h" -#include -#include - -// ----------------------------------------------------------------------------- -// Global variables - -extern SI_SEGMENT_VARIABLE(myUsbDevice, USBD_Device_TypeDef, MEM_MODEL_SEG); -extern SI_SEGMENT_VARIABLE(txZero[2], uint8_t, SI_SEG_CODE); - -// ----------------------------------------------------------------------------- -// Function prototypes - -static void handleUsbEp0Int(void); -static void handleUsbResetInt(void); -static void handleUsbSuspendInt(void); -static void handleUsbResumeInt(void); -static void handleUsbEp0Tx(void); -static void handleUsbEp0Rx(void); -static void USB_ReadFIFOSetup(void); - -#if (SLAB_USB_EP1IN_USED) -void handleUsbIn1Int(void); -#endif // SLAB_USB_EP1IN_USED -#if (SLAB_USB_EP2IN_USED) -void handleUsbIn2Int(void); -#endif // SLAB_USB_EP2IN_USED -#if (SLAB_USB_EP3IN_USED) -void handleUsbIn3Int(void); -#endif // SLAB_USB_EP3IN_USED - -#if (SLAB_USB_EP1OUT_USED) -void handleUsbOut1Int(void); -#endif // SLAB_USB_EP1OUT_USED -#if (SLAB_USB_EP2OUT_USED) -void handleUsbOut2Int(void); -#endif // SLAB_USB_EP2OUT_USED -#if (SLAB_USB_EP3OUT_USED) -void handleUsbOut3Int(void); -#endif // SLAB_USB_EP3OUT_USED - -void SendEp0Stall(void); - -// ----------------------------------------------------------------------------- -// Functions - -/***************************************************************************//** - * @brief First-level handler for USB peripheral interrupt - * @details If @ref SLAB_USB_POLLED_MODE is 1, this becomes a regular - * function instead of an ISR and must be called by the application - * periodically. - ******************************************************************************/ -#if (SLAB_USB_POLLED_MODE == 0) -SI_INTERRUPT(usbIrqHandler, USB0_IRQn) -#else -void usbIrqHandler(void) -#endif -{ - uint8_t statusCommon, statusIn, statusOut, indexSave; - -#if SLAB_USB_HANDLER_CB - // Callback to user before processing - USBD_EnterHandler(); -#endif - - // Get the interrupt sources - statusCommon = USB_GetCommonInts(); - statusIn = USB_GetInInts(); - statusOut = USB_GetOutInts(); - -#if SLAB_USB_POLLED_MODE - if ((statusCommon == 0) && (statusIn == 0) && (statusOut == 0)) - { - return; - } -#endif - - // Save the current index - indexSave = USB_GetIndex(); - - // Check Common USB Interrupts - if (USB_IsSofIntActive(statusCommon)) - { -#if SLAB_USB_SOF_CB - USBD_SofCb(USB_GetSofNumber()); -#endif // SLAB_USB_SOF_CB - - // Check for unhandled USB packets on EP0 and set the corresponding IN or - // OUT interrupt active flag if necessary. - if (((myUsbDevice.ep0.misc.bits.outPacketPending == true) && (myUsbDevice.ep0.state == D_EP_RECEIVING)) || - ((myUsbDevice.ep0.misc.bits.inPacketPending == true) && (myUsbDevice.ep0.state == D_EP_TRANSMITTING))) - { - USB_SetEp0IntActive(statusIn); - } - // Check for unhandled USB OUT packets and set the corresponding OUT - // interrupt active flag if necessary. -#if SLAB_USB_EP1OUT_USED - if ((myUsbDevice.ep1out.misc.bits.outPacketPending == true) && (myUsbDevice.ep1out.state == D_EP_RECEIVING)) - { - USB_SetOut1IntActive(statusOut); - } -#endif -#if SLAB_USB_EP2OUT_USED - if ((myUsbDevice.ep2out.misc.bits.outPacketPending == true) && (myUsbDevice.ep2out.state == D_EP_RECEIVING)) - { - USB_SetOut2IntActive(statusOut); - } -#endif -#if SLAB_USB_EP3OUT_USED - if ((myUsbDevice.ep3out.misc.bits.outPacketPending == true) && (myUsbDevice.ep3out.state == D_EP_RECEIVING)) - { - USB_SetOut3IntActive(statusOut); - } -#endif -#if (SLAB_USB_EP3IN_USED && (SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC)) - if ((myUsbDevice.ep3in.misc.bits.inPacketPending == true) && (myUsbDevice.ep3in.state == D_EP_TRANSMITTING)) - { - USB_SetIn3IntActive(statusIn); - } -#endif - } - - if (USB_IsResetIntActive(statusCommon)) - { - handleUsbResetInt(); - - // If VBUS is not present on detection of a USB reset, enter suspend mode. -#if (SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF) - if (USB_IsVbusOn() == false) - { - USB_SetSuspendIntActive(statusCommon); - } -#endif - } - - if (USB_IsResumeIntActive(statusCommon)) - { - handleUsbResumeInt(); - } - - if (USB_IsSuspendIntActive(statusCommon)) - { - handleUsbSuspendInt(); - } - -#if SLAB_USB_EP3IN_USED - if (USB_IsIn3IntActive(statusIn)) - { - handleUsbIn3Int(); - } -#endif // EP3IN_USED - -#if SLAB_USB_EP3OUT_USED - if (USB_IsOut3IntActive(statusOut)) - { - handleUsbOut3Int(); - } -#endif // EP3OUT_USED - -#if SLAB_USB_EP2IN_USED - if (USB_IsIn2IntActive(statusIn)) - { - handleUsbIn2Int(); - } -#endif // EP2IN_USED - -#if SLAB_USB_EP1IN_USED - if (USB_IsIn1IntActive(statusIn)) - { - handleUsbIn1Int(); - } -#endif // EP1IN_USED - -#if SLAB_USB_EP2OUT_USED - if (USB_IsOut2IntActive(statusOut)) - { - handleUsbOut2Int(); - } -#endif // EP2OUT_USED - -#if SLAB_USB_EP1OUT_USED - if (USB_IsOut1IntActive(statusOut)) - { - handleUsbOut1Int(); - } -#endif // EP1OUT_USED - - // Check USB Endpoint 0 Interrupt - if (USB_IsEp0IntActive(statusIn)) - { - handleUsbEp0Int(); - } - - // Restore index - USB_SetIndex(indexSave); - -#if SLAB_USB_HANDLER_CB - // Callback to user before exiting - USBD_ExitHandler(); -#endif -} - -/***************************************************************************//** - * @brief Handles Endpoint 0 transfer interrupt - ******************************************************************************/ -static void handleUsbEp0Int(void) -{ - USB_SetIndex(0); - - if (USB_Ep0SentStall() || USB_GetSetupEnd()) - { - USB_Ep0ClearSentStall(); - USB_ServicedSetupEnd(); - myUsbDevice.ep0.state = D_EP_IDLE; - myUsbDevice.ep0.misc.c = 0; - } - if (USB_Ep0OutPacketReady()) - { - if (myUsbDevice.ep0.misc.bits.waitForRead == true) - { - myUsbDevice.ep0.misc.bits.outPacketPending = true; - } - else if (myUsbDevice.ep0.state == D_EP_IDLE) - { - myUsbDevice.ep0String.c = USB_STRING_DESCRIPTOR_UTF16LE; - USB_ReadFIFOSetup(); - - // Vendor unique, Class or Standard setup commands override? -#if SLAB_USB_SETUP_CMD_CB - if (USBD_SetupCmdCb(&myUsbDevice.setup) == USB_STATUS_REQ_UNHANDLED) - { -#endif - if (myUsbDevice.setup.bmRequestType.Type == USB_SETUP_TYPE_STANDARD) - { - USBDCH9_SetupCmd(); - } - 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) - { - handleUsbEp0Rx(); - } - else - { - myUsbDevice.ep0.misc.bits.outPacketPending = true; - } - } - if ((myUsbDevice.ep0.state == D_EP_TRANSMITTING) && (USB_Ep0InPacketReady() == 0)) - { - handleUsbEp0Tx(); - } -} - -/***************************************************************************//** - * @brief Reads and formats a setup packet - ******************************************************************************/ -static void USB_ReadFIFOSetup(void) -{ - uint16_t MEM_MODEL_SEG *ptr = &myUsbDevice.setup; - - USB_ReadFIFO(0, 8, (uint8_t *)ptr); - - USB_Ep0ServicedOutPacketReady(); - - // Modify for Endian-ness of the compiler - ptr[1] = le16toh(ptr[1]); - ptr[2] = le16toh(ptr[2]); - ptr[3] = le16toh(ptr[3]); -} - -/***************************************************************************//** - * @brief Handles USB port reset interrupt - * @details After receiving a USB reset, halt all endpoints except for - * Endpoint 0, set the device state, and configure USB hardware. - ******************************************************************************/ -static void handleUsbResetInt(void) -{ - // Setup EP0 to receive SETUP packets - myUsbDevice.ep0.state = D_EP_IDLE; - - // Halt all other endpoints -#if SLAB_USB_EP1IN_USED - myUsbDevice.ep1in.state = D_EP_HALT; -#endif -#if SLAB_USB_EP2IN_USED - myUsbDevice.ep2in.state = D_EP_HALT; -#endif -#if SLAB_USB_EP3IN_USED - myUsbDevice.ep3in.state = D_EP_HALT; -#endif -#if SLAB_USB_EP1OUT_USED - myUsbDevice.ep1out.state = D_EP_HALT; -#endif -#if SLAB_USB_EP2OUT_USED - myUsbDevice.ep2out.state = D_EP_HALT; -#endif -#if SLAB_USB_EP3OUT_USED - myUsbDevice.ep3out.state = D_EP_HALT; -#endif - - // After a USB reset, some USB hardware configurations will be reset and must - // be reconfigured. - - // Re-enable clock recovery -#if SLAB_USB_CLOCK_RECOVERY_ENABLED -#if SLAB_USB_FULL_SPEED - USB_EnableFullSpeedClockRecovery(); -#else - USB_EnableLowSpeedClockRecovery(); -#endif -#endif - - // Re-enable USB interrupts - USB_EnableSuspendDetection(); - USB_EnableDeviceInts(); - - // 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); - } - else - { - USBD_SetUsbState(USBD_STATE_ATTACHED); - } -#else - USBD_SetUsbState(USBD_STATE_DEFAULT); -#endif // (!(SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF)) - -#if SLAB_USB_RESET_CB - // Make the USB Reset Callback - USBD_ResetCb(); -#endif -} - -/***************************************************************************//** - * @brief Handle USB port suspend interrupt - * @details After receiving a USB reset, set the device state and - * call @ref USBD_Suspend() if configured to do so in - * @ref SLAB_USB_PWRSAVE_MODE - ******************************************************************************/ -static void handleUsbSuspendInt(void) -{ - if (myUsbDevice.state >= USBD_STATE_POWERED) - { - USBD_SetUsbState(USBD_STATE_SUSPENDED); - -#if (SLAB_USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONSUSPEND) - USBD_Suspend(); -#endif - } -} - -/***************************************************************************//** - * @brief Handles USB port resume interrupt - * @details Restore the device state to its previous value. - ******************************************************************************/ -static void handleUsbResumeInt(void) -{ - USBD_SetUsbState(myUsbDevice.savedState); -} - -/***************************************************************************//** - * @brief Handles transmit data phase on Endpoint 0 - ******************************************************************************/ -static void handleUsbEp0Tx(void) -{ - uint8_t count, count_snapshot, i; - bool callback = myUsbDevice.ep0.misc.bits.callback; - - // The number of bytes to send in the next packet must be less than or equal - // to the maximum EP0 packet size. - count = (myUsbDevice.ep0.remaining >= USB_EP0_SIZE) ? - USB_EP0_SIZE : myUsbDevice.ep0.remaining; - - // Save the packet size for future use. - count_snapshot = count; - - // 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, - // 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 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) - { - USB_WriteFIFO(0, 2, myUsbDevice.ep0.buf, false); - myUsbDevice.ep0.buf += 2; - count -= 2; - myUsbDevice.ep0String.encoding.init = false; - } - - // Insert a 0x00 between each character of the string. - for (i = 0; i < count / 2; i++) - { - USB_WriteFIFO(0, 1, myUsbDevice.ep0.buf, false); - myUsbDevice.ep0.buf++; - USB_WriteFIFO(0, 1, &txZero, false); - } - } - // For any data other than USB_STRING_DESCRIPTOR_UTF16LE_PACKED, just send the - // data normally. - else - { - USB_WriteFIFO(0, count, myUsbDevice.ep0.buf, false); - myUsbDevice.ep0.buf += count; - } - - myUsbDevice.ep0.misc.bits.inPacketPending = false; - myUsbDevice.ep0.remaining -= count_snapshot; - - // If the last packet of the transfer is exactly the maximum EP0 packet size, - // we will have to send a ZLP (zero-length packet) after the last data packet - // to signal to the host that the transfer is complete. - // Check for the ZLP packet case here. - if ((myUsbDevice.ep0.remaining == 0) && (count_snapshot != USB_EP0_SIZE)) - { - USB_Ep0SetLastInPacketReady(); - myUsbDevice.ep0.state = D_EP_IDLE; - myUsbDevice.ep0String.c = USB_STRING_DESCRIPTOR_UTF16LE; - myUsbDevice.ep0.misc.c = 0; - } - else - { - // Do not call USB_Ep0SetLastInPacketReady() because we still need to send - // the ZLP. - USB_Ep0SetInPacketReady(); - } - // Make callback if requested - if (callback == true) - { - USBD_XferCompleteCb(EP0, USB_STATUS_OK, count_snapshot, myUsbDevice.ep0.remaining); - } -} - -/***************************************************************************//** - * @brief Handles receive data phase on Endpoint 0 - ******************************************************************************/ -void handleUsbEp0Rx(void) -{ - uint8_t count; - USB_Status_TypeDef status; - bool callback = myUsbDevice.ep0.misc.bits.callback; - - // Get the number of bytes received - count = USB_Ep0GetCount(); - - // If the call to USBD_Read() did not give a large enough buffer to hold this - // data, set the outPacketPending flag and signal an RX overrun. - if (myUsbDevice.ep0.remaining < count) - { - myUsbDevice.ep0.state = D_EP_IDLE; - myUsbDevice.ep0.misc.bits.outPacketPending = true; - status = USB_STATUS_EP_RX_BUFFER_OVERRUN; - } - else - { - USB_ReadFIFO(0, count, myUsbDevice.ep0.buf); - myUsbDevice.ep0.buf += count; - myUsbDevice.ep0.remaining -= count; - status = USB_STATUS_OK; - - // If the last packet of the transfer is exactly the maximum EP0 packet - // size, we will must wait to receive a ZLP (zero-length packet) after the - // last data packet. This signals that the host has completed the transfer. - // Check for the ZLP packet case here. - if ((myUsbDevice.ep0.remaining == 0) && (count != USB_EP0_SIZE)) - { - USB_Ep0SetLastOutPacketReady(); - myUsbDevice.ep0.state = D_EP_IDLE; - myUsbDevice.ep0.misc.bits.callback = false; - } - else - { - // Do not call USB_Ep0SetLastOutPacketReady() until we get the ZLP. - USB_Ep0ServicedOutPacketReady(); - } - } - - // Make callback if requested - if (callback == true) - { - USBD_XferCompleteCb(EP0, status, count, myUsbDevice.ep0.remaining); - } -} - - -/***************************************************************************//** - * @brief Send a procedural stall on Endpoint 0 - ******************************************************************************/ -void SendEp0Stall(void) -{ - USB_SetIndex(0); - myUsbDevice.ep0.state = D_EP_STALL; - USB_Ep0SendStall(); -} - -// 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 -// and the ISR will not be present. -void forceModuleLoad_usbint(void){} diff --git a/lib/efm8ub1/peripheralDrivers/inc/usb_0.h b/lib/efm8ub1/peripheralDrivers/inc/usb_0.h deleted file mode 100644 index be32bad..0000000 --- a/lib/efm8ub1/peripheralDrivers/inc/usb_0.h +++ /dev/null @@ -1,2087 +0,0 @@ -/***************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - ******************************************************************************/ - -#ifndef __SILICON_LABS_EFM8_USB_0_H__ -#define __SILICON_LABS_EFM8_USB_0_H__ - -#include "SI_EFM8UB1_Register_Enums.h" -#include -#include -#include "efm8_config.h" - -/******************************************************************************/ - -/** - * - * @addtogroup usb_0_group USB0 Driver - * @{ - * - * @brief Peripheral driver for USB 0 - * - * # Introduction # - * - * This module provides an API for using the USB0 peripheral. - * The API provides access to the USB hardware. A full-featured - * USB stack (EFM8 USB Library) is available in the SDK at "\lib\efm8_usb." - * The primary purpose of this USB peripheral driver is to abstract hardware - * accesses so that the EFM8 USB Library can run on multiple EFM8 devices - * (e.g. EFM8UB1, EFM8UB2). However, this driver can also be used to build - * custom USB stacks and applications in cases where greater optimization or - * performance than what the EFM8 USB Library provides is required. - * - ******************************************************************************/ - -/***************************************************************************//** - * @addtogroup usb_0_runtime USB0 Runtime API - * @brief - * Functions and macros to access the USB hardware. - * @{ - ******************************************************************************/ - -// ------------------------------- -// Macros - -/***************************************************************************//** - * @brief Reads an indirect USB register - * @details Sets USB0ADR and polls on the busy bit. - * When the macro completes, the value can be read from USB0DAT. - * @param addr - * The address of the USB indirect register to read - * @return The value of the USB indirect register is held in USB0DAT. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern uint8_t USB_READ_BYTE(uint8_t addr); -#else -#define USB_READ_BYTE(addr) \ - do \ - { \ - USB0ADR = (USB0ADR_BUSY__SET | (addr)); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Writes an indirect USB register - * @details Sets USB0ADR, writes a value to USB0DAT, and waits for the busy - * bit to clear. - * @param addr - * The address of the USB indirect register to read - * @param dat - * The value to write to the USB indirect register - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_WRITE_BYTE(uint8_t addr, uint8_t dat); -#else -#define USB_WRITE_BYTE(addr, dat) \ - do \ - { \ - USB0ADR = (addr); \ - USB0DAT = (dat); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Sets bits in an indirect USB register - * @details Sets the bits in the bitmask of the indirect USB register - * without disturbing the value of other bits in the indirect - * register. - * @param addr - * The address of the USB indirect register to write - * @param bitmask - * The bits to set - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SET_BITS(uint8_t addr, uint8_t bitmask); -#else -#define USB_SET_BITS(addr, bitmask) \ - do \ - { \ - USB0ADR = (USB0ADR_BUSY__SET | (addr)); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0DAT = (USB0DAT | (bitmask)); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Clears bits in an indirect USB register - * @details Clears the bits in the bitmask of an indirect USB register - * without disturbing the value of other bits in the indirect - * register. - * @param addr - * The address of the USB indirect register to write - * @param bitmask - * The bits to clear - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_CLEAR_BITS(uint8_t addr, uint8_t bitmask); -#else -#define USB_CLEAR_BITS(addr, bitmask) \ - do \ - { \ - USB0ADR = (USB0ADR_BUSY__SET | (addr)); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0DAT = (USB0DAT & ~(bitmask)); \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Enables USB interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableInts(void); -#else -#define USB_EnableInts() \ - do \ - { \ - SFRPAGE = PG2_PAGE; \ - EIE2 |= EIE2_EUSB0__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables USB interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableInts(void); -#else -#define USB_DisableInts() \ - do \ - { \ - SFRPAGE = PG2_PAGE; \ - EIE2 &= ~EIE2_EUSB0__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Returns state of USB interrupt enabler - * @return TRUE if USB interrupts are enabled, FALSE otherwise. - ******************************************************************************/ -bool USB_GetIntsEnabled(void); - -/***************************************************************************//** - * @brief Enables VBUS detection - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_VbusDetectEnable(void); -#else -#define USB_VbusDetectEnable() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF |= USB0CF_VBUSEN__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables VBUS detection - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_VbusDetectDisable(void); -#else -#define USB_VbusDetectDisable() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_VBUSEN__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Check status of VBUS signal - * @return TRUE if VBUS signal is present, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsVbusOn(void); -#else -#define USB_IsVbusOn() ((bool) P3_B1) -#endif - -/***************************************************************************//** - * @brief Enables the USB pull-up resistor - * @details Enables either the D+ or the D- pull-up resistor, depending on - * whether @ref USB_SelectFullSpeed() or @ref USB_SelectLowSpeed() - * was previously called. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnablePullUpResistor(void); -#else -#define USB_EnablePullUpResistor() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN |= USB0XCN_PREN__PULL_UP_ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables the USB pull-up resistor - * @details Disables either the D+ or the D- pull-up resistor, depending on - * whether @ref USB_SelectFullSpeed() or @ref USB_SelectLowSpeed() - * was previously called. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisablePullUpResistor(void); -#else -#define USB_DisablePullUpResistor() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN &= ~USB0XCN_PREN__PULL_UP_ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Enables the USB transceiver - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableTransceiver(void); -#else -#define USB_EnableTransceiver() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN |= USB0XCN_PHYEN__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables the USB transceiver - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableTransceiver(void); -#else -#define USB_DisableTransceiver() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN &= ~USB0XCN_PHYEN__ENABLED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Puts the USB in full-speed mode. - * @details Configures the USB to operate as a full-speed device by - * enabling the D+ pull-up resistor. After calling this - * function, the user must call @ref USB_EnablePullUpResistor(). - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SelectFullSpeed(void); -#else -#define USB_SelectFullSpeed() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN |= USB0XCN_SPEED__FULL_SPEED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Puts the USB in low-speed mode. - * @details Configures the USB to operate as a low-speed device by - * enabling the D- pull-up resistor. After calling this - * function, the user must call @ref USB_EnablePullUpResistor(). - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SelectLowSpeed(void); -#else -#define USB_SelectLowSpeed() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN &= ~USB0XCN_SPEED__FULL_SPEED; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Suspends the transceiver - * @details Puts the USB transceiver in suspend mode. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SuspendTransceiver(void); -#else -#define USB_SuspendTransceiver() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0XCN &= ~(USB0XCN_PHYEN__ENABLED \ - | USB0XCN_Dp__HIGH \ - | USB0XCN_Dn__HIGH); \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the internal oscillator as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockIntOsc(void); -#else -#define USB_SetClockIntOsc() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the internal oscillator / 8 as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockIntOscDiv8(void); -#else -#define USB_SetClockIntOscDiv8() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__HFOSC1_DIV_8; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the external oscillator as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockExtOsc(void); -#else -#define USB_SetClockExtOsc() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__EXTOSC; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the external oscillator / 2 as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockExtOscDiv2(void); -#else -#define USB_SetClockExtOscDiv2() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__EXTOSC_DIV_2; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the external oscillator / 3 as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockExtOscDiv3(void); -#else -#define USB_SetClockExtOscDiv3() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__EXTOSC_DIV_3; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the external oscillator / 4 as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockExtOscDiv4(void); -#else -#define USB_SetClockExtOscDiv4() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__EXTOSC_DIV_4; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the low-frequency oscillator as the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetClockLfo(void); -#else -#define USB_SetClockLfo() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - USB0CF &= ~USB0CF_USBCLK__FMASK; \ - USB0CF |= USB0CF_USBCLK__LFOSC; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Selects the normal setting for the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetNormalClock(void); -#else -#define USB_SetNormalClock() USB_SetClockIntOsc() -#endif - -/***************************************************************************//** - * @brief Selects the low-power setting for the USB clock - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetSuspendClock(void); -#else -#define USB_SetSuspendClock() USB_SetClockIntOscDiv8() -#endif - -/***************************************************************************//** - * @brief Suspends REG1 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SuspendRegulator(void); -#else -#define USB_SuspendRegulator() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - REG1CN |= REG1CN_SUSEN__SUSPEND; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Does not use regulator low-power modes - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SuspendRegulatorFastWake(void); -#else -#define USB_SuspendRegulatorFastWake() -#endif - -/***************************************************************************//** - * @brief Takes REG0 and REG1 out of suspend - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_UnsuspendRegulator(void); -#else -#define USB_UnsuspendRegulator() \ - do \ - { \ - SFRPAGE = PG3_PAGE; \ - REG1CN &= ~REG1CN_SUSEN__SUSPEND; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Determine if the internal regulator is enabled - * @return TRUE if the internal regulator is enabled, FALSE otherwise - ******************************************************************************/ -bool USB_IsRegulatorEnabled(void); - -/***************************************************************************//** - * @brief Disable the prefetch engine - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -void USB_DisablePrefetch(void); -#else -#define USB_DisablePrefetch() \ - do \ - { \ - SFRPAGE = PG2_PAGE; \ - PFE0CN &= ~(PFE0CN_PFEN__ENABLED | PFE0CN_FLRT__SYSCLK_BELOW_50_MHZ); \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Enable the prefetch engine - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -void USB_EnablePrefetch(void); -#else -#define USB_EnablePrefetch() \ - do \ - { \ - SFRPAGE = PG2_PAGE; \ - PFE0CN |= (PFE0CN_PFEN__ENABLED | PFE0CN_FLRT__SYSCLK_BELOW_50_MHZ); \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Determine if the prefetch engine is enabled - * @return TRUE if prefetch engine is enabled, FALSE otherwise. - ******************************************************************************/ -bool USB_IsPrefetchEnabled(void); - -/***************************************************************************//** - * @brief Suspends internal oscillator - ******************************************************************************/ -void USB_SuspendOscillator(void); - -/***************************************************************************//** - * @brief Enables clock recovery in full speed mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableFullSpeedClockRecovery(void); -#else -#define USB_EnableFullSpeedClockRecovery() \ - USB_WRITE_BYTE(CLKREC, (CLKREC_CRE__ENABLED | 0x0F)) -#endif - -/***************************************************************************//** - * @brief Enables clock recovery in low speed mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableLowSpeedClockRecovery(void); -#else -#define USB_EnableLowSpeedClockRecovery() \ - USB_WRITE_BYTE(CLKREC, \ - (CLKREC_CRE__ENABLED \ - | CLKREC_CRLOW__LOW_SPEED \ - | 0x0F)) -#endif - -/***************************************************************************//** - * @brief Disables clock recovery - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableClockRecovery(void); -#else -#define USB_DisableClockRecovery() USB_WRITE_BYTE(CLKREC, 0x0F) -#endif - -/***************************************************************************//** - * @brief Sets the USB function address - * @param addr - * USB Function Address value - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetAddress(uint8_t addr); -#else -#define USB_SetAddress(addr) \ - USB_WRITE_BYTE(FADDR, (FADDR_UPDATE__SET | (addr))) -#endif - -/***************************************************************************//** - * @brief Disable the USB Inhibit feature - * @details The USB block is inhibited after a power-on-reset or an - * asynchronous reset. Software should disable the inhibit bit - * after all USB and transceiver initialization is complete. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableInhibit(void); -#else -#define USB_DisableInhibit() \ - USB_WRITE_BYTE(POWER, (POWER_USBINH__ENABLED | POWER_SUSEN__ENABLED)) -#endif - -/***************************************************************************//** - * @brief Forces a USB reset - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_ForceReset(void); -#else -#define USB_ForceReset() USB_WRITE_BYTE(POWER, POWER_USBRST__SET) -#endif - -/***************************************************************************//** - * @brief Forces USB resume signaling - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_ForceResume(void); -#else -#define USB_ForceResume() \ - USB_WRITE_BYTE(POWER, (POWER_RESUME__START | POWER_SUSEN__ENABLED)) -#endif - -/***************************************************************************//** - * @brief Clears USB resume signaling - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_ClearResume(void); -#else -#define USB_ClearResume() USB_WRITE_BYTE(POWER, POWER_SUSEN__ENABLED) -#endif - -/***************************************************************************//** - * @brief Enables USB suspend detection - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableSuspendDetection(void); -#else -#define USB_EnableSuspendDetection() USB_WRITE_BYTE(POWER, POWER_SUSEN__ENABLED) -#endif - -/***************************************************************************//** - * @brief Disables USB suspend detection - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableSuspendDetection(void); -#else -#define USB_DisableSuspendDetection() USB_WRITE_BYTE(POWER, 0) -#endif - -/***************************************************************************//** - * @brief Setup End Serviced - * @details Software should call this function after servicing a Setup End - * event. Setup End is detected by calling usbGetSetupEnd - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_ServicedSetupEnd(void); -#else -#define USB_ServicedSetupEnd() \ - USB_WRITE_BYTE(E0CSR, E0CSR_SSUEND__SET) -#endif - -/***************************************************************************//** - * @brief Out Packet Ready Serviced - * @details Software should call this function after servicing a received - * Endpoint 0 packet. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0ServicedOutPacketReady(void); -#else -#define USB_Ep0ServicedOutPacketReady() \ - USB_WRITE_BYTE(E0CSR, E0CSR_SOPRDY__SET) -#endif - -/***************************************************************************//** - * @brief Sets In Packet Ready and Data End on Endpoint 0 - * @details This should be called instead of @ref USB_Ep0SetInPacketReady() - * when sending the last packet of a setup data phase. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0SetLastInPacketReady(void); -#else -#define USB_Ep0SetLastInPacketReady() \ - USB_WRITE_BYTE(E0CSR, (E0CSR_INPRDY__SET | E0CSR_DATAEND__SET)) -#endif - -/***************************************************************************//** - * @brief Sets In Packet Ready and Data End on Endpoint 0 - * @details This should be called instead of @ref USB_Ep0SetInPacketReady() - * when sending a zero-length packet. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0SetZLPInPacketReady(void); -#else -#define USB_Ep0SetZLPInPacketReady() \ - USB_WRITE_BYTE(E0CSR, (E0CSR_INPRDY__SET | E0CSR_DATAEND__SET)) -#endif - -/***************************************************************************//** - * @brief Serviced Out Packet Ready and Data End on Endpoint 0 - * @details This should be called instead of @ref USB_ServicedSetupEnd() - * after servicing the last incoming data packet. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0SetLastOutPacketReady(void); -#else -#define USB_Ep0SetLastOutPacketReady() \ - USB_WRITE_BYTE(E0CSR, (E0CSR_SOPRDY__SET | E0CSR_DATAEND__SET)) -#endif - -/***************************************************************************//** - * @brief Sends a stall on Endpoint 0 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0SendStall(void); -#else -#define USB_Ep0SendStall() USB_WRITE_BYTE(E0CSR, E0CSR_SDSTL__SET) -#endif - -/***************************************************************************//** - * @brief Clears sent stall condition on Endpoint 0 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0ClearSentStall(void); -#else -#define USB_Ep0ClearSentStall() USB_WRITE_BYTE(E0CSR, 0) -#endif - -/***************************************************************************//** - * @brief Sets InPacketReady on Endpoint 0 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_Ep0SetInPacketReady(void); -#else -#define USB_Ep0SetInPacketReady() USB_WRITE_BYTE(E0CSR, E0CSR_INPRDY__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Start-of-Frame Interrupt - * @param CMINT_snapshot - * Snapshot of the CMINT register taken previously with the - * @ref USB_GetCommonInts() function. - * @return TRUE if Start-of-Frame Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsSofIntActive(uint8_t CMINT_snapshot); -#else -#define USB_IsSofIntActive(CMINT_snapshot) ((CMINT_snapshot) & CMINT_SOF__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Reset Interrupt - * @param CMINT_snapshot - * Snapshot of the CMINT register taken previously with the - * @ref USB_GetCommonInts() function. - * @return TRUE if USB Reset Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsResetIntActive(uint8_t CMINT_snapshot); -#else -#define USB_IsResetIntActive(CMINT_snapshot) \ - ((CMINT_snapshot) & CMINT_RSTINT__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Resume Interrupt - * @param CMINT_snapshot - * Snapshot of the CMINT register taken previously with the - * @ref USB_GetCommonInts() function. - * @return TRUE if USB Resume Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsResumeIntActive(uint8_t CMINT_snapshot); -#else -#define USB_IsResumeIntActive(CMINT_snapshot) \ - ((CMINT_snapshot) & CMINT_RSUINT__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Suspend Interrupt - * @param CMINT_snapshot - * Snapshot of the CMINT register taken previously with the - * @ref USB_GetCommonInts() function. - * @return TRUE if USB Suspend Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsSuspendIntActive(uint8_t CMINT_snapshot); -#else -#define USB_IsSuspendIntActive(CMINT_snapshot) \ - ((CMINT_snapshot) & CMINT_SUSINT__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 0 Interrupt - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @return TRUE if USB Endpoint 0 Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsEp0IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_IsEp0IntActive(IN1INT_snapshot) \ - ((IN1INT_snapshot) & IN1INT_EP0__SET) -#endif - -/***************************************************************************//** - * @brief Returns 1 if any USB IN Interrupt is active - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @return TRUE if any USB IN Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsInIntActive(uint8_t IN1INT_snapshot); -#else -#define USB_IsInIntActive(IN1INT_snapshot) \ - ((IN1INT_snapshot) & (IN1INT_IN1__SET | IN1INT_IN2__SET | IN1INT_IN3__SET)) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 1 IN Interrupt - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @return TRUE if USB Endpoint 1 IN Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsIn1IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_IsIn1IntActive(IN1INT_snapshot) \ - ((IN1INT_snapshot) & IN1INT_IN1__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 2 IN Interrupt - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @return TRUE if USB Endpoint 2 IN Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsIn2IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_IsIn2IntActive(IN1INT_snapshot) \ - ((IN1INT_snapshot) & IN1INT_IN2__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 3 IN Interrupt - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @return TRUE if USB Endpoint 3 IN Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsIn3IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_IsIn3IntActive(IN1INT_snapshot) \ - ((IN1INT_snapshot) & IN1INT_IN3__SET) -#endif - -/***************************************************************************//** - * @brief Returns 1 if any USB Endpoint OUT Interrupt is active - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @return TRUE if any USB OUT Interrupt is active, FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsOutIntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_IsOutIntActive(OUT1INT_snapshot) \ - ((OUT1INT_snapshot) \ - & (OUT1INT_OUT1__SET | OUT1INT_OUT2__SET | OUT1INT_OUT3__SET)) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 1 OUT Interrupt - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @return TRUE if USB Endpoint 1 OUT Interrupt is active, - * FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsOut1IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_IsOut1IntActive(OUT1INT_snapshot) \ - ((OUT1INT_snapshot) & OUT1INT_OUT1__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 2 OUT Interrupt - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @return TRUE if USB Endpoint 2 OUT Interrupt is active, - * FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsOut2IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_IsOut2IntActive(OUT1INT_snapshot) \ - ((OUT1INT_snapshot) & OUT1INT_OUT2__SET) -#endif - -/***************************************************************************//** - * @brief Returns state of USB Endpoint 3 OUT Interrupt - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @return TRUE if USB Endpoint 3 OUT Interrupt is active, - * FALSE otherwise. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern bool USB_IsOut3IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_IsOut3IntActive(OUT1INT_snapshot) \ - ((OUT1INT_snapshot) & OUT1INT_OUT3__SET) -#endif - -/***************************************************************************//** - * @brief Sets the suspend interrupt flag to active - * @param CMINT_snapshot - * Snapshot of the CMINT register taken previously with the - * @ref USB_GetCommonInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetSuspendIntActive(uint8_t CMINT_snapshot); -#else -#define USB_SetSuspendIntActive(CMINT_snapshot) \ - (CMINT_snapshot |= CMINT_SUSINT__SET) -#endif - -/***************************************************************************//** - * @brief Sets the EP0 interrupt flag to active - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetEp0IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_SetEp0IntActive(IN1INT_snapshot) \ - (IN1INT_snapshot |= IN1INT_EP0__SET) -#endif - -/***************************************************************************//** - * @brief Sets the IN 1 interrupt flag to active - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetIn1IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_SetIn1IntActive(IN1INT_snapshot) \ - (IN1INT_snapshot |= IN1INT_IN1__SET) -#endif - -/***************************************************************************//** - * @brief Sets the IN 12interrupt flag to active - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetIn2IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_SetIn2IntActive(IN1INT_snapshot) \ - (IN1INT_snapshot |= IN1INT_IN2__SET) -#endif - -/***************************************************************************//** - * @brief Sets the IN 3 interrupt flag to active - * @param IN1INT_snapshot - * Snapshot of the IN1INT register taken previously with the - * @ref USB_GetInInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetIn3IntActive(uint8_t IN1INT_snapshot); -#else -#define USB_SetIn3IntActive(IN1INT_snapshot) \ - (IN1INT_snapshot |= IN1INT_IN3__SET) -#endif - -/***************************************************************************//** - * @brief Sets the OUT 1 interrupt flag to active - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetOut1IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_SetOut1IntActive(OUT1INT_snapshot) \ - (OUT1INT_snapshot |= OUT1INT_OUT1__SET) -#endif - -/***************************************************************************//** - * @brief Sets the OUT 2 interrupt flag to active - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetOut2IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_SetOut2IntActive(OUT1INT_snapshot) \ - (OUT1INT_snapshot |= OUT1INT_OUT2__SET) -#endif - -/***************************************************************************//** - * @brief Sets the OUT 3 interrupt flag to active - * @param OUT1INT_snapshot - * Snapshot of the OUT1INT register taken previously with the - * @ref USB_GetOutInts() function. - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetOut3IntActive(uint8_t OUT1INT_snapshot); -#else -#define USB_SetOut3IntActive(OUT1INT_snapshot) \ - (OUT1INT_snapshot |= OUT1INT_OUT3__SET) -#endif - -/***************************************************************************//** - * @brief Enables USB Start-of-Frame, Reset, Resume, and - * Suspend Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableDeviceInts(void); -#else -#define USB_EnableDeviceInts() \ - USB_WRITE_BYTE(CMIE, \ - (CMIE_SOFE__ENABLED \ - | CMIE_RSTINTE__ENABLED \ - | CMIE_RSUINTE__ENABLED \ - | CMIE_SUSINTE__ENABLED)); -#endif - -/***************************************************************************//** - * @brief Enables USB Start-of-Frame Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableSofInt(void); -#else -#define USB_EnableSofInt() USB_SET_BITS(CMIE, CMIE_SOFE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Start-of-Frame Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableSofInt(void); -#else -#define USB_DisableSofInt() USB_CLEAR_BITS(CMIE, CMIE_SOFE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Reset Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableResetInt(void); -#else -#define USB_EnableResetInt() USB_SET_BITS(CMIE, CMIE_RSTINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Reset Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableResetInt(void); -#else -#define USB_DisableResetInt() USB_CLEAR_BITS(CMIE, CMIE_RSTINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Resume Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableResumeInt(void); -#else -#define USB_EnableResumeInt() USB_SET_BITS(CMIE, CMIE_RSUINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Resume Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableResumeInt(void); -#else -#define USB_DisableResumeInt() USB_CLEAR_BITS(CMIE, CMIE_RSUINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Suspend Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableSuspendInt(void); -#else -#define USB_EnableSuspendInt() USB_SET_BITS(CMIE, CMIE_SUSINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Suspend Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableSuspendInt(void); -#else -#define USB_DisableSuspendInt() USB_CLEAR_BITS(CMIE, CMIE_SUSINTE__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 0 Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableEp0Int(void); -#else -#define USB_EnableEp0Int() USB_SET_BITS(IN1IE, IN1IE_EP0E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 0 Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableEp0Int(void); -#else -#define USB_DisableEp0Int() USB_CLEAR_BITS(IN1IE, IN1IE_EP0E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 1 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableIn1Int(void); -#else -#define USB_EnableIn1Int() USB_SET_BITS(IN1IE, IN1IE_IN1E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 1 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableIn1Int(void); -#else -#define USB_DisableIn1Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN1E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 2 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableIn2Int(void); -#else -#define USB_EnableIn2Int() USB_SET_BITS(IN1IE, IN1IE_IN2E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 2 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableIn2Int(void); -#else -#define USB_DisableIn2Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN2E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 3 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableIn3Int(void); -#else -#define USB_EnableIn3Int() USB_SET_BITS(IN1IE, IN1IE_IN3E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 3 IN Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableIn3Int(void); -#else -#define USB_DisableIn3Int() USB_CLEAR_BITS(IN1IE, IN1IE_IN3E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 1 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableOut1Int(void); -#else -#define USB_EnableOut1Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 1 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableOut1Int(void); -#else -#define USB_DisableOut1Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT1E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 2 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableOut2Int(void); -#else -#define USB_EnableOut2Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 2 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableOut2Int(void); -#else -#define USB_DisableOut2Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT2E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 3 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableOut3Int(void); -#else -#define USB_EnableOut3Int() USB_SET_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 3 OUT Interrupts - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableOut3Int(void); -#else -#define USB_DisableOut3Int() USB_CLEAR_BITS(OUT1IE, OUT1IE_OUT3E__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 1 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableEp1(void); -#else -#define USB_EnableEp1() USB_SET_BITS(EENABLE, EENABLE_EEN1__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 1 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableEp1(void); -#else -#define USB_DisableEp1() USB_CLEAR_BITS(EENABLE, EENABLE_EEN1__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 2 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableEp2(void); -#else -#define USB_EnableEp2() USB_SET_BITS(EENABLE, EENABLE_EEN2__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 2 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableEp2(void); -#else -#define USB_DisableEp2() USB_CLEAR_BITS(EENABLE, EENABLE_EEN2__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables USB Endpoint 3 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableEp3(void); -#else -#define USB_EnableEp3() USB_SET_BITS(EENABLE, EENABLE_EEN3__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables USB Endpoint 3 - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableEp3(void); -#else -#define USB_DisableEp3() USB_CLEAR_BITS(EENABLE, EENABLE_EEN3__ENABLED); -#endif - -/***************************************************************************//** - * @brief Configures Endpoint N for OUT - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnDirectionOut(void); -#else -#define USB_EpnDirectionOut() USB_CLEAR_BITS(EINCSRH, EINCSRH_DIRSEL__IN); -#endif - -/***************************************************************************//** - * @brief Configures Endpoint N for IN - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnDirectionIn(void); -#else -#define USB_EpnDirectionIn() USB_SET_BITS(EINCSRH, EINCSRH_DIRSEL__IN); -#endif - -/***************************************************************************//** - * @brief Enables split mode on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnEnableSplitMode(void); -#else -#define USB_EpnEnableSplitMode() \ - USB_SET_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables split mode Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnDisableSplitMode(void); -#else -#define USB_EpnDisableSplitMode() \ - USB_CLEAR_BITS(EINCSRH, EINCSRH_SPLIT__ENABLED); -#endif - -/***************************************************************************//** - * @brief Resets the IN endpoint data toggle to '0' - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInClearDataToggle(void); -#else -#define USB_EpnInClearDataToggle() USB_SET_BITS(EINCSRL, EINCSRL_CLRDT__BMASK); -#endif - -/***************************************************************************//** - * @brief Clears sent stall condition on Endpoint N IN - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInClearSentStall(void); -#else -#define USB_EpnInClearSentStall() USB_WRITE_BYTE(EINCSRL, 0); -#endif - -/***************************************************************************//** - * @brief Sends a stall for each IN token on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInStall(void); -#else -#define USB_EpnInStall() USB_WRITE_BYTE(EINCSRL, EINCSRL_SDSTL__SET); -#endif - -/***************************************************************************//** - * @brief Stops stalling for each IN token on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEndStall(void); -#else -#define USB_EpnInEndStall() USB_WRITE_BYTE(EINCSRL, 0); -#endif - -/***************************************************************************//** - * @brief Stops stalling for each IN token on Endpoint N and clears - * the data toggle - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEndStallAndClearDataToggle(void); -#else -#define USB_EpnInEndStallAndClearDataToggle() \ - USB_WRITE_BYTE(EINCSRL, EINCSRL_CLRDT__BMASK); -#endif - -/***************************************************************************//** - * @brief Flushes In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInFlush(void); -#else -#define USB_EpnInFlush() \ - do \ - { \ - USB_WRITE_BYTE(EINCSRL, EINCSRL_FLUSH__SET); \ - do \ - { \ - USB_READ_BYTE(EINCSRL); \ - } while (USB0DAT & EINCSRL_FLUSH__SET); \ - } while (0); -#endif - -/***************************************************************************//** - * @brief Clears underrun condition on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInClearUnderrun(void); -#else -#define USB_EpnInClearUnderrun() USB_CLEAR_BITS(EINCSRL, EINCSRL_UNDRUN__SET); -#endif - -/***************************************************************************//** - * @brief Sets InPacketReady on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnSetInPacketReady(void); -#else -#define USB_EpnSetInPacketReady() USB_SET_BITS(EINCSRL, EINCSRL_INPRDY__SET); -#endif - -/***************************************************************************//** - * @brief Enables double buffering on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEnableDoubleBuffer(void); -#else -#define USB_EpnInEnableDoubleBuffer() \ - USB_SET_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables double buffering on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInDisableDoubleBuffer(void); -#else -#define USB_EpnInDisableDoubleBuffer() \ - USB_CLEAR_BITS(EINCSRH, EINCSRH_DBIEN__ENABLED); -#endif - -/***************************************************************************//** - * @brief Configures In Endpoint N for Interrupt/Bulk Mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEnableInterruptBulkMode(void); -#else -#define USB_EpnInEnableInterruptBulkMode() \ - USB_CLEAR_BITS(EINCSRH, EINCSRH_ISO__ENABLED); -#endif - -/***************************************************************************//** - * @brief Configures In Endpoint N for Isochronous Mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEnableIsochronousMode(void); -#else -#define USB_EpnInEnableIsochronousMode() \ - USB_SET_BITS(EINCSRH, EINCSRH_ISO__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables forced data toggle on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInEnableForcedDataToggle(void); -#else -#define USB_EpnInEnableForcedDataToggle() \ - USB_SET_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE); -#endif - -/***************************************************************************//** - * @brief Disables forced data toggle on In Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnInDisableForcedDataToggle(void); -#else -#define USB_EpnInDisableForcedDataToggle() \ - USB_CLEAR_BITS(EINCSRH, EINCSRH_FCDT__ALWAYS_TOGGLE); -#endif - -/***************************************************************************//** - * @brief Resets the OUT endpoint data toggle to '0' - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutClearDataToggle(void); -#else -#define USB_EpnOutClearDataToggle() \ - USB_SET_BITS(EOUTCSRL, EOUTCSRL_CLRDT__BMASK); -#endif - -/***************************************************************************//** - * @brief Clears sent stall condition on Endpoint N OUT - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutClearSentStall(void); -#else -#define USB_EpnOutClearSentStall() \ - USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_STSTL__BMASK); -#endif - -/***************************************************************************//** - * @brief Sends a stall for each OUT token on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutStall(void); -#else -#define USB_EpnOutStall() \ - USB_SET_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET); -#endif - -/***************************************************************************//** - * @brief Stops stalling for each OUT token on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutEndStall(void); -#else -#define USB_EpnOutEndStall() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_SDSTL__SET); -#endif - -/***************************************************************************//** - * @brief Stops stalling for each OUT token on Endpoint N and clears - * the data toggle - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutEndStallAndClearDataToggle(void); -#else -#define USB_EpnOutEndStallAndClearDataToggle() \ - do \ - { \ - USB_READ_BYTE(EOUTCSRL); \ - USB0DAT &= ~EOUTCSRL_SDSTL__SET; \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0DAT |= EOUTCSRL_CLRDT__BMASK; \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - } while (0); -#endif - -/***************************************************************************//** - * @brief Flushes OUT Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutFlush(void); -#else -#define USB_EpnOutFlush() \ - do \ - { \ - USB_WRITE_BYTE(EOUTCSRL, EOUTCSRL_FLUSH__SET); \ - do \ - { \ - USB_READ_BYTE(EOUTCSRL); \ - } while (USB0DAT & EOUTCSRL_FLUSH__SET); \ - } while (0); -#endif - -/***************************************************************************//** - * @brief Clears overrun condition on OUT Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutClearOverrun(void); -#else -#define USB_EpnOutClearOverrun() USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OVRUN__SET); -#endif - -/***************************************************************************//** - * @brief Clears OutPacketReady on Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnClearOutPacketReady(void); -#else -#define USB_EpnClearOutPacketReady() \ - USB_CLEAR_BITS(EOUTCSRL, EOUTCSRL_OPRDY__SET); -#endif - -/***************************************************************************//** - * @brief Enables double buffering on OUT Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutEnableDoubleBuffer(void); -#else -#define USB_EpnOutEnableDoubleBuffer() \ - USB_SET_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED); -#endif - -/***************************************************************************//** - * @brief Disables double buffering on OUT Endpoint N - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutDisableDoubleBuffer(void); -#else -#define USB_EpnOutDisableDoubleBuffer() \ - USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_DBIEN__ENABLED); -#endif - -/***************************************************************************//** - * @brief Configures OUT Endpoint N for Interrupt/Bulk Mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutEnableInterruptBulkMode(void); -#else -#define USB_EpnOutEnableInterruptBulkMode() \ - USB_CLEAR_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED); -#endif - -/***************************************************************************//** - * @brief Configures OUT Endpoint N for Isochronous Mode - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EpnOutEnableIsochronousMode(void); -#else -#define USB_EpnOutEnableIsochronousMode() \ - USB_SET_BITS(EOUTCSRH, EOUTCSRH_ISO__ENABLED); -#endif - -/***************************************************************************//** - * @brief Enables FIFO read - * @param fifoNum - * FIFO to read - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableReadFIFO(uint8_t fifoNum); -#else -#define USB_EnableReadFIFO(fifoNum) \ - do \ - { \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0ADR = (USB0ADR_BUSY__SET \ - | USB0ADR_AUTORD__ENABLED \ - | (FIFO0 | fifoNum)); \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables FIFO read - * @param fifoNum - * FIFO that was read from - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableReadFIFO(uint8_t fifoNum); -#else -#define USB_DisableReadFIFO(fifoNum) -#endif - -/***************************************************************************//** - * @brief Reads a byte from the FIFO - * @param readDat - * Memory location to write the byte read from the FIFO - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_GetFIFOByte(uint8_t * readDat); -#else -#define USB_GetFIFOByte(readDat) \ - do \ - { \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - readDat = USB0DAT; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Reads the last byte from the FIFO - * @details The last read must be done with the AUTORD bit cleared. - * This prevents the read from triggering another read - * immediately thereafter. - * @param readDat - * Memory location to write the byte read from the FIFO - * @param fifoNum - * FIFO to read - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_GetLastFIFOByte(uint8_t * readDat, uint8_t fifoNum); -#else -#define USB_GetLastFIFOByte(readDat, fifoNum) \ - do \ - { \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0ADR = (FIFO0 | fifoNum);\ - readDat = USB0DAT; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Enables FIFO write - * @param fifoNum - * FIFO to write - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_EnableWriteFIFO(uint8_t fifoNum); -#else -#define USB_EnableWriteFIFO(fifoNum) \ - do \ - { \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0ADR = (FIFO0 | fifoNum); \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Disables FIFO write - * @param fifoNum - * FIFO that was written to - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_DisableWriteFIFO(uint8_t fifoNum); -#else -#define USB_DisableWriteFIFO(fifoNum) -#endif - -/***************************************************************************//** - * @brief Writes a byte to the FIFO - * @param writeDat - * Data to write to the FIFO - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SetFIFOByte(uint8_t writeDat); -#else -#define USB_SetFIFOByte(writeDat) \ - do \ - { \ - while (USB0ADR & USB0ADR_BUSY__SET) {} \ - USB0DAT = writeDat; \ - } while (0) -#endif - -/***************************************************************************//** - * @brief Saves the current SFR page - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_SaveSfrPage(); -#else -#define USB_SaveSfrPage() uint8_t SfrPageSave = SFRPAGE -#endif - -/***************************************************************************//** - * @brief Restores the SFR page - * @note @ref USB_SaveSfrPage() must be called before calling this macro - * @note This function is implemented as a macro. - ******************************************************************************/ -#ifdef IS_DOXYGEN -extern void USB_RestoreSfrPage(); -#else -#define USB_RestoreSfrPage() SFRPAGE = SfrPageSave -#endif - -// ------------------------------- -// Function Prototypes - -/***************************************************************************//** - * @brief Writes a value to INDEX - * @param epsel - * Endpoint index to target - ******************************************************************************/ -void USB_SetIndex(uint8_t epsel); - -/***************************************************************************//** - * @brief Reads the USB common interrupt register - * @return Value of CMINT - ******************************************************************************/ -uint8_t USB_GetCommonInts(void); - -/***************************************************************************//** - * @brief Reads the USB in interrupt register - * @return Value of IN1INT - ******************************************************************************/ -uint8_t USB_GetInInts(void); - -/***************************************************************************//** - * @brief Reads the out interrupt register - * @return Value of OUT1INT - ******************************************************************************/ -uint8_t USB_GetOutInts(void); - -/***************************************************************************//** - * @brief Reads the value in INDEX - * @return Value of INDEX - ******************************************************************************/ -uint8_t USB_GetIndex(void); - -/***************************************************************************//** - * @brief Determines if the USB is currently suspended - * @return TRUE if USB is in suspend mode - ******************************************************************************/ -bool USB_IsSuspended(void); - -/***************************************************************************//** - * @brief Gets Setup End state - * @return TRUE when a control transaction end before software has - * set the DATAEND bit. - ******************************************************************************/ -bool USB_GetSetupEnd(void); - -/***************************************************************************//** - * @brief Determines if STALL was send on Endpoint 0 - * @return TRUE after a STALL was sent on Endpoint 0 - ******************************************************************************/ -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 - ******************************************************************************/ -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 - ******************************************************************************/ -bool USB_Ep0OutPacketReady(void); - -/***************************************************************************//** - * @brief Gets Endpoint 0 data count - * @return Number of received data bytes in the Endpoint 0 FIFO - ******************************************************************************/ -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 - ******************************************************************************/ -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 - ******************************************************************************/ -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 - ******************************************************************************/ -bool USB_EpnOutGetSentStall(void); - -/***************************************************************************//** - * @brief Gets OutPacketReady on OUT Endpoint N - * @return TRUE if OUTPacketReady is set, FALSE otherwise - ******************************************************************************/ -bool USB_EpnGetOutPacketReady(void); - -/***************************************************************************//** - * @brief Gets number of bytes in the OUT FIFO - * OUT packet - * @return Number of bytes in the FIFO from the last received - * packet - ******************************************************************************/ -uint16_t USB_EpOutGetCount(void); - -/***************************************************************************//** - * @brief Reads the USB frame number - * @return The frame number on the most recent SOF packet - ******************************************************************************/ -uint16_t USB_GetSofNumber(void); - -/***************************************************************************//** - * @brief Aborts pending IN transactions on the selected endpoint - * @param fifoNum - * Endpoint to abort - ******************************************************************************/ -void USB_AbortInEp(uint8_t fifoNum); - -/***************************************************************************//** - * @brief Aborts pending OUT transactions on the selected endpoint - * @param fifoNum - * Endpoint to abort - ******************************************************************************/ -void USB_AbortOutEp(uint8_t fifoNum); - -/***************************************************************************//** - * @brief Activates the selected endpoint - * @param ep - * Endpoint to access - * @param packetSize - * Maximum packet size for endpoint - * @param inDir - * Set to 1 if endpoint is IN, 0 if it is OUT - * @param splitMode - * Set to 1 if endpoint is in split mode, 0 if it is not - * @param isoMode - * Set to 1 if endpoint is in isochronous mode, 0 if it is not - ******************************************************************************/ -void USB_ActivateEp(uint8_t ep, - uint16_t packetSize, - bool inDir, - bool splitMode, - bool isoMode); - -/** @} (end addtogroup usb_0_runtime USB0 Runtime API) */ -/** @} (end addtogroup usb_0_group USB0 Driver) */ - -// ----------------------------------------------------------------------------- -// Error Checking - -// ------------------------------- -// Verify that the maximum packet size specified for an endpoint is not too -// large for that endpoint - -#ifdef SLAB_USB_EP1IN_USED - #if SLAB_USB_EP1IN_USED - #if SLAB_USB_EP1IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #error Isochronous transfers are not supported on Endpoint 1. - #else // #if SLAB_USB_EP1IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP1IN_MAX_PACKET_SIZE > 64 - #error EP1IN packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP1IN_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP1IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP1IN_USED -#endif // #ifdef SLAB_USB_EP1IN_USED - -#ifdef SLAB_USB_EP1OUT_USED - #if SLAB_USB_EP1OUT_USED - #if SLAB_USB_EP1OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #error Isochronous transfers are not supported on Endpoint 1. - #else // #if SLAB_USB_EP1OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP1OUT_MAX_PACKET_SIZE > 64 - #error EP1OUT packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP1OUT_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP1OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP1OUT_USED -#endif // #ifdef SLAB_USB_EP1OUT_USED - -#ifdef SLAB_USB_EP2IN_USED - #if SLAB_USB_EP2IN_USED - #if SLAB_USB_EP2IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #error Isochronous transfers are not supported on Endpoint 2. - #else // #if SLAB_USB_EP2IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP2IN_MAX_PACKET_SIZE > 64 - #error EP2IN packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP2IN_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP2IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP2IN_USED -#endif // #ifdef SLAB_USB_EP2IN_USED - -#ifdef SLAB_USB_EP2OUT_USED - #if SLAB_USB_EP2OUT_USED - #if SLAB_USB_EP2OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #error Isochronous transfers are not supported on Endpoint 2. - #else // #if SLAB_USB_EP2OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP2OUT_MAX_PACKET_SIZE > 64 - #error EP2OUT packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP2OUT_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP2OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP2OUT_USED -#endif // #ifdef SLAB_USB_EP2OUT_USED - -#ifdef SLAB_USB_EP3IN_USED - #if SLAB_USB_EP3IN_USED - #if SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP3OUT_USED - #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 256 - #error EP3IN packet size too large. FIFO 3 split mode packet size must be 256 bytes or less. - #endif // #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 256 - #else // #if SLAB_USB_EP3OUT_USED - #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 512 - #error EP3IN packet size too large. FIFO 3 packet size must be 512 bytes or less. - #endif // #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 512 - #endif // #if SLAB_USB_EP3OUT_USED - #else // #if SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 64 - #error EP3IN packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP3IN_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP3IN_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP3IN_USED -#endif // #ifdef SLAB_USB_EP3IN_USED - -#ifdef SLAB_USB_EP3OUT_USED - #if SLAB_USB_EP3OUT_USED - #if SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP3IN_USED - #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 256 - #error EP3OUT packet size too large. FIFO 3 split mode packet size must be 256 bytes or less. - #endif // #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 256 - #else // #if SLAB_USB_EP3IN_USED - #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 512 - #error EP3OUT packet size too large. FIFO 3 packet size must be 512 bytes or less. - #endif // #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 512 - #endif // #if SLAB_USB_EP3IN_USED - #else // #if SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 64 - #error EP3OUT packet size too large. Interrupt/Bulk packet size must be 64 bytes or less. - #endif // #if SLAB_USB_EP3OUT_MAX_PACKET_SIZE > 64 - #endif // #if SLAB_USB_EP3OUT_TRANSFER_TYPE == USB_EPTYPE_ISOC - #endif // #if SLAB_USB_EP3OUT_USED -#endif // #ifdef SLAB_USB_EP3OUT_USED - -#endif // __SILICON_LABS_EFM8_USB_0_H__ diff --git a/lib/efm8ub1/peripheralDrivers/src/usb_0.c b/lib/efm8ub1/peripheralDrivers/src/usb_0.c deleted file mode 100644 index 9c44e3f..0000000 --- a/lib/efm8ub1/peripheralDrivers/src/usb_0.c +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************//** - * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. - * - * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt - *****************************************************************************/ - -#include "usb_0.h" -#include -#include - -/** @addtogroup usb_0_runtime USB0 Runtime API */ - -// ----------------------------------------------------------------------------- -// Functions - -// ------------------------------- -// Utility Functions - -/**************************************************************************//** - * @brief Reads a 16-bit indirect USB register value - * @param regAddr - * Address of high byte of 16-bit USB indirect register to read - * @return 16-bit register value - *****************************************************************************/ -static uint16_t USB_GetShortRegister(uint8_t regAddr) -{ - uint16_t retVal; - - USB_READ_BYTE(regAddr); - retVal = (USB0DAT << 8); - USB_READ_BYTE((regAddr - 1)); - retVal |= USB0DAT; - - return retVal; -} - -// ------------------------------- -// USB0 Peripheral Driver Functions - -void USB_SetIndex(uint8_t epsel) -{ - USB_WRITE_BYTE(INDEX, epsel); -} - -uint8_t USB_GetCommonInts(void) -{ - USB_READ_BYTE(CMINT); - return USB0DAT; -} - -uint8_t USB_GetInInts(void) -{ - USB_READ_BYTE(IN1INT); - return USB0DAT; -} - -uint8_t USB_GetOutInts(void) -{ - USB_READ_BYTE(OUT1INT); - return USB0DAT; -} - -uint8_t USB_GetIndex(void) -{ - USB_READ_BYTE(INDEX); - return USB0DAT; -} - -bool USB_IsSuspended(void) -{ - USB_READ_BYTE(POWER); - return USB0DAT & POWER_SUSMD__SUSPENDED; -} - -bool USB_GetSetupEnd(void) -{ - USB_READ_BYTE(E0CSR); - return USB0DAT & E0CSR_SUEND__SET; -} - -bool USB_Ep0SentStall(void) -{ - USB_READ_BYTE(E0CSR); - return USB0DAT & E0CSR_STSTL__SET; -} - -bool USB_Ep0OutPacketReady(void) -{ - USB_READ_BYTE(E0CSR); - return USB0DAT & E0CSR_OPRDY__SET; -} - -bool USB_Ep0InPacketReady(void) -{ - USB_READ_BYTE(E0CSR); - return USB0DAT & E0CSR_INPRDY__SET; -} - -uint8_t USB_Ep0GetCount(void) -{ - USB_READ_BYTE(E0CNT); - return USB0DAT; -} - -bool USB_EpnInGetSentStall(void) -{ - USB_READ_BYTE(EINCSRL); - return (bool)(USB0DAT & EINCSRL_STSTL__SET); -} - -void USB_AbortInEp(uint8_t fifoNum) -{ - USB_SetIndex(fifoNum); - USB_EpnInFlush(); - USB_EpnInFlush(); -} - -bool USB_EpnOutGetSentStall(void) -{ - USB_READ_BYTE(EOUTCSRL); - return (bool)(USB0DAT & EOUTCSRL_STSTL__SET); -} - -bool USB_EpnGetOutPacketReady(void) -{ - USB_READ_BYTE(EOUTCSRL); - return (bool)(USB0DAT & EOUTCSRL_OPRDY__SET); -} - -uint16_t USB_EpOutGetCount(void) -{ - return USB_GetShortRegister(EOUTCNTH); -} - -void USB_AbortOutEp(uint8_t fifoNum) -{ - USB_SetIndex(fifoNum); - USB_EpnOutFlush(); - USB_EpnOutFlush(); -} - -void USB_ActivateEp(uint8_t ep, - uint16_t packetSize, - bool inDir, - bool splitMode, - bool isoMode) -{ - uint8_t CSRH_mask = 0; - uint16_t fifoSize; - - USB_SetIndex(ep); - - // Determine the available fifoSize for a given endpoint based on the - // splitMode setting - fifoSize = (splitMode == true) ? (16 << ep) : (32 << ep); - - if (packetSize <= fifoSize) - { - CSRH_mask |= EINCSRH_DBIEN__ENABLED; - } - - if (isoMode == true) - { - CSRH_mask |= EINCSRH_ISO__ENABLED; - } - - if (inDir == true) - { - CSRH_mask |= EINCSRH_DIRSEL__IN; - - if (splitMode == true) - { - CSRH_mask |= EINCSRH_SPLIT__ENABLED; - } - USB_WRITE_BYTE(EINCSRL, EINCSRL_CLRDT__BMASK); - USB_WRITE_BYTE(EINCSRH, CSRH_mask); - } - else // OUT - { - USB_WRITE_BYTE(EOUTCSRL, EOUTCSRL_CLRDT__BMASK); - USB_WRITE_BYTE(EOUTCSRH, CSRH_mask); - - if (splitMode == false) - { - USB_WRITE_BYTE(EINCSRH, 0); - } - } -} - -uint16_t USB_GetSofNumber(void) -{ - return USB_GetShortRegister(FRAMEH); -} - -bool USB_GetIntsEnabled(void) -{ - SFRPAGE = PG2_PAGE; - return (bool)(EIE2 & EIE2_EUSB0__ENABLED); -} - -bool USB_IsPrefetchEnabled(void) -{ - SFRPAGE = PG2_PAGE; - return (bool)(PFE0CN & PFE0CN_PFEN__ENABLED); -} - -bool USB_IsRegulatorEnabled(void) -{ - SFRPAGE = PG3_PAGE; - return !(REG1CN & REG1CN_REG1ENB__DISABLED); -} - -void USB_SuspendOscillator(void) -{ - uint8_t clkSelSave = CLKSEL & 0x7F; - - CLKSEL = (CLKSEL_CLKDIV__SYSCLK_DIV_8 | CLKSEL_CLKSL__HFOSC0); - SFRPAGE = LEGACY_PAGE; - PCON1 |= PCON1_SUSPEND__SUSPEND; - CLKSEL = clkSelSave; - - // If the target frequency is over 24MHz, our write to CLKSEL will be ignored. - // If this is the case we need to do two writes: one to 24 MHz followed by the - // actual value. - if ((CLKSEL & 0x7F) != clkSelSave) - { - CLKSEL = (CLKSEL_CLKDIV__SYSCLK_DIV_1 | CLKSEL_CLKSL__HFOSC0); - CLKSEL = clkSelSave; - } -} - -/** @} (end addtogroup usb_0_runtime USB0 Runtime API) */ diff --git a/targets/efm32boot/.cproject b/targets/efm32boot/.cproject index 5bb2be4..626f875 100644 --- a/targets/efm32boot/.cproject +++ b/targets/efm32boot/.cproject @@ -48,11 +48,11 @@ - - - - - + + + + + diff --git a/targets/efm32boot/.project b/targets/efm32boot/.project index a9b2d9b..8c10efc 100644 --- a/targets/efm32boot/.project +++ b/targets/efm32boot/.project @@ -21,7 +21,7 @@ crypto 2 - $%7BPARENT-1-PROJECT_LOC%7D/crypto + PARENT-2-PROJECT_LOC/crypto efm32 @@ -31,7 +31,7 @@ fido2 2 - $%7BPARENT-1-PROJECT_LOC%7D/fido2 + PARENT-2-PROJECT_LOC/fido2 CMSIS/EFM32JG1B/startup_gcc_efm32jg1b.s diff --git a/nrf52840/Makefile b/targets/nrf52840/Makefile similarity index 100% rename from nrf52840/Makefile rename to targets/nrf52840/Makefile diff --git a/nrf52840/app_config.h b/targets/nrf52840/app_config.h similarity index 100% rename from nrf52840/app_config.h rename to targets/nrf52840/app_config.h diff --git a/nrf52840/blinky_gcc_nrf52.ld b/targets/nrf52840/blinky_gcc_nrf52.ld similarity index 100% rename from nrf52840/blinky_gcc_nrf52.ld rename to targets/nrf52840/blinky_gcc_nrf52.ld diff --git a/nrf52840/crypto.c b/targets/nrf52840/crypto.c similarity index 100% rename from nrf52840/crypto.c rename to targets/nrf52840/crypto.c diff --git a/nrf52840/device.c b/targets/nrf52840/device.c similarity index 100% rename from nrf52840/device.c rename to targets/nrf52840/device.c diff --git a/nrf52840/list.py b/targets/nrf52840/list.py similarity index 100% rename from nrf52840/list.py rename to targets/nrf52840/list.py diff --git a/nrf52840/main.c b/targets/nrf52840/main.c similarity index 100% rename from nrf52840/main.c rename to targets/nrf52840/main.c diff --git a/nrf52840/pyserial.py b/targets/nrf52840/pyserial.py similarity index 100% rename from nrf52840/pyserial.py rename to targets/nrf52840/pyserial.py diff --git a/nrf52840/retarget.c b/targets/nrf52840/retarget.c similarity index 100% rename from nrf52840/retarget.c rename to targets/nrf52840/retarget.c diff --git a/nrf52840/sdk_config.h b/targets/nrf52840/sdk_config.h similarity index 100% rename from nrf52840/sdk_config.h rename to targets/nrf52840/sdk_config.h diff --git a/nrf52840/usb.c b/targets/nrf52840/usb.c similarity index 100% rename from nrf52840/usb.c rename to targets/nrf52840/usb.c diff --git a/nrf52840/usb.h b/targets/nrf52840/usb.h similarity index 100% rename from nrf52840/usb.h rename to targets/nrf52840/usb.h diff --git a/nrf52840/usbhid.c b/targets/nrf52840/usbhid.c similarity index 100% rename from nrf52840/usbhid.c rename to targets/nrf52840/usbhid.c