From 82820a206666a6415148b0d26985ac5c7a9eb279 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 4 Dec 2012 14:12:48 +0700 Subject: [PATCH] able to build with lpc43xx demo --- .cproject | 812 ++++++++++++++++++++- tinyusb/class/cdc.c | 2 +- tinyusb/class/cdc.h | 3 + tinyusb/class/hid.c | 2 +- tinyusb/class/hid.h | 18 +- tinyusb/common/arch/arch.h | 3 +- tinyusb/common/arch/arch_lpc134x.h | 2 - tinyusb/common/arch/arch_lpc43xx.h | 2 + tinyusb/common/common.h | 2 +- tinyusb/device/dcd.c | 2 + tinyusb/{common/arch => hal}/hal.h | 0 tinyusb/{common/arch => hal}/hal_lpc134x.c | 0 tinyusb/hal/hal_lpc43xx.c | 54 ++ tinyusb/tusb_cfg.h | 2 +- 14 files changed, 887 insertions(+), 17 deletions(-) rename tinyusb/{common/arch => hal}/hal.h (100%) rename tinyusb/{common/arch => hal}/hal_lpc134x.c (100%) create mode 100644 tinyusb/hal/hal_lpc43xx.c diff --git a/.cproject b/.cproject index eda7dda78..6670b0b24 100644 --- a/.cproject +++ b/.cproject @@ -4,7 +4,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -801,6 +801,814 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tinyusb/class/cdc.c b/tinyusb/class/cdc.c index d62b7aa7d..a163be13a 100644 --- a/tinyusb/class/cdc.c +++ b/tinyusb/class/cdc.c @@ -38,7 +38,7 @@ #include "cdc.h" #include "common/fifo.h" -#ifdef CFG_CLASS_CDC +#if defined CFG_CLASS_CDC && defined CFG_TUSB_DEVICE static USBD_HANDLE_T g_hCdc; static CDC_LINE_CODING line_coding; diff --git a/tinyusb/class/cdc.h b/tinyusb/class/cdc.h index 5bcad17a0..e4660d9b0 100644 --- a/tinyusb/class/cdc.h +++ b/tinyusb/class/cdc.h @@ -93,6 +93,7 @@ uint16_t tusb_cdc_send(uint8_t* buffer, uint16_t count); */ uint16_t tusb_cdc_recv(uint8_t* buffer, uint16_t max); +#ifdef DEVICE_ROMDRIVER /** \brief initialize cdc driver * * \param[in] para1 @@ -111,3 +112,5 @@ TUSB_Error_t tusb_cdc_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c */ TUSB_Error_t tusb_cdc_configured(USBD_HANDLE_T hUsb); #endif + +#endif diff --git a/tinyusb/class/hid.c b/tinyusb/class/hid.c index 76a93d572..659765c1a 100644 --- a/tinyusb/class/hid.c +++ b/tinyusb/class/hid.c @@ -37,7 +37,7 @@ #include "hid.h" -#ifdef TUSB_CLASS_HID +#if defined TUSB_CLASS_HID && defined CFG_TUSB_DEVICE #ifdef CFG_CLASS_HID_KEYBOARD USB_HID_KeyboardReport_t hid_keyboard_report; diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h index 4e56ffb4e..b5516e259 100644 --- a/tinyusb/class/hid.h +++ b/tinyusb/class/hid.h @@ -51,6 +51,10 @@ #ifndef _TUSB_HID_H_ #define _TUSB_HID_H_ +#ifdef __cplusplus + extern "C" { +#endif + // TODO refractor #include "common/common.h" #include "device/dcd.h" @@ -61,24 +65,24 @@ * * Type define for a standard Boot Protocol Mouse report */ -typedef PRE_PACK struct +typedef ATTR_PREPACKED struct { uint8_t Button; /**< Button mask for currently pressed buttons in the mouse. */ int8_t X; /**< Current delta X movement of the mouse. */ int8_t Y; /**< Current delta Y movement on the mouse. */ -} POST_PACK USB_HID_MouseReport_t; +} ATTR_PACKED USB_HID_MouseReport_t; /** \struct USB_HID_KeyboardReport_t * \brief Standard HID Boot Protocol Keyboard Report. * * Type define for a standard Boot Protocol Keyboard report */ -typedef PRE_PACK struct +typedef ATTR_PREPACKED struct { uint8_t Modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */ uint8_t Reserved; /**< Reserved for OEM use, always set to 0. */ uint8_t KeyCode[6]; /**< Key codes of the currently pressed keys. */ -} POST_PACK USB_HID_KeyboardReport_t; +} ATTR_PACKED USB_HID_KeyboardReport_t; /** \enum USB_HID_MOUSE_BUTTON_CODE * \brief Button codes for HID mouse @@ -148,10 +152,7 @@ enum USB_HID_LOCAL_CODE HID_Local_Turkish_F }; -#ifdef __cplusplus - extern "C" { -#endif - +#ifdef DEVICE_ROMDRIVER /** \brief Initialize HID driver * * \param[in] para1 @@ -187,6 +188,7 @@ TUSB_Error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], ui * \note */ TUSB_Error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y); +#endif #ifdef __cplusplus } diff --git a/tinyusb/common/arch/arch.h b/tinyusb/common/arch/arch.h index aa806d3b0..1cc3fc83d 100644 --- a/tinyusb/common/arch/arch.h +++ b/tinyusb/common/arch/arch.h @@ -51,8 +51,9 @@ #ifndef _TUSB_ARCH_H_ #define _TUSB_ARCH_H_ -#define ARCH_LPC134X +//#define ARCH_LPC134X //#define ARCH_LPC11XX +#define ARCH_LPC43XX #define ENDIAN_LITTLE ///< MCU Endian #define ALIGNMENT (4) ///< MCU Alignment diff --git a/tinyusb/common/arch/arch_lpc134x.h b/tinyusb/common/arch/arch_lpc134x.h index b43bcea7c..1779b784b 100644 --- a/tinyusb/common/arch/arch_lpc134x.h +++ b/tinyusb/common/arch/arch_lpc134x.h @@ -54,8 +54,6 @@ #include "arm_mx.h" #include "LPC13Uxx.h" -#include "system_LPC13Uxx.h" - #endif /* _TUSB_ARCH_LPC134_X_H_ */ diff --git a/tinyusb/common/arch/arch_lpc43xx.h b/tinyusb/common/arch/arch_lpc43xx.h index a83d18c94..f96bbb0dc 100644 --- a/tinyusb/common/arch/arch_lpc43xx.h +++ b/tinyusb/common/arch/arch_lpc43xx.h @@ -53,6 +53,8 @@ //#define ARM_M0 #include "arm_mx.h" +#include "LPC43xx.h" +#include "lpc43xx_cgu.h" #endif /* _TUSB_ARCH_LPC43XX_H_ */ diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 97bc32ae3..d073b8cca 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -63,7 +63,7 @@ #include "tusb_cfg.h" #include "arch/arch.h" -#include "arch/hal.h" +#include "hal/hal.h" #include "compiler/compiler.h" #include "errors.h" #include "core/tusb_types.h" diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c index 480db2119..b3b97faf1 100644 --- a/tinyusb/device/dcd.c +++ b/tinyusb/device/dcd.c @@ -86,6 +86,7 @@ ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb) TUSB_Error_t dcd_init(uint8_t coreid) { +#ifdef DEVICE_ROMDRIVER // TODO refractor later /* ROM DRIVER INIT */ uint32_t membase = (uint32_t) usb_RomDriver_buffer; uint32_t memsize = USB_ROM_SIZE; @@ -139,6 +140,7 @@ TUSB_Error_t dcd_init(uint8_t coreid) /* Perform USB soft connect */ USBD_API->hw->Connect(g_hUsb, 1); +#endif return tERROR_NONE; } diff --git a/tinyusb/common/arch/hal.h b/tinyusb/hal/hal.h similarity index 100% rename from tinyusb/common/arch/hal.h rename to tinyusb/hal/hal.h diff --git a/tinyusb/common/arch/hal_lpc134x.c b/tinyusb/hal/hal_lpc134x.c similarity index 100% rename from tinyusb/common/arch/hal_lpc134x.c rename to tinyusb/hal/hal_lpc134x.c diff --git a/tinyusb/hal/hal_lpc43xx.c b/tinyusb/hal/hal_lpc43xx.c new file mode 100644 index 000000000..2291e7532 --- /dev/null +++ b/tinyusb/hal/hal_lpc43xx.c @@ -0,0 +1,54 @@ +/* + * hal_lpc43xx.c + * + * Created on: Dec 4, 2012 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the tiny usb stack. + */ + +#include "common/common.h" + +#ifdef ARCH_LPC43XX + +TUSB_Error_t hal_init() +{ + /* Set up USB0 clock */ + CGU_EnableEntity(CGU_CLKSRC_PLL0, DISABLE); /* Disable PLL first */ + ASSERT_MESSAGE( CGU_SetPLL0() == CGU_ERROR_SUCCESS, tERROR_FAILED, "set PLL failed"); /* the usb core require output clock = 480MHz */ + CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_CLKSRC_PLL0); + CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE); /* Enable PLL after all setting is done */ + LPC_CREG->CREG0 &= ~(1<<5); /* Turn on the phy */ + + return tERROR_NONE; +} + +#endif diff --git a/tinyusb/tusb_cfg.h b/tinyusb/tusb_cfg.h index b31246eac..6cda15830 100644 --- a/tinyusb/tusb_cfg.h +++ b/tinyusb/tusb_cfg.h @@ -60,7 +60,7 @@ #define CFG_TUSB_HOST /// Enable Device Support -#define CFG_TUSB_DEVICE +//#define CFG_TUSB_DEVICE /// Enable CDC Support #define CFG_CLASS_CDC