Make less use of linked files and folders for better long-term maintainability by moving the source files under the newly created src directory and only linking that directory to the workspace.
This commit is contained in:
39
right/src/action.h
Normal file
39
right/src/action.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __ACTION_H__
|
||||
#define __ACTION_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
// The value of action ID can be any valid HID_KEYBOARD_SC_* scancode constants of LUFA.
|
||||
// Hence, ACTION_ID_* values must not conflict with any of the HID_KEYBOARD_SC_* constants.
|
||||
#define ACTION_ID_NONE 0xFF
|
||||
#define ACTION_ID_SWITCH_LAYER 0xFE
|
||||
#define ACTION_ID_MOUSE 0xFD
|
||||
#define ACTION_ID_SWITCH_KEYMAP 0xFC
|
||||
#define ACTION_ID_PLAY_MACRO 0xFB
|
||||
|
||||
#define ACTION_ARG_NONE 0
|
||||
|
||||
#define ACTION_ARG_SWITCH_LAYER_MOD 0
|
||||
#define ACTION_ARG_SWITCH_LAYER_FN 1
|
||||
#define ACTION_ARG_SWITCH_LAYER_MOUSE 2
|
||||
|
||||
#define ACTION_ARG_MOUSE_MOVE_UP 0
|
||||
#define ACTION_ARG_MOUSE_MOVE_DOWN 1
|
||||
#define ACTION_ARG_MOUSE_MOVE_LEFT 3
|
||||
#define ACTION_ARG_MOUSE_MOVE_RIGHT 4
|
||||
#define ACTION_ARG_MOUSE_CLICK_LEFT 5
|
||||
#define ACTION_ARG_MOUSE_CLICK_MIDDLE 6
|
||||
#define ACTION_ARG_MOUSE_CLICK_RIGHT 7
|
||||
#define ACTION_ARG_MOUSE_WHEEL_UP 8
|
||||
#define ACTION_ARG_MOUSE_WHEEL_DOWN 9
|
||||
#define ACTION_ARG_MOUSE_WHEEL_LEFT 10
|
||||
#define ACTION_ARG_MOUSE_WHEEL_RIGHT 11
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
uint8_t arg;
|
||||
} action_t;
|
||||
|
||||
#endif
|
||||
4
right/src/include/README.md
Normal file
4
right/src/include/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Included files
|
||||
|
||||
This directory contains included files upon which the firmware of the right keyboard half depends.
|
||||
These dependencies are from external projects, and not supposed to be modified.
|
||||
5
right/src/include/board/README.md
Normal file
5
right/src/include/board/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Development board specific files
|
||||
|
||||
This directory contains files that are specific to the
|
||||
[FRDM-K22F development board](http://www.nxp.com/products/software-and-tools/hardware-development-tools/freedom-development-boards/freescale-freedom-development-platform-for-kinetis-k22-mcus:FRDM-K22F)
|
||||
upon which the firmware runs.
|
||||
0
right/src/include/board/board.c
Normal file
0
right/src/include/board/board.c
Normal file
42
right/src/include/board/board.h
Normal file
42
right/src/include/board/board.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 "fsl_gpio.h"
|
||||
|
||||
#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
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
219
right/src/include/board/clock_config.c
Normal file
219
right/src/include/board/clock_config.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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_smc.h"
|
||||
#include "clock_config.h"
|
||||
#include "fsl_rtc.h"
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#define MCG_PLL_DISABLE 0U /*!< MCGPLLCLK disabled */
|
||||
#define OSC_CAP0P 0U /*!< Oscillator 0pF capacitor load */
|
||||
#define OSC_ER_CLK_DISABLE 0U /*!< Disable external reference clock */
|
||||
#define RTC_OSC_CAP_LOAD_12PF 0x1800U /*!< RTC oscillator capacity load: 12pF */
|
||||
#define RTC_RTC32KCLK_PERIPHERALS_ENABLED 1U /*!< RTC32KCLK to other peripherals: enabled */
|
||||
#define SIM_CLKOUT_SEL_FLEXBUS_CLK 0U /*!< CLKOUT pin clock select: FlexBus clock */
|
||||
#define SIM_OSC32KSEL_RTC32KCLK_CLK 2U /*!< OSC32KSEL select: RTC32KCLK clock (32.768kHz) */
|
||||
#define SIM_PLLFLLSEL_IRC48MCLK_CLK 3U /*!< PLLFLL select: IRC48MCLK clock */
|
||||
#define SIM_PLLFLLSEL_MCGPLLCLK_CLK 1U /*!< PLLFLL select: MCGPLLCLK clock */
|
||||
#define SIM_RTC_CLKOUT_SEL_RTC1HZCLK_CLK 0U /*!< RTC clock output select: RTC1HzCLK clock */
|
||||
#define SIM_RTC_CLKOUT_SEL_RTC32KCLK_CLK 1U /*!< RTC clock output select: RTC32KCLK clock (32.768kHz) */
|
||||
#define SIM_TRACE_CLK_SEL_CORE_SYSTEM_CLK 1U /*!< Trace clock select: Core/system clock */
|
||||
#define SIM_USB_CLK_120000000HZ 120000000U /*!< Input SIM frequency for USB: 120000000Hz */
|
||||
#define SIM_USB_CLK_48000000HZ 48000000U /*!< Input SIM frequency for USB: 48000000Hz */
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/* System clock frequency. */
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
/*FUNCTION**********************************************************************
|
||||
*
|
||||
* Function Name : CLOCK_CONFIG_SetRtcClock
|
||||
* Description : This function is used to configuring RTC clock including
|
||||
* enabling RTC oscillator.
|
||||
* Param capLoad : RTC oscillator capacity load
|
||||
* Param enableOutPeriph : Enable (1U)/Disable (0U) clock to peripherals
|
||||
*
|
||||
*END**************************************************************************/
|
||||
static void CLOCK_CONFIG_SetRtcClock(uint32_t capLoad, uint8_t enableOutPeriph)
|
||||
{
|
||||
/* RTC clock gate enable */
|
||||
CLOCK_EnableClock(kCLOCK_Rtc0);
|
||||
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the Rtc oscillator is not already enabled */
|
||||
/* Set the specified capacitor configuration for the RTC oscillator */
|
||||
RTC_SetOscCapLoad(RTC, capLoad);
|
||||
/* Enable the RTC 32KHz oscillator */
|
||||
RTC->CR |= RTC_CR_OSCE_MASK;
|
||||
}
|
||||
/* Output to other peripherals */
|
||||
if (enableOutPeriph) {
|
||||
RTC->CR &= ~RTC_CR_CLKO_MASK;
|
||||
}
|
||||
else {
|
||||
RTC->CR |= RTC_CR_CLKO_MASK;
|
||||
}
|
||||
/* Set the XTAL32/RTC_CLKIN frequency based on board setting. */
|
||||
CLOCK_SetXtal32Freq(BOARD_XTAL32K_CLK_HZ);
|
||||
/* Set RTC_TSR if there is fault value in RTC */
|
||||
if (RTC->SR & RTC_SR_TIF_MASK) {
|
||||
RTC -> TSR = RTC -> TSR;
|
||||
}
|
||||
/* RTC clock gate disable */
|
||||
CLOCK_DisableClock(kCLOCK_Rtc0);
|
||||
}
|
||||
|
||||
/*FUNCTION**********************************************************************
|
||||
*
|
||||
* Function Name : CLOCK_CONFIG_SetFllExtRefDiv
|
||||
* Description : Configure FLL external reference divider (FRDIV).
|
||||
* Param frdiv : The value to set FRDIV.
|
||||
*
|
||||
*END**************************************************************************/
|
||||
static void CLOCK_CONFIG_SetFllExtRefDiv(uint8_t frdiv)
|
||||
{
|
||||
MCG->C1 = ((MCG->C1 & ~MCG_C1_FRDIV_MASK) | MCG_C1_FRDIV(frdiv));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
********************** Configuration BOARD_BootClockRUN ***********************
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables for BOARD_BootClockRUN configuration
|
||||
******************************************************************************/
|
||||
const mcg_config_t mcgConfig_BOARD_BootClockRUN =
|
||||
{
|
||||
.mcgMode = kMCG_ModePEE, /* PEE - PLL Engaged External */
|
||||
.irclkEnableMode = kMCG_IrclkEnable, /* MCGIRCLK enabled, MCGIRCLK disabled in STOP mode */
|
||||
.ircs = kMCG_IrcSlow, /* Slow internal reference clock selected */
|
||||
.fcrdiv = 0x0U, /* Fast IRC divider: divided by 1 */
|
||||
.frdiv = 0x0U, /* FLL reference clock divider: divided by 32 */
|
||||
.drs = kMCG_DrsLow, /* Low frequency range */
|
||||
.dmx32 = kMCG_Dmx32Default, /* DCO has a default range of 25% */
|
||||
.oscsel = kMCG_OscselIrc, /* Selects 48 MHz IRC Oscillator */
|
||||
.pll0Config =
|
||||
{
|
||||
.enableMode = MCG_PLL_DISABLE, /* MCGPLLCLK disabled */
|
||||
.prdiv = 0xbU, /* PLL Reference divider: divided by 12 */
|
||||
.vdiv = 0x6U, /* VCO divider: multiplied by 30 */
|
||||
},
|
||||
};
|
||||
const sim_clock_config_t simConfig_BOARD_BootClockRUN =
|
||||
{
|
||||
.pllFllSel = SIM_PLLFLLSEL_MCGPLLCLK_CLK, /* PLLFLL select: MCGPLLCLK clock */
|
||||
.er32kSrc = SIM_OSC32KSEL_RTC32KCLK_CLK, /* OSC32KSEL select: RTC32KCLK clock (32.768kHz) */
|
||||
.clkdiv1 = 0x1340000U, /* SIM_CLKDIV1 - OUTDIV1: /1, OUTDIV2: /2, OUTDIV3: /4, OUTDIV4: /5 */
|
||||
};
|
||||
const osc_config_t oscConfig_BOARD_BootClockRUN =
|
||||
{
|
||||
.freq = 0U, /* Oscillator frequency: 0Hz */
|
||||
.capLoad = (OSC_CAP0P), /* Oscillator capacity load: 0pF */
|
||||
.workMode = kOSC_ModeOscLowPower, /* Oscillator low power */
|
||||
.oscerConfig =
|
||||
{
|
||||
.enableMode = kOSC_ErClkEnable, /* Enable external reference clock, disable external reference clock in STOP mode */
|
||||
.erclkDiv = 0, /* Divider for OSCERCLK: divided by 1 */
|
||||
}
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Code for BOARD_BootClockRUN configuration
|
||||
******************************************************************************/
|
||||
void BOARD_BootClockRUN(void)
|
||||
{
|
||||
/* Set HSRUN power mode */
|
||||
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
|
||||
SMC_SetPowerModeHsrun(SMC);
|
||||
while (SMC_GetPowerModeState(SMC) != kSMC_PowerStateHsrun)
|
||||
{
|
||||
}
|
||||
/* Set the system clock dividers in SIM to safe value. */
|
||||
CLOCK_SetSimSafeDivs();
|
||||
/* Configure RTC clock including enabling RTC oscillator. */
|
||||
CLOCK_CONFIG_SetRtcClock(RTC_OSC_CAP_LOAD_12PF, RTC_RTC32KCLK_PERIPHERALS_ENABLED);
|
||||
/* Configure the Internal Reference clock (MCGIRCLK). */
|
||||
CLOCK_SetInternalRefClkConfig(mcgConfig_BOARD_BootClockRUN.irclkEnableMode,
|
||||
mcgConfig_BOARD_BootClockRUN.ircs,
|
||||
mcgConfig_BOARD_BootClockRUN.fcrdiv);
|
||||
/* Configure FLL external reference divider (FRDIV). */
|
||||
CLOCK_CONFIG_SetFllExtRefDiv(mcgConfig_BOARD_BootClockRUN.frdiv);
|
||||
/* Set MCG to PEE mode. */
|
||||
CLOCK_BootToPeeMode(mcgConfig_BOARD_BootClockRUN.oscsel,
|
||||
kMCG_PllClkSelPll0,
|
||||
&mcgConfig_BOARD_BootClockRUN.pll0Config);
|
||||
/* Set the clock configuration in SIM module. */
|
||||
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
|
||||
/* Set SystemCoreClock variable. */
|
||||
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
|
||||
/* Set RTC_CLKOUT source. */
|
||||
CLOCK_SetRtcClkOutClock(SIM_RTC_CLKOUT_SEL_RTC1HZCLK_CLK);
|
||||
/* Enable USB FS clock. */
|
||||
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcExt, SIM_USB_CLK_48000000HZ);
|
||||
/* Set CLKOUT source. */
|
||||
CLOCK_SetClkOutClock(SIM_CLKOUT_SEL_FLEXBUS_CLK);
|
||||
/* Set debug trace clock source. */
|
||||
CLOCK_SetTraceClock(SIM_TRACE_CLK_SEL_CORE_SYSTEM_CLK);
|
||||
}
|
||||
45
right/src/include/board/clock_config.h
Normal file
45
right/src/include/board/clock_config.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_
|
||||
#include "fsl_common.h"
|
||||
|
||||
#define BOARD_XTAL0_CLK_HZ 8000000U /*!< Board xtal0 frequency in Hz */
|
||||
#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board RTC xtal frequency in Hz */
|
||||
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 120000000U /*!< Core clock frequency: 120000000Hz */
|
||||
|
||||
extern const mcg_config_t mcgConfig_BOARD_BootClockRUN;
|
||||
extern const sim_clock_config_t simConfig_BOARD_BootClockRUN;
|
||||
extern const osc_config_t oscConfig_BOARD_BootClockRUN;
|
||||
|
||||
void BOARD_BootClockRUN(void);
|
||||
|
||||
#endif /* _CLOCK_CONFIG_H_ */
|
||||
68
right/src/include/board/pin_mux.c
Normal file
68
right/src/include/board/pin_mux.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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"
|
||||
#include "board.h"
|
||||
#include "test_led.h"
|
||||
|
||||
void BOARD_InitPins(void)
|
||||
{
|
||||
// Ungate ports.
|
||||
CLOCK_EnableClock(kCLOCK_PortA); // LEDs
|
||||
CLOCK_EnableClock(kCLOCK_PortB); // SW3
|
||||
CLOCK_EnableClock(kCLOCK_PortC); // SW2
|
||||
CLOCK_EnableClock(kCLOCK_PortD); // LEDs, I2C
|
||||
|
||||
// Set up switches
|
||||
port_pin_config_t switchConfig = {
|
||||
.pullSelect = kPORT_PullUp,
|
||||
.mux = kPORT_MuxAsGpio,
|
||||
};
|
||||
PORT_SetPinConfig(BOARD_SW2_PORT, BOARD_SW2_GPIO_PIN, &switchConfig);
|
||||
|
||||
// Initialize LEDs.
|
||||
|
||||
PORT_SetPinMux(TEST_LED_GPIO_PORT, TEST_LED_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
TEST_RED_INIT(LOGIC_LED_ON);
|
||||
GPIO_SetPinsOutput(TEST_LED_GPIO, 1 << TEST_LED_GPIO_PIN);
|
||||
|
||||
// Initialize I2C.
|
||||
|
||||
port_pin_config_t pinConfig = {0};
|
||||
pinConfig.pullSelect = kPORT_PullUp;
|
||||
pinConfig.openDrainEnable = kPORT_OpenDrainEnable;
|
||||
|
||||
PORT_SetPinConfig(PORTD, 2, &pinConfig);
|
||||
PORT_SetPinConfig(PORTD, 3, &pinConfig);
|
||||
|
||||
PORT_SetPinMux(PORTD, 2, kPORT_MuxAlt7);
|
||||
PORT_SetPinMux(PORTD, 3, kPORT_MuxAlt7);
|
||||
}
|
||||
50
right/src/include/board/pin_mux.h
Normal file
50
right/src/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_ */
|
||||
135
right/src/include/lufa/Common.h
Normal file
135
right/src/include/lufa/Common.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaims all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \dir
|
||||
* \brief Common library header files.
|
||||
*
|
||||
* This folder contains header files which are common to all parts of the LUFA library. They may be used freely in
|
||||
* user applications.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Common library convenience headers, macros and functions.
|
||||
*
|
||||
* \copydetails Group_Common
|
||||
*/
|
||||
|
||||
/** \defgroup Group_Common Common Utility Headers - LUFA/Drivers/Common/Common.h
|
||||
* \brief Common library convenience headers, macros and functions.
|
||||
*
|
||||
* Common utility headers containing macros, functions, enums and types which are common to all
|
||||
* aspects of the library.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** \defgroup Group_GlobalInt Global Interrupt Macros
|
||||
* \brief Convenience macros for the management of interrupts globally within the device.
|
||||
*
|
||||
* Macros and functions to create and control global interrupts within the device.
|
||||
*/
|
||||
|
||||
#ifndef __LUFA_COMMON_H__
|
||||
#define __LUFA_COMMON_H__
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
|
||||
/** Convenience macro to determine the larger of two values.
|
||||
*
|
||||
* \attention This macro should only be used with operands that do not have side effects from being evaluated
|
||||
* multiple times.
|
||||
*
|
||||
* \param[in] x First value to compare
|
||||
* \param[in] y First value to compare
|
||||
*
|
||||
* \return The larger of the two input parameters
|
||||
*/
|
||||
#if !defined(MAX) || defined(__DOXYGEN__)
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/** Convenience macro to determine the smaller of two values.
|
||||
*
|
||||
* \attention This macro should only be used with operands that do not have side effects from being evaluated
|
||||
* multiple times.
|
||||
*
|
||||
* \param[in] x First value to compare.
|
||||
* \param[in] y First value to compare.
|
||||
*
|
||||
* \return The smaller of the two input parameters
|
||||
*/
|
||||
#if !defined(MIN) || defined(__DOXYGEN__)
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#if !defined(STRINGIFY) || defined(__DOXYGEN__)
|
||||
/** Converts the given input into a string, via the C Preprocessor. This macro puts literal quotation
|
||||
* marks around the input, converting the source into a string literal.
|
||||
*
|
||||
* \param[in] x Input to convert into a string literal.
|
||||
*
|
||||
* \return String version of the input.
|
||||
*/
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
/** Converts the given input into a string after macro expansion, via the C Preprocessor. This macro puts
|
||||
* literal quotation marks around the expanded input, converting the source into a string literal.
|
||||
*
|
||||
* \param[in] x Input to expand and convert into a string literal.
|
||||
*
|
||||
* \return String version of the expanded input.
|
||||
*/
|
||||
#define STRINGIFY_EXPANDED(x) STRINGIFY(x)
|
||||
#endif
|
||||
|
||||
#if !defined(CONCAT) || defined(__DOXYGEN__)
|
||||
/** Concatenates the given input into a single token, via the C Preprocessor.
|
||||
*
|
||||
* \param[in] x First item to concatenate.
|
||||
* \param[in] y Second item to concatenate.
|
||||
*
|
||||
* \return Concatenated version of the input.
|
||||
*/
|
||||
#define CONCAT(x, y) x ## y
|
||||
|
||||
/** CConcatenates the given input into a single token after macro expansion, via the C Preprocessor.
|
||||
*
|
||||
* \param[in] x First item to concatenate.
|
||||
* \param[in] y Second item to concatenate.
|
||||
*
|
||||
* \return Concatenated version of the expanded input.
|
||||
*/
|
||||
#define CONCAT_EXPANDED(x, y) CONCAT(x, y)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
543
right/src/include/lufa/HIDClassCommon.h
Normal file
543
right/src/include/lufa/HIDClassCommon.h
Normal file
File diff suppressed because it is too large
Load Diff
126
right/src/include/lufa/HIDReportData.h
Normal file
126
right/src/include/lufa/HIDReportData.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
The author disclaims all warranties with regard to this
|
||||
software, including all implied warranties of merchantability
|
||||
and fitness. In no event shall the author be liable for any
|
||||
special, indirect or consequential damages or any damages
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief Constants for HID report item attributes.
|
||||
*
|
||||
* HID report item constants for report item attributes. Refer to the HID specification for
|
||||
* details on each flag's meaning when applied to an IN, OUT or FEATURE item.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_HIDParser
|
||||
* \defgroup Group_HIDReportItemConst HID Report Descriptor Item Constants
|
||||
*
|
||||
* General HID constant definitions for HID Report Descriptor elements.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __HIDREPORTDATA_H__
|
||||
#define __HIDREPORTDATA_H__
|
||||
|
||||
/* Private Interface - For use in library only: */
|
||||
#if !defined(__DOXYGEN__)
|
||||
/* Macros: */
|
||||
#define HID_RI_DATA_SIZE_MASK 0x03
|
||||
#define HID_RI_TYPE_MASK 0x0C
|
||||
#define HID_RI_TAG_MASK 0xF0
|
||||
|
||||
#define HID_RI_TYPE_MAIN 0x00
|
||||
#define HID_RI_TYPE_GLOBAL 0x04
|
||||
#define HID_RI_TYPE_LOCAL 0x08
|
||||
|
||||
#define HID_RI_DATA_BITS_0 0x00
|
||||
#define HID_RI_DATA_BITS_8 0x01
|
||||
#define HID_RI_DATA_BITS_16 0x02
|
||||
#define HID_RI_DATA_BITS_32 0x03
|
||||
#define HID_RI_DATA_BITS(DataBits) CONCAT_EXPANDED(HID_RI_DATA_BITS_, DataBits)
|
||||
|
||||
#define _HID_RI_ENCODE_0(Data)
|
||||
#define _HID_RI_ENCODE_8(Data) , (Data & 0xFF)
|
||||
#define _HID_RI_ENCODE_16(Data) _HID_RI_ENCODE_8(Data) _HID_RI_ENCODE_8(Data >> 8)
|
||||
#define _HID_RI_ENCODE_32(Data) _HID_RI_ENCODE_16(Data) _HID_RI_ENCODE_16(Data >> 16)
|
||||
#define _HID_RI_ENCODE(DataBits, ...) CONCAT_EXPANDED(_HID_RI_ENCODE_, DataBits(__VA_ARGS__))
|
||||
|
||||
#define _HID_RI_ENTRY(Type, Tag, DataBits, ...) (Type | Tag | HID_RI_DATA_BITS(DataBits)) _HID_RI_ENCODE(DataBits, (__VA_ARGS__))
|
||||
#endif
|
||||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Macros: */
|
||||
/** \name HID Input, Output and Feature Report Descriptor Item Flags */
|
||||
//@{
|
||||
#define HID_IOF_CONSTANT (1 << 0)
|
||||
#define HID_IOF_DATA (0 << 0)
|
||||
#define HID_IOF_VARIABLE (1 << 1)
|
||||
#define HID_IOF_ARRAY (0 << 1)
|
||||
#define HID_IOF_RELATIVE (1 << 2)
|
||||
#define HID_IOF_ABSOLUTE (0 << 2)
|
||||
#define HID_IOF_WRAP (1 << 3)
|
||||
#define HID_IOF_NO_WRAP (0 << 3)
|
||||
#define HID_IOF_NON_LINEAR (1 << 4)
|
||||
#define HID_IOF_LINEAR (0 << 4)
|
||||
#define HID_IOF_NO_PREFERRED_STATE (1 << 5)
|
||||
#define HID_IOF_PREFERRED_STATE (0 << 5)
|
||||
#define HID_IOF_NULLSTATE (1 << 6)
|
||||
#define HID_IOF_NO_NULL_POSITION (0 << 6)
|
||||
#define HID_IOF_VOLATILE (1 << 7)
|
||||
#define HID_IOF_NON_VOLATILE (0 << 7)
|
||||
#define HID_IOF_BUFFERED_BYTES (1 << 8)
|
||||
#define HID_IOF_BITFIELD (0 << 8)
|
||||
//@}
|
||||
|
||||
/** \name HID Report Descriptor Item Macros */
|
||||
//@{
|
||||
#define HID_RI_INPUT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0x80, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_OUTPUT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0x90, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_COLLECTION(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xA0, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_FEATURE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xB0, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_END_COLLECTION(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_MAIN , 0xC0, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_USAGE_PAGE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x00, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_LOGICAL_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x10, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_LOGICAL_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x20, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_PHYSICAL_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x30, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_PHYSICAL_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x40, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_UNIT_EXPONENT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x50, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_UNIT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x60, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_REPORT_SIZE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x70, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_REPORT_ID(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x80, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_REPORT_COUNT(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0x90, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_PUSH(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0xA0, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_POP(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_GLOBAL, 0xB0, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_USAGE(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x00, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_USAGE_MINIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x10, DataBits, __VA_ARGS__)
|
||||
#define HID_RI_USAGE_MAXIMUM(DataBits, ...) _HID_RI_ENTRY(HID_RI_TYPE_LOCAL , 0x20, DataBits, __VA_ARGS__)
|
||||
//@}
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
|
||||
12
right/src/include/lufa/README.md
Normal file
12
right/src/include/lufa/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# LUFA library header files
|
||||
|
||||
This directory contains some header files from
|
||||
[LUFA, the Lightweight USB Framework for AVRs](http://www.fourwalledcubicle.com/LUFA.php).
|
||||
|
||||
LUFA is an extremely well designed library that exposes a beautiful and intuitive API that is a joy
|
||||
to work with. LUFA being an AVR based library can't be used as a whole for ARM, but some parts of it
|
||||
can be.
|
||||
|
||||
The selected header files contain macros for USB scancodes and USB HID report items. USB HID report
|
||||
item macros are especially helpful and it's a much better idea to use them than a bunch of magic
|
||||
numbers backed by loads of comments.
|
||||
3
right/src/include/usb/README.md
Normal file
3
right/src/include/usb/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# KSDK USB library
|
||||
|
||||
This directory contains parts of the KSDK USB library. Ideally, these files should be contained in the KSDK core library, but instead they are bundled with KSDK USB demos on a per demo basis.
|
||||
931
right/src/include/usb/usb_device_ch9.c
Normal file
931
right/src/include/usb/usb_device_ch9.c
Normal file
File diff suppressed because it is too large
Load Diff
101
right/src/include/usb/usb_device_ch9.h
Normal file
101
right/src/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/src/include/usb/usb_device_class.c
Normal file
571
right/src/include/usb/usb_device_class.c
Normal file
File diff suppressed because it is too large
Load Diff
423
right/src/include/usb/usb_device_class.h
Normal file
423
right/src/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/src/include/usb/usb_device_hid.c
Normal file
667
right/src/include/usb/usb_device_hid.c
Normal file
File diff suppressed because it is too large
Load Diff
234
right/src/include/usb/usb_device_hid.h
Normal file
234
right/src/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__ */
|
||||
13
right/src/layer.h
Normal file
13
right/src/layer.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef __LAYER_H__
|
||||
#define __LAYER_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define LAYER_ID_BASE 0
|
||||
#define LAYER_ID_MOD 1
|
||||
#define LAYER_ID_FN 2
|
||||
#define LAYER_ID_MOUSE 3
|
||||
|
||||
#define LAYER_COUNT 4
|
||||
|
||||
#endif
|
||||
77
right/src/main.c
Normal file
77
right/src/main.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "fsl_i2c.h"
|
||||
#include "include/board/clock_config.h"
|
||||
#include "include/board/board.h"
|
||||
#include "include/board/pin_mux.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "i2c.h"
|
||||
#include "main.h"
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_port.h"
|
||||
|
||||
void tx(uint8_t txBuffer[], uint8_t size)
|
||||
{
|
||||
i2c_master_transfer_t masterXfer;
|
||||
masterXfer.slaveAddress = LEFT_LED_DRIVER_ADDRESS_7BIT;
|
||||
masterXfer.direction = kI2C_Write;
|
||||
masterXfer.subaddress = 0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
masterXfer.data = txBuffer;
|
||||
masterXfer.dataSize = size;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
masterXfer.slaveAddress = RIGHT_LED_DRIVER_ADDRESS_7BIT;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
}
|
||||
|
||||
void write(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t txBuffer[] = {0, 0};
|
||||
txBuffer[0] = reg;
|
||||
txBuffer[1] = val;
|
||||
tx(txBuffer, sizeof(txBuffer));
|
||||
}
|
||||
|
||||
void InitLedDisplay()
|
||||
{
|
||||
PORT_SetPinMux(PORTA, 2U, kPORT_MuxAsGpio);
|
||||
|
||||
gpio_pin_config_t led_config = {
|
||||
.pinDirection = kGPIO_DigitalOutput,
|
||||
.outputLogic = 0,
|
||||
};
|
||||
|
||||
GPIO_PinInit(GPIOA, 2U, &led_config);
|
||||
GPIO_SetPinsOutput(GPIOA, 0 << 2U);
|
||||
|
||||
write(0xfd, 0x0b); // point to page 9
|
||||
write(0x0a, 0x01); // set shutdown mode to normal
|
||||
write(0xfd, 0x00); // point to page 0
|
||||
|
||||
uint8_t i;
|
||||
for (i=0x00; i<=0x11; i++) {
|
||||
write(i, 0xff);
|
||||
}
|
||||
for (i=0x12; i<=0x23; i++) {
|
||||
write(i, 0x00);
|
||||
}
|
||||
for (i=0x24; i<=0xb3; i++) {
|
||||
write(i, 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
BOARD_InitPins();
|
||||
BOARD_BootClockRUN();
|
||||
|
||||
i2c_master_config_t masterConfig;
|
||||
uint32_t sourceClock;
|
||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||
masterConfig.baudRate_Bps = I2C_BAUD_RATE;
|
||||
sourceClock = CLOCK_GetFreq(I2C_MASTER_CLK_SRC);
|
||||
I2C_MasterInit(EXAMPLE_I2C_MASTER_BASEADDR, &masterConfig, sourceClock);
|
||||
|
||||
InitLedDisplay();
|
||||
InitUsb();
|
||||
|
||||
while (1);
|
||||
}
|
||||
9
right/src/main.h
Normal file
9
right/src/main.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
|
||||
#define EXAMPLE_I2C_MASTER_BASEADDR I2C0
|
||||
#define I2C_BAUD_RATE 100000
|
||||
#define I2C_MASTER_CLK_SRC I2C0_CLK_SRC
|
||||
#define I2C_DATA_LENGTH 2
|
||||
|
||||
#endif
|
||||
60
right/src/module.h
Normal file
60
right/src/module.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef __MODULE_H__
|
||||
#define __MODULE_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "action.h"
|
||||
#include "layer.h"
|
||||
#include "slot.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define MODULE_ID_LEFT_KEYBOARD_HALF 0
|
||||
#define MODULE_ID_KEY_CLUSTER_LEFT 1
|
||||
#define MODULE_ID_TRACKBALL_RIGHT 2
|
||||
#define MODULE_ID_TRACKPOINT_RIGHT 3
|
||||
#define MODULE_ID_TOUCHPAD 4
|
||||
|
||||
#define MODULE_REQUEST_GET_PROTOCOL_VERSION 0
|
||||
#define MODULE_REQUEST_GET_MODULE_ID 1
|
||||
#define MODULE_REQUEST_GET_MODULE_NAME 2
|
||||
#define MODULE_REQUEST_GET_FEATURES 3
|
||||
#define MODULE_REQUEST_GET_FACTORY_LAYER 4
|
||||
#define MODULE_REQUEST_GET_POINTER_INFO 5
|
||||
#define MODULE_REQUEST_GET_STATE 6
|
||||
#define MODULE_REQUEST_GET_GRAPHICS 7
|
||||
|
||||
#define MODULE_STATUS_ATTACHED MODULE_REQUEST_GET_STATE
|
||||
|
||||
#define POINTER_ROLE_MOVE 0
|
||||
#define POINTER_ROLE_SCROLL 1
|
||||
|
||||
#define MAX_MODULE_NAME_LENGTH 64
|
||||
#define MAX_KEY_COUNT_PER_MODULE 64
|
||||
#define MAX_POINTER_COUNT_PER_MODULE 2
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
uint8_t acceleration;
|
||||
uint8_t maxSpeed;
|
||||
uint8_t roles[LAYER_COUNT];
|
||||
} pointer_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t enumerationState;
|
||||
uint8_t enumerationSubstate;
|
||||
uint8_t moduleId;
|
||||
char moduleName[MAX_MODULE_NAME_LENGTH];
|
||||
uint8_t pointerCount;
|
||||
uint8_t keyCount;
|
||||
uint8_t keyStates[MAX_KEY_COUNT_PER_MODULE];
|
||||
pointer_t pointers[MAX_POINTER_COUNT_PER_MODULE];
|
||||
key_action_t keyActions[LAYER_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
} module_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern module_t AttachedModules[SLOT_COUNT];
|
||||
|
||||
#endif
|
||||
27
right/src/slot.h
Normal file
27
right/src/slot.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef __SLOT_H__
|
||||
#define __SLOT_H__
|
||||
|
||||
// Slots provide a way to avoid I2C address collision of modules as only a single module can
|
||||
// allocate a given slot.
|
||||
|
||||
// Macros:
|
||||
|
||||
#define SLOT_ID_RIGHT_KEYBOARD_HALF 0
|
||||
#define SLOT_ID_LEFT_KEYBOARD_HALF 1
|
||||
#define SLOT_ID_LEFT_MODULE 2
|
||||
#define SLOT_ID_RIGHT_MODULE 3
|
||||
#define SLOT_ID_BOTH_SIDED_MODULE 4
|
||||
|
||||
// The 7-bit I2C addresses below 0x08 are reserved.
|
||||
#define SLOT_I2C_ADDRESS_LEFT_KEYBOARD_HALF 0x08
|
||||
#define SLOT_I2C_ADDRESS_LEFT_MODULE 0x09
|
||||
#define SLOT_I2C_ADDRESS_RIGHT_MODULE 0x0A
|
||||
#define SLOT_I2C_ADDRESS_BOTH_SIDED_MODULE 0x0B
|
||||
#define SLOT_I2C_ADDRESS_LEFT_KEYBOARD_HALF 0x0C
|
||||
|
||||
#define SLOT_I2C_ADDRESS_MIN 0x08
|
||||
#define SLOT_I2C_ADDRESS_MAX 0x0C
|
||||
|
||||
#define SLOT_COUNT 5
|
||||
|
||||
#endif
|
||||
23
right/src/test_led.h
Normal file
23
right/src/test_led.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __TEST_LED_H__
|
||||
#define __TEST_LED_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "fsl_gpio.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define LOGIC_LED_ON 0U
|
||||
#define LOGIC_LED_OFF 1U
|
||||
|
||||
#define TEST_LED_GPIO GPIOD
|
||||
#define TEST_LED_GPIO_PORT PORTD
|
||||
#define TEST_LED_GPIO_PIN 7U
|
||||
|
||||
#define TEST_RED_INIT(output) GPIO_PinInit(TEST_LED_GPIO, TEST_LED_GPIO_PIN, \
|
||||
&(gpio_pin_config_t){kGPIO_DigitalOutput, (output)})
|
||||
#define TEST_RED_ON() GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
#define TEST_RED_OFF() GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
#define TEST_RED_TOGGLE() GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN)
|
||||
|
||||
#endif
|
||||
65
right/src/usb_api.h
Normal file
65
right/src/usb_api.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef __USB_REPORT_ITEM_MACROS__
|
||||
#define __USB_REPORT_ITEM_MACROS__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_device_config.h"
|
||||
#include "usb.h"
|
||||
#include "usb_device.h"
|
||||
#include "include/usb/usb_device_class.h"
|
||||
#include "include/usb/usb_device_hid.h"
|
||||
|
||||
#include "include/lufa/Common.h"
|
||||
#include "include/lufa/HIDClassCommon.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
// General constants
|
||||
|
||||
#define USB_DEVICE_CLASS 0x00
|
||||
#define USB_DEVICE_SUBCLASS 0x00
|
||||
#define USB_DEVICE_PROTOCOL 0x00
|
||||
|
||||
#define USB_INTERFACE_ALTERNATE_SETTING_NONE 0x00
|
||||
#define USB_STRING_DESCRIPTOR_NONE 0x00
|
||||
#define USB_LANGUAGE_ID_UNITED_STATES 0x0409
|
||||
|
||||
// HID related constants
|
||||
|
||||
#define USB_DESCRIPTOR_LENGTH_HID 9
|
||||
#define USB_CLASS_HID 0x03
|
||||
#define USB_HID_COUNTRY_CODE_NOT_SUPPORTED 0x00
|
||||
|
||||
#define USB_HID_SUBCLASS_NONE 0
|
||||
#define USB_HID_SUBCLASS_BOOT 1
|
||||
|
||||
#define USB_HID_PROTOCOL_NONE 0
|
||||
#define USB_HID_PROTOCOL_KEYBOARD 1
|
||||
#define USB_HID_PROTOCOL_MOUSE 2
|
||||
|
||||
// HID report item related constants
|
||||
|
||||
#define HID_RI_USAGE_PAGE_GENERIC_DESKTOP 0x01
|
||||
#define HID_RI_USAGE_PAGE_LEDS 0x08
|
||||
#define HID_RI_USAGE_PAGE_BUTTONS 0x09
|
||||
#define HID_RI_USAGE_PAGE_CONSUMER 0x0C
|
||||
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_POINTER 0x01
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_MOUSE 0x02
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_JOYSTICK 0x04
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_GAMEPAD 0x05
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_KEYBOARD 0x06
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_X 0x30
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_Y 0x31
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_WHEEL 0x38
|
||||
#define HID_RI_USAGE_GENERIC_DESKTOP_RESOLUTION_MULTIPLIER 0x48
|
||||
|
||||
#define HID_RI_USAGE_CONSUMER_AC_PAN 0x0238
|
||||
|
||||
#define HID_RI_COLLECTION_PHYSICAL 0x00
|
||||
#define HID_RI_COLLECTION_APPLICATION 0x01
|
||||
#define HID_RI_COLLECTION_LOGICAL 0x02
|
||||
|
||||
#define HID_RI_USAGE_PAGE_KEY_CODES 0x07
|
||||
|
||||
#endif
|
||||
117
right/src/usb_composite_device.c
Normal file
117
right/src/usb_composite_device.c
Normal file
@@ -0,0 +1,117 @@
|
||||
#include "fsl_common.h"
|
||||
#include "usb_api.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_descriptor_hid.h"
|
||||
#include "usb_descriptor_strings.h"
|
||||
|
||||
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
|
||||
usb_composite_device_t UsbCompositeDevice;
|
||||
|
||||
usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_DEVICE_CONFIG_HID] = {
|
||||
{UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass},
|
||||
{UsbKeyboardCallback, (class_handle_t)NULL, &UsbKeyboardClass},
|
||||
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass},
|
||||
};
|
||||
|
||||
usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = {
|
||||
UsbDeviceCompositeClassConfig,
|
||||
UsbDeviceCallback,
|
||||
USB_DEVICE_CONFIG_HID
|
||||
};
|
||||
|
||||
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
uint16_t *temp16 = (uint16_t*)param;
|
||||
uint8_t *temp8 = (uint8_t*)param;
|
||||
|
||||
if (!param && event != kUSB_DeviceEventBusReset && event != kUSB_DeviceEventSetInterface) {
|
||||
return error;
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case kUSB_DeviceEventBusReset:
|
||||
UsbCompositeDevice.attach = 0;
|
||||
error = kStatus_USB_Success;
|
||||
break;
|
||||
case kUSB_DeviceEventSetConfiguration:
|
||||
UsbCompositeDevice.attach = 1;
|
||||
UsbCompositeDevice.currentConfiguration = *temp8;
|
||||
UsbGenericHidSetConfiguration(UsbCompositeDevice.genericHidHandle, *temp8);
|
||||
UsbKeyboardSetConfiguration(UsbCompositeDevice.keyboardHandle, *temp8);
|
||||
UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8);
|
||||
error = kStatus_USB_Success;
|
||||
break;
|
||||
case kUSB_DeviceEventGetConfiguration:
|
||||
*temp8 = UsbCompositeDevice.currentConfiguration;
|
||||
error = kStatus_USB_Success;
|
||||
break;
|
||||
case kUSB_DeviceEventSetInterface:
|
||||
if (UsbCompositeDevice.attach) {
|
||||
uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 8);
|
||||
uint8_t alternateSetting = (uint8_t)(*temp16 & 0x00FF);
|
||||
if (interface < USB_DEVICE_CONFIG_HID) {
|
||||
UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting;
|
||||
UsbGenericHidSetInterface(UsbCompositeDevice.genericHidHandle, interface, alternateSetting);
|
||||
UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface, alternateSetting);
|
||||
UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting);
|
||||
error = kStatus_USB_Success;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kUSB_DeviceEventGetInterface: ;
|
||||
uint8_t interface = (uint8_t)((*temp16 & 0xFF00) >> 8);
|
||||
if (interface < USB_DEVICE_CONFIG_HID) {
|
||||
*temp16 = (*temp16 & 0xFF00) | UsbCompositeDevice.currentInterfaceAlternateSetting[interface];
|
||||
error = kStatus_USB_Success;
|
||||
} else {
|
||||
error = kStatus_USB_InvalidRequest;
|
||||
}
|
||||
break;
|
||||
case kUSB_DeviceEventGetDeviceDescriptor:
|
||||
error = USB_DeviceGetDeviceDescriptor(handle, (usb_device_get_device_descriptor_struct_t *)param);
|
||||
break;
|
||||
case kUSB_DeviceEventGetConfigurationDescriptor:
|
||||
error = USB_DeviceGetConfigurationDescriptor(handle, (usb_device_get_configuration_descriptor_struct_t *)param);
|
||||
break;
|
||||
case kUSB_DeviceEventGetStringDescriptor:
|
||||
error = USB_DeviceGetStringDescriptor(handle, (usb_device_get_string_descriptor_struct_t *)param);
|
||||
break;
|
||||
case kUSB_DeviceEventGetHidDescriptor:
|
||||
error = USB_DeviceGetHidDescriptor(handle, (usb_device_get_hid_descriptor_struct_t *)param);
|
||||
break;
|
||||
case kUSB_DeviceEventGetHidReportDescriptor:
|
||||
error = USB_DeviceGetHidReportDescriptor(handle, (usb_device_get_hid_report_descriptor_struct_t *)param);
|
||||
break;
|
||||
case kUSB_DeviceEventGetHidPhysicalDescriptor:
|
||||
error = USB_DeviceGetHidPhysicalDescriptor(handle, (usb_device_get_hid_physical_descriptor_struct_t *)param);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void USB0_IRQHandler()
|
||||
{
|
||||
USB_DeviceKhciIsrFunction(UsbCompositeDevice.deviceHandle);
|
||||
}
|
||||
|
||||
void InitUsb()
|
||||
{
|
||||
uint8_t usbDeviceKhciIrq[] = USB_IRQS;
|
||||
uint8_t irqNumber = usbDeviceKhciIrq[CONTROLLER_ID - kUSB_ControllerKhci0];
|
||||
|
||||
SystemCoreClockUpdate();
|
||||
CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000);
|
||||
|
||||
UsbCompositeDevice.attach = 0;
|
||||
USB_DeviceClassInit(CONTROLLER_ID, &UsbDeviceCompositeConfigList, &UsbCompositeDevice.deviceHandle);
|
||||
UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[USB_GENERIC_HID_INTERFACE_INDEX].classHandle;
|
||||
UsbCompositeDevice.keyboardHandle = UsbDeviceCompositeConfigList.config[USB_KEYBOARD_INTERFACE_INDEX].classHandle;
|
||||
UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[USB_MOUSE_INTERFACE_INDEX].classHandle;
|
||||
|
||||
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
|
||||
NVIC_EnableIRQ((IRQn_Type)irqNumber);
|
||||
|
||||
USB_DeviceRun(UsbCompositeDevice.deviceHandle);
|
||||
}
|
||||
33
right/src/usb_composite_device.h
Normal file
33
right/src/usb_composite_device.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef __USB_COMPOSITE_DEVICE_H__
|
||||
#define __USB_COMPOSITE_DEVICE_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_descriptor_configuration.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define CONTROLLER_ID kUSB_ControllerKhci0
|
||||
#define USB_DEVICE_INTERRUPT_PRIORITY 3
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
usb_device_handle deviceHandle;
|
||||
class_handle_t mouseHandle;
|
||||
class_handle_t keyboardHandle;
|
||||
class_handle_t genericHidHandle;
|
||||
uint8_t attach;
|
||||
uint8_t currentConfiguration;
|
||||
uint8_t currentInterfaceAlternateSetting[USB_DEVICE_CONFIG_HID];
|
||||
} usb_composite_device_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern usb_composite_device_t UsbCompositeDevice;
|
||||
|
||||
//Functions:
|
||||
|
||||
extern void InitUsb();
|
||||
|
||||
#endif
|
||||
144
right/src/usb_descriptor_configuration.c
Normal file
144
right/src/usb_descriptor_configuration.c
Normal file
@@ -0,0 +1,144 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_descriptor_mouse_report.h"
|
||||
#include "usb_descriptor_generic_hid_report.h"
|
||||
|
||||
uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] = {
|
||||
|
||||
// Configuration descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_CONFIGURE,
|
||||
USB_DESCRIPTOR_TYPE_CONFIGURE,
|
||||
USB_SHORT_GET_LOW(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH),
|
||||
USB_SHORT_GET_HIGH(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH),
|
||||
USB_DEVICE_CONFIG_HID,
|
||||
USB_COMPOSITE_CONFIGURATION_INDEX,
|
||||
USB_STRING_DESCRIPTOR_NONE,
|
||||
(USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
|
||||
(USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
|
||||
(USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
|
||||
USB_DEVICE_MAX_POWER,
|
||||
|
||||
// Generic HID interface descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||
USB_GENERIC_HID_INTERFACE_INDEX,
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
USB_GENERIC_HID_ENDPOINT_COUNT,
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_NONE,
|
||||
USB_HID_PROTOCOL_NONE,
|
||||
USB_STRING_DESCRIPTOR_NONE,
|
||||
|
||||
// Generic HID descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_HID,
|
||||
USB_DESCRIPTOR_TYPE_HID,
|
||||
USB_SHORT_GET_LOW(USB_HID_VERSION),
|
||||
USB_SHORT_GET_HIGH(USB_HID_VERSION),
|
||||
USB_HID_COUNTRY_CODE_NOT_SUPPORTED,
|
||||
USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE,
|
||||
USB_DESCRIPTOR_TYPE_HID_REPORT,
|
||||
USB_SHORT_GET_LOW(USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH),
|
||||
|
||||
// Generic HID IN endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_GENERIC_HID_ENDPOINT_IN_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_GENERIC_HID_INTERRUPT_IN_INTERVAL,
|
||||
|
||||
// Generic HID OUT endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_GENERIC_HID_ENDPOINT_OUT_INDEX | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE),
|
||||
USB_GENERIC_HID_INTERRUPT_IN_INTERVAL,
|
||||
|
||||
// Keyboard interface descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||
USB_KEYBOARD_INTERFACE_INDEX,
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
USB_KEYBOARD_ENDPOINT_COUNT,
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_BOOT,
|
||||
USB_HID_PROTOCOL_KEYBOARD,
|
||||
USB_STRING_DESCRIPTOR_NONE,
|
||||
|
||||
// Keyboard HID descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_HID,
|
||||
USB_DESCRIPTOR_TYPE_HID,
|
||||
USB_SHORT_GET_LOW(USB_HID_VERSION),
|
||||
USB_SHORT_GET_HIGH(USB_HID_VERSION),
|
||||
USB_HID_COUNTRY_CODE_NOT_SUPPORTED,
|
||||
USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE,
|
||||
USB_DESCRIPTOR_TYPE_HID_REPORT,
|
||||
USB_SHORT_GET_LOW(USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH),
|
||||
USB_SHORT_GET_HIGH(USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH),
|
||||
|
||||
// Keyboard endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_KEYBOARD_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_KEYBOARD_INTERRUPT_IN_INTERVAL,
|
||||
|
||||
// Mouse interface descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||
USB_MOUSE_INTERFACE_INDEX,
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
USB_MOUSE_ENDPOINT_COUNT,
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_BOOT,
|
||||
USB_HID_PROTOCOL_MOUSE,
|
||||
USB_STRING_DESCRIPTOR_NONE,
|
||||
|
||||
// Mouse HID descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_HID,
|
||||
USB_DESCRIPTOR_TYPE_HID,
|
||||
USB_SHORT_GET_LOW(USB_HID_VERSION),
|
||||
USB_SHORT_GET_HIGH(USB_HID_VERSION),
|
||||
USB_HID_COUNTRY_CODE_NOT_SUPPORTED,
|
||||
USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE,
|
||||
USB_DESCRIPTOR_TYPE_HID_REPORT,
|
||||
USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
|
||||
USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH),
|
||||
|
||||
// Mouse endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_MOUSE_INTERRUPT_IN_INTERVAL,
|
||||
};
|
||||
|
||||
usb_status_t USB_DeviceGetConfigurationDescriptor(
|
||||
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor)
|
||||
{
|
||||
if (USB_COMPOSITE_CONFIGURATION_INDEX > configurationDescriptor->configuration) {
|
||||
configurationDescriptor->buffer = UsbConfigurationDescriptor;
|
||||
configurationDescriptor->length = USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH;
|
||||
return kStatus_USB_Success;
|
||||
}
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
20
right/src/usb_descriptor_configuration.h
Normal file
20
right/src/usb_descriptor_configuration.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef __USB_DESCRIPTOR_CONFIGURATION_H__
|
||||
#define __USB_DESCRIPTOR_CONFIGURATION_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_interface_keyboard.h"
|
||||
#include "usb_interface_mouse.h"
|
||||
#include "usb_interface_generic_hid.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_COMPOSITE_CONFIGURATION_INDEX 1
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH 91
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t USB_DeviceGetConfigurationDescriptor(
|
||||
usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor);
|
||||
|
||||
#endif
|
||||
32
right/src/usb_descriptor_device.c
Normal file
32
right/src/usb_descriptor_device.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_descriptor_strings.h"
|
||||
|
||||
uint8_t UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
|
||||
USB_DESCRIPTOR_LENGTH_DEVICE,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE,
|
||||
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFICATION_VERSION),
|
||||
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFICATION_VERSION),
|
||||
USB_DEVICE_CLASS,
|
||||
USB_DEVICE_SUBCLASS,
|
||||
USB_DEVICE_PROTOCOL,
|
||||
USB_CONTROL_MAX_PACKET_SIZE,
|
||||
USB_SHORT_GET_LOW(USB_DEVICE_VENDOR_ID),
|
||||
USB_SHORT_GET_HIGH(USB_DEVICE_VENDOR_ID),
|
||||
USB_SHORT_GET_LOW(USB_DEVICE_PRODUCT_ID),
|
||||
USB_SHORT_GET_HIGH(USB_DEVICE_PRODUCT_ID),
|
||||
USB_SHORT_GET_LOW(USB_DEVICE_RELEASE_NUMBER),
|
||||
USB_SHORT_GET_HIGH(USB_DEVICE_RELEASE_NUMBER),
|
||||
USB_STRING_DESCRIPTOR_ID_MANUFACTURER,
|
||||
USB_STRING_DESCRIPTOR_ID_PRODUCT,
|
||||
USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES,
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
usb_status_t USB_DeviceGetDeviceDescriptor(
|
||||
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor)
|
||||
{
|
||||
deviceDescriptor->buffer = UsbDeviceDescriptor;
|
||||
deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
|
||||
return kStatus_USB_Success;
|
||||
}
|
||||
22
right/src/usb_descriptor_device.h
Normal file
22
right/src/usb_descriptor_device.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __USB_DESCRIPTOR_DEVICE_H__
|
||||
#define __USB_DESCRIPTOR_DEVICE_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_DEVICE_VENDOR_ID 0x16D3 // TODO: Change this to 15D0 for the final prototype.
|
||||
#define USB_DEVICE_PRODUCT_ID 0x05EA
|
||||
#define USB_DEVICE_RELEASE_NUMBER 0x0101
|
||||
|
||||
#define USB_DEVICE_SPECIFICATION_VERSION 0x0200
|
||||
#define USB_HID_VERSION 0x0110
|
||||
|
||||
#define USB_DEVICE_CONFIGURATION_COUNT 1
|
||||
#define USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE 1
|
||||
#define USB_DEVICE_MAX_POWER 50 // Expressed in 2mA units
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t USB_DeviceGetDeviceDescriptor(
|
||||
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor);
|
||||
|
||||
#endif
|
||||
27
right/src/usb_descriptor_generic_hid_report.c
Normal file
27
right/src/usb_descriptor_generic_hid_report.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_interface_generic_hid.h"
|
||||
#include "usb_descriptor_generic_hid_report.h"
|
||||
|
||||
uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH] = {
|
||||
HID_RI_USAGE_PAGE(8, USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_PAGE_INDEX),
|
||||
HID_RI_USAGE(8, USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_COLLECTION),
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_APPLICATION),
|
||||
|
||||
// Input flowing from device to host
|
||||
HID_RI_USAGE(8, USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_DATA_IN),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_REPORT_COUNT(8, USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Output flowing from host to device
|
||||
HID_RI_USAGE(8, USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_DATA_OUT),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_REPORT_COUNT(8, USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE),
|
||||
HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
|
||||
|
||||
HID_RI_END_COLLECTION(0)
|
||||
};
|
||||
17
right/src/usb_descriptor_generic_hid_report.h
Normal file
17
right/src/usb_descriptor_generic_hid_report.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __USB_DESCRIPTOR_GENERIC_HID_REPORT_H__
|
||||
#define __USB_DESCRIPTOR_GENERIC_HID_REPORT_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH 31
|
||||
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_PAGE_INDEX 0x80
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_COLLECTION 0x81
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_DATA_IN 0x82
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_VENDOR_USAGE_DATA_OUT 0x83
|
||||
|
||||
// Variables:
|
||||
|
||||
extern uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH];
|
||||
|
||||
#endif
|
||||
34
right/src/usb_descriptor_hid.c
Normal file
34
right/src/usb_descriptor_hid.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_hid.h"
|
||||
#include "usb_descriptor_mouse_report.h"
|
||||
#include "usb_descriptor_generic_hid_report.h"
|
||||
|
||||
usb_status_t USB_DeviceGetHidDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor)
|
||||
{
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
|
||||
usb_status_t USB_DeviceGetHidReportDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor)
|
||||
{
|
||||
if (USB_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||
hidReportDescriptor->buffer = UsbMouseReportDescriptor;
|
||||
hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH;
|
||||
} else if (USB_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||
hidReportDescriptor->buffer = UsbKeyboardReportDescriptor;
|
||||
hidReportDescriptor->length = USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH;
|
||||
} else if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||
hidReportDescriptor->buffer = UsbGenericHidReportDescriptor;
|
||||
hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH;
|
||||
} else {
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
return kStatus_USB_Success;
|
||||
}
|
||||
|
||||
usb_status_t USB_DeviceGetHidPhysicalDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor)
|
||||
{
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
21
right/src/usb_descriptor_hid.h
Normal file
21
right/src/usb_descriptor_hid.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __USB_DESCRIPTOR_HID_H__
|
||||
#define __USB_DESCRIPTOR_HID_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_interface_keyboard.h"
|
||||
#include "usb_interface_mouse.h"
|
||||
#include "usb_interface_generic_hid.h"
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t USB_DeviceGetHidDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor);
|
||||
|
||||
extern usb_status_t USB_DeviceGetHidReportDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor);
|
||||
|
||||
extern usb_status_t USB_DeviceGetHidPhysicalDescriptor(
|
||||
usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor);
|
||||
|
||||
#endif
|
||||
48
right/src/usb_descriptor_keyboard_report.c
Normal file
48
right/src/usb_descriptor_keyboard_report.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_keyboard_report.h"
|
||||
|
||||
uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH] = {
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_GENERIC_DESKTOP),
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_KEYBOARD),
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_APPLICATION),
|
||||
|
||||
// Modifiers
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_KEY_CODES),
|
||||
HID_RI_USAGE_MINIMUM(8, 0xE0),
|
||||
HID_RI_USAGE_MAXIMUM(8, 0xE7),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||
HID_RI_REPORT_SIZE(8, 0x01),
|
||||
HID_RI_REPORT_COUNT(8, 0x08),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Reserved for future use, always 0
|
||||
HID_RI_REPORT_COUNT(8, 0x01),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_INPUT(8, HID_IOF_CONSTANT),
|
||||
|
||||
// LED status
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_LEDS),
|
||||
HID_RI_USAGE_MINIMUM(8, 0x01),
|
||||
HID_RI_USAGE_MAXIMUM(8, 0x05),
|
||||
HID_RI_REPORT_COUNT(8, 0x05),
|
||||
HID_RI_REPORT_SIZE(8, 0x01),
|
||||
HID_RI_OUTPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NON_VOLATILE),
|
||||
|
||||
// LED status padding
|
||||
HID_RI_REPORT_COUNT(8, 0x01),
|
||||
HID_RI_REPORT_SIZE(8, 0x03),
|
||||
HID_RI_OUTPUT(8, HID_IOF_CONSTANT),
|
||||
|
||||
// Scancodes
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0xFF),
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_KEY_CODES),
|
||||
HID_RI_USAGE_MINIMUM(8, 0x00),
|
||||
HID_RI_USAGE_MAXIMUM(8, 0xFF),
|
||||
HID_RI_REPORT_COUNT(8, USB_KEYBOARD_MAX_KEYS),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||
|
||||
HID_RI_END_COLLECTION(0),
|
||||
};
|
||||
13
right/src/usb_descriptor_keyboard_report.h
Normal file
13
right/src/usb_descriptor_keyboard_report.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef __USB_DESCRIPTOR_KEYBOARD_REPORT_H__
|
||||
#define __USB_DESCRIPTOR_KEYBOARD_REPORT_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH 63
|
||||
#define USB_KEYBOARD_MAX_KEYS 6
|
||||
|
||||
// Variables:
|
||||
|
||||
extern uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH];
|
||||
|
||||
#endif
|
||||
85
right/src/usb_descriptor_mouse_report.c
Normal file
85
right/src/usb_descriptor_mouse_report.c
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_mouse_report.h"
|
||||
|
||||
uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = {
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_GENERIC_DESKTOP),
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_MOUSE),
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_APPLICATION),
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_POINTER),
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_PHYSICAL),
|
||||
|
||||
// Mouse buttons
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_BUTTONS),
|
||||
HID_RI_USAGE_MINIMUM(8, 0x01),
|
||||
HID_RI_USAGE_MAXIMUM(8, USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||
HID_RI_REPORT_COUNT(8, USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS),
|
||||
HID_RI_REPORT_SIZE(8, 0x01),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Mouse buttons padding
|
||||
HID_RI_REPORT_COUNT(8, 0x01),
|
||||
HID_RI_REPORT_SIZE(8, USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS_PADDING),
|
||||
HID_RI_INPUT(8, HID_IOF_CONSTANT),
|
||||
|
||||
// Mouse X and Y coordinates
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_GENERIC_DESKTOP),
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_X),
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_Y),
|
||||
HID_RI_LOGICAL_MINIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_VALUE),
|
||||
HID_RI_LOGICAL_MAXIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_VALUE),
|
||||
HID_RI_PHYSICAL_MINIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_PHYSICAL_VALUE),
|
||||
HID_RI_PHYSICAL_MAXIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_PHYSICAL_VALUE),
|
||||
HID_RI_REPORT_COUNT(8, 0x02),
|
||||
HID_RI_REPORT_SIZE(8, 16),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_LOGICAL),
|
||||
|
||||
// Vertical wheel resolution multiplier
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_RESOLUTION_MULTIPLIER),
|
||||
HID_RI_LOGICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
|
||||
HID_RI_PHYSICAL_MINIMUM(8, 0x01),
|
||||
HID_RI_PHYSICAL_MAXIMUM(8, 0x04),
|
||||
HID_RI_REPORT_SIZE(8, 0x02),
|
||||
HID_RI_REPORT_COUNT(8, 0x01),
|
||||
HID_RI_PUSH(0),
|
||||
HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Vertical wheel
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_WHEEL),
|
||||
HID_RI_LOGICAL_MINIMUM(8, -127),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 127),
|
||||
HID_RI_PHYSICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_PHYSICAL_MAXIMUM(8, 0x00),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||
|
||||
HID_RI_END_COLLECTION(0),
|
||||
HID_RI_COLLECTION(8, HID_RI_COLLECTION_LOGICAL),
|
||||
|
||||
// Horizontal wheel resolution multiplier
|
||||
HID_RI_USAGE(8, HID_RI_USAGE_GENERIC_DESKTOP_RESOLUTION_MULTIPLIER),
|
||||
HID_RI_POP(0),
|
||||
HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Padding
|
||||
HID_RI_PHYSICAL_MINIMUM(8, 0x00),
|
||||
HID_RI_PHYSICAL_MAXIMUM(8, 0x00),
|
||||
HID_RI_REPORT_SIZE(8, 0x04),
|
||||
HID_RI_FEATURE(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||
|
||||
// Horizontal wheel
|
||||
HID_RI_USAGE_PAGE(8, HID_RI_USAGE_PAGE_CONSUMER),
|
||||
HID_RI_USAGE(16, HID_RI_USAGE_CONSUMER_AC_PAN),
|
||||
HID_RI_LOGICAL_MINIMUM(8, -127),
|
||||
HID_RI_LOGICAL_MAXIMUM(8, 127),
|
||||
HID_RI_REPORT_SIZE(8, 0x08),
|
||||
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||
|
||||
HID_RI_END_COLLECTION(0),
|
||||
HID_RI_END_COLLECTION(0),
|
||||
HID_RI_END_COLLECTION(0)
|
||||
};
|
||||
22
right/src/usb_descriptor_mouse_report.h
Normal file
22
right/src/usb_descriptor_mouse_report.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef __USB_DESCRIPTOR_MOUSE_REPORT_H__
|
||||
#define __USB_DESCRIPTOR_MOUSE_REPORT_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH 121
|
||||
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_VALUE -4096
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_VALUE 4096
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_PHYSICAL_VALUE -4096
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_PHYSICAL_VALUE 4096
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS 8
|
||||
|
||||
#define USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS_PADDING ((USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS % 8) \
|
||||
? (8 - (USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS % 8)) \
|
||||
: 0)
|
||||
|
||||
// Variables:
|
||||
|
||||
extern uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH];
|
||||
|
||||
#endif
|
||||
101
right/src/usb_descriptor_strings.c
Normal file
101
right/src/usb_descriptor_strings.c
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_strings.h"
|
||||
|
||||
uint8_t UsbLanguageListStringDescriptor[USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH] = {
|
||||
sizeof(UsbLanguageListStringDescriptor),
|
||||
USB_DESCRIPTOR_TYPE_STRING,
|
||||
USB_SHORT_GET_LOW(USB_LANGUAGE_ID_UNITED_STATES),
|
||||
USB_SHORT_GET_HIGH(USB_LANGUAGE_ID_UNITED_STATES)
|
||||
};
|
||||
|
||||
uint8_t UsbManufacturerString[USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH] = {
|
||||
sizeof(UsbManufacturerString),
|
||||
USB_DESCRIPTOR_TYPE_STRING,
|
||||
'U', 0x00U,
|
||||
'l', 0x00U,
|
||||
't', 0x00U,
|
||||
'i', 0x00U,
|
||||
'm', 0x00U,
|
||||
'a', 0x00U,
|
||||
't', 0x00U,
|
||||
'e', 0x00U,
|
||||
' ', 0x00U,
|
||||
'G', 0x00U,
|
||||
'a', 0x00U,
|
||||
'd', 0x00U,
|
||||
'g', 0x00U,
|
||||
'e', 0x00U,
|
||||
't', 0x00U,
|
||||
' ', 0x00U,
|
||||
'L', 0x00U,
|
||||
'a', 0x00U,
|
||||
'b', 0x00U,
|
||||
'o', 0x00U,
|
||||
'r', 0x00U,
|
||||
'a', 0x00U,
|
||||
't', 0x00U,
|
||||
'o', 0x00U,
|
||||
'r', 0x00U,
|
||||
'i', 0x00U,
|
||||
'e', 0x00U,
|
||||
's', 0x00U,
|
||||
};
|
||||
|
||||
uint8_t UsbProductString[USB_PRODUCT_STRING_DESCRIPTOR_LENGTH] = {
|
||||
sizeof(UsbProductString),
|
||||
USB_DESCRIPTOR_TYPE_STRING,
|
||||
'U', 0x00U,
|
||||
'l', 0x00U,
|
||||
't', 0x00U,
|
||||
'i', 0x00U,
|
||||
'm', 0x00U,
|
||||
'a', 0x00U,
|
||||
't', 0x00U,
|
||||
'e', 0x00U,
|
||||
' ', 0x00U,
|
||||
'H', 0x00U,
|
||||
'a', 0x00U,
|
||||
'c', 0x00U,
|
||||
'k', 0x00U,
|
||||
'i', 0x00U,
|
||||
'n', 0x00U,
|
||||
'g', 0x00U,
|
||||
' ', 0x00U,
|
||||
'K', 0x00U,
|
||||
'e', 0x00U,
|
||||
'y', 0x00U,
|
||||
'b', 0x00U,
|
||||
'o', 0x00U,
|
||||
'a', 0x00U,
|
||||
'r', 0x00U,
|
||||
'd', 0x00U,
|
||||
};
|
||||
|
||||
uint32_t UsbStringDescriptorLengths[USB_STRING_DESCRIPTOR_COUNT] = {
|
||||
sizeof(UsbLanguageListStringDescriptor),
|
||||
sizeof(UsbManufacturerString),
|
||||
sizeof(UsbProductString),
|
||||
};
|
||||
|
||||
uint8_t *UsbStringDescriptors[USB_STRING_DESCRIPTOR_COUNT] = {
|
||||
UsbLanguageListStringDescriptor,
|
||||
UsbManufacturerString,
|
||||
UsbProductString,
|
||||
};
|
||||
|
||||
usb_status_t USB_DeviceGetStringDescriptor(
|
||||
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor)
|
||||
{
|
||||
if (stringDescriptor->stringIndex == 0) {
|
||||
stringDescriptor->buffer = UsbLanguageListStringDescriptor;
|
||||
stringDescriptor->length = sizeof(UsbLanguageListStringDescriptor);
|
||||
} else if (stringDescriptor->languageId == USB_LANGUAGE_ID_UNITED_STATES &&
|
||||
stringDescriptor->stringIndex < USB_STRING_DESCRIPTOR_COUNT)
|
||||
{
|
||||
stringDescriptor->buffer = UsbStringDescriptors[stringDescriptor->stringIndex];
|
||||
stringDescriptor->length = UsbStringDescriptorLengths[stringDescriptor->stringIndex];
|
||||
} else {
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
return kStatus_USB_Success;
|
||||
}
|
||||
21
right/src/usb_descriptor_strings.h
Normal file
21
right/src/usb_descriptor_strings.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __USB_DESCRIPTOR_STRINGS_H__
|
||||
#define __USB_DESCRIPTOR_STRINGS_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_STRING_DESCRIPTOR_COUNT 3
|
||||
|
||||
#define USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH 4
|
||||
#define USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH 58
|
||||
#define USB_PRODUCT_STRING_DESCRIPTOR_LENGTH 52
|
||||
|
||||
#define USB_STRING_DESCRIPTOR_ID_SUPPORTED_LANGUAGES 0
|
||||
#define USB_STRING_DESCRIPTOR_ID_MANUFACTURER 1
|
||||
#define USB_STRING_DESCRIPTOR_ID_PRODUCT 2
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t USB_DeviceGetStringDescriptor(
|
||||
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor);
|
||||
|
||||
#endif
|
||||
44
right/src/usb_device_config.h
Normal file
44
right/src/usb_device_config.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef __USB_DEVICE_CONFIG_H__
|
||||
#define __USB_DEVICE_CONFIG_H__
|
||||
|
||||
// KHCI instance count
|
||||
#define USB_DEVICE_CONFIG_KHCI 1
|
||||
|
||||
// Device instance count, the sum of KHCI and EHCI instance counts
|
||||
#define USB_DEVICE_CONFIG_NUM 1
|
||||
|
||||
// HID instance count
|
||||
#define USB_KEYBOARD_INTERFACE_COUNT 1
|
||||
#define USB_MOUSE_INTERFACE_COUNT 1
|
||||
#define USB_GENERIC_HID_INTERFACE_COUNT 1
|
||||
#define USB_DEVICE_CONFIG_HID \
|
||||
(USB_KEYBOARD_INTERFACE_COUNT + USB_MOUSE_INTERFACE_COUNT + USB_GENERIC_HID_INTERFACE_COUNT)
|
||||
|
||||
// Whether the device is self-powered: 1 supported, 0 not supported
|
||||
#define USB_DEVICE_CONFIG_SELF_POWER 1
|
||||
|
||||
// Whether device remote wakeup supported: 1 supported, 0 not supported
|
||||
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP 0
|
||||
|
||||
// How many endpoints are supported in the stack
|
||||
#define USB_DEVICE_CONFIG_ENDPOINTS 5
|
||||
|
||||
// The maximum buffer length for the KHCI DMA workaround
|
||||
#define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH 64
|
||||
|
||||
// Whether handle the USB KHCI bus error
|
||||
#define USB_DEVICE_CONFIG_KHCI_ERROR_HANDLING 0
|
||||
|
||||
// Whether the keep alive feature enabled
|
||||
#define USB_DEVICE_CONFIG_KEEP_ALIVE_MODE 0
|
||||
|
||||
// Whether the transfer buffer is cache-enabled or not
|
||||
#define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE 0
|
||||
|
||||
// Whether the low power mode is enabled or not
|
||||
#define USB_DEVICE_CONFIG_LOW_POWER_MODE 0
|
||||
|
||||
// Whether the device detached feature is enabled or not
|
||||
#define USB_DEVICE_CONFIG_DETACH_ENABLE 0
|
||||
|
||||
#endif
|
||||
126
right/src/usb_interface_generic_hid.c
Normal file
126
right/src/usb_interface_generic_hid.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "include/board/board.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_interface_generic_hid.h"
|
||||
#include "test_led.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
|
||||
{
|
||||
{
|
||||
USB_GENERIC_HID_ENDPOINT_IN_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE,
|
||||
},
|
||||
{
|
||||
USB_GENERIC_HID_ENDPOINT_OUT_INDEX | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE,
|
||||
}
|
||||
};
|
||||
|
||||
static usb_device_interface_struct_t UsbGenericHidInterface[] = {{
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
{USB_GENERIC_HID_ENDPOINT_COUNT, UsbGenericHidEndpoints},
|
||||
NULL,
|
||||
}};
|
||||
|
||||
static usb_device_interfaces_struct_t UsbGenericHidInterfaces[USB_GENERIC_HID_INTERFACE_COUNT] = {{
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_NONE,
|
||||
USB_HID_PROTOCOL_NONE,
|
||||
USB_GENERIC_HID_INTERFACE_INDEX,
|
||||
UsbGenericHidInterface,
|
||||
sizeof(UsbGenericHidInterface) / sizeof(usb_device_interfaces_struct_t),
|
||||
}};
|
||||
|
||||
static usb_device_interface_list_t UsbGenericHidInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
|
||||
USB_GENERIC_HID_INTERFACE_COUNT,
|
||||
UsbGenericHidInterfaces,
|
||||
}};
|
||||
|
||||
usb_device_class_struct_t UsbGenericHidClass = {
|
||||
UsbGenericHidInterfaceList,
|
||||
kUSB_DeviceClassTypeHid,
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
static uint8_t GenericHidBuffer[2][USB_GENERIC_HID_IN_BUFFER_LENGTH];
|
||||
static uint8_t GenericHidBufferIndex;
|
||||
|
||||
static usb_status_t UsbReceiveData()
|
||||
{
|
||||
return USB_DeviceHidRecv(UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_OUT_INDEX,
|
||||
&GenericHidBuffer[GenericHidBufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
uint8_t command, arg;
|
||||
|
||||
switch (event) {
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
break;
|
||||
case kUSB_DeviceHidEventRecvResponse:
|
||||
|
||||
command = GenericHidBuffer[GenericHidBufferIndex][0];
|
||||
arg = GenericHidBuffer[GenericHidBufferIndex][1];
|
||||
|
||||
switch (command) {
|
||||
case USB_COMMAND_JUMP_TO_BOOTLOADER:
|
||||
break;
|
||||
case USB_COMMAND_TEST_LED:
|
||||
switch (arg) {
|
||||
case 0:
|
||||
TEST_RED_ON();
|
||||
break;
|
||||
case 1:
|
||||
TEST_RED_OFF();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case USB_COMMAND_LED_DRIVER:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_IN_INDEX,
|
||||
&GenericHidBuffer[GenericHidBufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
GenericHidBufferIndex ^= 1U;
|
||||
return UsbReceiveData();
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetReport:
|
||||
case kUSB_DeviceHidEventSetReport:
|
||||
case kUSB_DeviceHidEventRequestReportBuffer:
|
||||
error = kStatus_USB_InvalidRequest;
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetIdle:
|
||||
case kUSB_DeviceHidEventGetProtocol:
|
||||
case kUSB_DeviceHidEventSetIdle:
|
||||
case kUSB_DeviceHidEventSetProtocol:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
usb_status_t UsbGenericHidSetConfiguration(class_handle_t handle, uint8_t configuration)
|
||||
{
|
||||
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
|
||||
return UsbReceiveData();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
|
||||
usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
|
||||
{
|
||||
if (USB_GENERIC_HID_INTERFACE_INDEX == interface) {
|
||||
return UsbReceiveData();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
39
right/src/usb_interface_generic_hid.h
Normal file
39
right/src/usb_interface_generic_hid.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __USB_INTERFACE_GENERIC_HID_H__
|
||||
#define __USB_INTERFACE_GENERIC_HID_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_device.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_GENERIC_HID_INTERFACE_INDEX 0
|
||||
|
||||
#define USB_GENERIC_HID_ENDPOINT_IN_INDEX 1
|
||||
#define USB_GENERIC_HID_ENDPOINT_OUT_INDEX 2
|
||||
#define USB_GENERIC_HID_ENDPOINT_COUNT 2
|
||||
|
||||
#define USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE 64
|
||||
#define USB_GENERIC_HID_INTERRUPT_IN_INTERVAL 4
|
||||
#define USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE 64
|
||||
#define USB_GENERIC_HID_INTERRUPT_OUT_INTERVAL 4
|
||||
|
||||
#define USB_GENERIC_HID_IN_BUFFER_LENGTH 64
|
||||
#define USB_GENERIC_HID_OUT_BUFFER_LENGTH 64
|
||||
|
||||
#define USB_COMMAND_JUMP_TO_BOOTLOADER 0
|
||||
#define USB_COMMAND_TEST_LED 1
|
||||
#define USB_COMMAND_LED_DRIVER 2
|
||||
|
||||
// Variables:
|
||||
|
||||
extern usb_device_class_struct_t UsbGenericHidClass;
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param);
|
||||
extern usb_status_t UsbGenericHidSetConfiguration(class_handle_t handle, uint8_t configuration);
|
||||
extern usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
|
||||
|
||||
#endif
|
||||
96
right/src/usb_interface_keyboard.c
Normal file
96
right/src/usb_interface_keyboard.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "include/board/board.h"
|
||||
#include "usb_api.h"
|
||||
#include "usb_composite_device.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
|
||||
USB_KEYBOARD_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
|
||||
}};
|
||||
|
||||
static usb_device_interface_struct_t UsbKeyboardInterface[] = {{
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
{USB_KEYBOARD_ENDPOINT_COUNT, UsbKeyboardEndpoints},
|
||||
NULL,
|
||||
}};
|
||||
|
||||
static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = {{
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_BOOT,
|
||||
USB_HID_PROTOCOL_KEYBOARD,
|
||||
USB_KEYBOARD_INTERFACE_INDEX,
|
||||
UsbKeyboardInterface,
|
||||
sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
|
||||
}};
|
||||
|
||||
static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
|
||||
USB_KEYBOARD_INTERFACE_COUNT,
|
||||
UsbKeyboardInterfaces,
|
||||
}};
|
||||
|
||||
usb_device_class_struct_t UsbKeyboardClass = {
|
||||
UsbKeyboardInterfaceList,
|
||||
kUSB_DeviceClassTypeHid,
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
static usb_keyboard_report_t UsbKeyboardReport;
|
||||
|
||||
static usb_status_t UsbKeyboardAction(void)
|
||||
{
|
||||
UsbKeyboardReport.modifiers = 0;
|
||||
UsbKeyboardReport.reserved = 0;
|
||||
for (uint8_t scancode_idx=0; scancode_idx<USB_KEYBOARD_MAX_KEYS; scancode_idx++) {
|
||||
UsbKeyboardReport.scancodes[scancode_idx] = 0;
|
||||
}
|
||||
|
||||
if (!GPIO_ReadPinInput(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PIN)) {
|
||||
UsbKeyboardReport.scancodes[0] = HID_KEYBOARD_SC_A;
|
||||
}
|
||||
|
||||
return USB_DeviceHidSend(UsbCompositeDevice.keyboardHandle, USB_KEYBOARD_ENDPOINT_INDEX,
|
||||
(uint8_t*)&UsbKeyboardReport, USB_KEYBOARD_REPORT_LENGTH);
|
||||
}
|
||||
|
||||
usb_status_t UsbKeyboardCallback(class_handle_t handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
|
||||
switch (event) {
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
if (UsbCompositeDevice.attach) {
|
||||
return UsbKeyboardAction();
|
||||
}
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetReport:
|
||||
case kUSB_DeviceHidEventSetReport:
|
||||
case kUSB_DeviceHidEventRequestReportBuffer:
|
||||
error = kStatus_USB_InvalidRequest;
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetIdle:
|
||||
case kUSB_DeviceHidEventGetProtocol:
|
||||
case kUSB_DeviceHidEventSetIdle:
|
||||
case kUSB_DeviceHidEventSetProtocol:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
usb_status_t UsbKeyboardSetConfiguration(class_handle_t handle, uint8_t configuration)
|
||||
{
|
||||
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
|
||||
return UsbKeyboardAction();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
|
||||
usb_status_t UsbKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
|
||||
{
|
||||
if (USB_KEYBOARD_INTERFACE_INDEX == interface) {
|
||||
return UsbKeyboardAction();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
39
right/src/usb_interface_keyboard.h
Normal file
39
right/src/usb_interface_keyboard.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __USB_INTERFACE_KEYBOARD_H__
|
||||
#define __USB_INTERFACE_KEYBOARD_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_keyboard_report.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_KEYBOARD_INTERFACE_INDEX 1
|
||||
|
||||
#define USB_KEYBOARD_ENDPOINT_INDEX 3
|
||||
#define USB_KEYBOARD_ENDPOINT_COUNT 1
|
||||
|
||||
#define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 8
|
||||
#define USB_KEYBOARD_INTERRUPT_IN_INTERVAL 4
|
||||
|
||||
#define USB_KEYBOARD_REPORT_LENGTH 8
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
uint8_t modifiers;
|
||||
uint8_t reserved; // Always must be 0
|
||||
uint8_t scancodes[USB_KEYBOARD_MAX_KEYS];
|
||||
} __attribute__ ((packed)) usb_keyboard_report_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern usb_device_class_struct_t UsbKeyboardClass;
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t UsbKeyboardCallback(class_handle_t handle, uint32_t event, void *param);
|
||||
extern usb_status_t UsbKeyboardSetConfiguration(class_handle_t handle, uint8_t configuration);
|
||||
extern usb_status_t UsbKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
|
||||
|
||||
#endif
|
||||
113
right/src/usb_interface_mouse.c
Normal file
113
right/src/usb_interface_mouse.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "include/board/board.h"
|
||||
#include "usb_composite_device.h"
|
||||
#include "usb_interface_mouse.h"
|
||||
#include "fsl_i2c.h"
|
||||
#include "i2c.h"
|
||||
#include "main.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{
|
||||
USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_MOUSE_INTERRUPT_IN_PACKET_SIZE,
|
||||
}};
|
||||
|
||||
static usb_device_interface_struct_t UsbMouseInterface[] = {{
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
{USB_MOUSE_ENDPOINT_COUNT, UsbMouseEndpoints},
|
||||
NULL,
|
||||
}};
|
||||
|
||||
static usb_device_interfaces_struct_t UsbMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = {{
|
||||
USB_CLASS_HID,
|
||||
USB_HID_SUBCLASS_BOOT,
|
||||
USB_HID_PROTOCOL_MOUSE,
|
||||
USB_MOUSE_INTERFACE_INDEX,
|
||||
UsbMouseInterface,
|
||||
sizeof(UsbMouseInterface) / sizeof(usb_device_interfaces_struct_t),
|
||||
}};
|
||||
|
||||
static usb_device_interface_list_t UsbMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
|
||||
USB_MOUSE_INTERFACE_COUNT,
|
||||
UsbMouseInterfaces,
|
||||
}};
|
||||
|
||||
usb_device_class_struct_t UsbMouseClass = {
|
||||
UsbMouseInterfaceList,
|
||||
kUSB_DeviceClassTypeHid,
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
static usb_mouse_report_t UsbMouseReport;
|
||||
|
||||
static uint8_t scrollCounter = 0;
|
||||
static volatile usb_status_t UsbMouseAction(void)
|
||||
{
|
||||
/* uint8_t i2cBuffer[I2C_DATA_LENGTH];
|
||||
i2c_master_transfer_t masterXfer;
|
||||
masterXfer.slaveAddress = LEFT_KEYBOARD_HALF_I2C_ADDRESS_7BIT;
|
||||
masterXfer.direction = kI2C_Read;
|
||||
masterXfer.subaddress = 0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
masterXfer.data = i2cBuffer;
|
||||
masterXfer.dataSize = I2C_DATA_LENGTH;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(EXAMPLE_I2C_MASTER_BASEADDR, &masterXfer);
|
||||
*/
|
||||
UsbMouseReport.buttons = 0;
|
||||
UsbMouseReport.x = 0;//i2cBuffer[1] - i2cBuffer[0];
|
||||
UsbMouseReport.y = 0;
|
||||
UsbMouseReport.wheelX = 0;
|
||||
UsbMouseReport.wheelY = 0;
|
||||
|
||||
if (!GPIO_ReadPinInput(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PIN)) {
|
||||
if (!(scrollCounter % 10)) {
|
||||
UsbMouseReport.wheelX = -1;
|
||||
}
|
||||
}
|
||||
scrollCounter++;
|
||||
return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_INDEX,
|
||||
(uint8_t*)&UsbMouseReport, USB_MOUSE_REPORT_LENGTH);
|
||||
}
|
||||
|
||||
usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
|
||||
switch (event) {
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
if (UsbCompositeDevice.attach) {
|
||||
return UsbMouseAction();
|
||||
}
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetReport:
|
||||
case kUSB_DeviceHidEventSetReport:
|
||||
case kUSB_DeviceHidEventRequestReportBuffer:
|
||||
error = kStatus_USB_InvalidRequest;
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetIdle:
|
||||
case kUSB_DeviceHidEventGetProtocol:
|
||||
case kUSB_DeviceHidEventSetIdle:
|
||||
case kUSB_DeviceHidEventSetProtocol:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
usb_status_t UsbMouseSetConfiguration(class_handle_t handle, uint8_t configuration)
|
||||
{
|
||||
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
|
||||
return UsbMouseAction();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
|
||||
usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
|
||||
{
|
||||
if (USB_MOUSE_INTERFACE_INDEX == interface) {
|
||||
return UsbMouseAction();
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
41
right/src/usb_interface_mouse.h
Normal file
41
right/src/usb_interface_mouse.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef __USB_INTERFACE_MOUSE_H__
|
||||
#define __USB_INTERFACE_MOUSE_H__
|
||||
|
||||
// Includes:
|
||||
|
||||
#include "usb_api.h"
|
||||
#include "usb_descriptor_device.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_MOUSE_INTERFACE_INDEX 2
|
||||
|
||||
#define USB_MOUSE_ENDPOINT_INDEX 4
|
||||
#define USB_MOUSE_ENDPOINT_COUNT 1
|
||||
|
||||
#define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE 8
|
||||
#define USB_MOUSE_INTERRUPT_IN_INTERVAL 4
|
||||
|
||||
#define USB_MOUSE_REPORT_LENGTH 7
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
uint8_t buttons;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int8_t wheelX;
|
||||
int8_t wheelY;
|
||||
} __attribute__ ((packed)) usb_mouse_report_t;
|
||||
|
||||
// Variables:
|
||||
|
||||
extern usb_device_class_struct_t UsbMouseClass;
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param);
|
||||
extern usb_status_t UsbMouseSetConfiguration(class_handle_t handle, uint8_t configuration);
|
||||
extern usb_status_t UsbMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user