Make the keyboard + mouse composite USB device work based on the KSDK 2.0 usb_device_composite_hid_mouse_hid_keyboard demo.
This commit is contained in:
49
right/include/board/board.c
Normal file
49
right/include/board/board.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_debug_console.h"
|
||||
#include "board.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
/* Initialize debug console. */
|
||||
void BOARD_InitDebugConsole(void)
|
||||
{
|
||||
uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
|
||||
|
||||
DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
|
||||
}
|
||||
158
right/include/board/board.h
Normal file
158
right/include/board/board.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include "clock_config.h"
|
||||
#include "fsl_gpio.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*! @brief The board name */
|
||||
#define BOARD_NAME "FRDM-K22F"
|
||||
|
||||
/*! @brief The UART to use for debug messages. */
|
||||
#define BOARD_USE_UART
|
||||
#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART
|
||||
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART1
|
||||
#define BOARD_DEBUG_UART_CLKSRC SYS_CLK
|
||||
#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetCoreSysClkFreq()
|
||||
#define BOARD_UART_IRQ UART1_RX_TX_IRQn
|
||||
#define BOARD_UART_IRQ_HANDLER UART1_RX_TX_IRQHandler
|
||||
|
||||
#ifndef BOARD_DEBUG_UART_BAUDRATE
|
||||
#define BOARD_DEBUG_UART_BAUDRATE 115200
|
||||
#endif /* BOARD_DEBUG_UART_BAUDRATE */
|
||||
|
||||
/*! @brief The Flextimer instance/channel used for board */
|
||||
#define BOARD_FTM_BASEADDR FTM0
|
||||
#define BOARD_FTM_CHANNEL 5U
|
||||
#define BOARD_FTM_X_CHANNEL 0U
|
||||
#define BOARD_FTM_Y_CHANNEL 1U
|
||||
#define BOARD_FTM_PERIOD_HZ 100U
|
||||
#define BOARD_FTM_IRQ_HANDLER FTM0_IRQHandler
|
||||
#define BOARD_FTM_IRQ_VECTOR FTM0_IRQn
|
||||
|
||||
/*! @brief The bubble level demo information */
|
||||
#define BOARD_FXOS8700_ADDR 0x1C
|
||||
#define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR
|
||||
#define BOARD_ACCEL_BAUDRATE 100
|
||||
#define BOARD_ACCEL_I2C_BASEADDR I2C0
|
||||
|
||||
/*! @brief The i2c instance used for i2c connection by default */
|
||||
#define BOARD_I2C_BASEADDR I2C0
|
||||
|
||||
/*! @brief The CMP instance/channel used for board. */
|
||||
#define BOARD_CMP_BASEADDR CMP0
|
||||
#define BOARD_CMP_CHANNEL 0U
|
||||
|
||||
/*! @brief The rtc instance used for board. */
|
||||
#define BOARD_RTC_FUNC_BASEADDR RTC
|
||||
|
||||
/*! @brief Define the port interrupt number for the board switches */
|
||||
#define BOARD_SW3_GPIO GPIOB
|
||||
#define BOARD_SW3_PORT PORTB
|
||||
#define BOARD_SW3_GPIO_PIN 17
|
||||
#define BOARD_SW3_IRQ PORTB_IRQn
|
||||
#define BOARD_SW3_IRQ_HANDLER PORTB_IRQHandler
|
||||
#define BOARD_SW3_NAME "SW3"
|
||||
|
||||
#define BOARD_SW2_GPIO GPIOC
|
||||
#define BOARD_SW2_PORT PORTC
|
||||
#define BOARD_SW2_GPIO_PIN 1
|
||||
#define BOARD_SW2_IRQ PORTC_IRQn
|
||||
#define BOARD_SW2_IRQ_HANDLER PORTC_IRQHandler
|
||||
#define BOARD_SW2_NAME "SW2"
|
||||
|
||||
/* Board led color mapping */
|
||||
#define LOGIC_LED_ON 0U
|
||||
#define LOGIC_LED_OFF 1U
|
||||
#define BOARD_LED_RED_GPIO GPIOA
|
||||
#define BOARD_LED_RED_GPIO_PORT PORTA
|
||||
#define BOARD_LED_RED_GPIO_PIN 1U
|
||||
#define BOARD_LED_GREEN_GPIO GPIOA
|
||||
#define BOARD_LED_GREEN_GPIO_PORT PORTA
|
||||
#define BOARD_LED_GREEN_GPIO_PIN 2U
|
||||
#define BOARD_LED_BLUE_GPIO GPIOD
|
||||
#define BOARD_LED_BLUE_GPIO_PORT PORTD
|
||||
#define BOARD_LED_BLUE_GPIO_PIN 5U
|
||||
|
||||
#define LED_RED_INIT(output) \
|
||||
GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, \
|
||||
&(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */
|
||||
#define LED_RED_ON() \
|
||||
GPIO_ClearPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
|
||||
#define LED_RED_OFF() \
|
||||
GPIO_SetPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
|
||||
#define LED_RED_TOGGLE() \
|
||||
GPIO_TogglePinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
|
||||
|
||||
#define LED_GREEN_INIT(output) \
|
||||
GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, \
|
||||
&(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */
|
||||
#define LED_GREEN_ON() \
|
||||
GPIO_ClearPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
|
||||
#define LED_GREEN_OFF() \
|
||||
GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
|
||||
#define LED_GREEN_TOGGLE() \
|
||||
GPIO_TogglePinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
|
||||
|
||||
#define LED_BLUE_INIT(output) \
|
||||
GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, \
|
||||
&(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */
|
||||
#define LED_BLUE_ON() \
|
||||
GPIO_ClearPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
|
||||
#define LED_BLUE_OFF() \
|
||||
GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
|
||||
#define LED_BLUE_TOGGLE() \
|
||||
GPIO_TogglePinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
|
||||
|
||||
/* @brief FreeRTOS tickless timer configuration. */
|
||||
#define vPortLptmrIsr LPTMR0_IRQHandler /*!< Timer IRQ handler. */
|
||||
#define TICKLESS_LPTMR_BASE_PTR LPTMR0 /*!< Tickless timer base address. */
|
||||
#define TICKLESS_LPTMR_IRQn LPTMR0_IRQn /*!< Tickless timer IRQ number. */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
void BOARD_InitDebugConsole(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
258
right/include/board/clock_config.c
Normal file
258
right/include/board/clock_config.c
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_smc.h"
|
||||
#include "clock_config.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*! @brief Clock configuration structure. */
|
||||
typedef struct _clock_config
|
||||
{
|
||||
mcg_config_t mcgConfig; /*!< MCG configuration. */
|
||||
sim_clock_config_t simConfig; /*!< SIM configuration. */
|
||||
osc_config_t oscConfig; /*!< OSC configuration. */
|
||||
uint32_t coreClock; /*!< core clock frequency. */
|
||||
} clock_config_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/* System clock frequency. */
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/* Configuration for enter VLPR mode. Core clock = 4MHz. */
|
||||
const clock_config_t g_defaultClockConfigVlpr = {
|
||||
.mcgConfig =
|
||||
{
|
||||
.mcgMode = kMCG_ModeBLPI, /* Work in BLPI mode. */
|
||||
.irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
|
||||
.ircs = kMCG_IrcFast, /* Select IRC4M. */
|
||||
.fcrdiv = 0U, /* FCRDIV is 0. */
|
||||
|
||||
.frdiv = 0U,
|
||||
.drs = kMCG_DrsLow, /* Low frequency range. */
|
||||
.dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
|
||||
.oscsel = kMCG_OscselOsc, /* Select OSC. */
|
||||
|
||||
.pll0Config =
|
||||
{
|
||||
.enableMode = 0U, /* Don't eanble PLL. */
|
||||
.prdiv = 0U,
|
||||
.vdiv = 0U,
|
||||
},
|
||||
},
|
||||
.simConfig =
|
||||
{
|
||||
.pllFllSel = 3U, /* PLLFLLSEL select IRC48MCLK. */
|
||||
.er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
|
||||
.clkdiv1 = 0x00040000U, /* SIM_CLKDIV1. */
|
||||
},
|
||||
.oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
|
||||
.capLoad = 0,
|
||||
.workMode = kOSC_ModeOscLowPower,
|
||||
.oscerConfig =
|
||||
{
|
||||
.enableMode = kOSC_ErClkEnable,
|
||||
#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
|
||||
.erclkDiv = 0U,
|
||||
#endif
|
||||
}},
|
||||
.coreClock = 4000000U, /* Core clock frequency */
|
||||
};
|
||||
|
||||
/* Configuration for enter RUN mode. Core clock = 80MHz. */
|
||||
const clock_config_t g_defaultClockConfigRun = {
|
||||
.mcgConfig =
|
||||
{
|
||||
.mcgMode = kMCG_ModePEE, /* Work in PEE mode. */
|
||||
.irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
|
||||
.ircs = kMCG_IrcSlow, /* Select IRC32k.*/
|
||||
.fcrdiv = 0U, /* FCRDIV is 0. */
|
||||
|
||||
.frdiv = 3U,
|
||||
.drs = kMCG_DrsLow, /* Low frequency range. */
|
||||
.dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
|
||||
.oscsel = kMCG_OscselOsc, /* Select OSC. */
|
||||
|
||||
.pll0Config =
|
||||
{
|
||||
.enableMode = 0U, .prdiv = 0x3U, .vdiv = 0x10U,
|
||||
},
|
||||
},
|
||||
.simConfig =
|
||||
{
|
||||
.pllFllSel = 1U, /* PLLFLLSEL select PLL. */
|
||||
.er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
|
||||
.clkdiv1 = 0x01230000U, /* SIM_CLKDIV1. */
|
||||
},
|
||||
.oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
|
||||
.capLoad = 0,
|
||||
.workMode = kOSC_ModeOscLowPower,
|
||||
.oscerConfig =
|
||||
{
|
||||
.enableMode = kOSC_ErClkEnable,
|
||||
#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
|
||||
.erclkDiv = 0U,
|
||||
#endif
|
||||
}},
|
||||
.coreClock = 80000000U, /* Core clock frequency */
|
||||
};
|
||||
|
||||
/* Configuration for HSRUN mode. Core clock = 120MHz. */
|
||||
const clock_config_t g_defaultClockConfigHsrun = {
|
||||
.mcgConfig =
|
||||
{
|
||||
.mcgMode = kMCG_ModePEE, /* Work in PEE mode. */
|
||||
.irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enable. */
|
||||
.ircs = kMCG_IrcSlow, /* Select IRC32k. */
|
||||
.fcrdiv = 0U, /* FCRDIV is 0. */
|
||||
|
||||
.frdiv = 3U,
|
||||
.drs = kMCG_DrsLow, /* Low frequency range. */
|
||||
.dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25%. */
|
||||
.oscsel = kMCG_OscselOsc, /* Select OSC. */
|
||||
|
||||
.pll0Config =
|
||||
{
|
||||
.enableMode = 0U, .prdiv = 0x1U, .vdiv = 0x6U,
|
||||
},
|
||||
},
|
||||
.simConfig =
|
||||
{
|
||||
.pllFllSel = 1U, /* PLLFLLSEL select PLL. */
|
||||
.er32kSrc = 2U, /* ERCLK32K selection, use RTC. */
|
||||
.clkdiv1 = 0x01340000U, /* SIM_CLKDIV1. */
|
||||
},
|
||||
.oscConfig = {.freq = BOARD_XTAL0_CLK_HZ,
|
||||
.capLoad = 0,
|
||||
.workMode = kOSC_ModeOscLowPower,
|
||||
.oscerConfig =
|
||||
{
|
||||
.enableMode = kOSC_ErClkEnable,
|
||||
#if (defined(FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER) && FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER)
|
||||
.erclkDiv = 0U,
|
||||
#endif
|
||||
}},
|
||||
.coreClock = 120000000U, /* Core clock frequency */
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
/*
|
||||
* How to setup clock using clock driver functions:
|
||||
*
|
||||
* 1. CLOCK_SetSimSafeDivs, to make sure core clock, bus clock, flexbus clock
|
||||
* and flash clock are in allowed range during clock mode switch.
|
||||
*
|
||||
* 2. Call CLOCK_Osc0Init to setup OSC clock, if it is used in target mode.
|
||||
*
|
||||
* 3. Set MCG configuration, MCG includes three parts: FLL clock, PLL clock and
|
||||
* internal reference clock(MCGIRCLK). Follow the steps to setup:
|
||||
*
|
||||
* 1). Call CLOCK_BootToXxxMode to set MCG to target mode.
|
||||
*
|
||||
* 2). If target mode is FBI/BLPI/PBI mode, the MCGIRCLK has been configured
|
||||
* correctly. For other modes, need to call CLOCK_SetInternalRefClkConfig
|
||||
* explicitly to setup MCGIRCLK.
|
||||
*
|
||||
* 3). Don't need to configure FLL explicitly, because if target mode is FLL
|
||||
* mode, then FLL has been configured by the function CLOCK_BootToXxxMode,
|
||||
* if the target mode is not FLL mode, the FLL is disabled.
|
||||
*
|
||||
* 4). If target mode is PEE/PBE/PEI/PBI mode, then the related PLL has been
|
||||
* setup by CLOCK_BootToXxxMode. In FBE/FBI/FEE/FBE mode, the PLL could
|
||||
* be enabled independently, call CLOCK_EnablePll0 explicitly in this case.
|
||||
*
|
||||
* 4. Call CLOCK_SetSimConfig to set the clock configuration in SIM.
|
||||
*/
|
||||
|
||||
void BOARD_BootClockVLPR(void)
|
||||
{
|
||||
CLOCK_SetSimSafeDivs();
|
||||
|
||||
CLOCK_BootToBlpiMode(g_defaultClockConfigVlpr.mcgConfig.fcrdiv, g_defaultClockConfigVlpr.mcgConfig.ircs,
|
||||
g_defaultClockConfigVlpr.mcgConfig.irclkEnableMode);
|
||||
|
||||
CLOCK_SetSimConfig(&g_defaultClockConfigVlpr.simConfig);
|
||||
|
||||
SystemCoreClock = g_defaultClockConfigVlpr.coreClock;
|
||||
|
||||
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
|
||||
SMC_SetPowerModeVlpr(SMC);
|
||||
while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateVlpr)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void BOARD_BootClockRUN(void)
|
||||
{
|
||||
CLOCK_SetSimSafeDivs();
|
||||
|
||||
CLOCK_InitOsc0(&g_defaultClockConfigRun.oscConfig);
|
||||
CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ);
|
||||
|
||||
CLOCK_BootToPeeMode(g_defaultClockConfigRun.mcgConfig.oscsel, kMCG_PllClkSelPll0,
|
||||
&g_defaultClockConfigRun.mcgConfig.pll0Config);
|
||||
|
||||
CLOCK_SetInternalRefClkConfig(g_defaultClockConfigRun.mcgConfig.irclkEnableMode,
|
||||
g_defaultClockConfigRun.mcgConfig.ircs, g_defaultClockConfigRun.mcgConfig.fcrdiv);
|
||||
|
||||
CLOCK_SetSimConfig(&g_defaultClockConfigRun.simConfig);
|
||||
|
||||
SystemCoreClock = g_defaultClockConfigRun.coreClock;
|
||||
}
|
||||
|
||||
void BOARD_BootClockHSRUN(void)
|
||||
{
|
||||
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
|
||||
SMC_SetPowerModeHsrun(SMC);
|
||||
while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)
|
||||
{
|
||||
}
|
||||
|
||||
CLOCK_SetSimSafeDivs();
|
||||
|
||||
CLOCK_InitOsc0(&g_defaultClockConfigHsrun.oscConfig);
|
||||
CLOCK_SetXtal0Freq(BOARD_XTAL0_CLK_HZ);
|
||||
|
||||
CLOCK_BootToPeeMode(g_defaultClockConfigHsrun.mcgConfig.oscsel, kMCG_PllClkSelPll0,
|
||||
&g_defaultClockConfigHsrun.mcgConfig.pll0Config);
|
||||
|
||||
CLOCK_SetInternalRefClkConfig(g_defaultClockConfigHsrun.mcgConfig.irclkEnableMode,
|
||||
g_defaultClockConfigHsrun.mcgConfig.ircs, g_defaultClockConfigHsrun.mcgConfig.fcrdiv);
|
||||
|
||||
CLOCK_SetSimConfig(&g_defaultClockConfigHsrun.simConfig);
|
||||
|
||||
SystemCoreClock = g_defaultClockConfigHsrun.coreClock;
|
||||
}
|
||||
54
right/include/board/clock_config.h
Normal file
54
right/include/board/clock_config.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _CLOCK_CONFIG_H_
|
||||
#define _CLOCK_CONFIG_H_
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#define BOARD_XTAL0_CLK_HZ 8000000U
|
||||
#define BOARD_XTAL32K_CLK_HZ 32768U
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
void BOARD_BootClockVLPR(void);
|
||||
void BOARD_BootClockRUN(void);
|
||||
void BOARD_BootClockHSRUN(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
#endif /* _CLOCK_CONFIG_H_ */
|
||||
49
right/include/board/pin_mux.c
Normal file
49
right/include/board/pin_mux.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
/* Function Name : BOARD_InitPins */
|
||||
void BOARD_InitPins(void)
|
||||
{
|
||||
/* Initialize UART1 pins below */
|
||||
/* Ungate the port clock */
|
||||
CLOCK_EnableClock(kCLOCK_PortE);
|
||||
|
||||
/* Affects PORTE_PCR0 register */
|
||||
PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);
|
||||
/* Affects PORTE_PCR1 register */
|
||||
PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);
|
||||
}
|
||||
50
right/include/board/pin_mux.h
Normal file
50
right/include/board/pin_mux.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PIN_MUX_H_
|
||||
#define _PIN_MUX_H_
|
||||
|
||||
#include "include/board/board.h"
|
||||
#include "fsl_common.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus*/
|
||||
/*!
|
||||
* @brief configure all pins for this demo/example
|
||||
*
|
||||
*/
|
||||
void BOARD_InitPins(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus*/
|
||||
|
||||
#endif /* _PIN_MUX_H_ */
|
||||
931
right/include/usb/usb_device_ch9.c
Normal file
931
right/include/usb/usb_device_ch9.c
Normal file
File diff suppressed because it is too large
Load Diff
101
right/include/usb/usb_device_ch9.h
Normal file
101
right/include/usb/usb_device_ch9.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __USB_DEVICE_CH9_H__
|
||||
#define __USB_DEVICE_CH9_H__
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*!
|
||||
* @addtogroup usb_device_ch9
|
||||
* @{
|
||||
*/
|
||||
/*! @brief Defines USB device status size when the host request to get device status */
|
||||
#define USB_DEVICE_STATUS_SIZE (0x02U)
|
||||
|
||||
/*! @brief Defines USB device interface status size when the host request to get interface status */
|
||||
#define USB_INTERFACE_STATUS_SIZE (0x02U)
|
||||
|
||||
/*! @brief Defines USB device endpoint status size when the host request to get endpoint status */
|
||||
#define USB_ENDPOINT_STATUS_SIZE (0x02U)
|
||||
|
||||
/*! @brief Defines USB device configuration size when the host request to get current configuration */
|
||||
#define USB_CONFIGURE_SIZE (0X01U)
|
||||
|
||||
/*! @brief Defines USB device interface alternate setting size when the host request to get interface alternate setting
|
||||
*/
|
||||
#define USB_INTERFACE_SIZE (0X01U)
|
||||
|
||||
/*! @brief Defines USB device status mask */
|
||||
#define USB_GET_STATUS_DEVICE_MASK (0x03U)
|
||||
|
||||
/*! @brief Defines USB device interface status mask */
|
||||
#define USB_GET_STATUS_INTERFACE_MASK (0x03U)
|
||||
|
||||
/*! @brief Defines USB device endpoint status mask */
|
||||
#define USB_GET_STATUS_ENDPOINT_MASK (0x03U)
|
||||
|
||||
/*! @brief Control read and write sequence */
|
||||
typedef enum _usb_device_control_read_write_sequence
|
||||
{
|
||||
kUSB_DeviceControlPipeSetupStage = 0U, /*!< Setup stage */
|
||||
kUSB_DeviceControlPipeDataStage, /*!< Data stage */
|
||||
kUSB_DeviceControlPipeStatusStage, /*!< status stage */
|
||||
} usb_device_control_read_write_sequence_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Initializes the control pipes.
|
||||
*
|
||||
* The function is used to initialize the control pipes. This function should be called when event
|
||||
* kUSB_DeviceEventBusReset is received.
|
||||
*
|
||||
* @param[in] handle The device handle.
|
||||
* @param[in] param The event parameter.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
extern usb_status_t USB_DeviceControlPipeInit(usb_device_handle handle, void *param);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* __USB_DEVICE_CH9_H__ */
|
||||
571
right/include/usb/usb_device_class.c
Normal file
571
right/include/usb/usb_device_class.c
Normal file
File diff suppressed because it is too large
Load Diff
423
right/include/usb/usb_device_class.h
Normal file
423
right/include/usb/usb_device_class.h
Normal file
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __USB_DEVICE_CLASS_H__
|
||||
#define __USB_DEVICE_CLASS_H__
|
||||
|
||||
/*!
|
||||
* @addtogroup usb_device_class_driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Macro to define class handle */
|
||||
#define class_handle_t uint32_t
|
||||
|
||||
/*! @brief Available class types. */
|
||||
typedef enum _usb_usb_device_class_type
|
||||
{
|
||||
kUSB_DeviceClassTypeHid = 1U,
|
||||
kUSB_DeviceClassTypeCdc,
|
||||
kUSB_DeviceClassTypeMsc,
|
||||
kUSB_DeviceClassTypeAudio,
|
||||
kUSB_DeviceClassTypePhdc,
|
||||
kUSB_DeviceClassTypeVideo,
|
||||
kUSB_DeviceClassTypePrinter,
|
||||
kUSB_DeviceClassTypeDfu,
|
||||
kUSB_DeviceClassTypeCcid,
|
||||
} usb_device_class_type_t;
|
||||
|
||||
/*! @brief Available common class events. */
|
||||
typedef enum _usb_device_class_event
|
||||
{
|
||||
kUSB_DeviceClassEventClassRequest = 1U,
|
||||
kUSB_DeviceClassEventDeviceReset,
|
||||
kUSB_DeviceClassEventSetConfiguration,
|
||||
kUSB_DeviceClassEventSetInterface,
|
||||
kUSB_DeviceClassEventSetEndpointHalt,
|
||||
kUSB_DeviceClassEventClearEndpointHalt,
|
||||
} usb_device_class_event_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the endpoint data structure.
|
||||
*
|
||||
* Define the endpoint data structure.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_endpoint_struct
|
||||
{
|
||||
uint8_t endpointAddress; /*!< Endpoint address*/
|
||||
uint8_t transferType; /*!< Endpoint transfer type*/
|
||||
uint16_t maxPacketSize; /*!< Endpoint maximum packet size */
|
||||
} usb_device_endpoint_struct_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the endpoint group.
|
||||
*
|
||||
* Structure representing endpoints and the number of endpoints that the user wants.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_endpoint_list
|
||||
{
|
||||
uint8_t count; /*!< How many endpoints in current interface*/
|
||||
usb_device_endpoint_struct_t *endpoint; /*!< Endpoint structure list*/
|
||||
} usb_device_endpoint_list_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the interface list data structure.
|
||||
*
|
||||
* Structure representing an interface.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_interface_struct
|
||||
{
|
||||
uint8_t alternateSetting; /*!< Alternate setting number*/
|
||||
usb_device_endpoint_list_t endpointList; /*!< Endpoints of the interface*/
|
||||
void *classSpecific; /*!< Class specific structure handle*/
|
||||
} usb_device_interface_struct_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the interface data structure.
|
||||
*
|
||||
* Structure representing interface.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_interfaces_struct
|
||||
{
|
||||
uint8_t classCode; /*!< Class code of the interface*/
|
||||
uint8_t subclassCode; /*!< Subclass code of the interface*/
|
||||
uint8_t protocolCode; /*!< Protocol code of the interface*/
|
||||
uint8_t interfaceNumber; /*!< Interface number*/
|
||||
usb_device_interface_struct_t *interface; /*!< Interface structure list*/
|
||||
uint8_t count; /*!< Number of interfaces in the current interface*/
|
||||
} usb_device_interfaces_struct_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the interface group.
|
||||
*
|
||||
* Structure representing how many interfaces in one class type.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_interface_list
|
||||
{
|
||||
uint8_t count; /*!< Number of interfaces of the class*/
|
||||
usb_device_interfaces_struct_t *interfaces; /*!< All interfaces*/
|
||||
} usb_device_interface_list_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the class data structure.
|
||||
*
|
||||
* Structure representing how many configurations in one class type.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_class_struct
|
||||
{
|
||||
usb_device_interface_list_t *interfaceList; /*!< Interfaces of the class*/
|
||||
usb_device_class_type_t type; /*!< Class type*/
|
||||
uint8_t configurations; /*!< Number of configurations of the class*/
|
||||
} usb_device_class_struct_t;
|
||||
|
||||
/*callback function pointer structure for application to provide class parameters*/
|
||||
typedef usb_status_t (*usb_device_class_callback_t)(class_handle_t classHandle,
|
||||
uint32_t callbackEvent,
|
||||
void *eventParam);
|
||||
|
||||
/*!
|
||||
* @brief Obtains the device class information structure.
|
||||
*
|
||||
* Structure representing the device class information. This structure only can be stored in RAM space.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_class_config_struct
|
||||
{
|
||||
usb_device_class_callback_t classCallback; /*!< Class callback function to handle the device status-related event
|
||||
for the specified type of class*/
|
||||
class_handle_t classHandle; /*!< The class handle of the class, filled by the common driver.*/
|
||||
usb_device_class_struct_t *classInfomation; /*!< Detailed information of the class*/
|
||||
} usb_device_class_config_struct_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the device class configuration structure.
|
||||
*
|
||||
* Structure representing the device class configuration information.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_class_config_list_struct
|
||||
{
|
||||
usb_device_class_config_struct_t *config; /*!< Array of class configuration structures */
|
||||
usb_device_callback_t deviceCallback; /*!< Device callback function */
|
||||
uint8_t count; /*!< Number of class supported */
|
||||
} usb_device_class_config_list_struct_t;
|
||||
|
||||
/*!
|
||||
* @brief Obtains the control request structure.
|
||||
*
|
||||
* This structure is used to pass the control request information.
|
||||
* The structure is used in following two cases.
|
||||
* Case one, the host wants to send data to the device in the control data stage: @n
|
||||
* 1. If a setup packet is received, the structure is used to pass the setup packet data and wants to get the
|
||||
* buffer to receive data sent from the host.
|
||||
* The field isSetup is 1.
|
||||
* The length is the requested buffer length.
|
||||
* The buffer is filled by the class or application by using the valid buffer address.
|
||||
* The setup is the setup packet address.
|
||||
* 2. If the data received is sent by the host, the structure is used to pass the data buffer address and the data
|
||||
* length sent by the host.
|
||||
* In this way, the field isSetup is 0.
|
||||
* The buffer is the address of the data sent from the host.
|
||||
* The length is the received data length.
|
||||
* The setup is the setup packet address. @n
|
||||
* Case two, the host wants to get data from the device in control data stage: @n
|
||||
* 1. If the setup packet is received, the structure is used to pass the setup packet data and wants to get the
|
||||
* data buffer address to send data to the host.
|
||||
* The field isSetup is 1.
|
||||
* The length is the requested data length.
|
||||
* The buffer is filled by the class or application by using the valid buffer address.
|
||||
* The setup is the setup packet address.
|
||||
*
|
||||
*/
|
||||
typedef struct _usb_device_control_request_struct
|
||||
{
|
||||
usb_setup_struct_t *setup; /*!< The pointer of the setup packet data. */
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length or requested length. */
|
||||
uint8_t isSetup; /*!< Indicates whether a setup packet is received. */
|
||||
} usb_device_control_request_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get descriptor request common structure. */
|
||||
typedef struct _usb_device_get_descriptor_common_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
} usb_device_get_descriptor_common_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get device descriptor request structure. */
|
||||
typedef struct _usb_device_get_device_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
} usb_device_get_device_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get configuration descriptor request structure. */
|
||||
typedef struct _usb_device_get_configuration_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
uint8_t configuration; /*!< The configuration number. */
|
||||
} usb_device_get_configuration_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get string descriptor request structure. */
|
||||
typedef struct _usb_device_get_string_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
uint16_t languageId; /*!< Language ID. */
|
||||
uint8_t stringIndex; /*!< String index. */
|
||||
} usb_device_get_string_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get hid descriptor request structure. */
|
||||
typedef struct _usb_device_get_hid_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
uint8_t interfaceNumber; /*!< The interface number. */
|
||||
} usb_device_get_hid_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get hid report descriptor request structure. */
|
||||
typedef struct _usb_device_get_hid_report_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
uint8_t interfaceNumber; /*!< The interface number. */
|
||||
} usb_device_get_hid_report_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get hid physical descriptor request structure. */
|
||||
typedef struct _usb_device_get_hid_physical_descriptor_struct
|
||||
{
|
||||
uint8_t *buffer; /*!< Pass the buffer address. */
|
||||
uint32_t length; /*!< Pass the buffer length. */
|
||||
uint8_t index; /*!< Physical index */
|
||||
uint8_t interfaceNumber; /*!< The interface number. */
|
||||
} usb_device_get_hid_physical_descriptor_struct_t;
|
||||
|
||||
/*! @brief Obtains the control get descriptor request common union. */
|
||||
typedef union _usb_device_get_descriptor_common_union
|
||||
{
|
||||
usb_device_get_descriptor_common_struct_t commonDescriptor; /*!< Common structure. */
|
||||
usb_device_get_device_descriptor_struct_t deviceDescriptor; /*!< The structure to get device descriptor. */
|
||||
usb_device_get_configuration_descriptor_struct_t
|
||||
configurationDescriptor; /*!< The structure to get configuration descriptor. */
|
||||
usb_device_get_string_descriptor_struct_t stringDescriptor; /*!< The structure to get string descriptor. */
|
||||
usb_device_get_hid_descriptor_struct_t hidDescriptor; /*!< The structure to get hid descriptor. */
|
||||
usb_device_get_hid_report_descriptor_struct_t
|
||||
hidReportDescriptor; /*!< The structure to get hid report descriptor. */
|
||||
usb_device_get_hid_physical_descriptor_struct_t
|
||||
hidPhysicalDescriptor; /*!< The structure to get hid physical descriptor. */
|
||||
} usb_device_get_descriptor_common_union_t;
|
||||
|
||||
/*! @brief Define function type for class device instance initialization */
|
||||
typedef usb_status_t (*usb_device_class_init_call_t)(uint8_t controllerId,
|
||||
usb_device_class_config_struct_t *classConfig,
|
||||
class_handle_t *classHandle);
|
||||
/*! @brief Define function type for class device instance deinitialization, internal */
|
||||
typedef usb_status_t (*usb_device_class_deinit_call_t)(class_handle_t handle);
|
||||
/*! @brief Define function type for class device instance Event change */
|
||||
typedef usb_status_t (*usb_device_class_event_callback_t)(void *classHandle, uint32_t event, void *param);
|
||||
|
||||
/*! @brief Define class driver interface structure. */
|
||||
typedef struct _usb_device_class_map
|
||||
{
|
||||
usb_device_class_init_call_t classInit; /*!< Class driver initialization- entry of the class driver */
|
||||
usb_device_class_deinit_call_t classDeinit; /*!< Class driver de-initialization*/
|
||||
usb_device_class_event_callback_t classEventCallback; /*!< Class driver event callback*/
|
||||
usb_device_class_type_t type; /*!< Class type*/
|
||||
} usb_device_class_map_t;
|
||||
|
||||
/*! @brief Structure holding common class state information */
|
||||
typedef struct _usb_device_common_class_struct
|
||||
{
|
||||
usb_device_handle handle; /*!< USB device handle*/
|
||||
usb_device_class_config_list_struct_t *configList; /*!< USB device configure list*/
|
||||
uint8_t setupBuffer[USB_SETUP_PACKET_SIZE]; /*!< Setup packet data buffer*/
|
||||
uint16_t standardTranscationBuffer; /*!<
|
||||
* This variable is used in:
|
||||
* get status request
|
||||
* get configuration request
|
||||
* get interface request
|
||||
* set interface request
|
||||
* get sync frame request
|
||||
*/
|
||||
uint8_t controllerId; /*!< Controller ID*/
|
||||
} usb_device_common_class_struct_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Initializes the common class and the supported classes.
|
||||
*
|
||||
* This function is used to initialize the common class and the supported classes.
|
||||
*
|
||||
* @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
|
||||
* @param[in] configList The class configurations. The pointer must point to the goblal variable.
|
||||
* See the structure #usb_device_class_config_list_struct_t.
|
||||
* @param[out] handle An parameter used to return pointer of the device handle to the caller.
|
||||
* The value of the parameter is a pointer to the device handle. This design is used to
|
||||
* make a simple device align with the composite device. For the composite device, there are many
|
||||
* kinds of class handles. However, there is only one device handle. Therefore, the handle points to
|
||||
* a device instead of a class. The class handle can be received from the
|
||||
* #usb_device_class_config_struct_t::classHandle after the the function successfully.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassInit(uint8_t controllerId,
|
||||
usb_device_class_config_list_struct_t *configList,
|
||||
usb_device_handle *handle);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes the common class and the supported classes.
|
||||
*
|
||||
* This function is used to deinitialize the common class and the supported classes.
|
||||
*
|
||||
* @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassDeinit(uint8_t controllerId);
|
||||
|
||||
/*!
|
||||
* @brief Gets the USB bus speed.
|
||||
*
|
||||
* This function is used to get the USB bus speed.
|
||||
*
|
||||
* @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
|
||||
* @param[out] speed It is an OUT parameter, which returns the current speed of the controller.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassGetSpeed(uint8_t controllerId, uint8_t *speed);
|
||||
|
||||
/*!
|
||||
* @brief Handles the event passed to the class drivers.
|
||||
*
|
||||
* A valid request has been handled.
|
||||
*
|
||||
* @param[in] handle The device handle received from the #USB_DeviceInit.
|
||||
* @param[in] event The event codes. See the enumeration #usb_device_class_event_t.
|
||||
* @param[in,out] param The parameter type is determined by the event code.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
* @retval kStatus_USB_Success A valid request has been handled.
|
||||
* @retval kStatus_USB_InvalidParameter The device handle not be found.
|
||||
* @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe is stalled by the caller.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassEvent(usb_device_handle handle, usb_device_class_event_t event, void *param);
|
||||
|
||||
/*!
|
||||
* @brief Handles the common class callback.
|
||||
*
|
||||
* This function handles the common class callback.
|
||||
*
|
||||
* @param[in] handle The device handle received from the #USB_DeviceInit.
|
||||
* @param[in] event The event codes. See the enumeration #usb_device_event_t.
|
||||
* @param[in,out] param The parameter type is determined by the event code.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassCallback(usb_device_handle handle, uint32_t event, void *param);
|
||||
|
||||
/*!
|
||||
* @brief Gets the device handle according to the controller ID.
|
||||
*
|
||||
* This function gets the device handle according to the controller ID.
|
||||
*
|
||||
* @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
|
||||
* @param[out] handle An out parameter used to return the pointer of the device handle to the caller.
|
||||
*
|
||||
* @retval kStatus_USB_Success Get device handle successfully.
|
||||
* @retval kStatus_USB_InvalidParameter The device handle can't be found.
|
||||
*/
|
||||
usb_status_t USB_DeviceClassGetDeviceHandle(uint8_t controllerId, usb_device_handle *handle);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* __USB_DEVICE_CLASS_H__ */
|
||||
667
right/include/usb/usb_device_hid.c
Normal file
667
right/include/usb/usb_device_hid.c
Normal file
File diff suppressed because it is too large
Load Diff
234
right/include/usb/usb_device_hid.h
Normal file
234
right/include/usb/usb_device_hid.h
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* o Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* o Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __USB_DEVICE_HID_H__
|
||||
#define __USB_DEVICE_HID_H__
|
||||
|
||||
/*!
|
||||
* @addtogroup usb_device_hid_drv
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief The class code of the HID class */
|
||||
#define USB_DEVICE_CONFIG_HID_CLASS_CODE (0x03U)
|
||||
|
||||
/*! @brief Request code to get report of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_GET_REPORT (0x01U)
|
||||
#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_INPUT (0x01U)
|
||||
#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_OUPUT (0x02U)
|
||||
#define USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_FEATURE (0x03U)
|
||||
/*! @brief Request code to get idle of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_GET_IDLE (0x02U)
|
||||
/*! @brief Request code to get protocol of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_GET_PROTOCOL (0x03U)
|
||||
/*! @brief Request code to set report of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_SET_REPORT (0x09U)
|
||||
/*! @brief Request code to set idle of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_SET_IDLE (0x0AU)
|
||||
/*! @brief Request code to set protocol of HID class. */
|
||||
#define USB_DEVICE_HID_REQUEST_SET_PROTOCOL (0x0BU)
|
||||
|
||||
/*! @brief Available common EVENT types in HID class callback */
|
||||
typedef enum _usb_device_hid_event
|
||||
{
|
||||
kUSB_DeviceHidEventSendResponse = 0x01U, /*!< Send data completed */
|
||||
kUSB_DeviceHidEventRecvResponse, /*!< Data received */
|
||||
kUSB_DeviceHidEventGetReport, /*!< Get report request */
|
||||
kUSB_DeviceHidEventGetIdle, /*!< Get idle request */
|
||||
kUSB_DeviceHidEventGetProtocol, /*!< Get protocol request */
|
||||
kUSB_DeviceHidEventSetReport, /*!< Set report request */
|
||||
kUSB_DeviceHidEventSetIdle, /*!< Set idle request */
|
||||
kUSB_DeviceHidEventSetProtocol, /*!< Set protocol request */
|
||||
kUSB_DeviceHidEventRequestReportBuffer, /*!< Get buffer to save the data of the set report request. */
|
||||
} usb_device_hid_event_t;
|
||||
|
||||
/*!
|
||||
* @brief The device HID GET/SET report structure.
|
||||
*
|
||||
* This structure is used to pass data when the event type is kUSB_DeviceHidEventGetReport,
|
||||
* kUSB_DeviceHidEventSetReport, and kUSB_DeviceHidEventRequestReportBuffer.
|
||||
* 1. kUSB_DeviceHidEventGetReport
|
||||
* The structure is used to save the report buffer and report length got from the application.
|
||||
* The reportBuffer is the report data buffer address filled by the application.
|
||||
* The reportLength is the report length.
|
||||
* The reportType is the requested report type.
|
||||
* The reportId is the requested report ID.
|
||||
*
|
||||
* 2. kUSB_DeviceHidEventSetReport
|
||||
* The structure is used to pass the report data received from the host to the application.
|
||||
* The reportBuffer is buffer address of the report data received from the host.
|
||||
* The reportLength is the report data length.
|
||||
* The reportType is the requested report type.
|
||||
* The reportId is the requested report ID.
|
||||
*
|
||||
* 3. kUSB_DeviceHidEventRequestReportBuffer
|
||||
* The structure is used to get the buffer to save the report data sent by the host.
|
||||
* The reportBuffer is buffer address to receive to report data. It is filled by the application.
|
||||
* The reportLength is the requested report data buffer length.
|
||||
* The reportType is the requested report type.
|
||||
* The reportId is the requested report ID.
|
||||
*/
|
||||
typedef struct _usb_device_hid_report_struct
|
||||
{
|
||||
uint8_t *reportBuffer; /*!< The report buffer address */
|
||||
uint32_t reportLength; /*!< The report data length */
|
||||
uint8_t reportType; /*!< The report type */
|
||||
uint8_t reportId; /*!< The report ID */
|
||||
} usb_device_hid_report_struct_t;
|
||||
|
||||
/*! @brief The HID device class status structure */
|
||||
typedef struct _usb_device_hid_struct
|
||||
{
|
||||
usb_device_handle handle; /*!< The device handle */
|
||||
usb_device_class_config_struct_t *configStruct; /*!< The configuration of the class. */
|
||||
usb_device_interface_struct_t *interfaceHandle; /*!< Current interface handle */
|
||||
uint8_t configuration; /*!< Current configuration */
|
||||
uint8_t interfaceNumber; /*!< The interface number of the class */
|
||||
uint8_t alternate; /*!< Current alternate setting of the interface */
|
||||
uint8_t idleRate; /*!< The idle rate of the HID device */
|
||||
uint8_t protocol; /*!< Current protocol */
|
||||
uint8_t interruptInPipeBusy; /*!< Interrupt IN pipe busy flag */
|
||||
uint8_t interruptOutPipeBusy; /*!< Interrupt OUT pipe busy flag */
|
||||
} usb_device_hid_struct_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Initializes the HID class.
|
||||
*
|
||||
* This function is used to initialize the HID class. This function only can be called by #USB_DeviceClassInit.
|
||||
*
|
||||
* @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
|
||||
* @param[in] config The class configuration information.
|
||||
* @param[out] handle An parameter used to return pointer of the HID class handle to the caller.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
extern usb_status_t USB_DeviceHidInit(uint8_t controllerId,
|
||||
usb_device_class_config_struct_t *config,
|
||||
class_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* @brief Deinitializes the device HID class.
|
||||
*
|
||||
* The function deinitializes the device HID class. This function only can be called by #USB_DeviceClassDeinit.
|
||||
*
|
||||
* @param[in] handle The HID class handle got from usb_device_class_config_struct_t::classHandle.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*/
|
||||
extern usb_status_t USB_DeviceHidDeinit(class_handle_t handle);
|
||||
|
||||
/*!
|
||||
* @brief Handles the event passed to the HID class.
|
||||
*
|
||||
* This function handles the event passed to the HID class. This function only can be called by #USB_DeviceClassEvent.
|
||||
*
|
||||
* @param[in] handle The HID class handle received from the usb_device_class_config_struct_t::classHandle.
|
||||
* @param[in] event The event codes. See the enumeration usb_device_class_event_t.
|
||||
* @param[in,out] param The parameter type is determined by the event code.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
* @retval kStatus_USB_Success Free device handle successfully.
|
||||
* @retval kStatus_USB_InvalidParameter The device handle not be found.
|
||||
* @retval kStatus_USB_InvalidRequest The request is invalid, and the control pipe is stalled by the caller.
|
||||
*/
|
||||
extern usb_status_t USB_DeviceHidEvent(void *handle, uint32_t event, void *param);
|
||||
|
||||
/*!
|
||||
* @name USB device HID class APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @brief Sends data through a specified endpoint.
|
||||
*
|
||||
* The function is used to send data through a specified endpoint.
|
||||
* The function calls #USB_DeviceSendRequest internally.
|
||||
*
|
||||
* @param[in] handle The HID class handle received from usb_device_class_config_struct_t::classHandle.
|
||||
* @param[in] ep Endpoint index.
|
||||
* @param[in] buffer The memory address to hold the data need to be sent.
|
||||
* @param[in] length The data length to be sent.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*
|
||||
* @note The return value indicates whether the sending request is successful or not. The transfer done is notified by
|
||||
* usb_device_hid_interrupt_in.
|
||||
* Currently, only one transfer request can be supported for one specific endpoint.
|
||||
* If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application
|
||||
* should implement a queue in the application level.
|
||||
* The subsequent transfer can begin only when the previous transfer is done (a notification is received through the endpoint
|
||||
* callback).
|
||||
*/
|
||||
extern usb_status_t USB_DeviceHidSend(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length);
|
||||
|
||||
/*!
|
||||
* @brief Receives data through a specified endpoint.
|
||||
*
|
||||
* The function is used to receive data through a specified endpoint.
|
||||
* The function calls #USB_DeviceRecvRequest internally.
|
||||
*
|
||||
* @param[in] handle The HID class handle received from the usb_device_class_config_struct_t::classHandle.
|
||||
* @param[in] ep Endpoint index.
|
||||
* @param[in] buffer The memory address to save the received data.
|
||||
* @param[in] length The data length to be received.
|
||||
*
|
||||
* @return A USB error code or kStatus_USB_Success.
|
||||
*
|
||||
* @note The return value indicates whether the receiving request is successful or not. The transfer done is notified by
|
||||
* usb_device_hid_interrupt_out.
|
||||
* Currently, only one transfer request can be supported for a specific endpoint.
|
||||
* If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application
|
||||
* should implement a queue in the application level.
|
||||
* The subsequent transfer can begin only when the previous transfer is done (a notification is received through the endpoint
|
||||
* callback).
|
||||
*/
|
||||
extern usb_status_t USB_DeviceHidRecv(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length);
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! @}*/
|
||||
|
||||
#endif /* __USB_DEVICE_HID_H__ */
|
||||
Reference in New Issue
Block a user