├── sources ├── kinx.h ├── hid_mouse.h ├── composite.h ├── usb_device_descriptor.h ├── usb_device_config.h ├── hid_mouse.c ├── hid_keyboard.c └── hid_keyboard.h ├── Dockerfile ├── doc └── readme.txt ├── README.md ├── .project ├── CMSIS ├── cmsis_version.h ├── fsl_device_registers.h ├── arm_const_structs.h ├── arm_common_tables.h ├── system_MK66F18.h └── mpu_armv7.h ├── copyright ├── board ├── board.c ├── clock_config.h └── board.h ├── utilities ├── fsl_assert.c ├── fsl_str.h ├── fsl_io.h ├── fsl_log.h ├── fsl_debug_console_conf.h └── fsl_debug_console.h ├── osa └── usb_osa_bm.h ├── usb ├── device │ └── source │ │ ├── khci │ │ └── usb_khci.h │ │ ├── usb_device_ch9.h │ │ ├── ehci │ │ ├── usb_ehci.h │ │ └── usb_device_ehci.h │ │ └── usb_device_dci.h ├── phy │ ├── usb_phy.h │ └── usb_phy.c └── include │ └── usb.h ├── drivers ├── fsl_sim.c ├── fsl_common.c ├── fsl_sim.h └── fsl_gpio.c ├── source └── semihost_hardfault.c └── script.ld /sources/kinx.h: -------------------------------------------------------------------------------- 1 | void kinx_set_leds(const uint8_t led_report); 2 | 3 | void kinx_scan(void); 4 | 5 | void kinx_init(void); 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:sid 2 | 3 | RUN apt-get update && apt-get install -y \ 4 | make \ 5 | gcc-arm-none-eabi \ 6 | && rm -rf /var/lib/apt/lists/* 7 | 8 | VOLUME /usr/src/mk66f-fw 9 | -------------------------------------------------------------------------------- /doc/readme.txt: -------------------------------------------------------------------------------- 1 | For detail information, please refer to the example's readme.pdf. 2 | /boards//usb_examples/usb_device_composite_hid_mouse_hid_keyboard//readme.pdf. 3 | For lite version, the files path is: 4 | /boards//usb_examples/usb_device_composite_hid_mouse_hid_keyboard_lite//readme.pdf. 5 | Note 6 | The is bm or freertos. 7 | The is one specific board name, such as twrk65f180m,lpcxpresso54608. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Installation 2 | 3 | You can find all released firmware versions in the `archive` directory. 4 | 5 | To install a firmware file, first install the `teensy-loader-cli` Debian 6 | package, then run e.g.: 7 | ``` 8 | teensy_loader_cli -w -v --mcu=TEENSY36 fw-2018-03-24.hex 9 | ``` 10 | …and press the physical programming mode switch on the kinX board. 11 | 12 | ## Development 13 | 14 | ### Dependencies 15 | 16 | On Debian stretch, use: 17 | ``` 18 | apt install make gcc-arm-none-eabi 19 | ``` 20 | 21 | ### Compilation 22 | 23 | ``` 24 | mkdir Debug 25 | (cd Debug && make -f ../Makefile) 26 | ``` 27 | 28 | Follow the Installation section above for how to install the resulting .hex 29 | file. 30 | 31 | ### Compilation (with Docker) 32 | 33 | ``` 34 | mkdir Debug 35 | docker run -v $PWD:/usr/src/mk66f-fw kinxproject/mk66f-fw bash -c 'cd /usr/src/mk66f-fw/Debug && make -f ../Makefile' 36 | ``` 37 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | frdmk66f_usb_examples_dev_composite_hid_mouse_hid_keyboard_bm 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | com.nxp.mcuxpresso.core.datamodels.sdkNature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /CMSIS/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 0U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /copyright: -------------------------------------------------------------------------------- 1 | Files without a license header are licensed as Apache 2 (see LICENSE). 2 | 3 | Some NXP SDK components are licensed as Apache 2. 4 | 5 | Some NXP SDK components are licensed as Clear BSD: 6 | The Clear BSD License 7 | Copyright 2017 NXP 8 | All rights reserved. 9 | 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted (subject to the limitations in the disclaimer below) provided 13 | that the following conditions are met: 14 | 15 | o Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | o Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or 20 | other materials provided with the distribution. 21 | 22 | o Neither the name of Freescale Semiconductor, Inc. nor the names of its 23 | contributors may be used to endorse or promote products derived from this 24 | software without specific prior written permission. 25 | 26 | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 28 | ANY EPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 31 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EEMPLARY, OR CONSEQUENTIAL DAMAGES 32 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 34 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | -------------------------------------------------------------------------------- /board/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include 36 | #include "fsl_device_registers.h" 37 | #include "board.h" 38 | #include "fsl_debug_console.h" 39 | 40 | /******************************************************************************* 41 | * Variables 42 | ******************************************************************************/ 43 | 44 | /******************************************************************************* 45 | * Code 46 | ******************************************************************************/ 47 | 48 | /* Initialize debug console. */ 49 | void BOARD_InitDebugConsole(void) 50 | { 51 | uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ; 52 | DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq); 53 | } 54 | -------------------------------------------------------------------------------- /utilities/fsl_assert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015-2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted (subject to the limitations in the disclaimer below) provided 10 | * that the following conditions are met: 11 | * 12 | * o Redistributions of source code must retain the above copyright notice, this list 13 | * of conditions and the following disclaimer. 14 | * 15 | * o Redistributions in binary form must reproduce the above copyright notice, this 16 | * list of conditions and the following disclaimer in the documentation and/or 17 | * other materials provided with the distribution. 18 | * 19 | * o Neither the name of the copyright holder nor the names of its 20 | * contributors may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "fsl_common.h" 37 | #include "fsl_debug_console.h" 38 | 39 | #ifndef NDEBUG 40 | #if (defined(__CC_ARM)) || (defined(__ICCARM__)) 41 | void __aeabi_assert(const char *failedExpr, const char *file, int line) 42 | { 43 | PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line); 44 | for (;;) 45 | { 46 | __BKPT(0); 47 | } 48 | } 49 | #elif(defined(__GNUC__)) 50 | void __assert_func(const char *file, int line, const char *func, const char *failedExpr) 51 | { 52 | PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func); 53 | for (;;) 54 | { 55 | __BKPT(0); 56 | } 57 | } 58 | #endif /* (defined(__CC_ARM)) || (defined (__ICCARM__)) */ 59 | #endif /* NDEBUG */ 60 | -------------------------------------------------------------------------------- /CMSIS/fsl_device_registers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright 2014-2016 Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef __FSL_DEVICE_REGISTERS_H__ 37 | #define __FSL_DEVICE_REGISTERS_H__ 38 | 39 | /* 40 | * Include the cpu specific register header files. 41 | * 42 | * The CPU macro should be declared in the project or makefile. 43 | */ 44 | #if (defined(CPU_MK66FN2M0VLQ18) || defined(CPU_MK66FN2M0VMD18) || defined(CPU_MK66FX1M0VLQ18) || \ 45 | defined(CPU_MK66FX1M0VMD18)) 46 | 47 | #define K66F18_SERIES 48 | 49 | /* CMSIS-style register definitions */ 50 | #include "MK66F18.h" 51 | /* CPU specific feature definitions */ 52 | #include "MK66F18_features.h" 53 | 54 | #else 55 | #error "No valid CPU defined!" 56 | #endif 57 | 58 | #endif /* __FSL_DEVICE_REGISTERS_H__ */ 59 | 60 | /******************************************************************************* 61 | * EOF 62 | ******************************************************************************/ 63 | -------------------------------------------------------------------------------- /osa/usb_osa_bm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_OSA_BM_H__ 36 | #define __USB_OSA_BM_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #define USB_OSA_SR_ALLOC() uint32_t usbOsaCurrentSr; 43 | #define USB_OSA_ENTER_CRITICAL() USB_OsaEnterCritical(&usbOsaCurrentSr) 44 | #define USB_OSA_EXIT_CRITICAL() USB_OsaExitCritical(usbOsaCurrentSr) 45 | 46 | /******************************************************************************* 47 | * API 48 | ******************************************************************************/ 49 | 50 | #if defined(__cplusplus) 51 | extern "C" { 52 | #endif 53 | 54 | extern void USB_OsaEnterCritical(uint32_t *sr); 55 | extern void USB_OsaExitCritical(uint32_t sr); 56 | 57 | #if defined(__cplusplus) 58 | } 59 | #endif 60 | 61 | #endif /* __USB_OSA_BM_H__ */ 62 | -------------------------------------------------------------------------------- /sources/hid_mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_HID_MOUSE_H__ 36 | #define __USB_DEVICE_HID_MOUSE_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | typedef struct _usb_device_hid_mouse_struct 43 | { 44 | uint8_t *buffer; 45 | uint8_t idleRate; 46 | } usb_device_hid_mouse_struct_t; 47 | 48 | /******************************************************************************* 49 | * API 50 | ******************************************************************************/ 51 | 52 | extern usb_status_t USB_DeviceHidMouseInit(usb_device_composite_struct_t *deviceComposite); 53 | extern usb_status_t USB_DeviceHidMouseCallback(class_handle_t handle, uint32_t event, void *param); 54 | extern usb_status_t USB_DeviceHidMouseSetConfigure(class_handle_t handle, uint8_t configure); 55 | extern usb_status_t USB_DeviceHidMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting); 56 | 57 | #endif /* __USB_DEVICE_HID_MOUSE_H__ */ 58 | -------------------------------------------------------------------------------- /usb/device/source/khci/usb_khci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_KHCI_H__ 36 | #define __USB_KHCI_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #define USB_KHCI_BDT_DEVICE_OUT_TOKEN (0x01U) 43 | #define USB_KHCI_BDT_DEVICE_IN_TOKEN (0x09U) 44 | #define USB_KHCI_BDT_DEVICE_SETUP_TOKEN (0x0DU) 45 | 46 | #define USB_KHCI_BDT_OWN (0x80U) 47 | #define USB_KHCI_BDT_DATA01(x) ((((uint32_t)(x)) & 0x01U) << 0x06U) 48 | #define USB_KHCI_BDT_BC(x) ((((uint32_t)(x)) & 0x3FFU) << 0x10U) 49 | #define UBS_KHCI_BDT_KEEP (0x20U) 50 | #define UBS_KHCI_BDT_NINC (0x10U) 51 | #define USB_KHCI_BDT_DTS (0x08U) 52 | #define USB_KHCI_BDT_STALL (0x04U) 53 | 54 | typedef enum _usb_khci_interrupt_type 55 | { 56 | kUSB_KhciInterruptReset = 0x01U, 57 | kUSB_KhciInterruptError = 0x02U, 58 | kUSB_KhciInterruptSofToken = 0x04U, 59 | kUSB_KhciInterruptTokenDone = 0x08U, 60 | kUSB_KhciInterruptSleep = 0x10U, 61 | kUSB_KhciInterruptResume = 0x20U, 62 | kUSB_KhciInterruptAttach = 0x40U, 63 | kUSB_KhciInterruptStall = 0x80U, 64 | } usb_khci_interrupt_type_t; 65 | 66 | #endif /* __USB_KHCI_H__ */ 67 | -------------------------------------------------------------------------------- /drivers/fsl_sim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "fsl_sim.h" 36 | 37 | /******************************************************************************* 38 | * Codes 39 | ******************************************************************************/ 40 | #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) 41 | void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask) 42 | { 43 | SIM->SOPT1CFG |= (SIM_SOPT1CFG_URWE_MASK | SIM_SOPT1CFG_UVSWE_MASK | SIM_SOPT1CFG_USSWE_MASK); 44 | 45 | SIM->SOPT1 = (SIM->SOPT1 & ~kSIM_UsbVoltRegEnableInAllModes) | mask; 46 | } 47 | #endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */ 48 | 49 | void SIM_GetUniqueId(sim_uid_t *uid) 50 | { 51 | #if defined(SIM_UIDH) 52 | uid->H = SIM->UIDH; 53 | #endif 54 | #if (defined(FSL_FEATURE_SIM_HAS_UIDM) && FSL_FEATURE_SIM_HAS_UIDM) 55 | uid->M = SIM->UIDM; 56 | #else 57 | uid->MH = SIM->UIDMH; 58 | uid->ML = SIM->UIDML; 59 | #endif /* FSL_FEATURE_SIM_HAS_UIDM */ 60 | uid->L = SIM->UIDL; 61 | } 62 | 63 | #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) 64 | void SIM_GetRfAddr(sim_rf_addr_t *info) 65 | { 66 | info->rfAddrL = SIM->RFADDRL; 67 | info->rfAddrH = SIM->RFADDRH; 68 | } 69 | #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */ 70 | -------------------------------------------------------------------------------- /CMSIS/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_const_structs.h 4 | * Description: Constant structs that are initialized for user convenience. 5 | * For example, some can be given as arguments to the arm_cfft_f32() function. 6 | * 7 | * $Date: 27. January 2017 8 | * $Revision: V.1.5.1 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #ifndef _ARM_CONST_STRUCTS_H 31 | #define _ARM_CONST_STRUCTS_H 32 | 33 | #include "arm_math.h" 34 | #include "arm_common_tables.h" 35 | 36 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; 37 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; 38 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; 39 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; 40 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; 41 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; 42 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; 43 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; 44 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; 45 | 46 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; 47 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; 48 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; 49 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; 50 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; 51 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; 52 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; 53 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; 54 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; 55 | 56 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; 57 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; 58 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; 59 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; 60 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; 61 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; 62 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; 63 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; 64 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /sources/composite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_COMPOSITE_H__ 36 | #define __USB_DEVICE_COMPOSITE_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U) 43 | #define CONTROLLER_ID kUSB_ControllerEhci0 44 | #endif 45 | #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0U) 46 | #define CONTROLLER_ID kUSB_ControllerKhci0 47 | #endif 48 | #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U) 49 | #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0 50 | #endif 51 | #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U) 52 | #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0 53 | #endif 54 | 55 | #define USB_DEVICE_INTERRUPT_PRIORITY (3U) 56 | 57 | typedef struct _usb_device_composite_struct 58 | { 59 | usb_device_handle deviceHandle; 60 | class_handle_t hidMouseHandle; 61 | class_handle_t hidKeyboardHandle; 62 | uint8_t speed; 63 | uint8_t attach; 64 | uint8_t currentConfiguration; 65 | uint8_t currentInterfaceAlternateSetting[USB_COMPOSITE_INTERFACE_COUNT]; 66 | } usb_device_composite_struct_t; 67 | 68 | /******************************************************************************* 69 | * API 70 | ******************************************************************************/ 71 | 72 | #endif /* __USB_DEVICE_COMPOSITE_H__ */ 73 | -------------------------------------------------------------------------------- /utilities/fsl_str.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright 2017 NXP 4 | * All rights reserved. 5 | * 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _FSL_STR_H 37 | #define _FSL_STR_H 38 | 39 | #include "fsl_common.h" 40 | 41 | /*! 42 | * @addtogroup debugconsole 43 | * @{ 44 | */ 45 | 46 | /******************************************************************************* 47 | * Prototypes 48 | ******************************************************************************/ 49 | #if defined(__cplusplus) 50 | extern "C" { 51 | #endif /* __cplusplus */ 52 | 53 | /*! 54 | * @brief A function pointer which is used when format printf log. 55 | */ 56 | typedef void (*printfCb)(char *buf, int32_t *indicator, char val, int len); 57 | 58 | /*! 59 | * @brief This function outputs its parameters according to a formatted string. 60 | * 61 | * @note I/O is performed by calling given function pointer using following 62 | * (*func_ptr)(c); 63 | * 64 | * @param[in] fmt_ptr Format string for printf. 65 | * @param[in] args_ptr Arguments to printf. 66 | * @param[in] buf pointer to the buffer 67 | * @param cb print callbck function pointer 68 | * 69 | * @return Number of characters to be print 70 | */ 71 | int StrFormatPrintf(const char *fmt, va_list ap, char *buf, printfCb cb); 72 | 73 | /*! 74 | * @brief Converts an input line of ASCII characters based upon a provided 75 | * string format. 76 | * 77 | * @param[in] line_ptr The input line of ASCII data. 78 | * @param[in] format Format first points to the format string. 79 | * @param[in] args_ptr The list of parameters. 80 | * 81 | * @return Number of input items converted and assigned. 82 | * @retval IO_EOF When line_ptr is empty string "". 83 | */ 84 | int StrFormatScanf(const char *line_ptr, char *format, va_list args_ptr); 85 | 86 | #if defined(__cplusplus) 87 | } 88 | #endif /* __cplusplus */ 89 | 90 | /*! @} */ 91 | 92 | #endif /* _FSL_STR_H */ 93 | -------------------------------------------------------------------------------- /usb/device/source/usb_device_ch9.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_CH9_H__ 36 | #define __USB_DEVICE_CH9_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | /*! 42 | * @addtogroup usb_device_ch9 43 | * @{ 44 | */ 45 | /*! @brief Defines USB device status size when the host request to get device status */ 46 | #define USB_DEVICE_STATUS_SIZE (0x02U) 47 | 48 | /*! @brief Defines USB device interface status size when the host request to get interface status */ 49 | #define USB_INTERFACE_STATUS_SIZE (0x02U) 50 | 51 | /*! @brief Defines USB device endpoint status size when the host request to get endpoint status */ 52 | #define USB_ENDPOINT_STATUS_SIZE (0x02U) 53 | 54 | /*! @brief Defines USB device configuration size when the host request to get current configuration */ 55 | #define USB_CONFIGURE_SIZE (0X01U) 56 | 57 | /*! @brief Defines USB device interface alternate setting size when the host request to get interface alternate setting 58 | */ 59 | #define USB_INTERFACE_SIZE (0X01U) 60 | 61 | /*! @brief Defines USB device status mask */ 62 | #define USB_GET_STATUS_DEVICE_MASK (0x03U) 63 | 64 | /*! @brief Defines USB device interface status mask */ 65 | #define USB_GET_STATUS_INTERFACE_MASK (0x03U) 66 | 67 | /*! @brief Defines USB device endpoint status mask */ 68 | #define USB_GET_STATUS_ENDPOINT_MASK (0x03U) 69 | 70 | /*! @brief Control read and write sequence */ 71 | typedef enum _usb_device_control_read_write_sequence 72 | { 73 | kUSB_DeviceControlPipeSetupStage = 0U, /*!< Setup stage */ 74 | kUSB_DeviceControlPipeDataStage, /*!< Data stage */ 75 | kUSB_DeviceControlPipeStatusStage, /*!< status stage */ 76 | } usb_device_control_read_write_sequence_t; 77 | 78 | #if defined(__cplusplus) 79 | extern "C" { 80 | #endif 81 | 82 | /******************************************************************************* 83 | * API 84 | ******************************************************************************/ 85 | 86 | /*! 87 | * @brief Initializes the control pipes. 88 | * 89 | * The function is used to initialize the control pipes. This function should be called when event 90 | * kUSB_DeviceEventBusReset is received. 91 | * 92 | * @param[in] handle The device handle. 93 | * @param[in] param The event parameter. 94 | * 95 | * @return A USB error code or kStatus_USB_Success. 96 | */ 97 | extern usb_status_t USB_DeviceControlPipeInit(usb_device_handle handle, void *param); 98 | 99 | #if defined(__cplusplus) 100 | } 101 | #endif 102 | 103 | /*! @}*/ 104 | 105 | #endif /* __USB_DEVICE_CH9_H__ */ 106 | -------------------------------------------------------------------------------- /utilities/fsl_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright 2017 NXP 4 | * All rights reserved. 5 | * 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _FSL_IO_H 37 | #define _FSL_IO_H 38 | 39 | #include "fsl_common.h" 40 | 41 | /*! 42 | * @addtogroup debugconsole 43 | * @{ 44 | */ 45 | 46 | /******************************************************************************* 47 | * Definitions 48 | ******************************************************************************/ 49 | /*! @brief define a notify callback for IO 50 | * @param size , transfer data size. 51 | * @param rx, indicate a rx transfer is success. 52 | * @param tx, indicate a tx transfer is success. 53 | */ 54 | typedef void (*notify)(size_t *size, bool rx, bool tx); 55 | 56 | /*! @brief State structure storing io. */ 57 | typedef struct io_State 58 | { 59 | void *ioBase; /*!< Base of the IP register. */ 60 | uint8_t ioType; /*!< device type */ 61 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 62 | notify callBack; /*!< define the callback function for buffer */ 63 | #endif 64 | 65 | } io_state_t; 66 | 67 | /******************************************************************************* 68 | * Prototypes 69 | ******************************************************************************/ 70 | #if defined(__cplusplus) 71 | extern "C" { 72 | #endif /* __cplusplus */ 73 | 74 | /*! 75 | * @brief io init function. 76 | * 77 | * Call this function to init IO. 78 | * 79 | * @param io configuration pointer 80 | * @param baudRate baud rate 81 | * @param clkSrcFreq clock freq 82 | * @param ringbuffer used to receive character 83 | */ 84 | void IO_Init(io_state_t *io, uint32_t baudRate, uint32_t clkSrcFreq, uint8_t *ringBuffer); 85 | 86 | /*! 87 | * @brief Deinit IO. 88 | * 89 | * Call this function to Deinit IO. 90 | * 91 | * @return deinit status 92 | */ 93 | status_t IO_Deinit(void); 94 | 95 | /*! 96 | * @brief io transfer function. 97 | * 98 | * Call this function to transfer log. 99 | * Print log: 100 | * @code 101 | * IO_Transfer(ch, size, true); 102 | * @endcode 103 | * Scanf log: 104 | * @code 105 | * IO_Transfer(ch, size, false); 106 | * @endcode 107 | * 108 | * @param ch transfer buffer pointer 109 | * @param size transfer size 110 | * @param tx indicate the transfer is TX or RX 111 | */ 112 | status_t IO_Transfer(uint8_t *ch, size_t size, bool tx); 113 | 114 | /*! 115 | * @brief io wait idle. 116 | * 117 | * Call this function to wait the io idle 118 | * 119 | * @return Indicates whether wait idle was successful or not. 120 | */ 121 | status_t IO_WaitIdle(void); 122 | 123 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 124 | /*! 125 | * @brief io try to receive one character. 126 | * 127 | * Call this function try to receive character 128 | * @param ch the address of char to receive 129 | * @return Indicates try getchar was successful or not. 130 | */ 131 | status_t IO_TryReceiveCharacter(uint8_t *ch); 132 | #endif 133 | 134 | #if defined(__cplusplus) 135 | } 136 | #endif /* __cplusplus */ 137 | 138 | /*! @} */ 139 | 140 | #endif /* _FSL_IO_H */ 141 | -------------------------------------------------------------------------------- /drivers/fsl_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015-2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted (subject to the limitations in the disclaimer below) provided 10 | * that the following conditions are met: 11 | * 12 | * o Redistributions of source code must retain the above copyright notice, this list 13 | * of conditions and the following disclaimer. 14 | * 15 | * o Redistributions in binary form must reproduce the above copyright notice, this 16 | * list of conditions and the following disclaimer in the documentation and/or 17 | * other materials provided with the distribution. 18 | * 19 | * o Neither the name of the copyright holder nor the names of its 20 | * contributors may be used to endorse or promote products derived from this 21 | * software without specific prior written permission. 22 | * 23 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "fsl_common.h" 37 | 38 | #ifndef __GIC_PRIO_BITS 39 | #if defined(ENABLE_RAM_VECTOR_TABLE) 40 | uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler) 41 | { 42 | /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */ 43 | #if defined(__CC_ARM) 44 | extern uint32_t Image$$VECTOR_ROM$$Base[]; 45 | extern uint32_t Image$$VECTOR_RAM$$Base[]; 46 | extern uint32_t Image$$RW_m_data$$Base[]; 47 | 48 | #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base 49 | #define __VECTOR_RAM Image$$VECTOR_RAM$$Base 50 | #define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base)) 51 | #elif defined(__ICCARM__) 52 | extern uint32_t __RAM_VECTOR_TABLE_SIZE[]; 53 | extern uint32_t __VECTOR_TABLE[]; 54 | extern uint32_t __VECTOR_RAM[]; 55 | #elif defined(__GNUC__) 56 | extern uint32_t __VECTOR_TABLE[]; 57 | extern uint32_t __VECTOR_RAM[]; 58 | extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[]; 59 | uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES); 60 | #endif /* defined(__CC_ARM) */ 61 | uint32_t n; 62 | uint32_t ret; 63 | uint32_t irqMaskValue; 64 | 65 | irqMaskValue = DisableGlobalIRQ(); 66 | if (SCB->VTOR != (uint32_t)__VECTOR_RAM) 67 | { 68 | /* Copy the vector table from ROM to RAM */ 69 | for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++) 70 | { 71 | __VECTOR_RAM[n] = __VECTOR_TABLE[n]; 72 | } 73 | /* Point the VTOR to the position of vector table */ 74 | SCB->VTOR = (uint32_t)__VECTOR_RAM; 75 | } 76 | 77 | ret = __VECTOR_RAM[irq + 16]; 78 | /* make sure the __VECTOR_RAM is noncachable */ 79 | __VECTOR_RAM[irq + 16] = irqHandler; 80 | 81 | EnableGlobalIRQ(irqMaskValue); 82 | 83 | /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping 84 | exception return operation might vector to incorrect interrupt */ 85 | #if defined __CORTEX_M && (__CORTEX_M == 4U) 86 | __DSB(); 87 | #endif 88 | 89 | return ret; 90 | } 91 | #endif /* ENABLE_RAM_VECTOR_TABLE. */ 92 | #endif /* __GIC_PRIO_BITS. */ 93 | 94 | #ifndef QN908XC_SERIES 95 | #if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) 96 | 97 | void EnableDeepSleepIRQ(IRQn_Type interrupt) 98 | { 99 | uint32_t index = 0; 100 | uint32_t intNumber = (uint32_t)interrupt; 101 | while (intNumber >= 32u) 102 | { 103 | index++; 104 | intNumber -= 32u; 105 | } 106 | 107 | SYSCON->STARTERSET[index] = 1u << intNumber; 108 | EnableIRQ(interrupt); /* also enable interrupt at NVIC */ 109 | } 110 | 111 | void DisableDeepSleepIRQ(IRQn_Type interrupt) 112 | { 113 | uint32_t index = 0; 114 | uint32_t intNumber = (uint32_t)interrupt; 115 | while (intNumber >= 32u) 116 | { 117 | index++; 118 | intNumber -= 32u; 119 | } 120 | 121 | DisableIRQ(interrupt); /* also disable interrupt at NVIC */ 122 | SYSCON->STARTERCLR[index] = 1u << intNumber; 123 | } 124 | #endif /* FSL_FEATURE_SOC_SYSCON_COUNT */ 125 | 126 | #endif /* QN908XC_SERIES */ 127 | -------------------------------------------------------------------------------- /usb/phy/usb_phy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 - 2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | #ifndef __USB_PHY_H__ 35 | #define __USB_PHY_H__ 36 | 37 | /******************************************************************************* 38 | * Definitions 39 | ******************************************************************************/ 40 | typedef struct _usb_phy_config_struct 41 | { 42 | uint8_t D_CAL; /* Decode to trim the nominal 17.78mA current source */ 43 | uint8_t TXCAL45DP; /* Decode to trim the nominal 45-Ohm series termination resistance to the USB_DP output pin */ 44 | uint8_t TXCAL45DM; /* Decode to trim the nominal 45-Ohm series termination resistance to the USB_DM output pin */ 45 | } usb_phy_config_struct_t; 46 | 47 | #if defined(__cplusplus) 48 | extern "C" { 49 | #endif 50 | 51 | /******************************************************************************* 52 | * API 53 | ******************************************************************************/ 54 | /*! 55 | * @brief EHCI PHY get USB phy bass address. 56 | * 57 | * This function is used to get USB phy bass address. 58 | * 59 | * @param[in] controllerId EHCI controller ID; See the #usb_controller_index_t. 60 | * 61 | * @retval USB phy bass address. 62 | */ 63 | extern void *USB_EhciPhyGetBase(uint8_t controllerId); 64 | 65 | /*! 66 | * @brief EHCI PHY initialization. 67 | * 68 | * This function initializes the EHCI PHY IP. 69 | * 70 | * @param[in] controllerId EHCI controller ID; See the #usb_controller_index_t. 71 | * @param[in] freq The external input clock. 72 | * 73 | * @retval kStatus_USB_Success Cancel successfully. 74 | * @retval kStatus_USB_Error The freq value is incorrect. 75 | */ 76 | extern uint32_t USB_EhciPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig); 77 | 78 | /*! 79 | * @brief ehci phy initialization for suspend and resume. 80 | * 81 | * This function initialize ehci phy IP for suspend and resume. 82 | * 83 | * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t. 84 | * @param[in] freq the external input clock. 85 | * for example: if the external input clock is 16M, the parameter freq should be 16000000. 86 | * 87 | * @retval kStatus_USB_Success cancel successfully. 88 | * @retval kStatus_USB_Error the freq value is incorrect. 89 | */ 90 | extern uint32_t USB_EhciLowPowerPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig); 91 | 92 | /*! 93 | * @brief EHCI PHY deinitialization. 94 | * 95 | * This function deinitializes the EHCI PHY IP. 96 | * 97 | * @param[in] controllerId EHCI controller ID; See #usb_controller_index_t. 98 | */ 99 | extern void USB_EhciPhyDeinit(uint8_t controllerId); 100 | 101 | /*! 102 | * @brief EHCI PHY disconnect detection enable or disable. 103 | * 104 | * This function enable/disable the host EHCI disconnect detection. 105 | * 106 | * @param[in] controllerId EHCI controller ID; See #usb_controller_index_t. 107 | * @param[in] enable 108 | * 1U - enable; 109 | * 0U - disable; 110 | */ 111 | extern void USB_EhcihostPhyDisconnectDetectCmd(uint8_t controllerId, uint8_t enable); 112 | 113 | #if defined(__cplusplus) 114 | } 115 | #endif 116 | 117 | #endif /* __USB_PHY_H__ */ 118 | -------------------------------------------------------------------------------- /utilities/fsl_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright 2017 NXP 4 | * All rights reserved. 5 | * 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | 36 | #ifndef _FSL_LOG_H 37 | #define _FSL_LOG_H 38 | 39 | #include "fsl_common.h" 40 | 41 | /*! 42 | * @addtogroup debugconsole 43 | * @{ 44 | */ 45 | 46 | /******************************************************************************* 47 | * Definitions 48 | ******************************************************************************/ 49 | 50 | /************************************************************************************************* 51 | * Prototypes 52 | ************************************************************************************************/ 53 | #if defined(__cplusplus) 54 | extern "C" { 55 | #endif /* __cplusplus */ 56 | 57 | /*! 58 | * @brief Initializes 59 | * 60 | * Call this function to init the buffer 61 | * @param baseAddr, device base address 62 | * @param device, device type 63 | * @param baudRate, device communicate baudrate 64 | * @param clkSrcFreq, device source clock freq 65 | * 66 | * @return Indicates whether initialization was successful or not. 67 | * @retval kStatus_Success Execution successfully 68 | * @retval kStatus_Fail Execution failure 69 | */ 70 | status_t LOG_Init(uint32_t baseAddr, uint8_t device, uint32_t baudRate, uint32_t clkSrcFreq); 71 | 72 | /*! 73 | * @brief De-Initializes 74 | * 75 | * Call this function to deinit the buffer 76 | * 77 | * @return Indicates whether Deinit was successful or not. 78 | */ 79 | void LOG_Deinit(void); 80 | 81 | /*! 82 | * @brief log push interface 83 | * 84 | * Call this function to print log 85 | * @param fmt, buffer pointer 86 | * @param size, avaliable size 87 | * @return indicate the push size 88 | * @retval-1 indicate buffer is full or transfer fail. 89 | * @retval size return the push log size. 90 | */ 91 | int LOG_Push(uint8_t *buf, size_t size); 92 | 93 | /*! 94 | * @brief log read one line function 95 | * 96 | * Call this function to print log 97 | * @param fmt, buffer pointer 98 | * @param size, avaliable size 99 | * @reutrn the number of the recieved character 100 | */ 101 | int LOG_ReadLine(uint8_t *buf, size_t size); 102 | 103 | /*! 104 | * @brief log read one character function 105 | * 106 | * Call this function to GETCHAR 107 | * @param ch receive address 108 | * @reutrn the number of the recieved character 109 | */ 110 | int LOG_ReadCharacter(uint8_t *ch); 111 | 112 | /*! 113 | * @brief wait log and io idle 114 | * 115 | * Call this function to wait log buffer empty and io idle before enter low power mode. 116 | * @return Indicates whether wait idle was successful or not. 117 | */ 118 | status_t LOG_WaitIdle(void); 119 | 120 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 121 | /*! 122 | * @brief log try read one character 123 | * Call this function to check character avaliable or not, if not return fail, otherwise return it. 124 | * @param ch the address of char to receive 125 | * @return Indicates try getchar was successful or not. 126 | */ 127 | status_t LOG_TryReadCharacter(uint8_t *ch); 128 | #endif 129 | 130 | /*! 131 | * @brief log pop function 132 | * 133 | * Call this function to pop log from buffer. 134 | * @param buf buffer address to pop 135 | * @param size log size to pop 136 | * @return pop log size. 137 | */ 138 | int LOG_Pop(uint8_t *buf, size_t size); 139 | 140 | #if defined(__cplusplus) 141 | } 142 | #endif /* __cplusplus */ 143 | 144 | /*! @} */ 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /source/semihost_hardfault.c: -------------------------------------------------------------------------------- 1 | // **************************************************************************** 2 | // semihost_hardfault.c 3 | // - Provides hard fault handler to allow semihosting code not 4 | // to hang application when debugger not connected. 5 | // 6 | // **************************************************************************** 7 | // Copyright(C) NXP Semiconductors, 2017 8 | // All rights reserved. 9 | // 10 | // Software that is described herein is for illustrative purposes only 11 | // which provides customers with programming information regarding the 12 | // NXP Cortex-M based MCUs. This software is supplied "AS IS" without any 13 | // warranties of any kind, and NXP Semiconductors and its licensor disclaim any 14 | // and all warranties, express or implied, including all implied warranties of 15 | // merchantability, fitness for a particular purpose and non-infringement of 16 | // intellectual property rights. NXP Semiconductors assumes no responsibility 17 | // or liability for the use of the software, conveys no license or rights under 18 | // any patent, copyright, mask work right, or any other intellectual property 19 | // rights in or to any products. NXP Semiconductors reserves the right to make 20 | // changes in the software without notification. NXP Semiconductors also makes 21 | // no representation or warranty that such application will be suitable for the 22 | // specified use without further testing or modification. 23 | // 24 | // Permission to use, copy, modify, and distribute this software and its 25 | // documentation is hereby granted, under NXP Semiconductors' and its 26 | // licensor's relevant copyrights in the software, without fee, provided that it 27 | // is used in conjunction with NXP Semiconductors microcontrollers. This 28 | // copyright, permission, and disclaimer notice must appear in all copies of 29 | // this code. 30 | // **************************************************************************** 31 | // 32 | // ===== DESCRIPTION ===== 33 | // 34 | // One of the issues with applications that make use of semihosting operations 35 | // (such as printf calls) is that the code will not execute correctly when the 36 | // debugger is not connected. Generally this will show up with the application 37 | // appearing to just hang. This may include the application running from reset 38 | // or powering up the board (with the application already in FLASH), and also 39 | // as the application failing to continue to execute after a debug session is 40 | // terminated. 41 | // 42 | // The problem here is that the "bottom layer" of the semihosted variants of 43 | // the C library, semihosting is implemented by a "BKPT 0xAB" instruction. 44 | // When the debug tools are not connected, this instruction triggers a hard 45 | // fault - and the default hard fault handler within an application will 46 | // typically just contains an infinite loop - causing the application to 47 | // appear to have hang when no debugger is connected. 48 | // 49 | // The below code provides an example hard fault handler which instead looks 50 | // to see what the instruction that caused the hard fault was - and if it 51 | // was a "BKPT 0xAB", then it instead returns back to the user application. 52 | // 53 | // In most cases this will allow applications containing semihosting 54 | // operations to execute (to some degree) when the debugger is not connected. 55 | // 56 | // == NOTE == 57 | // 58 | // Correct execution of the application containing semihosted operations 59 | // which are vectored onto this hard fault handler cannot be guaranteed. This 60 | // is because the handler may not return data or return codes that the higher 61 | // level C library code or application code expects. This hard fault handler 62 | // is meant as a development aid, and it is not recommended to leave 63 | // semihosted code in a production build of your application! 64 | // 65 | // **************************************************************************** 66 | 67 | // Allow handler to be removed by setting a define (via command line) 68 | #if !defined (__SEMIHOST_HARDFAULT_DISABLE) 69 | 70 | __attribute__((naked)) 71 | void HardFault_Handler(void){ 72 | __asm( ".syntax unified\n" 73 | // Check which stack is in use 74 | "MOVS R0, #4 \n" 75 | "MOV R1, LR \n" 76 | "TST R0, R1 \n" 77 | "BEQ _MSP \n" 78 | "MRS R0, PSP \n" 79 | "B _process \n" 80 | "_MSP: \n" 81 | "MRS R0, MSP \n" 82 | // Load the instruction that triggered hard fault 83 | "_process: \n" 84 | "LDR R1,[R0,#24] \n" 85 | "LDRH R2,[r1] \n" 86 | // Semihosting instruction is "BKPT 0xAB" (0xBEAB) 87 | "LDR R3,=0xBEAB \n" 88 | "CMP R2,R3 \n" 89 | "BEQ _semihost_return \n" 90 | // Wasn't semihosting instruction so enter infinite loop 91 | "B . \n" 92 | // Was semihosting instruction, so adjust location to 93 | // return to by 1 instruction (2 bytes), then exit function 94 | "_semihost_return: \n" 95 | "ADDS R1,#2 \n" 96 | "STR R1,[R0,#24] \n" 97 | // Set a return value from semihosting operation. 98 | // 32 is slightly arbitrary, but appears to allow most 99 | // C Library IO functions sitting on top of semihosting to 100 | // continue to operate to some degree 101 | "MOVS R0,#32 \n" 102 | // Return from hard fault handler to application 103 | "BX LR \n" 104 | ".syntax divided\n") ; 105 | } 106 | 107 | #endif 108 | 109 | -------------------------------------------------------------------------------- /board/clock_config.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************************************************************** 2 | * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file 3 | * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. 4 | **********************************************************************************************************************/ 5 | 6 | #ifndef _CLOCK_CONFIG_H_ 7 | #define _CLOCK_CONFIG_H_ 8 | 9 | #include "fsl_common.h" 10 | 11 | /******************************************************************************* 12 | * Definitions 13 | ******************************************************************************/ 14 | #define BOARD_XTAL0_CLK_HZ 16000000U /*!< Board xtal0 frequency in Hz */ 15 | 16 | /******************************************************************************* 17 | ************************ BOARD_InitBootClocks function ************************ 18 | ******************************************************************************/ 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif /* __cplusplus*/ 23 | 24 | /*! 25 | * @brief This function executes default configuration of clocks. 26 | * 27 | */ 28 | void BOARD_InitBootClocks(void); 29 | 30 | #if defined(__cplusplus) 31 | } 32 | #endif /* __cplusplus*/ 33 | 34 | /******************************************************************************* 35 | ********************* Configuration BOARD_BootClockHSRUN ********************** 36 | ******************************************************************************/ 37 | /******************************************************************************* 38 | * Definitions for BOARD_BootClockHSRUN configuration 39 | ******************************************************************************/ 40 | #define BOARD_BOOTCLOCKHSRUN_CORE_CLOCK 180000000U /*!< Core clock frequency: 180000000Hz */ 41 | 42 | /*! @brief MCG set for BOARD_BootClockHSRUN configuration. 43 | */ 44 | extern const mcg_config_t mcgConfig_BOARD_BootClockHSRUN; 45 | /*! @brief SIM module set for BOARD_BootClockHSRUN configuration. 46 | */ 47 | extern const sim_clock_config_t simConfig_BOARD_BootClockHSRUN; 48 | /*! @brief OSC set for BOARD_BootClockHSRUN configuration. 49 | */ 50 | extern const osc_config_t oscConfig_BOARD_BootClockHSRUN; 51 | 52 | /******************************************************************************* 53 | * API for BOARD_BootClockHSRUN configuration 54 | ******************************************************************************/ 55 | #if defined(__cplusplus) 56 | extern "C" { 57 | #endif /* __cplusplus*/ 58 | 59 | /*! 60 | * @brief This function executes configuration of clocks. 61 | * 62 | */ 63 | void BOARD_BootClockHSRUN(void); 64 | 65 | #if defined(__cplusplus) 66 | } 67 | #endif /* __cplusplus*/ 68 | 69 | /******************************************************************************* 70 | ********************* Configuration BOARD_BootClockVLPR *********************** 71 | ******************************************************************************/ 72 | /******************************************************************************* 73 | * Definitions for BOARD_BootClockVLPR configuration 74 | ******************************************************************************/ 75 | #define BOARD_BOOTCLOCKVLPR_CORE_CLOCK 4000000U /*!< Core clock frequency: 4000000Hz */ 76 | 77 | /*! @brief MCG set for BOARD_BootClockVLPR configuration. 78 | */ 79 | extern const mcg_config_t mcgConfig_BOARD_BootClockVLPR; 80 | /*! @brief SIM module set for BOARD_BootClockVLPR configuration. 81 | */ 82 | extern const sim_clock_config_t simConfig_BOARD_BootClockVLPR; 83 | /*! @brief OSC set for BOARD_BootClockVLPR configuration. 84 | */ 85 | extern const osc_config_t oscConfig_BOARD_BootClockVLPR; 86 | 87 | /******************************************************************************* 88 | * API for BOARD_BootClockVLPR configuration 89 | ******************************************************************************/ 90 | #if defined(__cplusplus) 91 | extern "C" { 92 | #endif /* __cplusplus*/ 93 | 94 | /*! 95 | * @brief This function executes configuration of clocks. 96 | * 97 | */ 98 | void BOARD_BootClockVLPR(void); 99 | 100 | #if defined(__cplusplus) 101 | } 102 | #endif /* __cplusplus*/ 103 | 104 | /******************************************************************************* 105 | ********************** Configuration BOARD_BootClockRUN *********************** 106 | ******************************************************************************/ 107 | /******************************************************************************* 108 | * Definitions for BOARD_BootClockRUN configuration 109 | ******************************************************************************/ 110 | #define BOARD_BOOTCLOCKRUN_CORE_CLOCK 120000000U /*!< Core clock frequency: 120000000Hz */ 111 | 112 | /*! @brief MCG set for BOARD_BootClockRUN configuration. 113 | */ 114 | extern const mcg_config_t mcgConfig_BOARD_BootClockRUN; 115 | /*! @brief SIM module set for BOARD_BootClockRUN configuration. 116 | */ 117 | extern const sim_clock_config_t simConfig_BOARD_BootClockRUN; 118 | /*! @brief OSC set for BOARD_BootClockRUN configuration. 119 | */ 120 | extern const osc_config_t oscConfig_BOARD_BootClockRUN; 121 | 122 | /******************************************************************************* 123 | * API for BOARD_BootClockRUN configuration 124 | ******************************************************************************/ 125 | #if defined(__cplusplus) 126 | extern "C" { 127 | #endif /* __cplusplus*/ 128 | 129 | /*! 130 | * @brief This function executes configuration of clocks. 131 | * 132 | */ 133 | void BOARD_BootClockRUN(void); 134 | 135 | #if defined(__cplusplus) 136 | } 137 | #endif /* __cplusplus*/ 138 | 139 | #endif /* _CLOCK_CONFIG_H_ */ 140 | 141 | -------------------------------------------------------------------------------- /usb/device/source/ehci/usb_ehci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_EHCI_H__ 36 | #define __USB_EHCI_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | /* Device QH */ 43 | #define USB_DEVICE_EHCI_QH_POINTER_MASK (0xFFFFFFC0U) 44 | #define USB_DEVICE_EHCI_QH_MULT_MASK (0xC0000000U) 45 | #define USB_DEVICE_EHCI_QH_ZLT_MASK (0x20000000U) 46 | #define USB_DEVICE_EHCI_QH_MAX_PACKET_SIZE_MASK (0x07FF0000U) 47 | #define USB_DEVICE_EHCI_QH_MAX_PACKET_SIZE (0x00000800U) 48 | #define USB_DEVICE_EHCI_QH_IOS_MASK (0x00008000U) 49 | 50 | /* Device DTD */ 51 | #define USB_DEVICE_ECHI_DTD_POINTER_MASK (0xFFFFFFE0U) 52 | #define USB_DEVICE_ECHI_DTD_TERMINATE_MASK (0x00000001U) 53 | #define USB_DEVICE_ECHI_DTD_PAGE_MASK (0xFFFFF000U) 54 | #define USB_DEVICE_ECHI_DTD_PAGE_OFFSET_MASK (0x00000FFFU) 55 | #define USB_DEVICE_ECHI_DTD_PAGE_BLOCK (0x00001000U) 56 | #define USB_DEVICE_ECHI_DTD_TOTAL_BYTES_MASK (0x7FFF0000U) 57 | #define USB_DEVICE_ECHI_DTD_TOTAL_BYTES (0x00004000U) 58 | #define USB_DEVICE_ECHI_DTD_IOC_MASK (0x00008000U) 59 | #define USB_DEVICE_ECHI_DTD_MULTIO_MASK (0x00000C00U) 60 | #define USB_DEVICE_ECHI_DTD_STATUS_MASK (0x000000FFU) 61 | #define USB_DEVICE_EHCI_DTD_STATUS_ERROR_MASK (0x00000068U) 62 | #define USB_DEVICE_ECHI_DTD_STATUS_ACTIVE (0x00000080U) 63 | #define USB_DEVICE_ECHI_DTD_STATUS_HALTED (0x00000040U) 64 | #define USB_DEVICE_ECHI_DTD_STATUS_DATA_BUFFER_ERROR (0x00000020U) 65 | #define USB_DEVICE_ECHI_DTD_STATUS_TRANSACTION_ERROR (0x00000008U) 66 | 67 | typedef struct _usb_device_ehci_qh_struct 68 | { 69 | union 70 | { 71 | volatile uint32_t capabilttiesCharacteristics; 72 | struct 73 | { 74 | volatile uint32_t reserved1 : 15; 75 | volatile uint32_t ios : 1; 76 | volatile uint32_t maxPacketSize : 11; 77 | volatile uint32_t reserved2 : 2; 78 | volatile uint32_t zlt : 1; 79 | volatile uint32_t mult : 2; 80 | } capabilttiesCharacteristicsBitmap; 81 | } capabilttiesCharacteristicsUnion; 82 | volatile uint32_t currentDtdPointer; 83 | volatile uint32_t nextDtdPointer; 84 | union 85 | { 86 | volatile uint32_t dtdToken; 87 | struct 88 | { 89 | volatile uint32_t status : 8; 90 | volatile uint32_t reserved1 : 2; 91 | volatile uint32_t multiplierOverride : 2; 92 | volatile uint32_t reserved2 : 3; 93 | volatile uint32_t ioc : 1; 94 | volatile uint32_t totalBytes : 15; 95 | volatile uint32_t reserved3 : 1; 96 | } dtdTokenBitmap; 97 | } dtdTokenUnion; 98 | volatile uint32_t bufferPointerPage[5]; 99 | volatile uint32_t reserved1; 100 | uint32_t setupBuffer[2]; 101 | uint32_t setupBufferBack[2]; 102 | union 103 | { 104 | uint32_t endpointStatus; 105 | struct 106 | { 107 | uint32_t isOpened : 1; 108 | uint32_t : 31; 109 | } endpointStatusBitmap; 110 | } endpointStatusUnion; 111 | uint32_t reserved2; 112 | } usb_device_ehci_qh_struct_t; 113 | 114 | typedef struct _usb_device_ehci_dtd_struct 115 | { 116 | volatile uint32_t nextDtdPointer; 117 | union 118 | { 119 | volatile uint32_t dtdToken; 120 | struct 121 | { 122 | volatile uint32_t status : 8; 123 | volatile uint32_t reserved1 : 2; 124 | volatile uint32_t multiplierOverride : 2; 125 | volatile uint32_t reserved2 : 3; 126 | volatile uint32_t ioc : 1; 127 | volatile uint32_t totalBytes : 15; 128 | volatile uint32_t reserved3 : 1; 129 | } dtdTokenBitmap; 130 | } dtdTokenUnion; 131 | volatile uint32_t bufferPointerPage[5]; 132 | union 133 | { 134 | volatile uint32_t reserved; 135 | struct 136 | { 137 | uint32_t originalBufferOffest : 12; 138 | uint32_t originalBufferLength : 19; 139 | uint32_t dtdInvalid : 1; 140 | } originalBufferInfo; 141 | } reservedUnion; 142 | } usb_device_ehci_dtd_struct_t; 143 | 144 | #endif /* __USB_EHCI_H__ */ 145 | -------------------------------------------------------------------------------- /CMSIS/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_common_tables.h 4 | * Description: Extern declaration for common tables 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #ifndef _ARM_COMMON_TABLES_H 30 | #define _ARM_COMMON_TABLES_H 31 | 32 | #include "arm_math.h" 33 | 34 | extern const uint16_t armBitRevTable[1024]; 35 | extern const q15_t armRecipTableQ15[64]; 36 | extern const q31_t armRecipTableQ31[64]; 37 | extern const float32_t twiddleCoef_16[32]; 38 | extern const float32_t twiddleCoef_32[64]; 39 | extern const float32_t twiddleCoef_64[128]; 40 | extern const float32_t twiddleCoef_128[256]; 41 | extern const float32_t twiddleCoef_256[512]; 42 | extern const float32_t twiddleCoef_512[1024]; 43 | extern const float32_t twiddleCoef_1024[2048]; 44 | extern const float32_t twiddleCoef_2048[4096]; 45 | extern const float32_t twiddleCoef_4096[8192]; 46 | #define twiddleCoef twiddleCoef_4096 47 | extern const q31_t twiddleCoef_16_q31[24]; 48 | extern const q31_t twiddleCoef_32_q31[48]; 49 | extern const q31_t twiddleCoef_64_q31[96]; 50 | extern const q31_t twiddleCoef_128_q31[192]; 51 | extern const q31_t twiddleCoef_256_q31[384]; 52 | extern const q31_t twiddleCoef_512_q31[768]; 53 | extern const q31_t twiddleCoef_1024_q31[1536]; 54 | extern const q31_t twiddleCoef_2048_q31[3072]; 55 | extern const q31_t twiddleCoef_4096_q31[6144]; 56 | extern const q15_t twiddleCoef_16_q15[24]; 57 | extern const q15_t twiddleCoef_32_q15[48]; 58 | extern const q15_t twiddleCoef_64_q15[96]; 59 | extern const q15_t twiddleCoef_128_q15[192]; 60 | extern const q15_t twiddleCoef_256_q15[384]; 61 | extern const q15_t twiddleCoef_512_q15[768]; 62 | extern const q15_t twiddleCoef_1024_q15[1536]; 63 | extern const q15_t twiddleCoef_2048_q15[3072]; 64 | extern const q15_t twiddleCoef_4096_q15[6144]; 65 | extern const float32_t twiddleCoef_rfft_32[32]; 66 | extern const float32_t twiddleCoef_rfft_64[64]; 67 | extern const float32_t twiddleCoef_rfft_128[128]; 68 | extern const float32_t twiddleCoef_rfft_256[256]; 69 | extern const float32_t twiddleCoef_rfft_512[512]; 70 | extern const float32_t twiddleCoef_rfft_1024[1024]; 71 | extern const float32_t twiddleCoef_rfft_2048[2048]; 72 | extern const float32_t twiddleCoef_rfft_4096[4096]; 73 | 74 | /* floating-point bit reversal tables */ 75 | #define ARMBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) 76 | #define ARMBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) 77 | #define ARMBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) 78 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) 79 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) 80 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) 81 | #define ARMBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) 82 | #define ARMBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) 83 | #define ARMBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) 84 | 85 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE_16_TABLE_LENGTH]; 86 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE_32_TABLE_LENGTH]; 87 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE_64_TABLE_LENGTH]; 88 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 89 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 90 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 91 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE_1024_TABLE_LENGTH]; 92 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE_2048_TABLE_LENGTH]; 93 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE_4096_TABLE_LENGTH]; 94 | 95 | /* fixed-point bit reversal tables */ 96 | #define ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) 97 | #define ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) 98 | #define ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) 99 | #define ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) 100 | #define ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) 101 | #define ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) 102 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) 103 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 104 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 105 | 106 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; 107 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; 108 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; 109 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; 110 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; 111 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; 112 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 113 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 114 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 115 | 116 | /* Tables for Fast Math Sine and Cosine */ 117 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 118 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 119 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 120 | 121 | #endif /* ARM_COMMON_TABLES_H */ 122 | -------------------------------------------------------------------------------- /usb/include/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_H__ 36 | #define __USB_H__ 37 | 38 | #include 39 | #include 40 | #include "fsl_common.h" 41 | #include "usb_osa.h" 42 | #include "usb_misc.h" 43 | #include "usb_spec.h" 44 | 45 | /*! 46 | * @addtogroup usb_drv 47 | * @{ 48 | */ 49 | 50 | /******************************************************************************* 51 | * Definitions 52 | ******************************************************************************/ 53 | /*! @brief Defines USB stack major version */ 54 | #define USB_STACK_VERSION_MAJOR (1U) 55 | /*! @brief Defines USB stack minor version */ 56 | #define USB_STACK_VERSION_MINOR (6U) 57 | /*! @brief Defines USB stack bugfix version */ 58 | #define USB_STACK_VERSION_BUGFIX (3U) 59 | 60 | /*! @brief USB stack version definition */ 61 | #define USB_MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix)) 62 | 63 | /*! @brief USB error code */ 64 | typedef enum _usb_status 65 | { 66 | kStatus_USB_Success = 0x00U, /*!< Success */ 67 | kStatus_USB_Error, /*!< Failed */ 68 | 69 | kStatus_USB_Busy, /*!< Busy */ 70 | kStatus_USB_InvalidHandle, /*!< Invalid handle */ 71 | kStatus_USB_InvalidParameter, /*!< Invalid parameter */ 72 | kStatus_USB_InvalidRequest, /*!< Invalid request */ 73 | kStatus_USB_ControllerNotFound, /*!< Controller cannot be found */ 74 | kStatus_USB_InvalidControllerInterface, /*!< Invalid controller interface */ 75 | 76 | kStatus_USB_NotSupported, /*!< Configuration is not supported */ 77 | kStatus_USB_Retry, /*!< Enumeration get configuration retry */ 78 | kStatus_USB_TransferStall, /*!< Transfer stalled */ 79 | kStatus_USB_TransferFailed, /*!< Transfer failed */ 80 | kStatus_USB_AllocFail, /*!< Allocation failed */ 81 | kStatus_USB_LackSwapBuffer, /*!< Insufficient swap buffer for KHCI */ 82 | kStatus_USB_TransferCancel, /*!< The transfer cancelled */ 83 | kStatus_USB_BandwidthFail, /*!< Allocate bandwidth failed */ 84 | kStatus_USB_MSDStatusFail, /*!< For MSD, the CSW status means fail */ 85 | kStatus_USB_EHCIAttached, 86 | kStatus_USB_EHCIDetached, 87 | } usb_status_t; 88 | 89 | /*! @brief USB host handle type define */ 90 | typedef void *usb_host_handle; 91 | 92 | /*! @brief USB device handle type define. For device stack it is the whole device handle; for host stack it is the 93 | * attached device instance handle*/ 94 | typedef void *usb_device_handle; 95 | 96 | /*! @brief USB OTG handle type define */ 97 | typedef void *usb_otg_handle; 98 | 99 | /*! @brief USB controller ID */ 100 | typedef enum _usb_controller_index 101 | { 102 | kUSB_ControllerKhci0 = 0U, /*!< KHCI 0U */ 103 | kUSB_ControllerKhci1 = 1U, /*!< KHCI 1U, Currently, there are no platforms which have two KHCI IPs, this is reserved 104 | to be used in the future. */ 105 | kUSB_ControllerEhci0 = 2U, /*!< EHCI 0U */ 106 | kUSB_ControllerEhci1 = 3U, /*!< EHCI 1U, Currently, there are no platforms which have two EHCI IPs, this is reserved 107 | to be used in the future. */ 108 | 109 | kUSB_ControllerLpcIp3511Fs0 = 4U, /*!< LPC USB IP3511 FS controller 0 */ 110 | kUSB_ControllerLpcIp3511Fs1 = 111 | 5U, /*!< LPC USB IP3511 FS controller 1, there are no platforms which have two IP3511 IPs, this is reserved 112 | to be used in the future. */ 113 | 114 | kUSB_ControllerLpcIp3511Hs0 = 6U, /*!< LPC USB IP3511 HS controller 0 */ 115 | kUSB_ControllerLpcIp3511Hs1 = 116 | 7U, /*!< LPC USB IP3511 HS controller 1, there are no platforms which have two IP3511 IPs, this is reserved 117 | to be used in the future. */ 118 | 119 | kUSB_ControllerOhci0 = 8U, /*!< OHCI 0U */ 120 | kUSB_ControllerOhci1 = 9U, /*!< OHCI 1U, Currently, there are no platforms which have two OHCI IPs, this is reserved 121 | to be used in the future. */ 122 | 123 | kUSB_ControllerIp3516Hs0 = 10U, /*!< IP3516HS 0U */ 124 | kUSB_ControllerIp3516Hs1 = 125 | 11U, /*!< IP3516HS 1U, Currently, there are no platforms which have two IP3516HS IPs, this is reserved 126 | to be used in the future. */ 127 | } usb_controller_index_t; 128 | 129 | /** 130 | * @brief USB stack version fields 131 | */ 132 | typedef struct _usb_version 133 | { 134 | uint8_t major; /*!< Major */ 135 | uint8_t minor; /*!< Minor */ 136 | uint8_t bugfix; /*!< Bug fix */ 137 | } usb_version_t; 138 | 139 | /******************************************************************************* 140 | * API 141 | ******************************************************************************/ 142 | 143 | /*! @} */ 144 | 145 | #endif /* __USB_H__ */ 146 | -------------------------------------------------------------------------------- /sources/usb_device_descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 - 2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_DESCRIPTOR_H__ 36 | #define __USB_DEVICE_DESCRIPTOR_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200U) 43 | #define USB_DEVICE_DEMO_BCD_VERSION (0x0101U) 44 | 45 | #define USB_DEVICE_CLASS (0x00U) 46 | #define USB_DEVICE_SUBCLASS (0x00U) 47 | #define USB_DEVICE_PROTOCOL (0x00U) 48 | 49 | #define USB_DEVICE_MAX_POWER (0x32U) 50 | 51 | #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (sizeof(g_UsbDeviceConfigurationDescriptor)) 52 | #define USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT (sizeof(g_UsbDeviceHidMouseReportDescriptor)) 53 | #define USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT (sizeof(g_UsbDeviceHidKeyboardReportDescriptor)) 54 | #define USB_DESCRIPTOR_LENGTH_HID (9U) 55 | #define USB_DESCRIPTOR_LENGTH_STRING0 (sizeof(g_UsbDeviceString0)) 56 | #define USB_DESCRIPTOR_LENGTH_STRING1 (sizeof(g_UsbDeviceString1)) 57 | #define USB_DESCRIPTOR_LENGTH_STRING2 (sizeof(g_UsbDeviceString2)) 58 | #define USB_DESCRIPTOR_LENGTH_STRING3 (sizeof(g_UsbDeviceString3)) 59 | #define USB_DESCRIPTOR_LENGTH_STRING4 (sizeof(g_UsbDeviceString4)) 60 | 61 | #define USB_DEVICE_CONFIGURATION_COUNT (1U) 62 | #define USB_DEVICE_STRING_COUNT (5U) 63 | #define USB_DEVICE_LANGUAGE_COUNT (1U) 64 | 65 | #define USB_COMPOSITE_CONFIGURE_INDEX (1U) 66 | 67 | #define USB_HID_MOUSE_INTERFACE_COUNT (1U) 68 | #define USB_HID_MOUSE_INTERFACE_INDEX (0U) 69 | #define USB_HID_MOUSE_IN_BUFFER_LENGTH (8U) 70 | #define USB_HID_MOUSE_ENDPOINT_COUNT (1U) 71 | #define USB_HID_MOUSE_ENDPOINT_IN (1U) 72 | 73 | #define USB_HID_MOUSE_REPORT_LENGTH (0x04U) 74 | 75 | #define USB_HID_MOUSE_CLASS (0x03U) 76 | #define USB_HID_MOUSE_SUBCLASS (0x01U) 77 | #define USB_HID_MOUSE_PROTOCOL (0x02U) 78 | 79 | #define HS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U) 80 | #define FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U) 81 | #define HS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x01U) /* 125us */ 82 | #define FS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x01U) /* 1ms */ 83 | 84 | #define USB_HID_KEYBOARD_CLASS (0x03U) 85 | #define USB_HID_KEYBOARD_SUBCLASS (0x01U) 86 | #define USB_HID_KEYBOARD_PROTOCOL (0x01U) 87 | 88 | #define USB_HID_KEYBOARD_INTERFACE_COUNT (1U) 89 | #define USB_HID_KEYBOARD_INTERFACE_INDEX (1U) 90 | #define USB_HID_KEYBOARD_IN_BUFFER_LENGTH (8U) 91 | #define USB_HID_KEYBOARD_ENDPOINT_COUNT (1U) 92 | #define USB_HID_KEYBOARD_ENDPOINT_IN (2U) 93 | 94 | #define HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U) 95 | #define FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U) 96 | #define HS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL (0x01U) /* 125us */ 97 | #define FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL (0x01U) /* 1ms */ 98 | 99 | #define USB_HID_KEYBOARD_REPORT_LENGTH (0x08U) 100 | 101 | #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_KEYBOARD_INTERFACE_COUNT + USB_HID_MOUSE_INTERFACE_COUNT) 102 | /******************************************************************************* 103 | * API 104 | ******************************************************************************/ 105 | 106 | /* Configure the device according to the USB speed. */ 107 | extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed); 108 | #if (defined(USB_DEVICE_CONFIG_CV_TEST) && (USB_DEVICE_CONFIG_CV_TEST > 0U)) 109 | /* Get device qualifier descriptor request */ 110 | usb_status_t USB_DeviceGetDeviceQualifierDescriptor( 111 | usb_device_handle handle, usb_device_get_device_qualifier_descriptor_struct_t *deviceQualifierDescriptor); 112 | #endif 113 | /* Get device descriptor request */ 114 | usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle, 115 | usb_device_get_device_descriptor_struct_t *deviceDescriptor); 116 | 117 | /* Get device configuration descriptor request */ 118 | usb_status_t USB_DeviceGetConfigurationDescriptor( 119 | usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor); 120 | 121 | /* Get device string descriptor request */ 122 | usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle, 123 | usb_device_get_string_descriptor_struct_t *stringDescriptor); 124 | 125 | /* Get hid descriptor request */ 126 | usb_status_t USB_DeviceGetHidDescriptor(usb_device_handle handle, 127 | usb_device_get_hid_descriptor_struct_t *hidDescriptor); 128 | 129 | /* Get hid report descriptor request */ 130 | usb_status_t USB_DeviceGetHidReportDescriptor(usb_device_handle handle, 131 | usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor); 132 | 133 | /* Get hid physical descriptor request */ 134 | usb_status_t USB_DeviceGetHidPhysicalDescriptor(usb_device_handle handle, 135 | usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor); 136 | 137 | #endif /* __USB_DEVICE_DESCRIPTOR_H__ */ 138 | -------------------------------------------------------------------------------- /sources/usb_device_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 - 2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _USB_DEVICE_CONFIG_H_ 36 | #define _USB_DEVICE_CONFIG_H_ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | /*! 42 | * @addtogroup usb_device_configuration 43 | * @{ 44 | */ 45 | 46 | /*! 47 | * @name Hardware instance define 48 | * @{ 49 | */ 50 | 51 | /*! @brief KHCI instance count */ 52 | #define USB_DEVICE_CONFIG_KHCI (0U) 53 | 54 | /*! @brief EHCI instance count */ 55 | #define USB_DEVICE_CONFIG_EHCI (1U) 56 | 57 | /*! @brief LPC USB IP3511 FS instance count */ 58 | #define USB_DEVICE_CONFIG_LPCIP3511FS (0U) 59 | 60 | /*! @brief LPC USB IP3511 HS instance count */ 61 | #define USB_DEVICE_CONFIG_LPCIP3511HS (0U) 62 | 63 | /*! @brief Device instance count, the sum of KHCI and EHCI instance counts*/ 64 | #define USB_DEVICE_CONFIG_NUM \ 65 | (USB_DEVICE_CONFIG_KHCI + USB_DEVICE_CONFIG_EHCI + USB_DEVICE_CONFIG_LPCIP3511FS + USB_DEVICE_CONFIG_LPCIP3511HS) 66 | 67 | /* @} */ 68 | 69 | /*! 70 | * @name class instance define 71 | * @{ 72 | */ 73 | 74 | /*! @brief HID instance count */ 75 | #define USB_DEVICE_CONFIG_HID (2U) 76 | 77 | /*! @brief CDC ACM instance count */ 78 | #define USB_DEVICE_CONFIG_CDC_ACM (0U) 79 | 80 | /*! @brief MSC instance count */ 81 | #define USB_DEVICE_CONFIG_MSC (0U) 82 | 83 | /*! @brief Audio instance count */ 84 | #define USB_DEVICE_CONFIG_AUDIO (0U) 85 | 86 | /*! @brief PHDC instance count */ 87 | #define USB_DEVICE_CONFIG_PHDC (0U) 88 | 89 | /*! @brief Video instance count */ 90 | #define USB_DEVICE_CONFIG_VIDEO (0U) 91 | 92 | /*! @brief CCID instance count */ 93 | #define USB_DEVICE_CONFIG_CCID (0U) 94 | 95 | /*! @brief Printer instance count */ 96 | #define USB_DEVICE_CONFIG_PRINTER (0U) 97 | 98 | /*! @brief DFU instance count */ 99 | #define USB_DEVICE_CONFIG_DFU (0U) 100 | 101 | /* @} */ 102 | 103 | /*! @brief Whether device is self power. 1U supported, 0U not supported */ 104 | #define USB_DEVICE_CONFIG_SELF_POWER (1U) 105 | 106 | /*! @brief How many endpoints are supported in the stack. */ 107 | #define USB_DEVICE_CONFIG_ENDPOINTS (4U) 108 | 109 | /*! @brief Whether the device task is enabled. */ 110 | #define USB_DEVICE_CONFIG_USE_TASK (0U) 111 | 112 | /*! @brief How many the notification message are supported when the device task is enabled. */ 113 | #define USB_DEVICE_CONFIG_MAX_MESSAGES (8U) 114 | 115 | /*! @brief Whether test mode enabled. */ 116 | #define USB_DEVICE_CONFIG_USB20_TEST_MODE (0U) 117 | 118 | /*! @brief Whether device CV test is enabled. */ 119 | #define USB_DEVICE_CONFIG_CV_TEST (0U) 120 | 121 | /*! @brief Whether device compliance test is enabled. If the macro is enabled, 122 | the test mode and CV test macroes will be set.*/ 123 | #define USB_DEVICE_CONFIG_COMPLIANCE_TEST (0U) 124 | 125 | #if ((defined(USB_DEVICE_CONFIG_COMPLIANCE_TEST)) && (USB_DEVICE_CONFIG_COMPLIANCE_TEST > 0U)) 126 | 127 | /*! @brief Undefine the marco USB_DEVICE_CONFIG_USB20_TEST_MODE. */ 128 | #undef USB_DEVICE_CONFIG_USB20_TEST_MODE 129 | /*! @brief Undefine the marco USB_DEVICE_CONFIG_CV_TEST. */ 130 | #undef USB_DEVICE_CONFIG_CV_TEST 131 | 132 | /*! @brief enable the test mode. */ 133 | #define USB_DEVICE_CONFIG_USB20_TEST_MODE (1U) 134 | 135 | /*! @brief enable the CV test */ 136 | #define USB_DEVICE_CONFIG_CV_TEST (1U) 137 | 138 | #endif 139 | 140 | #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U)) 141 | 142 | /*! @brief The MAX buffer length for the KHCI DMA workaround.*/ 143 | #define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH (64U) 144 | #endif 145 | 146 | #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U)) 147 | /*! @brief How many the DTD are supported. */ 148 | #define USB_DEVICE_CONFIG_EHCI_MAX_DTD (16U) 149 | 150 | /*! @brief Whether the EHCI ID pin detect feature enabled. */ 151 | #define USB_DEVICE_CONFIG_EHCI_ID_PIN_DETECT (0U) 152 | #endif 153 | 154 | /*! @brief Whether the keep alive feature enabled. */ 155 | #define USB_DEVICE_CONFIG_KEEP_ALIVE_MODE (0U) 156 | 157 | /*! @brief Whether the transfer buffer is cache-enabled or not. */ 158 | #define USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE (0U) 159 | 160 | /*! @brief Whether the low power mode is enabled or not. */ 161 | #define USB_DEVICE_CONFIG_LOW_POWER_MODE (0U) 162 | 163 | #if ((defined(USB_DEVICE_CONFIG_LOW_POWER_MODE)) && (USB_DEVICE_CONFIG_LOW_POWER_MODE > 0U)) 164 | /*! @brief Whether device remote wakeup supported. 1U supported, 0U not supported */ 165 | #define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U) 166 | 167 | /*! @brief Whether LPM is supported. 1U supported, 0U not supported */ 168 | #define USB_DEVICE_CONFIG_LPM_L1 (0U) 169 | #else 170 | /*! @brief The device remote wakeup is unsupported. */ 171 | #define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U) 172 | #endif 173 | 174 | /*! @brief Whether the device detached feature is enabled or not. */ 175 | #define USB_DEVICE_CONFIG_DETACH_ENABLE (0U) 176 | 177 | /*! @brief Whether handle the USB bus error. */ 178 | #define USB_DEVICE_CONFIG_ERROR_HANDLING (0U) 179 | 180 | /* @} */ 181 | 182 | #endif /* _USB_DEVICE_CONFIG_H_ */ 183 | -------------------------------------------------------------------------------- /drivers/fsl_sim.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _FSL_SIM_H_ 36 | #define _FSL_SIM_H_ 37 | 38 | #include "fsl_common.h" 39 | 40 | /*! @addtogroup sim */ 41 | /*! @{*/ 42 | 43 | /******************************************************************************* 44 | * Definitions 45 | *******************************************************************************/ 46 | 47 | /*! @name Driver version */ 48 | /*@{*/ 49 | #define FSL_SIM_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*!< Driver version 2.1.0 */ 50 | /*@}*/ 51 | 52 | #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) 53 | /*!@brief USB voltage regulator enable setting. */ 54 | enum _sim_usb_volt_reg_enable_mode 55 | { 56 | kSIM_UsbVoltRegEnable = SIM_SOPT1_USBREGEN_MASK, /*!< Enable voltage regulator. */ 57 | kSIM_UsbVoltRegEnableInLowPower = SIM_SOPT1_USBVSTBY_MASK, /*!< Enable voltage regulator in VLPR/VLPW modes. */ 58 | kSIM_UsbVoltRegEnableInStop = SIM_SOPT1_USBSSTBY_MASK, /*!< Enable voltage regulator in STOP/VLPS/LLS/VLLS modes. */ 59 | kSIM_UsbVoltRegEnableInAllModes = SIM_SOPT1_USBREGEN_MASK | SIM_SOPT1_USBSSTBY_MASK | 60 | SIM_SOPT1_USBVSTBY_MASK /*!< Enable voltage regulator in all power modes. */ 61 | }; 62 | #endif /* (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) */ 63 | 64 | /*!@brief Unique ID. */ 65 | typedef struct _sim_uid 66 | { 67 | #if defined(SIM_UIDH) 68 | uint32_t H; /*!< UIDH. */ 69 | #endif 70 | 71 | #if (defined(FSL_FEATURE_SIM_HAS_UIDM) && FSL_FEATURE_SIM_HAS_UIDM) 72 | uint32_t M; /*!< SIM_UIDM. */ 73 | #else 74 | uint32_t MH; /*!< UIDMH. */ 75 | uint32_t ML; /*!< UIDML. */ 76 | #endif /* FSL_FEATURE_SIM_HAS_UIDM */ 77 | uint32_t L; /*!< UIDL. */ 78 | } sim_uid_t; 79 | 80 | #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) 81 | /*! @brief RF Mac Address.*/ 82 | typedef struct _sim_rf_addr 83 | { 84 | uint32_t rfAddrL; /*!< RFADDRL. */ 85 | uint32_t rfAddrH; /*!< RFADDRH. */ 86 | } sim_rf_addr_t; 87 | #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */ 88 | 89 | /*!@brief Flash enable mode. */ 90 | enum _sim_flash_mode 91 | { 92 | kSIM_FlashDisableInWait = SIM_FCFG1_FLASHDOZE_MASK, /*!< Disable flash in wait mode. */ 93 | kSIM_FlashDisable = SIM_FCFG1_FLASHDIS_MASK /*!< Disable flash in normal mode. */ 94 | }; 95 | 96 | /******************************************************************************* 97 | * API 98 | ******************************************************************************/ 99 | 100 | #if defined(__cplusplus) 101 | extern "C" { 102 | #endif /* __cplusplus*/ 103 | 104 | #if (defined(FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) && FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR) 105 | /*! 106 | * @brief Sets the USB voltage regulator setting. 107 | * 108 | * This function configures whether the USB voltage regulator is enabled in 109 | * normal RUN mode, STOP/VLPS/LLS/VLLS modes, and VLPR/VLPW modes. The configurations 110 | * are passed in as mask value of \ref _sim_usb_volt_reg_enable_mode. For example, to enable 111 | * USB voltage regulator in RUN/VLPR/VLPW modes and disable in STOP/VLPS/LLS/VLLS mode, 112 | * use: 113 | * 114 | * SIM_SetUsbVoltRegulatorEnableMode(kSIM_UsbVoltRegEnable | kSIM_UsbVoltRegEnableInLowPower); 115 | * 116 | * @param mask USB voltage regulator enable setting. 117 | */ 118 | void SIM_SetUsbVoltRegulatorEnableMode(uint32_t mask); 119 | #endif /* FSL_FEATURE_SIM_OPT_HAS_USB_VOLTAGE_REGULATOR */ 120 | 121 | /*! 122 | * @brief Gets the unique identification register value. 123 | * 124 | * @param uid Pointer to the structure to save the UID value. 125 | */ 126 | void SIM_GetUniqueId(sim_uid_t *uid); 127 | 128 | /*! 129 | * @brief Sets the flash enable mode. 130 | * 131 | * @param mode The mode to set; see \ref _sim_flash_mode for mode details. 132 | */ 133 | static inline void SIM_SetFlashMode(uint8_t mode) 134 | { 135 | SIM->FCFG1 = mode; 136 | } 137 | 138 | #if (defined(FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) && FSL_FEATURE_SIM_HAS_RF_MAC_ADDR) 139 | /*! 140 | * @brief Gets the RF address register value. 141 | * 142 | * @param info Pointer to the structure to save the RF address value. 143 | */ 144 | void SIM_GetRfAddr(sim_rf_addr_t *info); 145 | #endif /* FSL_FEATURE_SIM_HAS_RF_MAC_ADDR */ 146 | 147 | #if (defined(FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN) && FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN) 148 | 149 | /*! 150 | * @brief Enable the Systick clock or not. 151 | * 152 | * The Systick clock is enabled by default. 153 | * 154 | * @param enable The switcher for Systick clock. 155 | */ 156 | static inline void SIM_EnableSystickClock(bool enable) 157 | { 158 | if (enable) 159 | { 160 | SIM->MISC2 &= ~SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Clear to enable. */ 161 | } 162 | else 163 | { 164 | SIM->MISC2 |= SIM_MISC2_SYSTICK_CLK_EN_MASK; /* Set to disable. */ 165 | } 166 | } 167 | 168 | #endif /* FSL_FEATURE_SIM_MISC2_HAS_SYSTICK_CLK_EN */ 169 | 170 | #if defined(__cplusplus) 171 | } 172 | #endif /* __cplusplus*/ 173 | 174 | /*! @}*/ 175 | 176 | #endif /* _FSL_SIM_H_ */ 177 | -------------------------------------------------------------------------------- /sources/hid_mouse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "usb_device_config.h" 36 | #include "usb.h" 37 | #include "usb_device.h" 38 | 39 | #include "usb_device_class.h" 40 | #include "usb_device_hid.h" 41 | 42 | #include "usb_device_ch9.h" 43 | #include "usb_device_descriptor.h" 44 | 45 | #include "composite.h" 46 | 47 | #include "hid_mouse.h" 48 | 49 | /******************************************************************************* 50 | * Definitions 51 | ******************************************************************************/ 52 | 53 | /******************************************************************************* 54 | * Prototypes 55 | ******************************************************************************/ 56 | 57 | static usb_status_t USB_DeviceHidMouseAction(void); 58 | 59 | /******************************************************************************* 60 | * Variables 61 | ******************************************************************************/ 62 | 63 | USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_MouseBuffer[USB_HID_MOUSE_REPORT_LENGTH]; 64 | static usb_device_composite_struct_t *s_UsbDeviceComposite; 65 | static usb_device_hid_mouse_struct_t s_UsbDeviceHidMouse; 66 | 67 | /******************************************************************************* 68 | * Code 69 | ******************************************************************************/ 70 | 71 | /* Update mouse pointer location. Draw a rectangular rotation*/ 72 | static usb_status_t USB_DeviceHidMouseAction(void) 73 | { 74 | return kStatus_USB_Success; 75 | static int8_t x = 0U; 76 | static int8_t y = 0U; 77 | enum 78 | { 79 | RIGHT, 80 | DOWN, 81 | LEFT, 82 | UP 83 | }; 84 | static uint8_t dir = RIGHT; 85 | 86 | switch (dir) 87 | { 88 | case RIGHT: 89 | /* Move right. Increase X value. */ 90 | s_UsbDeviceHidMouse.buffer[1] = 1U; 91 | s_UsbDeviceHidMouse.buffer[2] = 0U; 92 | x++; 93 | if (x > 99U) 94 | { 95 | dir++; 96 | } 97 | break; 98 | case DOWN: 99 | /* Move down. Increase Y value. */ 100 | s_UsbDeviceHidMouse.buffer[1] = 0U; 101 | s_UsbDeviceHidMouse.buffer[2] = 1U; 102 | y++; 103 | if (y > 99U) 104 | { 105 | dir++; 106 | } 107 | break; 108 | case LEFT: 109 | /* Move left. Discrease X value. */ 110 | s_UsbDeviceHidMouse.buffer[1] = (uint8_t)(0xFFU); 111 | s_UsbDeviceHidMouse.buffer[2] = 0U; 112 | x--; 113 | if (x < 1U) 114 | { 115 | dir++; 116 | } 117 | break; 118 | case UP: 119 | /* Move up. Discrease Y value. */ 120 | s_UsbDeviceHidMouse.buffer[1] = 0U; 121 | s_UsbDeviceHidMouse.buffer[2] = (uint8_t)(0xFFU); 122 | y--; 123 | if (y < 1U) 124 | { 125 | dir = RIGHT; 126 | } 127 | break; 128 | default: 129 | break; 130 | } 131 | return USB_DeviceHidSend(s_UsbDeviceComposite->hidMouseHandle, USB_HID_MOUSE_ENDPOINT_IN, 132 | s_UsbDeviceHidMouse.buffer, USB_HID_MOUSE_REPORT_LENGTH); 133 | } 134 | 135 | /* The device HID class callback */ 136 | usb_status_t USB_DeviceHidMouseCallback(class_handle_t handle, uint32_t event, void *param) 137 | { 138 | usb_status_t error = kStatus_USB_Error; 139 | 140 | switch (event) 141 | { 142 | case kUSB_DeviceHidEventSendResponse: 143 | if (s_UsbDeviceComposite->attach) 144 | { 145 | return USB_DeviceHidMouseAction(); 146 | } 147 | break; 148 | case kUSB_DeviceHidEventGetReport: 149 | case kUSB_DeviceHidEventSetReport: 150 | case kUSB_DeviceHidEventRequestReportBuffer: 151 | error = kStatus_USB_InvalidRequest; 152 | break; 153 | case kUSB_DeviceHidEventGetIdle: 154 | case kUSB_DeviceHidEventGetProtocol: 155 | case kUSB_DeviceHidEventSetIdle: 156 | case kUSB_DeviceHidEventSetProtocol: 157 | break; 158 | default: 159 | break; 160 | } 161 | 162 | return error; 163 | } 164 | 165 | /* The device callback */ 166 | usb_status_t USB_DeviceHidMouseSetConfigure(class_handle_t handle, uint8_t configure) 167 | { 168 | if (USB_COMPOSITE_CONFIGURE_INDEX == configure) 169 | { 170 | return USB_DeviceHidMouseAction(); /* run the cursor movement code */ 171 | } 172 | return kStatus_USB_Error; 173 | } 174 | 175 | /* Set interface */ 176 | usb_status_t USB_DeviceHidMouseSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting) 177 | { 178 | if (USB_HID_KEYBOARD_INTERFACE_INDEX == interface) 179 | { 180 | return USB_DeviceHidMouseAction(); /* run the cursor movement code */ 181 | } 182 | return kStatus_USB_Error; 183 | } 184 | 185 | /* Initialize the HID mouse */ 186 | usb_status_t USB_DeviceHidMouseInit(usb_device_composite_struct_t *deviceComposite) 187 | { 188 | s_UsbDeviceComposite = deviceComposite; 189 | s_UsbDeviceHidMouse.buffer = s_MouseBuffer; 190 | return kStatus_USB_Success; 191 | } 192 | -------------------------------------------------------------------------------- /sources/hid_keyboard.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "usb_device_config.h" 36 | #include "usb.h" 37 | #include "usb_device.h" 38 | 39 | #include "usb_device_class.h" 40 | #include "usb_device_hid.h" 41 | 42 | #include "usb_device_ch9.h" 43 | #include "usb_device_descriptor.h" 44 | 45 | #include "composite.h" 46 | 47 | #include "hid_keyboard.h" 48 | 49 | #include "kinx.h" 50 | 51 | /******************************************************************************* 52 | * Definitions 53 | ******************************************************************************/ 54 | 55 | /******************************************************************************* 56 | * Prototypes 57 | ******************************************************************************/ 58 | 59 | static usb_status_t USB_DeviceHidKeyboardAction(void); 60 | 61 | /******************************************************************************* 62 | * Variables 63 | ******************************************************************************/ 64 | 65 | USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_KeyboardBuffer[USB_HID_KEYBOARD_REPORT_LENGTH]; 66 | static usb_device_composite_struct_t *s_UsbDeviceComposite; 67 | static usb_device_hid_keyboard_struct_t s_UsbDeviceHidKeyboard; 68 | 69 | /******************************************************************************* 70 | * Code 71 | ******************************************************************************/ 72 | 73 | static usb_status_t USB_DeviceHidKeyboardAction(void) 74 | { 75 | return kStatus_USB_Success; 76 | static int x = 0U; 77 | enum 78 | { 79 | DOWN, 80 | UP 81 | }; 82 | static uint8_t dir = DOWN; 83 | 84 | s_UsbDeviceHidKeyboard.buffer[2] = 0x00U; 85 | switch (dir) 86 | { 87 | case DOWN: 88 | x++; 89 | if (x > 200U) 90 | { 91 | dir++; 92 | s_UsbDeviceHidKeyboard.buffer[2] = KEY_PAGEUP; 93 | } 94 | break; 95 | case UP: 96 | x--; 97 | if (x < 1U) 98 | { 99 | dir = DOWN; 100 | s_UsbDeviceHidKeyboard.buffer[2] = KEY_PAGEDOWN; 101 | } 102 | break; 103 | default: 104 | break; 105 | } 106 | return USB_DeviceHidSend(s_UsbDeviceComposite->hidKeyboardHandle, USB_HID_KEYBOARD_ENDPOINT_IN, 107 | s_UsbDeviceHidKeyboard.buffer, USB_HID_KEYBOARD_REPORT_LENGTH); 108 | } 109 | 110 | static usb_device_hid_report_struct_t* g_output_report; 111 | static uint8_t s_UsbDeviceHidReportBuffer[HS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE]; 112 | 113 | usb_status_t USB_DeviceHidKeyboardCallback(class_handle_t handle, uint32_t event, void *param) 114 | { 115 | usb_status_t error = kStatus_USB_Error; 116 | 117 | switch (event) 118 | { 119 | case kUSB_DeviceHidEventSendResponse: 120 | if (s_UsbDeviceComposite->attach) 121 | { 122 | return USB_DeviceHidKeyboardAction(); 123 | } 124 | break; 125 | case kUSB_DeviceHidEventGetReport: 126 | error = kStatus_USB_InvalidRequest; 127 | break; 128 | case kUSB_DeviceHidEventRequestReportBuffer: 129 | if (s_UsbDeviceComposite->attach) 130 | { 131 | g_output_report = (usb_device_hid_report_struct_t *)param; 132 | if (g_output_report->reportLength <= sizeof(s_UsbDeviceHidReportBuffer)) 133 | { 134 | g_output_report->reportBuffer = &s_UsbDeviceHidReportBuffer[0]; 135 | error = kStatus_USB_Success; 136 | } 137 | else 138 | { 139 | error = kStatus_USB_InvalidRequest; 140 | } 141 | } 142 | break; 143 | case kUSB_DeviceHidEventSetReport: 144 | if (s_UsbDeviceComposite->attach) 145 | { 146 | g_output_report = (usb_device_hid_report_struct_t *)param; 147 | if (g_output_report->reportId == 0 && g_output_report->reportLength == 1) 148 | { 149 | kinx_set_leds(g_output_report->reportBuffer[0]); 150 | } 151 | error = kStatus_USB_Success; 152 | } 153 | break; 154 | case kUSB_DeviceHidEventGetIdle: 155 | case kUSB_DeviceHidEventGetProtocol: 156 | case kUSB_DeviceHidEventSetIdle: 157 | case kUSB_DeviceHidEventSetProtocol: 158 | break; 159 | default: 160 | break; 161 | } 162 | 163 | return error; 164 | } 165 | 166 | usb_status_t USB_DeviceHidKeyboardSetConfigure(class_handle_t handle, uint8_t configure) 167 | { 168 | if (USB_COMPOSITE_CONFIGURE_INDEX == configure) 169 | { 170 | return USB_DeviceHidKeyboardAction(); /* run the cursor movement code */ 171 | } 172 | return kStatus_USB_Error; 173 | } 174 | 175 | usb_status_t USB_DeviceHidKeyboardSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting) 176 | { 177 | if (USB_HID_KEYBOARD_INTERFACE_INDEX == interface) 178 | { 179 | return USB_DeviceHidKeyboardAction(); /* run the cursor movement code */ 180 | } 181 | return kStatus_USB_Error; 182 | } 183 | 184 | usb_status_t USB_DeviceHidKeyboardInit(usb_device_composite_struct_t *deviceComposite) 185 | { 186 | s_UsbDeviceComposite = deviceComposite; 187 | s_UsbDeviceHidKeyboard.buffer = s_KeyboardBuffer; 188 | return kStatus_USB_Success; 189 | } 190 | -------------------------------------------------------------------------------- /CMSIS/system_MK66F18.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** ################################################################### 3 | ** Processors: MK66FN2M0VLQ18 4 | ** MK66FN2M0VMD18 5 | ** MK66FX1M0VLQ18 6 | ** MK66FX1M0VMD18 7 | ** 8 | ** Compilers: Keil ARM C/C++ Compiler 9 | ** Freescale C/C++ for Embedded ARM 10 | ** GNU C Compiler 11 | ** IAR ANSI C/C++ Compiler for ARM 12 | ** MCUXpresso Compiler 13 | ** 14 | ** Reference manual: K66P144M180SF5RMV2, Rev. 1, Mar 2015 15 | ** Version: rev. 3.0, 2015-03-25 16 | ** Build: b170713 17 | ** 18 | ** Abstract: 19 | ** Provides a system configuration function and a global variable that 20 | ** contains the system frequency. It configures the device and initializes 21 | ** the oscillator (PLL) that is part of the microcontroller device. 22 | ** 23 | ** Copyright 2016 Freescale Semiconductor, Inc. 24 | ** Copyright 2016-2017 NXP 25 | ** Redistribution and use in source and binary forms, with or without modification, 26 | ** are permitted provided that the following conditions are met: 27 | ** 28 | ** 1. Redistributions of source code must retain the above copyright notice, this list 29 | ** of conditions and the following disclaimer. 30 | ** 31 | ** 2. Redistributions in binary form must reproduce the above copyright notice, this 32 | ** list of conditions and the following disclaimer in the documentation and/or 33 | ** other materials provided with the distribution. 34 | ** 35 | ** 3. Neither the name of the copyright holder nor the names of its 36 | ** contributors may be used to endorse or promote products derived from this 37 | ** software without specific prior written permission. 38 | ** 39 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 40 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 41 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 42 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 43 | ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 44 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 46 | ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 47 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 48 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | ** 50 | ** http: www.nxp.com 51 | ** mail: support@nxp.com 52 | ** 53 | ** Revisions: 54 | ** - rev. 1.0 (2013-09-02) 55 | ** Initial version. 56 | ** - rev. 2.0 (2014-02-17) 57 | ** Register accessor macros added to the memory map. 58 | ** Symbols for Processor Expert memory map compatibility added to the memory map. 59 | ** Startup file for gcc has been updated according to CMSIS 3.2. 60 | ** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled. 61 | ** Update according to reference manual rev. 2 62 | ** - rev. 2.1 (2014-04-16) 63 | ** Update of SystemInit() and SystemCoreClockUpdate() functions. 64 | ** - rev. 2.2 (2014-10-14) 65 | ** Interrupt INT_LPTimer renamed to INT_LPTMR0, interrupt INT_Watchdog renamed to INT_WDOG_EWM. 66 | ** - rev. 2.3 (2014-11-20) 67 | ** Update according to reverence manual K65P169M180SF5RMV2_NDA, Rev. 0 Draft A, October 2014. 68 | ** Update of SystemInit() to use 16MHz external crystal. 69 | ** - rev. 2.4 (2015-02-19) 70 | ** Renamed interrupt vector LLW to LLWU. 71 | ** - rev. 3.0 (2015-03-25) 72 | ** Registers updated according to the reference manual revision 1, March 2015 73 | ** 74 | ** ################################################################### 75 | */ 76 | 77 | /*! 78 | * @file MK66F18 79 | * @version 3.0 80 | * @date 2015-03-25 81 | * @brief Device specific configuration file for MK66F18 (header file) 82 | * 83 | * Provides a system configuration function and a global variable that contains 84 | * the system frequency. It configures the device and initializes the oscillator 85 | * (PLL) that is part of the microcontroller device. 86 | */ 87 | 88 | #ifndef _SYSTEM_MK66F18_H_ 89 | #define _SYSTEM_MK66F18_H_ /**< Symbol preventing repeated inclusion */ 90 | 91 | #ifdef __cplusplus 92 | extern "C" { 93 | #endif 94 | 95 | #include 96 | 97 | 98 | #ifndef DISABLE_WDOG 99 | #define DISABLE_WDOG 1 100 | #endif 101 | 102 | /* Define clock source values */ 103 | 104 | #define CPU_XTAL_CLK_HZ 16000000U /* Value of the external crystal or oscillator clock frequency of the system oscillator (OSC) in Hz */ 105 | #define CPU_XTAL32k_CLK_HZ 32768U /* Value of the external 32k crystal or oscillator clock frequency of the RTC in Hz */ 106 | #define CPU_INT_SLOW_CLK_HZ 32768U /* Value of the slow internal oscillator clock frequency in Hz */ 107 | #define CPU_INT_FAST_CLK_HZ 4000000U /* Value of the fast internal oscillator clock frequency in Hz */ 108 | #define CPU_INT_IRC_CLK_HZ 48000000U /* Value of the 48M internal oscillator clock frequency in Hz */ 109 | 110 | /* RTC oscillator setting */ 111 | /* RTC_CR: SC2P=0,SC4P=0,SC8P=0,SC16P=0,CLKO=1,OSCE=1,WPS=0,UM=0,SUP=0,WPE=0,SWR=0 */ 112 | #define SYSTEM_RTC_CR_VALUE 0x0300U /* RTC_CR */ 113 | 114 | /* Low power mode enable */ 115 | /* SMC_PMPROT: AHSRUN=1,AVLP=1,ALLS=1,AVLLS=1 */ 116 | #define SYSTEM_SMC_PMPROT_VALUE 0xAAU /* SMC_PMPROT */ 117 | 118 | #define DEFAULT_SYSTEM_CLOCK 20971520u 119 | 120 | 121 | /** 122 | * @brief System clock frequency (core clock) 123 | * 124 | * The system clock frequency supplied to the SysTick timer and the processor 125 | * core clock. This variable can be used by the user application to setup the 126 | * SysTick timer or configure other parameters. It may also be used by debugger to 127 | * query the frequency of the debug timer or configure the trace clock speed 128 | * SystemCoreClock is initialized with a correct predefined value. 129 | */ 130 | extern uint32_t SystemCoreClock; 131 | 132 | /** 133 | * @brief Setup the microcontroller system. 134 | * 135 | * Typically this function configures the oscillator (PLL) that is part of the 136 | * microcontroller device. For systems with variable clock speed it also updates 137 | * the variable SystemCoreClock. SystemInit is called from startup_device file. 138 | */ 139 | void SystemInit (void); 140 | 141 | /** 142 | * @brief Updates the SystemCoreClock variable. 143 | * 144 | * It must be called whenever the core clock is changed during program 145 | * execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates 146 | * the current core clock. 147 | */ 148 | void SystemCoreClockUpdate (void); 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | 154 | #endif /* _SYSTEM_MK66F18_H_ */ 155 | -------------------------------------------------------------------------------- /utilities/fsl_debug_console_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright 2017 NXP 4 | * All rights reserved. 5 | * 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | #ifndef _FSL_DEBUG_CONSOLE_CONF_H_ 35 | #define _FSL_DEBUG_CONSOLE_CONF_H_ 36 | 37 | /****************Debug console configuration********************/ 38 | 39 | /*! @brief If Non-blocking mode is needed, please define it at project setting, 40 | * otherwise blocking mode is the default transfer mode. 41 | * Warning: If you want to use non-blocking transfer,please make sure the corresponding 42 | * IO interrupt is enable, otherwise there is no output. 43 | * And non-blocking is combine with buffer, no matter bare-metal or rtos. 44 | */ 45 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 46 | /*! @brief define the transmit buffer length which is used to store the multi task log, buffer is enabled automatically 47 | * when 48 | * non-blocking transfer is using, 49 | * This value will affect the RAM's ultilization, should be set per paltform's capability and software requirement. 50 | * If it is configured too small, log maybe missed , because the log will not be 51 | * buffered if the buffer is full, and the print will return immediately with -1. 52 | * And this value should be multiple of 4 to meet memory alignment. 53 | * 54 | */ 55 | #ifndef DEBUG_CONSOLE_TRANSMIT_BUFFER_LEN 56 | #define DEBUG_CONSOLE_TRANSMIT_BUFFER_LEN (512U) 57 | #endif /* DEBUG_CONSOLE_TRANSMIT_BUFFER_LEN */ 58 | 59 | /*! @brief define the receive buffer length which is used to store the user input, buffer is enabled automatically when 60 | * non-blocking transfer is using, 61 | * This value will affect the RAM's ultilization, should be set per paltform's capability and software requirement. 62 | * If it is configured too small, log maybe missed, because buffer will be overwrited if buffer is too small. 63 | * And this value should be multiple of 4 to meet memory alignment. 64 | * 65 | */ 66 | #ifndef DEBUG_CONSOLE_RECEIVE_BUFFER_LEN 67 | #define DEBUG_CONSOLE_RECEIVE_BUFFER_LEN (512U) 68 | #endif /* DEBUG_CONSOLE_RECEIVE_BUFFER_LEN */ 69 | 70 | #else 71 | #define DEBUG_CONSOLE_TRANSFER_BLOCKING 72 | #endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */ 73 | 74 | /*!@ brief define the MAX log length debug console support , that is when you call printf("log", x);, the log 75 | * length can not bigger than this value. 76 | * This macro decide the local log buffer length, the buffer locate at stack, the stack maybe overflow if 77 | * the buffer is too big and current task stack size not big enough. 78 | */ 79 | #ifndef DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN 80 | #define DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN (128U) 81 | #endif /* DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN */ 82 | 83 | /*!@ brief define the buffer support buffer scanf log length, that is when you call scanf("log", &x);, the log 84 | * length can not bigger than this value. 85 | * As same as the DEBUG_CONSOLE_BUFFER_PRINTF_MAX_LOG_LEN. 86 | */ 87 | #ifndef DEBUG_CONSOLE_SCANF_MAX_LOG_LEN 88 | #define DEBUG_CONSOLE_SCANF_MAX_LOG_LEN (20U) 89 | #endif /* DEBUG_CONSOLE_SCANF_MAX_LOG_LEN */ 90 | 91 | /*! @brief Debug console synchronization 92 | * User should not change these macro for synchronization mode, but add the 93 | * corresponding synchronization mechanism per different software environment. 94 | * Such as, if another RTOS is used, 95 | * add: 96 | * #define DEBUG_CONSOLE_SYNCHRONIZATION_XXXX 3 97 | * in this configuration file and implement the synchronization in fsl.log.c. 98 | */ 99 | /*! @brief synchronization for baremetal software */ 100 | #define DEBUG_CONSOLE_SYNCHRONIZATION_BM 0 101 | /*! @brief synchronization for freertos software */ 102 | #define DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS 1 103 | 104 | /*! @brief RTOS synchronization mechanism disable 105 | * If not defined, default is enable, to avoid multitask log print mess. 106 | * If other RTOS is used, you can implement the RTOS's specific synchronization mechanism in fsl.log.c 107 | * If synchronization is disabled, log maybe messed on terminal. 108 | */ 109 | #ifndef DEBUG_CONSOLE_DISABLE_RTOS_SYNCHRONIZATION 110 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 111 | #ifdef FSL_RTOS_FREE_RTOS 112 | #define DEBUG_CONSOLE_SYNCHRONIZATION_MODE DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS 113 | #else 114 | #define DEBUG_CONSOLE_SYNCHRONIZATION_MODE DEBUG_CONSOLE_SYNCHRONIZATION_BM 115 | #endif /* FSL_RTOS_FREE_RTOS */ 116 | #endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */ 117 | #endif /* DEBUG_CONSOLE_DISABLE_RTOS_SYNCHRONIZATION */ 118 | 119 | /*! @brief echo function support 120 | * If you want to use the echo function,please define DEBUG_CONSOLE_ENABLE_ECHO 121 | * at your project setting. 122 | */ 123 | #ifndef DEBUG_CONSOLE_ENABLE_ECHO 124 | #define DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION 0 125 | #else 126 | #define DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION 1 127 | #endif /* DEBUG_CONSOLE_ENABLE_ECHO */ 128 | 129 | /*********************************************************************/ 130 | 131 | /***************Debug console other configuration*********************/ 132 | /*! @brief Definition to printf the float number. */ 133 | #ifndef PRINTF_FLOAT_ENABLE 134 | #define PRINTF_FLOAT_ENABLE 0U 135 | #endif /* PRINTF_FLOAT_ENABLE */ 136 | 137 | /*! @brief Definition to scanf the float number. */ 138 | #ifndef SCANF_FLOAT_ENABLE 139 | #define SCANF_FLOAT_ENABLE 0U 140 | #endif /* SCANF_FLOAT_ENABLE */ 141 | 142 | /*! @brief Definition to support advanced format specifier for printf. */ 143 | #ifndef PRINTF_ADVANCED_ENABLE 144 | #define PRINTF_ADVANCED_ENABLE 0U 145 | #endif /* PRINTF_ADVANCED_ENABLE */ 146 | 147 | /*! @brief Definition to support advanced format specifier for scanf. */ 148 | #ifndef SCANF_ADVANCED_ENABLE 149 | #define SCANF_ADVANCED_ENABLE 0U 150 | #endif /* SCANF_ADVANCED_ENABLE */ 151 | 152 | /*******************************************************************/ 153 | 154 | #endif /* _FSL_DEBUG_CONSOLE_CONF_H_ */ 155 | -------------------------------------------------------------------------------- /CMSIS/mpu_armv7.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file mpu_armv7.h 3 | * @brief CMSIS MPU API for ARMv7 MPU 4 | * @version V5.0.2 5 | * @date 09. June 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef ARM_MPU_ARMV7_H 26 | #define ARM_MPU_ARMV7_H 27 | 28 | #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) 29 | #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) 30 | #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) 31 | #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) 32 | #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) 33 | #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) 34 | #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) 35 | #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) 36 | #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) 37 | #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) 38 | #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) 39 | #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) 40 | #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) 41 | #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) 42 | #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) 43 | #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) 44 | #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) 45 | #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) 46 | #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) 47 | #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) 48 | #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) 49 | #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) 50 | #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) 51 | #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) 52 | #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) 53 | #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) 54 | #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) 55 | #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) 56 | 57 | #define ARM_MPU_AP_NONE 0u 58 | #define ARM_MPU_AP_PRIV 1u 59 | #define ARM_MPU_AP_URO 2u 60 | #define ARM_MPU_AP_FULL 3u 61 | #define ARM_MPU_AP_PRO 5u 62 | #define ARM_MPU_AP_RO 6u 63 | 64 | /** MPU Region Base Address Register Value 65 | * 66 | * \param Region The region to be configured, number 0 to 15. 67 | * \param BaseAddress The base address for the region. 68 | */ 69 | #define ARM_MPU_RBAR(Region, BaseAddress) ((BaseAddress & MPU_RBAR_ADDR_Msk) | (Region & MPU_RBAR_REGION_Msk) | (1UL << MPU_RBAR_VALID_Pos)) 70 | 71 | /** 72 | * MPU Region Attribut and Size Register Value 73 | * 74 | * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. 75 | * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. 76 | * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. 77 | * \param IsShareable Region is shareable between multiple bus masters. 78 | * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. 79 | * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. 80 | * \param SubRegionDisable Sub-region disable field. 81 | * \param Size Region size of the region to be configured, for example 4K, 8K. 82 | */ 83 | #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ 84 | ((DisableExec << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ 85 | ((AccessPermission << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ 86 | ((TypeExtField << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ 87 | ((IsShareable << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ 88 | ((IsCacheable << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ 89 | ((IsBufferable << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | \ 90 | ((SubRegionDisable << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ 91 | ((Size << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ 92 | ((1UL << MPU_RASR_ENABLE_Pos) & MPU_RASR_ENABLE_Msk) 93 | 94 | 95 | /** 96 | * Struct for a single MPU Region 97 | */ 98 | typedef struct _ARM_MPU_Region_t { 99 | uint32_t RBAR; //!< The region base address register value (RBAR) 100 | uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR 101 | } ARM_MPU_Region_t; 102 | 103 | /** Enable the MPU. 104 | * \param MPU_Control Default access permissions for unconfigured regions. 105 | */ 106 | __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) 107 | { 108 | __DSB(); 109 | __ISB(); 110 | MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; 111 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 112 | SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; 113 | #endif 114 | } 115 | 116 | /** Disable the MPU. 117 | */ 118 | __STATIC_INLINE void ARM_MPU_Disable() 119 | { 120 | __DSB(); 121 | __ISB(); 122 | #ifdef SCB_SHCSR_MEMFAULTENA_Msk 123 | SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; 124 | #endif 125 | MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; 126 | } 127 | 128 | /** Clear and disable the given MPU region. 129 | * \param rnr Region number to be cleared. 130 | */ 131 | __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) 132 | { 133 | MPU->RNR = rnr; 134 | MPU->RASR = 0u; 135 | } 136 | 137 | /** Configure an MPU region. 138 | * \param rbar Value for RBAR register. 139 | * \param rsar Value for RSAR register. 140 | */ 141 | __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) 142 | { 143 | MPU->RBAR = rbar; 144 | MPU->RASR = rasr; 145 | } 146 | 147 | /** Configure the given MPU region. 148 | * \param rnr Region number to be configured. 149 | * \param rbar Value for RBAR register. 150 | * \param rsar Value for RSAR register. 151 | */ 152 | __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) 153 | { 154 | MPU->RNR = rnr; 155 | MPU->RBAR = rbar; 156 | MPU->RASR = rasr; 157 | } 158 | 159 | /** Memcopy with strictly ordered memory access, e.g. for register targets. 160 | * \param dst Destination data is copied to. 161 | * \param src Source data is copied from. 162 | * \param len Amount of data words to be copied. 163 | */ 164 | __STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) 165 | { 166 | uint32_t i; 167 | for (i = 0u; i < len; ++i) 168 | { 169 | dst[i] = src[i]; 170 | } 171 | } 172 | 173 | /** Load the given number of MPU regions from a table. 174 | * \param table Pointer to the MPU configuration table. 175 | * \param cnt Amount of regions to be configured. 176 | */ 177 | __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) 178 | { 179 | orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*sizeof(ARM_MPU_Region_t)/4u); 180 | } 181 | 182 | #endif 183 | -------------------------------------------------------------------------------- /utilities/fsl_debug_console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * Debug console shall provide input and output functions to scan and print formatted data. 35 | * o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier" 36 | * - [flags] :'-', '+', '#', ' ', '0' 37 | * - [width]: number (0,1...) 38 | * - [.precision]: number (0,1...) 39 | * - [length]: do not support 40 | * - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n' 41 | * o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier" 42 | * - [*]: is supported. 43 | * - [width]: number (0,1...) 44 | * - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t') 45 | * - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's' 46 | */ 47 | 48 | #ifndef _FSL_DEBUGCONSOLE_H_ 49 | #define _FSL_DEBUGCONSOLE_H_ 50 | 51 | #include "fsl_common.h" 52 | /*! 53 | * @addtogroup debugconsole 54 | * @{ 55 | */ 56 | 57 | /******************************************************************************* 58 | * Definitions 59 | ******************************************************************************/ 60 | 61 | /*! @brief Definition to select sdk or toolchain printf, scanf. */ 62 | #ifndef SDK_DEBUGCONSOLE 63 | #define SDK_DEBUGCONSOLE 1U 64 | #endif 65 | 66 | #if defined(SDK_DEBUGCONSOLE) && !(SDK_DEBUGCONSOLE) 67 | #include 68 | #endif 69 | 70 | #if SDK_DEBUGCONSOLE /* Select printf, scanf, putchar, getchar of SDK version. */ 71 | #define PRINTF DbgConsole_Printf 72 | #define SCANF DbgConsole_Scanf 73 | #define PUTCHAR DbgConsole_Putchar 74 | #define GETCHAR DbgConsole_Getchar 75 | #else /* Select printf, scanf, putchar, getchar of toolchain. */ 76 | #define PRINTF printf 77 | #define SCANF scanf 78 | #define PUTCHAR putchar 79 | #define GETCHAR getchar 80 | #endif /* SDK_DEBUGCONSOLE */ 81 | 82 | /******************************************************************************* 83 | * Prototypes 84 | ******************************************************************************/ 85 | 86 | #if defined(__cplusplus) 87 | extern "C" { 88 | #endif /* __cplusplus */ 89 | 90 | /*! @name Initialization*/ 91 | /* @{ */ 92 | 93 | /*! 94 | * @brief Initializes the the peripheral used for debug messages. 95 | * 96 | * Call this function to enable debug log messages to be output via the specified peripheral, 97 | * frequency of peripheral source clock, and base address at the specified baud rate. 98 | * After this function has returned, stdout and stdin are connected to the selected peripheral. 99 | * 100 | * @param baseAddr Indicates the address of the peripheral used to send debug messages. 101 | * @param baudRate The desired baud rate in bits per second. 102 | * @param device Low level device type for the debug console, can be one of the following. 103 | * @arg DEBUG_CONSOLE_DEVICE_TYPE_UART, 104 | * @arg DEBUG_CONSOLE_DEVICE_TYPE_LPUART, 105 | * @arg DEBUG_CONSOLE_DEVICE_TYPE_LPSCI, 106 | * @arg DEBUG_CONSOLE_DEVICE_TYPE_USBCDC. 107 | * @param clkSrcFreq Frequency of peripheral source clock. 108 | * 109 | * @return Indicates whether initialization was successful or not. 110 | * @retval kStatus_Success Execution successfully 111 | * @retval kStatus_Fail Execution failure 112 | * @retval kStatus_InvalidArgument Invalid argument existed 113 | */ 114 | status_t DbgConsole_Init(uint32_t baseAddr, uint32_t baudRate, uint8_t device, uint32_t clkSrcFreq); 115 | 116 | /*! 117 | * @brief De-initializes the peripheral used for debug messages. 118 | * 119 | * Call this function to disable debug log messages to be output via the specified peripheral 120 | * base address and at the specified baud rate. 121 | * 122 | * @return Indicates whether de-initialization was successful or not. 123 | */ 124 | status_t DbgConsole_Deinit(void); 125 | 126 | #if SDK_DEBUGCONSOLE 127 | /*! 128 | * @brief Writes formatted output to the standard output stream. 129 | * 130 | * Call this function to write a formatted output to the standard output stream. 131 | * 132 | * @param fmt_s Format control string. 133 | * @return Returns the number of characters printed or a negative value if an error occurs. 134 | */ 135 | int DbgConsole_Printf(const char *fmt_s, ...); 136 | 137 | /*! 138 | * @brief Writes a character to stdout. 139 | * 140 | * Call this function to write a character to stdout. 141 | * 142 | * @param ch Character to be written. 143 | * @return Returns the character written. 144 | */ 145 | int DbgConsole_Putchar(int ch); 146 | 147 | /*! 148 | * @brief Reads formatted data from the standard input stream. 149 | * 150 | * Call this function to read formatted data from the standard input stream. 151 | * 152 | * @param fmt_ptr Format control string. 153 | * @return Returns the number of fields successfully converted and assigned. 154 | */ 155 | int DbgConsole_Scanf(char *fmt_ptr, ...); 156 | 157 | /*! 158 | * @brief Reads a character from standard input. 159 | * 160 | * Call this function to read a character from standard input. 161 | * 162 | * @return Returns the character read. 163 | */ 164 | int DbgConsole_Getchar(void); 165 | 166 | /*! 167 | * @brief Debug console flush log. 168 | * 169 | * Call this function to wait the buffer empty and io idle before. 170 | * If interrupt transfer is using, make sure the global IRQ is enable before call this function 171 | * This function should be called when 172 | * 1, before enter power down mode 173 | * 2, log is required to print to terminal immediately 174 | * @return Indicates whether wait idle was successful or not. 175 | */ 176 | status_t DbgConsole_Flush(void); 177 | 178 | #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING 179 | /*! 180 | * @brief Debug console try to get char 181 | * This function provide a api which will not block current task, if character is 182 | * avaliable return it , otherwise return fail. 183 | * @param ch the address of char to receive 184 | * @return Indicates get char was successful or not. 185 | */ 186 | status_t DbgConsole_TryGetchar(char *ch); 187 | #endif 188 | 189 | #endif /* SDK_DEBUGCONSOLE */ 190 | 191 | /*! @} */ 192 | 193 | #if defined(__cplusplus) 194 | } 195 | #endif /* __cplusplus */ 196 | 197 | /*! @} */ 198 | 199 | #endif /* _FSL_DEBUGCONSOLE_H_ */ 200 | -------------------------------------------------------------------------------- /script.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * GENERATED FILE - DO NOT EDIT 3 | * (c) Code Red Technologies Ltd, 2008-2013 4 | * (c) NXP Semiconductors 2013-2018 5 | * Generated linker script file for MK66FN2M0xxx18 6 | * Created from linkscript.ldt by FMCreateLinkLibraries 7 | * Using Freemarker v2.3.23 8 | * MCUXpresso IDE v10.1.0 [Build 589] [2017-11-14] on Mar 24, 2018 12:01:18 AM 9 | */ 10 | 11 | 12 | /* 13 | * GENERATED FILE - DO NOT EDIT 14 | * (c) Code Red Technologies Ltd, 2008-2013 15 | * (c) NXP Semiconductors 2013-2018 16 | * Generated linker script file for MK66FN2M0xxx18 17 | * Created from memory.ldt by FMCreateLinkMemory 18 | * Using Freemarker v2.3.23 19 | * MCUXpresso IDE v10.1.0 [Build 589] [2017-11-14] on Mar 24, 2018 12:01:18 AM 20 | */ 21 | 22 | MEMORY 23 | { 24 | /* Define each memory region */ 25 | PROGRAM_FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x200000 /* 2M bytes (alias Flash) */ 26 | SRAM_UPPER (rwx) : ORIGIN = 0x20000000, LENGTH = 0x30000 /* 192K bytes (alias RAM) */ 27 | SRAM_LOWER (rwx) : ORIGIN = 0x1fff0000, LENGTH = 0x10000 /* 64K bytes (alias RAM2) */ 28 | FLEX_RAM (rwx) : ORIGIN = 0x14000000, LENGTH = 0x1000 /* 4K bytes (alias RAM3) */ 29 | } 30 | 31 | /* Define a symbol for the top of each memory region */ 32 | __base_PROGRAM_FLASH = 0x0 ; /* PROGRAM_FLASH */ 33 | __base_Flash = 0x0 ; /* Flash */ 34 | __top_PROGRAM_FLASH = 0x0 + 0x200000 ; /* 2M bytes */ 35 | __top_Flash = 0x0 + 0x200000 ; /* 2M bytes */ 36 | __base_SRAM_UPPER = 0x20000000 ; /* SRAM_UPPER */ 37 | __base_RAM = 0x20000000 ; /* RAM */ 38 | __top_SRAM_UPPER = 0x20000000 + 0x30000 ; /* 192K bytes */ 39 | __top_RAM = 0x20000000 + 0x30000 ; /* 192K bytes */ 40 | __base_SRAM_LOWER = 0x1fff0000 ; /* SRAM_LOWER */ 41 | __base_RAM2 = 0x1fff0000 ; /* RAM2 */ 42 | __top_SRAM_LOWER = 0x1fff0000 + 0x10000 ; /* 64K bytes */ 43 | __top_RAM2 = 0x1fff0000 + 0x10000 ; /* 64K bytes */ 44 | __base_FLEX_RAM = 0x14000000 ; /* FLEX_RAM */ 45 | __base_RAM3 = 0x14000000 ; /* RAM3 */ 46 | __top_FLEX_RAM = 0x14000000 + 0x1000 ; /* 4K bytes */ 47 | __top_RAM3 = 0x14000000 + 0x1000 ; /* 4K bytes */ 48 | 49 | ENTRY(ResetISR) 50 | 51 | SECTIONS 52 | { 53 | /* MAIN TEXT SECTION */ 54 | .text : ALIGN(4) 55 | { 56 | FILL(0xff) 57 | __vectors_start__ = ABSOLUTE(.) ; 58 | KEEP(*(.isr_vector)) 59 | /* Global Section Table */ 60 | . = ALIGN(4) ; 61 | __section_table_start = .; 62 | __data_section_table = .; 63 | LONG(LOADADDR(.data)); 64 | LONG( ADDR(.data)); 65 | LONG( SIZEOF(.data)); 66 | LONG(LOADADDR(.data_RAM2)); 67 | LONG( ADDR(.data_RAM2)); 68 | LONG( SIZEOF(.data_RAM2)); 69 | LONG(LOADADDR(.data_RAM3)); 70 | LONG( ADDR(.data_RAM3)); 71 | LONG( SIZEOF(.data_RAM3)); 72 | __data_section_table_end = .; 73 | __bss_section_table = .; 74 | LONG( ADDR(.bss)); 75 | LONG( SIZEOF(.bss)); 76 | LONG( ADDR(.bss_RAM2)); 77 | LONG( SIZEOF(.bss_RAM2)); 78 | LONG( ADDR(.bss_RAM3)); 79 | LONG( SIZEOF(.bss_RAM3)); 80 | __bss_section_table_end = .; 81 | __section_table_end = . ; 82 | /* End of Global Section Table */ 83 | 84 | *(.after_vectors*) 85 | 86 | 87 | /* Kinetis Flash Configuration data */ 88 | . = 0x400 ; 89 | PROVIDE(__FLASH_CONFIG_START__ = .) ; 90 | KEEP(*(.FlashConfig)) 91 | PROVIDE(__FLASH_CONFIG_END__ = .) ; 92 | ASSERT(!(__FLASH_CONFIG_START__ == __FLASH_CONFIG_END__), "Linker Flash Config Support Enabled, but no .FlashConfig section provided within application"); 93 | /* End of Kinetis Flash Configuration data */ 94 | 95 | 96 | } >PROGRAM_FLASH 97 | 98 | .text : ALIGN(4) 99 | { 100 | *(.text*) 101 | *(.rodata .rodata.* .constdata .constdata.*) 102 | . = ALIGN(4); 103 | } > PROGRAM_FLASH 104 | /* 105 | * for exception handling/unwind - some Newlib functions (in common 106 | * with C++ and STDC++) use this. 107 | */ 108 | .ARM.extab : ALIGN(4) 109 | { 110 | *(.ARM.extab* .gnu.linkonce.armextab.*) 111 | } > PROGRAM_FLASH 112 | __exidx_start = .; 113 | 114 | .ARM.exidx : ALIGN(4) 115 | { 116 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 117 | } > PROGRAM_FLASH 118 | __exidx_end = .; 119 | 120 | _etext = .; 121 | 122 | 123 | /* USB_RAM */ 124 | .m_usb_data (NOLOAD) : 125 | { 126 | *(m_usb_bdt) 127 | } > SRAM_UPPER 128 | /* DATA section for SRAM_LOWER */ 129 | .data_RAM2 : ALIGN(4) 130 | { 131 | FILL(0xff) 132 | PROVIDE(__start_data_RAM2 = .) ; 133 | *(.ramfunc.$RAM2) 134 | *(.ramfunc.$SRAM_LOWER) 135 | *(.data.$RAM2*) 136 | *(.data.$SRAM_LOWER*) 137 | . = ALIGN(4) ; 138 | PROVIDE(__end_data_RAM2 = .) ; 139 | } > SRAM_LOWER AT>PROGRAM_FLASH 140 | 141 | /* DATA section for FLEX_RAM */ 142 | .data_RAM3 : ALIGN(4) 143 | { 144 | FILL(0xff) 145 | PROVIDE(__start_data_RAM3 = .) ; 146 | *(.ramfunc.$RAM3) 147 | *(.ramfunc.$FLEX_RAM) 148 | *(.data.$RAM3*) 149 | *(.data.$FLEX_RAM*) 150 | . = ALIGN(4) ; 151 | PROVIDE(__end_data_RAM3 = .) ; 152 | } > FLEX_RAM AT>PROGRAM_FLASH 153 | 154 | /* MAIN DATA SECTION */ 155 | .uninit_RESERVED : ALIGN(4) 156 | { 157 | KEEP(*(.bss.$RESERVED*)) 158 | . = ALIGN(4) ; 159 | _end_uninit_RESERVED = .; 160 | } > SRAM_UPPER 161 | /* Main DATA section (SRAM_UPPER) */ 162 | .data : ALIGN(4) 163 | { 164 | FILL(0xff) 165 | _data = . ; 166 | *(vtable) 167 | *(.ramfunc*) 168 | *(.data*) 169 | . = ALIGN(4) ; 170 | _edata = . ; 171 | } > SRAM_UPPER AT>PROGRAM_FLASH 172 | /* BSS section for SRAM_LOWER */ 173 | .bss_RAM2 : ALIGN(4) 174 | { 175 | PROVIDE(__start_bss_RAM2 = .) ; 176 | *(.bss.$RAM2*) 177 | *(.bss.$SRAM_LOWER*) 178 | . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ 179 | PROVIDE(__end_bss_RAM2 = .) ; 180 | } > SRAM_LOWER 181 | /* BSS section for FLEX_RAM */ 182 | .bss_RAM3 : ALIGN(4) 183 | { 184 | PROVIDE(__start_bss_RAM3 = .) ; 185 | *(.bss.$RAM3*) 186 | *(.bss.$FLEX_RAM*) 187 | . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ 188 | PROVIDE(__end_bss_RAM3 = .) ; 189 | } > FLEX_RAM 190 | /* MAIN BSS SECTION */ 191 | .bss : ALIGN(4) 192 | { 193 | _bss = .; 194 | *(.bss*) 195 | *(COMMON) 196 | . = ALIGN(4) ; 197 | _ebss = .; 198 | PROVIDE(end = .); 199 | } > SRAM_UPPER 200 | /* NOINIT section for SRAM_LOWER */ 201 | .noinit_RAM2 (NOLOAD) : ALIGN(4) 202 | { 203 | *(.noinit.$RAM2*) 204 | *(.noinit.$SRAM_LOWER*) 205 | . = ALIGN(4) ; 206 | } > SRAM_LOWER 207 | /* NOINIT section for FLEX_RAM */ 208 | .noinit_RAM3 (NOLOAD) : ALIGN(4) 209 | { 210 | *(.noinit.$RAM3*) 211 | *(.noinit.$FLEX_RAM*) 212 | . = ALIGN(4) ; 213 | } > FLEX_RAM 214 | /* DEFAULT NOINIT SECTION */ 215 | .noinit (NOLOAD): ALIGN(4) 216 | { 217 | _noinit = .; 218 | *(.noinit*) 219 | . = ALIGN(4) ; 220 | _end_noinit = .; 221 | } > SRAM_UPPER 222 | 223 | /* Reserve and place Heap within memory map */ 224 | _HeapSize = 0x2000; 225 | .heap : ALIGN(4) 226 | { 227 | _pvHeapStart = .; 228 | . += _HeapSize; 229 | . = ALIGN(4); 230 | _pvHeapLimit = .; 231 | } > SRAM_UPPER 232 | 233 | _StackSize = 0x2000; 234 | /* Reserve space in memory for Stack */ 235 | .heap2stackfill : 236 | { 237 | . += _StackSize; 238 | } > SRAM_UPPER 239 | /* Locate actual Stack in memory map */ 240 | .stack ORIGIN(SRAM_UPPER) + LENGTH(SRAM_UPPER) - _StackSize - 0: ALIGN(4) 241 | { 242 | _vStackBase = .; 243 | . = ALIGN(4); 244 | _vStackTop = . + _StackSize; 245 | } > SRAM_UPPER 246 | 247 | /* Provide basic symbols giving location and size of main text 248 | * block, including initial values of RW data sections. Note that 249 | * these will need extending to give a complete picture with 250 | * complex images (e.g multiple Flash banks). 251 | */ 252 | _image_start = LOADADDR(.text); 253 | _image_end = LOADADDR(.data) + SIZEOF(.data); 254 | _image_size = _image_end - _image_start; 255 | } 256 | -------------------------------------------------------------------------------- /drivers/fsl_gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "fsl_gpio.h" 36 | 37 | /******************************************************************************* 38 | * Variables 39 | ******************************************************************************/ 40 | 41 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 42 | static PORT_Type *const s_portBases[] = PORT_BASE_PTRS; 43 | static GPIO_Type *const s_gpioBases[] = GPIO_BASE_PTRS; 44 | #endif 45 | 46 | #if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT 47 | 48 | #if defined(FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL) && FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL 49 | 50 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) 51 | /*! @brief Array to map FGPIO instance number to clock name. */ 52 | static const clock_ip_name_t s_fgpioClockName[] = FGPIO_CLOCKS; 53 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ 54 | 55 | #endif /* FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL */ 56 | 57 | #endif /* FSL_FEATURE_SOC_FGPIO_COUNT */ 58 | 59 | /******************************************************************************* 60 | * Prototypes 61 | ******************************************************************************/ 62 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 63 | /*! 64 | * @brief Gets the GPIO instance according to the GPIO base 65 | * 66 | * @param base GPIO peripheral base pointer(PTA, PTB, PTC, etc.) 67 | * @retval GPIO instance 68 | */ 69 | static uint32_t GPIO_GetInstance(GPIO_Type *base); 70 | #endif 71 | /******************************************************************************* 72 | * Code 73 | ******************************************************************************/ 74 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 75 | static uint32_t GPIO_GetInstance(GPIO_Type *base) 76 | { 77 | uint32_t instance; 78 | 79 | /* Find the instance index from base address mappings. */ 80 | for (instance = 0; instance < ARRAY_SIZE(s_gpioBases); instance++) 81 | { 82 | if (s_gpioBases[instance] == base) 83 | { 84 | break; 85 | } 86 | } 87 | 88 | assert(instance < ARRAY_SIZE(s_gpioBases)); 89 | 90 | return instance; 91 | } 92 | #endif 93 | void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config) 94 | { 95 | assert(config); 96 | 97 | if (config->pinDirection == kGPIO_DigitalInput) 98 | { 99 | base->PDDR &= ~(1U << pin); 100 | } 101 | else 102 | { 103 | GPIO_WritePinOutput(base, pin, config->outputLogic); 104 | base->PDDR |= (1U << pin); 105 | } 106 | } 107 | 108 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 109 | uint32_t GPIO_PortGetInterruptFlags(GPIO_Type *base) 110 | { 111 | uint8_t instance; 112 | PORT_Type *portBase; 113 | instance = GPIO_GetInstance(base); 114 | portBase = s_portBases[instance]; 115 | return portBase->ISFR; 116 | } 117 | 118 | void GPIO_PortClearInterruptFlags(GPIO_Type *base, uint32_t mask) 119 | { 120 | uint8_t instance; 121 | PORT_Type *portBase; 122 | instance = GPIO_GetInstance(base); 123 | portBase = s_portBases[instance]; 124 | portBase->ISFR = mask; 125 | } 126 | #endif 127 | 128 | #if defined(FSL_FEATURE_GPIO_HAS_ATTRIBUTE_CHECKER) && FSL_FEATURE_GPIO_HAS_ATTRIBUTE_CHECKER 129 | void GPIO_CheckAttributeBytes(GPIO_Type *base, gpio_checker_attribute_t attribute) 130 | { 131 | base->GACR = ((uint32_t)attribute << GPIO_GACR_ACB0_SHIFT) | ((uint32_t)attribute << GPIO_GACR_ACB1_SHIFT) | 132 | ((uint32_t)attribute << GPIO_GACR_ACB2_SHIFT) | ((uint32_t)attribute << GPIO_GACR_ACB3_SHIFT); 133 | } 134 | #endif 135 | 136 | #if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT 137 | 138 | /******************************************************************************* 139 | * Variables 140 | ******************************************************************************/ 141 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 142 | static FGPIO_Type *const s_fgpioBases[] = FGPIO_BASE_PTRS; 143 | #endif 144 | /******************************************************************************* 145 | * Prototypes 146 | ******************************************************************************/ 147 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 148 | /*! 149 | * @brief Gets the FGPIO instance according to the GPIO base 150 | * 151 | * @param base FGPIO peripheral base pointer(PTA, PTB, PTC, etc.) 152 | * @retval FGPIO instance 153 | */ 154 | static uint32_t FGPIO_GetInstance(FGPIO_Type *base); 155 | #endif 156 | /******************************************************************************* 157 | * Code 158 | ******************************************************************************/ 159 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 160 | static uint32_t FGPIO_GetInstance(FGPIO_Type *base) 161 | { 162 | uint32_t instance; 163 | 164 | /* Find the instance index from base address mappings. */ 165 | for (instance = 0; instance < ARRAY_SIZE(s_fgpioBases); instance++) 166 | { 167 | if (s_fgpioBases[instance] == base) 168 | { 169 | break; 170 | } 171 | } 172 | 173 | assert(instance < ARRAY_SIZE(s_fgpioBases)); 174 | 175 | return instance; 176 | } 177 | #endif 178 | #if defined(FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL) && FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL 179 | void FGPIO_PortInit(FGPIO_Type *base) 180 | { 181 | #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) 182 | /* Ungate FGPIO periphral clock */ 183 | CLOCK_EnableClock(s_fgpioClockName[FGPIO_GetInstance(base)]); 184 | #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ 185 | } 186 | #endif /* FSL_FEATURE_PCC_HAS_FGPIO_CLOCK_GATE_CONTROL */ 187 | 188 | void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config) 189 | { 190 | assert(config); 191 | 192 | if (config->pinDirection == kGPIO_DigitalInput) 193 | { 194 | base->PDDR &= ~(1U << pin); 195 | } 196 | else 197 | { 198 | FGPIO_WritePinOutput(base, pin, config->outputLogic); 199 | base->PDDR |= (1U << pin); 200 | } 201 | } 202 | #if !(defined(FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) && FSL_FEATURE_GPIO_HAS_NO_PORTINTERRUPT) 203 | uint32_t FGPIO_PortGetInterruptFlags(FGPIO_Type *base) 204 | { 205 | uint8_t instance; 206 | instance = FGPIO_GetInstance(base); 207 | PORT_Type *portBase; 208 | portBase = s_portBases[instance]; 209 | return portBase->ISFR; 210 | } 211 | 212 | void FGPIO_PortClearInterruptFlags(FGPIO_Type *base, uint32_t mask) 213 | { 214 | uint8_t instance; 215 | instance = FGPIO_GetInstance(base); 216 | PORT_Type *portBase; 217 | portBase = s_portBases[instance]; 218 | portBase->ISFR = mask; 219 | } 220 | #endif 221 | #if defined(FSL_FEATURE_FGPIO_HAS_ATTRIBUTE_CHECKER) && FSL_FEATURE_FGPIO_HAS_ATTRIBUTE_CHECKER 222 | void FGPIO_CheckAttributeBytes(FGPIO_Type *base, gpio_checker_attribute_t attribute) 223 | { 224 | base->GACR = (attribute << FGPIO_GACR_ACB0_SHIFT) | (attribute << FGPIO_GACR_ACB1_SHIFT) | 225 | (attribute << FGPIO_GACR_ACB2_SHIFT) | (attribute << FGPIO_GACR_ACB3_SHIFT); 226 | } 227 | #endif 228 | 229 | #endif /* FSL_FEATURE_SOC_FGPIO_COUNT */ 230 | -------------------------------------------------------------------------------- /usb/phy/usb_phy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 - 2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include "usb.h" 36 | #include "fsl_device_registers.h" 37 | 38 | #include "usb_phy.h" 39 | 40 | void *USB_EhciPhyGetBase(uint8_t controllerId) 41 | { 42 | void *usbPhyBase = NULL; 43 | #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U)) 44 | uint32_t instance; 45 | uint32_t newinstance = 0; 46 | uint32_t usbphy_base_temp[] = USBPHY_BASE_ADDRS; 47 | uint32_t usbphy_base[] = USBPHY_BASE_ADDRS; 48 | 49 | if (controllerId < kUSB_ControllerEhci0) 50 | { 51 | return NULL; 52 | } 53 | 54 | controllerId = controllerId - kUSB_ControllerEhci0; 55 | 56 | for (instance = 0; instance < (sizeof(usbphy_base_temp) / sizeof(usbphy_base_temp[0])); instance++) 57 | { 58 | if (usbphy_base_temp[instance]) 59 | { 60 | usbphy_base[newinstance++] = usbphy_base_temp[instance]; 61 | } 62 | } 63 | if (controllerId > newinstance) 64 | { 65 | return NULL; 66 | } 67 | 68 | usbPhyBase = (void *)usbphy_base[controllerId]; 69 | #endif 70 | return usbPhyBase; 71 | } 72 | 73 | /*! 74 | * @brief ehci phy initialization. 75 | * 76 | * This function initialize ehci phy IP. 77 | * 78 | * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t. 79 | * @param[in] freq the external input clock. 80 | * for example: if the external input clock is 16M, the parameter freq should be 16000000. 81 | * 82 | * @retval kStatus_USB_Success cancel successfully. 83 | * @retval kStatus_USB_Error the freq value is incorrect. 84 | */ 85 | uint32_t USB_EhciPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig) 86 | { 87 | #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U)) 88 | USBPHY_Type *usbPhyBase; 89 | 90 | usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId); 91 | if (NULL == usbPhyBase) 92 | { 93 | return kStatus_USB_Error; 94 | } 95 | #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT))) 96 | 97 | usbPhyBase->TRIM_OVERRIDE_EN = 0x001fU; /* override IFR value */ 98 | #endif 99 | usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL2_MASK; /* support LS device. */ 100 | usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL3_MASK; /* support external FS Hub with LS device connected. */ 101 | /* PWD register provides overall control of the PHY power state */ 102 | usbPhyBase->PWD = 0U; 103 | 104 | /* Decode to trim the nominal 17.78mA current source for the High Speed TX drivers on USB_DP and USB_DM. */ 105 | usbPhyBase->TX = 106 | ((usbPhyBase->TX & (~(USBPHY_TX_D_CAL_MASK | USBPHY_TX_TXCAL45DM_MASK | USBPHY_TX_TXCAL45DP_MASK))) | 107 | (USBPHY_TX_D_CAL(phyConfig->D_CAL) | USBPHY_TX_TXCAL45DP(phyConfig->TXCAL45DP) | 108 | USBPHY_TX_TXCAL45DM(phyConfig->TXCAL45DM))); 109 | #endif 110 | 111 | return kStatus_USB_Success; 112 | } 113 | 114 | /*! 115 | * @brief ehci phy initialization for suspend and resume. 116 | * 117 | * This function initialize ehci phy IP for suspend and resume. 118 | * 119 | * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t. 120 | * @param[in] freq the external input clock. 121 | * for example: if the external input clock is 16M, the parameter freq should be 16000000. 122 | * 123 | * @retval kStatus_USB_Success cancel successfully. 124 | * @retval kStatus_USB_Error the freq value is incorrect. 125 | */ 126 | uint32_t USB_EhciLowPowerPhyInit(uint8_t controllerId, uint32_t freq, usb_phy_config_struct_t *phyConfig) 127 | { 128 | #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U)) 129 | USBPHY_Type *usbPhyBase; 130 | 131 | usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId); 132 | if (NULL == usbPhyBase) 133 | { 134 | return kStatus_USB_Error; 135 | } 136 | 137 | #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT))) 138 | usbPhyBase->TRIM_OVERRIDE_EN = 0x001fU; /* override IFR value */ 139 | #endif 140 | 141 | #if ((defined USBPHY_CTRL_AUTORESUME_EN_MASK) && (USBPHY_CTRL_AUTORESUME_EN_MASK > 0U)) 142 | usbPhyBase->CTRL |= USBPHY_CTRL_AUTORESUME_EN_MASK; 143 | #else 144 | usbPhyBase->CTRL |= USBPHY_CTRL_ENAUTO_PWRON_PLL_MASK; 145 | #endif 146 | usbPhyBase->CTRL |= USBPHY_CTRL_ENAUTOCLR_CLKGATE_MASK | USBPHY_CTRL_ENAUTOCLR_PHY_PWD_MASK; 147 | usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL2_MASK; /* support LS device. */ 148 | usbPhyBase->CTRL |= USBPHY_CTRL_SET_ENUTMILEVEL3_MASK; /* support external FS Hub with LS device connected. */ 149 | /* PWD register provides overall control of the PHY power state */ 150 | usbPhyBase->PWD = 0U; 151 | #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT))) 152 | /* now the 480MHz USB clock is up, then configure fractional divider after PLL with PFD 153 | * pfd clock = 480MHz*18/N, where N=18~35 154 | * Please note that USB1PFDCLK has to be less than 180MHz for RUN or HSRUN mode 155 | */ 156 | usbPhyBase->ANACTRL |= USBPHY_ANACTRL_PFD_FRAC(24); /* N=24 */ 157 | usbPhyBase->ANACTRL |= USBPHY_ANACTRL_PFD_CLK_SEL(1); /* div by 4 */ 158 | 159 | usbPhyBase->ANACTRL &= ~USBPHY_ANACTRL_DEV_PULLDOWN_MASK; 160 | usbPhyBase->ANACTRL &= ~USBPHY_ANACTRL_PFD_CLKGATE_MASK; 161 | while (!(usbPhyBase->ANACTRL & USBPHY_ANACTRL_PFD_STABLE_MASK)) 162 | { 163 | } 164 | #endif 165 | /* Decode to trim the nominal 17.78mA current source for the High Speed TX drivers on USB_DP and USB_DM. */ 166 | usbPhyBase->TX = 167 | ((usbPhyBase->TX & (~(USBPHY_TX_D_CAL_MASK | USBPHY_TX_TXCAL45DM_MASK | USBPHY_TX_TXCAL45DP_MASK))) | 168 | (USBPHY_TX_D_CAL(phyConfig->D_CAL) | USBPHY_TX_TXCAL45DP(phyConfig->TXCAL45DP) | 169 | USBPHY_TX_TXCAL45DM(phyConfig->TXCAL45DM))); 170 | #endif 171 | 172 | return kStatus_USB_Success; 173 | } 174 | 175 | /*! 176 | * @brief ehci phy de-initialization. 177 | * 178 | * This function de-initialize ehci phy IP. 179 | * 180 | * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t. 181 | */ 182 | void USB_EhciPhyDeinit(uint8_t controllerId) 183 | { 184 | #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U)) 185 | USBPHY_Type *usbPhyBase; 186 | 187 | usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId); 188 | if (NULL == usbPhyBase) 189 | { 190 | return; 191 | } 192 | #if ((!(defined FSL_FEATURE_SOC_CCM_ANALOG_COUNT)) && (!(defined FSL_FEATURE_SOC_ANATOP_COUNT))) 193 | usbPhyBase->PLL_SIC &= ~USBPHY_PLL_SIC_PLL_POWER_MASK; /* power down PLL */ 194 | usbPhyBase->PLL_SIC &= ~USBPHY_PLL_SIC_PLL_EN_USB_CLKS_MASK; /* disable USB clock output from USB PHY PLL */ 195 | #endif 196 | usbPhyBase->CTRL |= USBPHY_CTRL_CLKGATE_MASK; /* set to 1U to gate clocks */ 197 | #endif 198 | } 199 | 200 | /*! 201 | * @brief ehci phy disconnect detection enable or disable. 202 | * 203 | * This function enable/disable host ehci disconnect detection. 204 | * 205 | * @param[in] controllerId ehci controller id, please reference to #usb_controller_index_t. 206 | * @param[in] enable 207 | * 1U - enable; 208 | * 0U - disable; 209 | */ 210 | void USB_EhcihostPhyDisconnectDetectCmd(uint8_t controllerId, uint8_t enable) 211 | { 212 | #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U)) 213 | USBPHY_Type *usbPhyBase; 214 | 215 | usbPhyBase = (USBPHY_Type *)USB_EhciPhyGetBase(controllerId); 216 | if (NULL == usbPhyBase) 217 | { 218 | return; 219 | } 220 | 221 | if (enable) 222 | { 223 | usbPhyBase->CTRL |= USBPHY_CTRL_ENHOSTDISCONDETECT_MASK; 224 | } 225 | else 226 | { 227 | usbPhyBase->CTRL &= (~USBPHY_CTRL_ENHOSTDISCONDETECT_MASK); 228 | } 229 | #endif 230 | } 231 | -------------------------------------------------------------------------------- /board/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016-2017 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef _BOARD_H_ 36 | #define _BOARD_H_ 37 | 38 | #include "clock_config.h" 39 | #include "fsl_gpio.h" 40 | 41 | /******************************************************************************* 42 | * Definitions 43 | ******************************************************************************/ 44 | 45 | /*! @brief The board name */ 46 | #define BOARD_NAME "FRDM-K66F" 47 | 48 | /*! @brief The UART to use for debug messages. */ 49 | #define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART 50 | #define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0 51 | #define BOARD_DEBUG_UART_INSTANCE 0U 52 | #define BOARD_DEBUG_UART_CLKSRC SYS_CLK 53 | #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetCoreSysClkFreq() 54 | #define BOARD_UART_IRQ UART0_RX_TX_IRQn 55 | #define BOARD_UART_IRQ_HANDLER UART0_RX_TX_IRQHandler 56 | 57 | #ifndef BOARD_DEBUG_UART_BAUDRATE 58 | #define BOARD_DEBUG_UART_BAUDRATE 115200 59 | #endif /* BOARD_DEBUG_UART_BAUDRATE */ 60 | 61 | #define BOARD_ACCEL_I2C_BASE I2C0 62 | 63 | /*! @brief The CAN instance used for board. */ 64 | #define BOARD_CAN_BASEADDR CAN0 65 | 66 | /*! @brief The i2c instance used for i2c connection by default */ 67 | #define BOARD_I2C_BASEADDR I2C1 68 | 69 | /*! @brief The ENET PHY address. */ 70 | #define BOARD_ENET0_PHY_ADDRESS (0x00U) /* Phy address of enet port 0. */ 71 | 72 | /*! @brief The TPM instance/channel used for board */ 73 | #define BOARD_TPM_BASEADDR TPM2 74 | #define BOARD_TPM_CHANNEL 1U 75 | 76 | #define BOARD_FTM_BASEADDR FTM3 77 | #define BOARD_FTM_X_CHANNEL 0U 78 | #define BOARD_FTM_Y_CHANNEL 1U 79 | #define BOARD_FTM_PERIOD_HZ 100 80 | #define BOARD_FTM_IRQ_HANDLER FTM0_IRQHandler 81 | #define BOARD_FTM_IRQ_VECTOR FTM0_IRQn 82 | 83 | /*! @brief The bubble level demo information */ 84 | #define BOARD_FXOS8700_ADDR 0x1D 85 | #define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR 86 | #define BOARD_ACCEL_BAUDRATE 100 87 | #define BOARD_ACCEL_I2C_BASEADDR I2C0 88 | 89 | /*! @brief The FlexBus instance used for board.*/ 90 | #define BOARD_FLEXBUS_BASEADDR FB 91 | 92 | /*! @brief The SDHC instance/channel used for board. */ 93 | #define BOARD_SDHC_BASEADDR SDHC 94 | #define BOARD_SDHC_CD_GPIO_IRQ_HANDLER PORTD_IRQHandler 95 | 96 | /*! @brief The CMP instance/channel used for board. */ 97 | #define BOARD_CMP_BASEADDR CMP2 98 | #define BOARD_CMP_CHANNEL 2U 99 | 100 | /*! @brief The i2c instance used for board. */ 101 | #define BOARD_SAI_DEMO_I2C_BASEADDR I2C0 102 | 103 | /*! @brief The rtc instance used for board. */ 104 | #define BOARD_RTC_FUNC_BASEADDR RTC 105 | 106 | /*! @brief If connected the TWR_MEM, this is spi sd card */ 107 | #define BOARD_SDCARD_CARD_DETECTION_GPIO_PORT GPIOD 108 | #define SDCARD_CARD_DETECTION_GPIO_PIN 10U 109 | #define SDCARD_CARD_INSERTED 0U 110 | 111 | /*! @brief Define the port interrupt number for the board switches */ 112 | #ifndef BOARD_SW3_GPIO 113 | #define BOARD_SW3_GPIO GPIOA 114 | #endif 115 | #ifndef BOARD_SW3_PORT 116 | #define BOARD_SW3_PORT PORTA 117 | #endif 118 | #ifndef BOARD_SW3_GPIO_PIN 119 | #define BOARD_SW3_GPIO_PIN 10U 120 | #endif 121 | #define BOARD_SW3_IRQ PORTA_IRQn 122 | #define BOARD_SW3_IRQ_HANDLER PORTA_IRQHandler 123 | #define BOARD_SW3_NAME "SW3" 124 | 125 | #define LLWU_SW_GPIO BOARD_SW3_GPIO 126 | #define LLWU_SW_PORT BOARD_SW3_PORT 127 | #define LLWU_SW_GPIO_PIN BOARD_SW3_GPIO_PIN 128 | #define LLWU_SW_IRQ BOARD_SW3_IRQ 129 | #define LLWU_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER 130 | #define LLWU_SW_NAME BOARD_SW3_NAME 131 | 132 | /* Board led color mapping */ 133 | #define LOGIC_LED_ON 0U 134 | #define LOGIC_LED_OFF 1U 135 | #ifndef BOARD_LED_RED_GPIO 136 | #define BOARD_LED_RED_GPIO GPIOC 137 | #endif 138 | #define BOARD_LED_RED_GPIO_PORT PORTC 139 | #ifndef BOARD_LED_RED_GPIO_PIN 140 | #define BOARD_LED_RED_GPIO_PIN 9U 141 | #endif 142 | #ifndef BOARD_LED_GREEN_GPIO 143 | #define BOARD_LED_GREEN_GPIO GPIOE 144 | #endif 145 | #define BOARD_LED_GREEN_GPIO_PORT PORTE 146 | #ifndef BOARD_LED_GREEN_GPIO_PIN 147 | #define BOARD_LED_GREEN_GPIO_PIN 6U 148 | #endif 149 | #ifndef BOARD_LED_BLUE_GPIO 150 | #define BOARD_LED_BLUE_GPIO GPIOA 151 | #endif 152 | #define BOARD_LED_BLUE_GPIO_PORT PORTA 153 | #ifndef BOARD_LED_BLUE_GPIO_PIN 154 | #define BOARD_LED_BLUE_GPIO_PIN 11U 155 | #endif 156 | 157 | #define LED_RED_INIT(output) \ 158 | GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \ 159 | BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */ 160 | #define LED_RED_ON() \ 161 | GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */ 162 | #define LED_RED_OFF() \ 163 | GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */ 164 | #define LED_RED_TOGGLE() \ 165 | GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ 166 | 167 | #define LED_GREEN_INIT(output) \ 168 | GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \ 169 | BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */ 170 | #define LED_GREEN_ON() \ 171 | GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */ 172 | #define LED_GREEN_OFF() \ 173 | GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */ 174 | #define LED_GREEN_TOGGLE() \ 175 | GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ 176 | 177 | #define LED_BLUE_INIT(output) \ 178 | GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \ 179 | BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */ 180 | #define LED_BLUE_ON() \ 181 | GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */ 182 | #define LED_BLUE_OFF() \ 183 | GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */ 184 | #define LED_BLUE_TOGGLE() \ 185 | GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 186 | 187 | /*! @brief Define the port interrupt number for the usb id gpio pin */ 188 | #define BOARD_ID_GPIO GPIOE 189 | #define BOARD_ID_PORT PORTE 190 | #define BOARD_ID_GPIO_PIN 10U 191 | #define BOARD_ID_IRQ PORTE_IRQn 192 | 193 | /* SDHC base address, clock and card detection pin */ 194 | #define BOARD_SDHC_BASEADDR SDHC 195 | #define BOARD_SDHC_CLKSRC kCLOCK_CoreSysClk 196 | #define BOARD_SDHC_CLK_FREQ CLOCK_GetFreq(kCLOCK_CoreSysClk) 197 | #define BOARD_SDHC_IRQ SDHC_IRQn 198 | #define BOARD_SDHC_CD_GPIO_BASE GPIOD 199 | #ifndef BOARD_SDHC_CD_GPIO_PIN 200 | #define BOARD_SDHC_CD_GPIO_PIN 10U 201 | #endif 202 | #define BOARD_SDHC_CD_PORT_BASE PORTD 203 | #define BOARD_SDHC_CD_PORT_IRQ PORTD_IRQn 204 | #define BOARD_SDHC_CD_PORT_IRQ_HANDLER PORTD_IRQHandler 205 | #define BOARD_SDHC_CARD_INSERT_CD_LEVEL (1U) 206 | 207 | /* ERPC DSPI configuration */ 208 | #define ERPC_BOARD_DSPI_BASEADDR SPI0 209 | #define ERPC_BOARD_DSPI_BAUDRATE 500000U 210 | #define ERPC_BOARD_DSPI_CLKSRC DSPI0_CLK_SRC 211 | #define ERPC_BOARD_DSPI_CLK_FREQ CLOCK_GetFreq(DSPI0_CLK_SRC) 212 | #define ERPC_BOARD_DSPI_INT_GPIO GPIOB 213 | #define ERPC_BOARD_DSPI_INT_PORT PORTB 214 | #define ERPC_BOARD_DSPI_INT_PIN 2U 215 | #define ERPC_BOARD_DSPI_INT_PIN_IRQ PORTB_IRQn 216 | #define ERPC_BOARD_DSPI_INT_PIN_IRQ_HANDLER PORTB_IRQHandler 217 | /* USB PHY condfiguration */ 218 | #define BOARD_USB_PHY_D_CAL (0x0CU) 219 | #define BOARD_USB_PHY_TXCAL45DP (0x06U) 220 | #define BOARD_USB_PHY_TXCAL45DM (0x06U) 221 | 222 | /* DAC base address */ 223 | #define BOARD_DAC_BASEADDR DAC0 224 | 225 | /* Board accelerometer driver */ 226 | #define BOARD_ACCEL_FXOS 227 | 228 | #if defined(__cplusplus) 229 | extern "C" { 230 | #endif /* __cplusplus */ 231 | 232 | /******************************************************************************* 233 | * API 234 | ******************************************************************************/ 235 | 236 | void BOARD_InitDebugConsole(void); 237 | 238 | #if defined(__cplusplus) 239 | } 240 | #endif /* __cplusplus */ 241 | 242 | #endif /* _BOARD_H_ */ 243 | -------------------------------------------------------------------------------- /usb/device/source/usb_device_dci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_DCI_H__ 36 | #define __USB_DEVICE_DCI_H__ 37 | 38 | /*! 39 | * @addtogroup usb_device_controller_driver 40 | * @{ 41 | */ 42 | 43 | /******************************************************************************* 44 | * Definitions 45 | ******************************************************************************/ 46 | 47 | /*! @brief Macro to define controller handle */ 48 | #define usb_device_controller_handle usb_device_handle 49 | 50 | /*! @brief Available notify types for device notification */ 51 | typedef enum _usb_device_notification 52 | { 53 | kUSB_DeviceNotifyBusReset = 0x10U, /*!< Reset signal detected */ 54 | kUSB_DeviceNotifySuspend, /*!< Suspend signal detected */ 55 | kUSB_DeviceNotifyResume, /*!< Resume signal detected */ 56 | kUSB_DeviceNotifyLPMSleep, /*!< LPM signal detected */ 57 | kUSB_DeviceNotifyLPMResume, /*!< Resume signal detected */ 58 | kUSB_DeviceNotifyError, /*!< Errors happened in bus */ 59 | kUSB_DeviceNotifyDetach, /*!< Device disconnected from a host */ 60 | kUSB_DeviceNotifyAttach, /*!< Device connected to a host */ 61 | #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) 62 | kUSB_DeviceNotifyDcdTimeOut, /*!< Device charger detection timeout */ 63 | kUSB_DeviceNotifyDcdUnknownPortType, /*!< Device charger detection unknown port type */ 64 | kUSB_DeviceNotifySDPDetected, /*!< The SDP facility is detected */ 65 | kUSB_DeviceNotifyChargingPortDetected, /*!< The charging port is detected */ 66 | kUSB_DeviceNotifyChargingHostDetected, /*!< The CDP facility is detected */ 67 | kUSB_DeviceNotifyDedicatedChargerDetected, /*!< The DCP facility is detected */ 68 | #endif 69 | } usb_device_notification_t; 70 | 71 | /*! @brief Device notification message structure */ 72 | typedef struct _usb_device_callback_message_struct 73 | { 74 | uint8_t *buffer; /*!< Transferred buffer */ 75 | uint32_t length; /*!< Transferred data length */ 76 | uint8_t code; /*!< Notification code */ 77 | uint8_t isSetup; /*!< Is in a setup phase */ 78 | } usb_device_callback_message_struct_t; 79 | 80 | /*! @brief Control type for controller */ 81 | typedef enum _usb_device_control_type 82 | { 83 | kUSB_DeviceControlRun = 0U, /*!< Enable the device functionality */ 84 | kUSB_DeviceControlStop, /*!< Disable the device functionality */ 85 | kUSB_DeviceControlEndpointInit, /*!< Initialize a specified endpoint */ 86 | kUSB_DeviceControlEndpointDeinit, /*!< De-initialize a specified endpoint */ 87 | kUSB_DeviceControlEndpointStall, /*!< Stall a specified endpoint */ 88 | kUSB_DeviceControlEndpointUnstall, /*!< Unstall a specified endpoint */ 89 | kUSB_DeviceControlGetDeviceStatus, /*!< Get device status */ 90 | kUSB_DeviceControlGetEndpointStatus, /*!< Get endpoint status */ 91 | kUSB_DeviceControlSetDeviceAddress, /*!< Set device address */ 92 | kUSB_DeviceControlGetSynchFrame, /*!< Get current frame */ 93 | kUSB_DeviceControlResume, /*!< Drive controller to generate a resume signal in USB bus */ 94 | kUSB_DeviceControlSleepResume, /*!< Drive controller to generate a LPM resume signal in USB bus */ 95 | kUSB_DeviceControlSuspend, /*!< Drive controller to enetr into suspend mode */ 96 | kUSB_DeviceControlSleep, /*!< Drive controller to enetr into sleep mode */ 97 | kUSB_DeviceControlSetDefaultStatus, /*!< Set controller to default status */ 98 | kUSB_DeviceControlGetSpeed, /*!< Get current speed */ 99 | kUSB_DeviceControlGetOtgStatus, /*!< Get OTG status */ 100 | kUSB_DeviceControlSetOtgStatus, /*!< Set OTG status */ 101 | kUSB_DeviceControlSetTestMode, /*!< Drive xCHI into test mode */ 102 | kUSB_DeviceControlGetRemoteWakeUp, /*!< Get flag of LPM Remote Wake-up Enabled by USB host. */ 103 | #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) 104 | kUSB_DeviceControlDcdInitModule, 105 | kUSB_DeviceControlDcdDeinitModule, 106 | #endif 107 | } usb_device_control_type_t; 108 | 109 | /*! @brief USB device controller initialization function typedef */ 110 | typedef usb_status_t (*usb_device_controller_init_t)(uint8_t controllerId, 111 | usb_device_handle handle, 112 | usb_device_controller_handle *controllerHandle); 113 | 114 | /*! @brief USB device controller de-initialization function typedef */ 115 | typedef usb_status_t (*usb_device_controller_deinit_t)(usb_device_controller_handle controllerHandle); 116 | 117 | /*! @brief USB device controller send data function typedef */ 118 | typedef usb_status_t (*usb_device_controller_send_t)(usb_device_controller_handle controllerHandle, 119 | uint8_t endpointAddress, 120 | uint8_t *buffer, 121 | uint32_t length); 122 | 123 | /*! @brief USB device controller receive data function typedef */ 124 | typedef usb_status_t (*usb_device_controller_recv_t)(usb_device_controller_handle controllerHandle, 125 | uint8_t endpointAddress, 126 | uint8_t *buffer, 127 | uint32_t length); 128 | 129 | /*! @brief USB device controller cancel transfer function in a specified endpoint typedef */ 130 | typedef usb_status_t (*usb_device_controller_cancel_t)(usb_device_controller_handle controllerHandle, 131 | uint8_t endpointAddress); 132 | 133 | /*! @brief USB device controller control function typedef */ 134 | typedef usb_status_t (*usb_device_controller_control_t)(usb_device_controller_handle controllerHandle, 135 | usb_device_control_type_t command, 136 | void *param); 137 | 138 | /*! @brief USB device controller interface structure */ 139 | typedef struct _usb_device_controller_interface_struct 140 | { 141 | usb_device_controller_init_t deviceInit; /*!< Controller initialization */ 142 | usb_device_controller_deinit_t deviceDeinit; /*!< Controller de-initialization */ 143 | usb_device_controller_send_t deviceSend; /*!< Controller send data */ 144 | usb_device_controller_recv_t deviceRecv; /*!< Controller receive data */ 145 | usb_device_controller_cancel_t deviceCancel; /*!< Controller cancel transfer */ 146 | usb_device_controller_control_t deviceControl; /*!< Controller control */ 147 | } usb_device_controller_interface_struct_t; 148 | 149 | /*! @brief USB device status structure */ 150 | typedef struct _usb_device_struct 151 | { 152 | #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) 153 | volatile uint64_t hwTick; /*!< Current hw tick(ms)*/ 154 | #endif 155 | usb_device_controller_handle controllerHandle; /*!< Controller handle */ 156 | const usb_device_controller_interface_struct_t *controllerInterface; /*!< Controller interface handle */ 157 | #if USB_DEVICE_CONFIG_USE_TASK 158 | usb_osa_msgq_handle notificationQueue; /*!< Message queue */ 159 | #endif 160 | usb_device_callback_t deviceCallback; /*!< Device callback function pointer */ 161 | usb_device_endpoint_callback_struct_t 162 | epCallback[USB_DEVICE_CONFIG_ENDPOINTS << 1U]; /*!< Endpoint callback function structure */ 163 | uint8_t deviceAddress; /*!< Current device address */ 164 | uint8_t controllerId; /*!< Controller ID */ 165 | uint8_t state; /*!< Current device state */ 166 | #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U)) 167 | uint8_t remotewakeup; /*!< Remote wakeup is enabled or not */ 168 | #endif 169 | uint8_t isResetting; /*!< Is doing device reset or not */ 170 | #if (defined(USB_DEVICE_CONFIG_USE_TASK) && (USB_DEVICE_CONFIG_USE_TASK > 0U)) 171 | uint8_t epCallbackDirectly; /*!< Whether call ep callback directly when the task is enabled */ 172 | #endif 173 | } usb_device_struct_t; 174 | 175 | /******************************************************************************* 176 | * API 177 | ******************************************************************************/ 178 | 179 | /*! @}*/ 180 | 181 | #endif /* __USB_DEVICE_DCI_H__ */ 182 | -------------------------------------------------------------------------------- /sources/hid_keyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_HID_KEYBOARD_H__ 36 | #define __USB_DEVICE_HID_KEYBOARD_H__ 37 | 38 | /******************************************************************************* 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | typedef struct _usb_device_hid_keyboard_struct 43 | { 44 | uint8_t *buffer; 45 | uint8_t idleRate; 46 | } usb_device_hid_keyboard_struct_t; 47 | 48 | /*Key Code*/ 49 | #define KEY_ERRORROLLOVER 0x01U 50 | #define KEY_POSTFAIL 0x02U 51 | #define KEY_ERRORUNDEFINED 0x03U 52 | #define KEY_A 0x04U 53 | #define KEY_B 0x05U 54 | #define KEY_C 0x06U 55 | #define KEY_D 0x07U 56 | #define KEY_E 0x08U 57 | #define KEY_F 0x09U 58 | #define KEY_G 0x0AU 59 | #define KEY_H 0x0BU 60 | #define KEY_I 0x0CU 61 | #define KEY_J 0x0DU 62 | #define KEY_K 0x0EU 63 | #define KEY_L 0x0FU 64 | #define KEY_M 0x10U 65 | #define KEY_N 0x11U 66 | #define KEY_O 0x12U 67 | #define KEY_P 0x13U 68 | #define KEY_Q 0x14U 69 | #define KEY_R 0x15U 70 | #define KEY_S 0x16U 71 | #define KEY_T 0x17U 72 | #define KEY_U 0x18U 73 | #define KEY_V 0x19U 74 | #define KEY_W 0x1AU 75 | #define KEY_X 0x1BU 76 | #define KEY_Y 0x1CU 77 | #define KEY_Z 0x1DU 78 | #define KEY_1_EXCLAMATION_MARK 0x1EU 79 | #define KEY_2_AT 0x1FU 80 | #define KEY_3_NUMBER_SIGN 0x20U 81 | #define KEY_4_DOLLAR 0x21U 82 | #define KEY_5_PERCENT 0x22U 83 | #define KEY_6_CARET 0x23U 84 | #define KEY_7_AMPERSAND 0x24U 85 | #define KEY_8_ASTERISK 0x25U 86 | #define KEY_9_OPARENTHESIS 0x26U 87 | #define KEY_0_CPARENTHESIS 0x27U 88 | #define KEY_ENTER 0x28U 89 | #define KEY_ESCAPE 0x29U 90 | #define KEY_BACKSPACE 0x2AU 91 | #define KEY_TAB 0x2BU 92 | #define KEY_SPACEBAR 0x2CU 93 | #define KEY_MINUS_UNDERSCORE 0x2DU 94 | #define KEY_EQUAL_PLUS 0x2EU 95 | #define KEY_OBRACKET_AND_OBRACE 0x2FU 96 | #define KEY_CBRACKET_AND_CBRACE 0x30U 97 | #define KEY_BACKSLASH_VERTICAL_BAR 0x31U 98 | #define KEY_NONUS_NUMBER_SIGN_TILDE 0x32U 99 | #define KEY_SEMICOLON_COLON 0x33U 100 | #define KEY_SINGLE_AND_DOUBLE_QUOTE 0x34U 101 | #define KEY_GRAVE_ACCENT_AND_TILDE 0x35U 102 | #define KEY_COMMA_AND_LESS 0x36U 103 | #define KEY_DOT_GREATER 0x37U 104 | #define KEY_SLASH_QUESTION 0x38U 105 | #define KEY_CAPS_LOCK 0x39U 106 | #define KEY_F1 0x3AU 107 | #define KEY_F2 0x3BU 108 | #define KEY_F3 0x3CU 109 | #define KEY_F4 0x3DU 110 | #define KEY_F5 0x3EU 111 | #define KEY_F6 0x3FU 112 | #define KEY_F7 0x40U 113 | #define KEY_F8 0x41U 114 | #define KEY_F9 0x42U 115 | #define KEY_F10 0x43U 116 | #define KEY_F11 0x44U 117 | #define KEY_F12 0x45U 118 | #define KEY_PRINTSCREEN 0x46U 119 | #define KEY_SCROLL_LOCK 0x47U 120 | #define KEY_PAUSE 0x48U 121 | #define KEY_INSERT 0x49U 122 | #define KEY_HOME 0x4AU 123 | #define KEY_PAGEUP 0x4BU 124 | #define KEY_DELETE 0x4CU 125 | #define KEY_END1 0x4DU 126 | #define KEY_PAGEDOWN 0x4EU 127 | #define KEY_RIGHTARROW 0x4FU 128 | #define KEY_LEFTARROW 0x50U 129 | #define KEY_DOWNARROW 0x51U 130 | #define KEY_UPARROW 0x52U 131 | #define KEY_KEYPAD_NUM_LOCK_AND_CLEAR 0x53U 132 | #define KEY_KEYPAD_SLASH 0x54U 133 | #define KEY_KEYPAD_ASTERIKS 0x55U 134 | #define KEY_KEYPAD_MINUS 0x56U 135 | #define KEY_KEYPAD_PLUS 0x57U 136 | #define KEY_KEYPAD_ENTER 0x58U 137 | #define KEY_KEYPAD_1_END 0x59U 138 | #define KEY_KEYPAD_2_DOWN_ARROW 0x5AU 139 | #define KEY_KEYPAD_3_PAGEDN 0x5BU 140 | #define KEY_KEYPAD_4_LEFT_ARROW 0x5CU 141 | #define KEY_KEYPAD_5 0x5DU 142 | #define KEY_KEYPAD_6_RIGHT_ARROW 0x5EU 143 | #define KEY_KEYPAD_7_HOME 0x5FU 144 | #define KEY_KEYPAD_8_UP_ARROW 0x60U 145 | #define KEY_KEYPAD_9_PAGEUP 0x61U 146 | #define KEY_KEYPAD_0_INSERT 0x62U 147 | #define KEY_KEYPAD_DECIMAL_SEPARATOR_DELETE 0x63U 148 | #define KEY_NONUS_BACK_SLASH_VERTICAL_BAR 0x64U 149 | #define KEY_APPLICATION 0x65U 150 | #define KEY_POWER 0x66U 151 | #define KEY_KEYPAD_EQUAL 0x67U 152 | #define KEY_F13 0x68U 153 | #define KEY_F14 0x69U 154 | #define KEY_F15 0x6AU 155 | #define KEY_F16 0x6BU 156 | #define KEY_F17 0x6CU 157 | #define KEY_F18 0x6DU 158 | #define KEY_F19 0x6EU 159 | #define KEY_F20 0x6FU 160 | #define KEY_F21 0x70U 161 | #define KEY_F22 0x71U 162 | #define KEY_F23 0x72U 163 | #define KEY_F24 0x73U 164 | #define KEY_EXECUTE 0x74U 165 | #define KEY_HELP 0x75U 166 | #define KEY_MENU 0x76U 167 | #define KEY_SELECT 0x77U 168 | #define KEY_STOP 0x78U 169 | #define KEY_AGAIN 0x79U 170 | #define KEY_UNDO 0x7AU 171 | #define KEY_CUT 0x7BU 172 | #define KEY_COPY 0x7CU 173 | #define KEY_PASTE 0x7DU 174 | #define KEY_FIND 0x7EU 175 | #define KEY_MUTE 0x7FU 176 | #define KEY_VOLUME_UP 0x80U 177 | #define KEY_VOLUME_DOWN 0x81U 178 | #define KEY_LOCKING_CAPS_LOCK 0x82U 179 | #define KEY_LOCKING_NUM_LOCK 0x83U 180 | #define KEY_LOCKING_SCROLL_LOCK 0x84U 181 | #define KEY_KEYPAD_COMMA 0x85U 182 | #define KEY_KEYPAD_EQUAL_SIGN 0x86U 183 | #define KEY_INTERNATIONAL1 0x87U 184 | #define KEY_INTERNATIONAL2 0x88U 185 | #define KEY_INTERNATIONAL3 0x89U 186 | #define KEY_INTERNATIONAL4 0x8AU 187 | #define KEY_INTERNATIONAL5 0x8BU 188 | #define KEY_INTERNATIONAL6 0x8CU 189 | #define KEY_INTERNATIONAL7 0x8DU 190 | #define KEY_INTERNATIONAL8 0x8EU 191 | #define KEY_INTERNATIONAL9 0x8FU 192 | #define KEY_LANG1 0x90U 193 | #define KEY_LANG2 0x91U 194 | #define KEY_LANG3 0x92U 195 | #define KEY_LANG4 0x93U 196 | #define KEY_LANG5 0x94U 197 | #define KEY_LANG6 0x95U 198 | #define KEY_LANG7 0x96U 199 | #define KEY_LANG8 0x97U 200 | #define KEY_LANG9 0x98U 201 | #define KEY_ALTERNATE_ERASE 0x99U 202 | #define KEY_SYSREQ 0x9AU 203 | #define KEY_CANCEL 0x9BU 204 | #define KEY_CLEAR 0x9CU 205 | #define KEY_PRIOR 0x9DU 206 | #define KEY_RETURN 0x9EU 207 | #define KEY_SEPARATOR 0x9FU 208 | #define KEY_OUT 0xA0U 209 | #define KEY_OPER 0xA1U 210 | #define KEY_CLEAR_AGAIN 0xA2U 211 | #define KEY_CRSEL 0xA3U 212 | #define KEY_EXSEL 0xA4U 213 | #define KEY_KEYPAD_00 0xB0U 214 | #define KEY_KEYPAD_000 0xB1U 215 | #define KEY_THOUSANDS_SEPARATOR 0xB2U 216 | #define KEY_DECIMAL_SEPARATOR 0xB3U 217 | #define KEY_CURRENCY_UNIT 0xB4U 218 | #define KEY_CURRENCY_SUB_UNIT 0xB5U 219 | #define KEY_KEYPAD_OPARENTHESIS 0xB6U 220 | #define KEY_KEYPAD_CPARENTHESIS 0xB7U 221 | #define KEY_KEYPAD_OBRACE 0xB8U 222 | #define KEY_KEYPAD_CBRACE 0xB9U 223 | #define KEY_KEYPAD_TAB 0xBAU 224 | #define KEY_KEYPAD_BACKSPACE 0xBBU 225 | #define KEY_KEYPAD_A 0xBCU 226 | #define KEY_KEYPAD_B 0xBDU 227 | #define KEY_KEYPAD_C 0xBEU 228 | #define KEY_KEYPAD_D 0xBFU 229 | #define KEY_KEYPAD_E 0xC0U 230 | #define KEY_KEYPAD_F 0xC1U 231 | #define KEY_KEYPAD_XOR 0xC2U 232 | #define KEY_KEYPAD_CARET 0xC3U 233 | #define KEY_KEYPAD_PERCENT 0xC4U 234 | #define KEY_KEYPAD_LESS 0xC5U 235 | #define KEY_KEYPAD_GREATER 0xC6U 236 | #define KEY_KEYPAD_AMPERSAND 0xC7U 237 | #define KEY_KEYPAD_LOGICAL_AND 0xC8U 238 | #define KEY_KEYPAD_VERTICAL_BAR 0xC9U 239 | #define KEY_KEYPAD_LOGIACL_OR 0xCAU 240 | #define KEY_KEYPAD_COLON 0xCBU 241 | #define KEY_KEYPAD_NUMBER_SIGN 0xCCU 242 | #define KEY_KEYPAD_SPACE 0xCDU 243 | #define KEY_KEYPAD_AT 0xCEU 244 | #define KEY_KEYPAD_EXCLAMATION_MARK 0xCFU 245 | #define KEY_KEYPAD_MEMORY_STORE 0xD0U 246 | #define KEY_KEYPAD_MEMORY_RECALL 0xD1U 247 | #define KEY_KEYPAD_MEMORY_CLEAR 0xD2U 248 | #define KEY_KEYPAD_MEMORY_ADD 0xD3U 249 | #define KEY_KEYPAD_MEMORY_SUBTRACT 0xD4U 250 | #define KEY_KEYPAD_MEMORY_MULTIPLY 0xD5U 251 | #define KEY_KEYPAD_MEMORY_DIVIDE 0xD6U 252 | #define KEY_KEYPAD_PLUSMINUS 0xD7U 253 | #define KEY_KEYPAD_CLEAR 0xD8U 254 | #define KEY_KEYPAD_CLEAR_ENTRY 0xD9U 255 | #define KEY_KEYPAD_BINARY 0xDAU 256 | #define KEY_KEYPAD_OCTAL 0xDBU 257 | #define KEY_KEYPAD_DECIMAL 0xDCU 258 | #define KEY_KEYPAD_HEXADECIMAL 0xDDU 259 | #define KEY_LEFTCONTROL 0xE0U 260 | #define KEY_LEFTSHIFT 0xE1U 261 | #define KEY_LEFTALT 0xE2U 262 | #define KEY_LEFT_GUI 0xE3U 263 | #define KEY_RIGHTCONTROL 0xE4U 264 | #define KEY_RIGHTSHIFT 0xE5U 265 | #define KEY_RIGHTALT 0xE6U 266 | #define KEY_RIGHT_GUI 0xE7U 267 | 268 | #define MODIFERKEYS_LEFT_CTRL 0x01U 269 | #define MODIFERKEYS_LEFT_SHIFT 0x02U 270 | #define MODIFERKEYS_LEFT_ALT 0x04U 271 | #define MODIFERKEYS_LEFT_GUI 0x08U 272 | #define MODIFERKEYS_RIGHT_CTRL 0x10U 273 | #define MODIFERKEYS_RIGHT_SHIFT 0x20U 274 | #define MODIFERKEYS_RIGHT_ALT 0x40U 275 | #define MODIFERKEYS_RIGHT_GUI 0x80U 276 | 277 | /******************************************************************************* 278 | * API 279 | ******************************************************************************/ 280 | 281 | extern usb_status_t USB_DeviceHidKeyboardInit(usb_device_composite_struct_t *deviceComposite); 282 | extern usb_status_t USB_DeviceHidKeyboardCallback(class_handle_t handle, uint32_t event, void *param); 283 | extern usb_status_t USB_DeviceHidKeyboardSetConfigure(class_handle_t handle, uint8_t configure); 284 | extern usb_status_t USB_DeviceHidKeyboardSetInterface(class_handle_t handle, 285 | uint8_t interface, 286 | uint8_t alternateSetting); 287 | 288 | #endif /* __USB_DEVICE_HID_KEYBOARD_H__ */ 289 | -------------------------------------------------------------------------------- /usb/device/source/ehci/usb_device_ehci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The Clear BSD License 3 | * Copyright (c) 2015, Freescale Semiconductor, Inc. 4 | * Copyright 2016 NXP 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted (subject to the limitations in the disclaimer below) provided 9 | * that the following conditions are met: 10 | * 11 | * o Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * o Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or 16 | * other materials provided with the distribution. 17 | * 18 | * o Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef __USB_DEVICE_EHCI_H__ 36 | #define __USB_DEVICE_EHCI_H__ 37 | 38 | #include "usb_ehci.h" 39 | 40 | /*! 41 | * @addtogroup usb_device_controller_ehci_driver 42 | * @{ 43 | */ 44 | 45 | /******************************************************************************* 46 | * Definitions 47 | ******************************************************************************/ 48 | 49 | /*! @brief The maximum value of ISO type maximum packet size for HS in USB specification 2.0 */ 50 | #define USB_DEVICE_MAX_HS_ISO_MAX_PACKET_SIZE (1024U) 51 | 52 | /*! @brief The maximum value of interrupt type maximum packet size for HS in USB specification 2.0 */ 53 | #define USB_DEVICE_MAX_HS_INTERUPT_MAX_PACKET_SIZE (1024U) 54 | 55 | /*! @brief The maximum value of bulk type maximum packet size for HS in USB specification 2.0 */ 56 | #define USB_DEVICE_MAX_HS_BULK_MAX_PACKET_SIZE (512U) 57 | 58 | /*! @brief The maximum value of control type maximum packet size for HS in USB specification 2.0 */ 59 | #define USB_DEVICE_MAX_HS_CONTROL_MAX_PACKET_SIZE (64U) 60 | 61 | /*! @brief EHCI state structure */ 62 | typedef struct _usb_device_ehci_state_struct 63 | { 64 | usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object is belonged to */ 65 | USBHS_Type *registerBase; /*!< The base address of the register */ 66 | #if (defined(USB_DEVICE_CONFIG_LOW_POWER_MODE) && (USB_DEVICE_CONFIG_LOW_POWER_MODE > 0U)) 67 | USBPHY_Type *registerPhyBase; /*!< The base address of the PHY register */ 68 | #if (defined(FSL_FEATURE_SOC_USBNC_COUNT) && (FSL_FEATURE_SOC_USBNC_COUNT > 0U)) 69 | USBNC_Type *registerNcBase; /*!< The base address of the USBNC register */ 70 | #endif 71 | #endif 72 | usb_device_ehci_qh_struct_t *qh; /*!< The QH structure base address */ 73 | usb_device_ehci_dtd_struct_t *dtd; /*!< The DTD structure base address */ 74 | usb_device_ehci_dtd_struct_t *dtdFree; /*!< The idle DTD list head */ 75 | usb_device_ehci_dtd_struct_t 76 | *dtdHard[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list head for each endpoint */ 77 | usb_device_ehci_dtd_struct_t 78 | *dtdTail[USB_DEVICE_CONFIG_ENDPOINTS * 2]; /*!< The transferring DTD list tail for each endpoint */ 79 | int8_t dtdCount; /*!< The idle DTD node count */ 80 | uint8_t endpointCount; /*!< The endpoint number of EHCI */ 81 | uint8_t isResetting; /*!< Whether a PORT reset is occurring or not */ 82 | uint8_t controllerId; /*!< Controller ID */ 83 | uint8_t speed; /*!< Current speed of EHCI */ 84 | uint8_t isSuspending; /*!< Is suspending of the PORT */ 85 | } usb_device_ehci_state_struct_t; 86 | 87 | #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U)) && \ 88 | (defined(FSL_FEATURE_SOC_USBHSDCD_COUNT) && (FSL_FEATURE_SOC_USBHSDCD_COUNT > 0U)) 89 | typedef struct _usb_device_dcd_state_struct 90 | { 91 | usb_device_struct_t *deviceHandle; /*!< Device handle used to identify the device object belongs to */ 92 | USBHSDCD_Type *dcdRegisterBase; /*!< The base address of the dcd module */ 93 | uint8_t controllerId; /*!< Controller ID */ 94 | } usb_device_dcd_state_struct_t; 95 | #endif 96 | 97 | #if defined(__cplusplus) 98 | extern "C" { 99 | #endif 100 | 101 | /*! 102 | * @name USB device EHCI functions 103 | * @{ 104 | */ 105 | 106 | /******************************************************************************* 107 | * API 108 | ******************************************************************************/ 109 | 110 | /*! 111 | * @brief Initializes the USB device EHCI instance. 112 | * 113 | * This function initializes the USB device EHCI module specified by the controllerId. 114 | * 115 | * @param[in] controllerId The controller ID of the USB IP. See the enumeration type usb_controller_index_t. 116 | * @param[in] handle Pointer of the device handle used to identify the device object is belonged to. 117 | * @param[out] ehciHandle An out parameter used to return the pointer of the device EHCI handle to the caller. 118 | * 119 | * @return A USB error code or kStatus_USB_Success. 120 | */ 121 | usb_status_t USB_DeviceEhciInit(uint8_t controllerId, 122 | usb_device_handle handle, 123 | usb_device_controller_handle *ehciHandle); 124 | 125 | /*! 126 | * @brief Deinitializes the USB device EHCI instance. 127 | * 128 | * This function deinitializes the USB device EHCI module. 129 | * 130 | * @param[in] ehciHandle Pointer of the device EHCI handle. 131 | * 132 | * @return A USB error code or kStatus_USB_Success. 133 | */ 134 | usb_status_t USB_DeviceEhciDeinit(usb_device_controller_handle ehciHandle); 135 | 136 | /*! 137 | * @brief Sends data through a specified endpoint. 138 | * 139 | * This function sends data through a specified endpoint. 140 | * 141 | * @param[in] ehciHandle Pointer of the device EHCI handle. 142 | * @param[in] endpointAddress Endpoint index. 143 | * @param[in] buffer The memory address to hold the data need to be sent. 144 | * @param[in] length The data length to be sent. 145 | * 146 | * @return A USB error code or kStatus_USB_Success. 147 | * 148 | * @note The return value means whether the sending request is successful or not. The transfer completion is indicated 149 | * by the 150 | * corresponding callback function. 151 | * Currently, only one transfer request can be supported for a specific endpoint. 152 | * If there is a specific requirement to support multiple transfer requests for a specific endpoint, the application 153 | * should implement a queue in the application level. 154 | * The subsequent transfer can begin only when the previous transfer is done (a notification is received through the 155 | * endpoint 156 | * callback). 157 | */ 158 | usb_status_t USB_DeviceEhciSend(usb_device_controller_handle ehciHandle, 159 | uint8_t endpointAddress, 160 | uint8_t *buffer, 161 | uint32_t length); 162 | 163 | /*! 164 | * @brief Receive data through a specified endpoint. 165 | * 166 | * This function Receives data through a specified endpoint. 167 | * 168 | * @param[in] ehciHandle Pointer of the device EHCI handle. 169 | * @param[in] endpointAddress Endpoint index. 170 | * @param[in] buffer The memory address to save the received data. 171 | * @param[in] length The data length want to be received. 172 | * 173 | * @return A USB error code or kStatus_USB_Success. 174 | * 175 | * @note The return value just means if the receiving request is successful or not; the transfer done is notified by the 176 | * corresponding callback function. 177 | * Currently, only one transfer request can be supported for one specific endpoint. 178 | * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application 179 | * should implement a queue in the application level. 180 | * The subsequent transfer could begin only when the previous transfer is done (get notification through the endpoint 181 | * callback). 182 | */ 183 | usb_status_t USB_DeviceEhciRecv(usb_device_controller_handle ehciHandle, 184 | uint8_t endpointAddress, 185 | uint8_t *buffer, 186 | uint32_t length); 187 | 188 | /*! 189 | * @brief Cancels the pending transfer in a specified endpoint. 190 | * 191 | * The function is used to cancel the pending transfer in a specified endpoint. 192 | * 193 | * @param[in] ehciHandle Pointer of the device EHCI handle. 194 | * @param[in] ep Endpoint address, bit7 is the direction of endpoint, 1U - IN, 0U - OUT. 195 | * 196 | * @return A USB error code or kStatus_USB_Success. 197 | */ 198 | usb_status_t USB_DeviceEhciCancel(usb_device_controller_handle ehciHandle, uint8_t ep); 199 | 200 | /*! 201 | * @brief Controls the status of the selected item. 202 | * 203 | * The function is used to control the status of the selected item. 204 | * 205 | * @param[in] ehciHandle Pointer of the device EHCI handle. 206 | * @param[in] type The selected item. See enumeration type usb_device_control_type_t. 207 | * @param[in,out] param The parameter type is determined by the selected item. 208 | * 209 | * @return A USB error code or kStatus_USB_Success. 210 | */ 211 | usb_status_t USB_DeviceEhciControl(usb_device_controller_handle ehciHandle, 212 | usb_device_control_type_t type, 213 | void *param); 214 | 215 | /*! @} */ 216 | 217 | #if defined(__cplusplus) 218 | } 219 | #endif 220 | 221 | /*! @} */ 222 | 223 | #endif /* __USB_DEVICE_EHCI_H__ */ 224 | --------------------------------------------------------------------------------