diff --git a/examples/device/device_virtual_com/src/main.c b/examples/device/device_virtual_com/src/main.c
index b72c0ee22..3ee3a74d3 100644
--- a/examples/device/device_virtual_com/src/main.c
+++ b/examples/device/device_virtual_com/src/main.c
@@ -114,7 +114,7 @@ void led_blinking_task(void)
{
enum { BLINK_INTEVAL = 1000 };
- static uint32_t led_on_mask = 0;
+ static bool led_state = false;
static uint32_t last_blink = 0;
// not enough time
@@ -122,8 +122,8 @@ void led_blinking_task(void)
last_blink += BLINK_INTEVAL;
- board_leds(led_on_mask, 1 - led_on_mask);
- led_on_mask = 1 - led_on_mask; // toggle
+ board_led_control(BOARD_LED0, led_state);
+ led_state = 1 - led_state; // toggle
}
//--------------------------------------------------------------------+
diff --git a/examples/device/device_virtual_com/xpresso/.project b/examples/device/device_virtual_com/xpresso/.project
index ecd387b48..bd43de66d 100644
--- a/examples/device/device_virtual_com/xpresso/.project
+++ b/examples/device/device_virtual_com/xpresso/.project
@@ -40,4 +40,24 @@
PARENT-4-PROJECT_LOC/tinyusb
+
+
+ 1520932840443
+
+ 22
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.d
+
+
+
+ 1520932840444
+
+ 22
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.o
+
+
+
diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c
index 65a21ff77..48e7f1cce 100644
--- a/examples/device/nrf52840/src/main.c
+++ b/examples/device/nrf52840/src/main.c
@@ -63,7 +63,7 @@ int main(void)
board_init();
print_greeting();
- //tusb_init();
+ tusb_init();
while (1)
{
@@ -114,7 +114,7 @@ void led_blinking_task(void)
{
enum { BLINK_INTEVAL = 1000 };
- static uint32_t led_on_mask = 0;
+ static bool led_state = false;
static uint32_t last_blink = 0;
// not enough time
@@ -122,8 +122,8 @@ void led_blinking_task(void)
last_blink += BLINK_INTEVAL;
- board_leds(led_on_mask, 1 - led_on_mask);
- led_on_mask = 1 - led_on_mask; // toggle
+ board_led_control(BOARD_LED0, led_state);
+ led_state = 1 - led_state; // toggle
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/board.h b/hw/bsp/board.h
index ee986facd..aaedf27d6 100644
--- a/hw/bsp/board.h
+++ b/hw/bsp/board.h
@@ -131,13 +131,21 @@
/// Initialize all required peripherals on board including uart, led, buttons etc ...
void board_init(void);
-/** \brief Turns on and off leds on the board
- * \param[in] on_mask Bitmask for LED's numbers is turning ON
- * \param[out] off_mask Bitmask for LED's numbers is turning OFF
- * \note the \a on_mask is more priority then \a off_mask, if an led's number is present on both.
- * It will be turned ON.
- */
-void board_leds(uint32_t on_mask, uint32_t off_mask);
+
+#define BOARD_LED0 0
+
+void board_led_control(uint32_t led_id, bool state);
+
+static inline void board_led_on(uint32_t led_id)
+{
+ board_led_control(led_id, true);
+}
+
+static inline void board_led_off(uint32_t led_id)
+{
+ board_led_control(led_id, false);
+}
+
/** \brief Get the current state of the buttons on the board
* \return Bitmask where a '1' means active (pressed), a '0' means inactive.
@@ -156,19 +164,6 @@ void board_uart_putchar(uint8_t c);
/** @} */
-#if 0
-//------------- Board Application -------------//
-void led_blinking_task(void* param);
-
-/// Initialize the LED blinking task application. The initial blinking rate is 1 Hert (1 per second)
-void led_blinking_init(void);
-
-/** \brief Change the blinking rate.
- * \param[in] ms The interval between on and off.
- */
-void led_blinking_set_interval(uint32_t ms);
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/board_ea4357.c
index 1aec84871..bfd100e1e 100644
--- a/hw/bsp/ea4357/board_ea4357.c
+++ b/hw/bsp/ea4357/board_ea4357.c
@@ -116,9 +116,11 @@ void board_init(void)
//--------------------------------------------------------------------+
// LEDS
//--------------------------------------------------------------------+
-void board_leds(uint32_t on_mask, uint32_t off_mask)
+void board_led_control(uint32_t id, bool state)
{
- pca9532_setLeds( on_mask << 8, off_mask << 8);
+ uint16_t on_mask = state ? (1 << id) : 0;
+ uint16_t off_mask = state ? 0 : (1 << id);
+ pca9532_setLeds( on_mask << 8, off_mask << 8 );
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/ea4357/board_ea4357.h b/hw/bsp/ea4357/board_ea4357.h
index e241a2bfd..518b37abc 100644
--- a/hw/bsp/ea4357/board_ea4357.h
+++ b/hw/bsp/ea4357/board_ea4357.h
@@ -53,6 +53,8 @@
#include "oem_base_board/pca9532.h" // LEDs
+#define BOARD_LED_NUM 1
+
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c
index 76d7ad06d..701e05d84 100644
--- a/hw/bsp/pca10056/board_pca10056.c
+++ b/hw/bsp/pca10056/board_pca10056.c
@@ -43,6 +43,7 @@
*------------------------------------------------------------------*/
#define LED_1 13
#define LED_STATE_ON 0
+#define LED_STATE_OFF (1-LED_STATE_ON)
/*------------------------------------------------------------------*/
@@ -60,17 +61,10 @@ void board_init(void)
NVIC_EnableIRQ(SysTick_IRQn);
}
-void board_leds(uint32_t on_mask, uint32_t off_mask)
+void board_led_control(uint32_t led_id, bool state)
{
- if (on_mask)
- {
- nrf_gpio_pin_write(LED_1, LED_STATE_ON);
- }
-
- if ( off_mask)
- {
- nrf_gpio_pin_write(LED_1, 1-LED_STATE_ON);
- }
+ (void) led_id;
+ nrf_gpio_pin_write(LED_1, state ? LED_STATE_ON : LED_STATE_OFF);
}
uint32_t board_buttons(void)
diff --git a/hw/bsp/pca10056/board_pca10056.h b/hw/bsp/pca10056/board_pca10056.h
index bc8d1d7cb..cb477aab8 100644
--- a/hw/bsp/pca10056/board_pca10056.h
+++ b/hw/bsp/pca10056/board_pca10056.h
@@ -42,6 +42,7 @@
extern "C" {
#endif
+#define BOARD_LED_NUM 1
#ifdef __cplusplus
}
diff --git a/hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c b/hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c
new file mode 100644
index 000000000..e70bde105
--- /dev/null
+++ b/hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.c
@@ -0,0 +1,67 @@
+/**************************************************************************/
+/*!
+ @file dcd_nrf52.c
+ @author hathach
+
+ @section LICENSE
+
+ Software License Agreement (BSD License)
+
+ Copyright (c) 2018, hathach (tinyusb.org)
+ 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. Neither the name of the copyright holders nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
+*/
+/**************************************************************************/
+
+// TODO remove
+#include "nrf.h"
+#include "nrf_power.h"
+#include "nrf_drv_usbd.h"
+
+/*------------------------------------------------------------------*/
+/* MACRO TYPEDEF CONSTANT ENUM
+ *------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------*/
+/* VARIABLE DECLARATION
+ *------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------*/
+/* Controller API
+ *------------------------------------------------------------------*/
+bool tusb_dcd_init (uint8_t port)
+{
+ // TODO USB power detection
+ nrf_power_int_enable(
+ NRF_POWER_INT_USBDETECTED_MASK |
+ NRF_POWER_INT_USBREMOVED_MASK |
+ NRF_POWER_INT_USBPWRRDY_MASK);
+
+ nrf_drv_usbd_enable();
+}
+
+void tusb_dcd_connect (uint8_t port);
+void tusb_dcd_disconnect (uint8_t port);
+void tusb_dcd_set_address (uint8_t port, uint8_t dev_addr);
+void tusb_dcd_set_config (uint8_t port, uint8_t config_num);
diff --git a/hw/bsp/board.c b/hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.h
similarity index 67%
rename from hw/bsp/board.c
rename to hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.h
index b8b795d60..7d830da6f 100644
--- a/hw/bsp/board.c
+++ b/hw/mcu/nordic/nrf52/tusb_port/dcd_nrf52.h
@@ -1,13 +1,13 @@
/**************************************************************************/
/*!
- @file board.c
- @author hathach (tinyusb.org)
+ @file dcd_nrf52.h
+ @author hathach
@section LICENSE
Software License Agreement (BSD License)
- Copyright (c) 2013, hathach (tinyusb.org)
+ Copyright (c) 2018, hathach (tinyusb.org)
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -26,38 +26,25 @@
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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
+ (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
+ (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 tinyusb stack.
*/
/**************************************************************************/
+#ifndef DCD_NRF52_H_
+#define DCD_NRF52_H_
-#include "board.h"
-//#include "app_os_prio.h"
-#if TUSB_CFG_OS == TUSB_OS_NONE
-
-volatile uint32_t system_ticks = 0;
-
-void SysTick_Handler (void)
-{
- system_ticks++;
-}
-
-uint32_t tusb_hal_tick_get(void)
-{
- return system_ticks;
-}
+#ifdef __cplusplus
+ extern "C" {
#endif
-// TODO remove legacy cmsis code
-void check_failed(uint8_t *file, uint32_t line)
-{
- (void) file;
- (void) line;
-}
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif /* DCD_NRF52_H_ */
diff --git a/hw/mcu/nordic/nrf52/tusb_port/hal_nrf52.c b/hw/mcu/nordic/nrf52/tusb_port/hal_nrf52.c
index c2fb42dc5..13e5de46f 100644
--- a/hw/mcu/nordic/nrf52/tusb_port/hal_nrf52.c
+++ b/hw/mcu/nordic/nrf52/tusb_port/hal_nrf52.c
@@ -62,16 +62,16 @@ void SysTick_Handler (void)
bool tusb_hal_init(void)
{
-
+ return true;
}
-void tusb_hal_init_enable(uint8_t port)
+void tusb_hal_int_enable(uint8_t port)
{
(void) port;
NVIC_EnableIRQ(USBD_IRQn);
}
-void tusb_hal_init_disable(uint8_t port)
+void tusb_hal_int_disable(uint8_t port)
{
(void) port;
NVIC_DisableIRQ(USBD_IRQn);
diff --git a/hw/mcu/nxp/lpc11uxx/hal_mcu/hal_lpc11uxx.c b/hw/mcu/nxp/lpc11uxx/hal_mcu/hal_lpc11uxx.c
index 0c76ac55b..d98f7a72f 100644
--- a/hw/mcu/nxp/lpc11uxx/hal_mcu/hal_lpc11uxx.c
+++ b/hw/mcu/nxp/lpc11uxx/hal_mcu/hal_lpc11uxx.c
@@ -41,13 +41,13 @@
#if TUSB_CFG_MCU == MCU_LPC11UXX
-void tusb_hal_init_enable(uint8_t port)
+void tusb_hal_int_enable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_EnableIRQ(USB_IRQn);
}
-void tusb_hal_init_disable(uint8_t port)
+void tusb_hal_int_disable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_DisableIRQ(USB_IRQn);
diff --git a/hw/mcu/nxp/lpc13uxx/hal_mcu/hal_lpc13uxx.c b/hw/mcu/nxp/lpc13uxx/hal_mcu/hal_lpc13uxx.c
index 18f5c1a39..d8d35c41b 100644
--- a/hw/mcu/nxp/lpc13uxx/hal_mcu/hal_lpc13uxx.c
+++ b/hw/mcu/nxp/lpc13uxx/hal_mcu/hal_lpc13uxx.c
@@ -41,13 +41,13 @@
#if TUSB_CFG_MCU == MCU_LPC13UXX
-void tusb_hal_init_enable(uint8_t port)
+void tusb_hal_int_enable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_EnableIRQ(USB_IRQ_IRQn);
}
-void tusb_hal_init_disable(uint8_t port)
+void tusb_hal_int_disable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_DisableIRQ(USB_IRQ_IRQn);
diff --git a/hw/mcu/nxp/lpc175x_6x/hal_mcu/hal_lpc175x_6x.c b/hw/mcu/nxp/lpc175x_6x/hal_mcu/hal_lpc175x_6x.c
index aff018be9..6951b0b0d 100644
--- a/hw/mcu/nxp/lpc175x_6x/hal_mcu/hal_lpc175x_6x.c
+++ b/hw/mcu/nxp/lpc175x_6x/hal_mcu/hal_lpc175x_6x.c
@@ -41,13 +41,13 @@
#if TUSB_CFG_MCU == MCU_LPC175X_6X
-void tusb_hal_init_enable(uint8_t port)
+void tusb_hal_int_enable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_EnableIRQ(USB_IRQn);
}
-void tusb_hal_init_disable(uint8_t port)
+void tusb_hal_int_disable(uint8_t port)
{
(void) port; // discard compiler's warning
NVIC_DisableIRQ(USB_IRQn);
@@ -111,4 +111,10 @@ void USB_IRQHandler(void)
#endif
}
+void check_failed(uint8_t *file, uint32_t line)
+{
+ (void) file;
+ (void) line;
+}
+
#endif
diff --git a/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c b/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c
index 34a83e670..b54ea1280 100644
--- a/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c
+++ b/hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c
@@ -160,6 +160,9 @@ bool tusb_dcd_init(uint8_t port)
lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0
lpc_usb->USBCMD_D |= BIT_(0); // connect
+ // enable interrupt
+ NVIC_EnableIRQ(port ? USB1_IRQn : USB0_IRQn);
+
return true;
}
diff --git a/hw/mcu/nxp/lpc43xx/tusb_port/hal_lpc43xx.c b/hw/mcu/nxp/lpc43xx/tusb_port/hal_lpc43xx.c
index b86f5024e..bd62d9de3 100644
--- a/hw/mcu/nxp/lpc43xx/tusb_port/hal_lpc43xx.c
+++ b/hw/mcu/nxp/lpc43xx/tusb_port/hal_lpc43xx.c
@@ -53,6 +53,22 @@ enum {
LPC43XX_USBMODE_VBUS_HIGH = 1
};
+#if TUSB_CFG_OS == TUSB_OS_NONE
+
+volatile uint32_t system_ticks = 0;
+
+void SysTick_Handler (void)
+{
+ system_ticks++;
+}
+
+uint32_t tusb_hal_tick_get(void)
+{
+ return system_ticks;
+}
+
+#endif
+
void tusb_hal_dbg_breakpoint(void)
{
// M0 cannot check if debugger is attached or not
@@ -65,12 +81,12 @@ void tusb_hal_dbg_breakpoint(void)
#endif
}
-void tusb_hal_init_enable(uint8_t port)
+void tusb_hal_int_enable(uint8_t port)
{
NVIC_EnableIRQ(port ? USB1_IRQn : USB0_IRQn);
}
-void tusb_hal_init_disable(uint8_t port)
+void tusb_hal_int_disable(uint8_t port)
{
NVIC_DisableIRQ(port ? USB1_IRQn : USB0_IRQn);
}
@@ -167,4 +183,11 @@ void USB1_IRQHandler(void)
}
#endif
+
+void check_failed(uint8_t *file, uint32_t line)
+{
+ (void) file;
+ (void) line;
+}
+
#endif
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 229c51b99..f640c470a 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -204,11 +204,11 @@ static inline void osal_queue_flush(osal_queue_t const queue_hdl)
else\
return TUSB_ERROR_OSAL_WAITING;\
} else{\
- /*TODO mutex lock tusb_hal_init_disable */\
+ /*TODO mutex lock tusb_hal_int_disable */\
memcpy(p_data, queue_hdl->buffer + (queue_hdl->rd_idx * queue_hdl->item_size), queue_hdl->item_size);\
queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
queue_hdl->count--;\
- /*TODO mutex unlock tusb_hal_init_enable */\
+ /*TODO mutex unlock tusb_hal_int_enable */\
*(p_error) = TUSB_ERROR_NONE;\
}\
}while(0)
@@ -258,7 +258,7 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
else\
return TUSB_ERROR_OSAL_WAITING;\
} else{\
- if (sem_hdl->count) sem_hdl->count--; /*TODO mutex tusb_hal_init_disable consideration*/\
+ if (sem_hdl->count) sem_hdl->count--; /*TODO mutex tusb_hal_int_disable consideration*/\
*(p_error) = TUSB_ERROR_NONE;\
}\
}while(0)
diff --git a/tinyusb/tusb.c b/tinyusb/tusb.c
index b9af2092f..29f1ade95 100644
--- a/tinyusb/tusb.c
+++ b/tinyusb/tusb.c
@@ -52,14 +52,6 @@ tusb_error_t tusb_init(void)
ASSERT_STATUS ( usbd_init() ); // device stack init
#endif
-#if (TUSB_CFG_CONTROLLER_0_MODE)
- tusb_hal_init_enable(0);
-#endif
-
-#if (TUSB_CFG_CONTROLLER_1_MODE)
- tusb_hal_init_enable(1);
-#endif
-
return TUSB_ERROR_NONE;
}
diff --git a/tinyusb/tusb_dcd.h b/tinyusb/tusb_dcd.h
index 8776c3348..084ab04b5 100644
--- a/tinyusb/tusb_dcd.h
+++ b/tinyusb/tusb_dcd.h
@@ -43,8 +43,7 @@
#ifndef _TUSB_DCD_H_
#define _TUSB_DCD_H_
-#include
-#include
+#include "common/tusb_common.h"
#ifdef __cplusplus
extern "C" {
diff --git a/tinyusb/tusb_hal.h b/tinyusb/tusb_hal.h
index b36cb29f3..b85763cd4 100644
--- a/tinyusb/tusb_hal.h
+++ b/tinyusb/tusb_hal.h
@@ -46,12 +46,7 @@ extern "C" {
//--------------------------------------------------------------------+
// INCLUDES
//--------------------------------------------------------------------+
-#include "tusb_option.h"
-#include
-#include
-
-#include "common/tusb_errors.h"
-#include "common/compiler/compiler.h"
+#include "common/tusb_common.h"
//--------------------------------------------------------------------+
// HAL API
@@ -73,12 +68,12 @@ bool tusb_hal_init(void);
/** \brief Enable USB Interrupt on a specific USB Controller
* \param[in] port is a zero-based index to identify USB controller's ID
*/
-void tusb_hal_init_enable(uint8_t port);
+void tusb_hal_int_enable(uint8_t port);
/** \brief Disable USB Interrupt on a specific USB Controller
* \param[in] port is a zero-based index to identify USB controller's ID
*/
-void tusb_hal_init_disable(uint8_t port);
+void tusb_hal_int_disable(uint8_t port);
uint32_t tusb_hal_tick_get(void);