diff --git a/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.c b/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.c
index 8c1a92247..099b953ba 100644
--- a/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.c
+++ b/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.c
@@ -63,11 +63,14 @@ void board_init(void)
//--------------------------------------------------------------------+
// LEDS
//--------------------------------------------------------------------+
-void board_leds(uint32_t mask, uint32_t state)
+void board_leds(uint32_t on_mask, uint32_t off_mask)
{
- if (mask)
+ if (on_mask & BIT_(0))
{
- GPIOSetBitValue(CFG_LED_PORT, CFG_LED_PIN, mask & state ? CFG_LED_ON : CFG_LED_OFF);
+ GPIOSetBitValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
+ }else if (off_mask & BIT_(0))
+ {
+ GPIOSetBitValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);
}
}
diff --git a/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.h b/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.h
index 8a5ceafba..bca6e9ab0 100644
--- a/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.h
+++ b/demos/bsp/boards/lpcxpresso/board_lpcxpresso1347.h
@@ -65,7 +65,7 @@
#define CFG_LED_ON (1)
#define CFG_LED_OFF (0)
-#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
+#define CFG_PRINTF_TARGET PRINTF_TARGET_DEBUG_CONSOLE
#ifdef __cplusplus
}
diff --git a/demos/device/keyboard/.cproject b/demos/device/keyboard/.cproject
index dd8283469..71034c4cd 100644
--- a/demos/device/keyboard/.cproject
+++ b/demos/device/keyboard/.cproject
@@ -30,7 +30,7 @@
-
+
-
+
-
+
@@ -72,7 +72,7 @@
-
+
@@ -682,7 +682,7 @@
-
+
-
+
-
+
@@ -1337,7 +1337,7 @@
-
+
-
+
-
+
@@ -1970,82 +1970,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<TargetConfig>
-<Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="1"/>
-<infoList vendor="NXP"><info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" stub="crt_emu_lpc18_43_nxp"><chip><name>LPC4357</name>
-<family>LPC43xx</family>
+<Properties property_0="" property_3="NXP" property_4="LPC1347" property_count="5" version="1"/>
+<infoList vendor="NXP"><info chip="LPC1347" match_id="0x08020543" name="LPC1347" stub="crt_emu_lpc11_13_nxp"><chip><name>LPC1347</name>
+<family>LPC13xx (12bit ADC)</family>
<vendor>NXP (formerly Philips)</vendor>
<reset board="None" core="Real" sys="Real"/>
-<clock changeable="TRUE" freq="20MHz" is_accurate="TRUE"/>
+<clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/>
<memory can_program="true" id="Flash" is_ro="true" type="Flash"/>
<memory id="RAM" type="RAM"/>
<memory id="Periph" is_volatile="true" type="Peripheral"/>
-<memoryInstance derived_from="Flash" id="MFlashA512" location="0x1a000000" size="0x80000"/>
-<memoryInstance derived_from="Flash" id="MFlashB512" location="0x1b000000" size="0x80000"/>
-<memoryInstance derived_from="RAM" id="RamLoc32" location="0x10000000" size="0x8000"/>
-<memoryInstance derived_from="RAM" id="RamLoc40" location="0x10080000" size="0xa000"/>
-<memoryInstance derived_from="RAM" id="RamAHB32" location="0x20000000" size="0x8000"/>
-<memoryInstance derived_from="RAM" id="RamAHB16" location="0x20008000" size="0x4000"/>
-<memoryInstance derived_from="RAM" id="RamAHB_ETB16" location="0x2000c000" size="0x4000"/>
-<prog_flash blocksz="0x2000" location="0x1a000000" maxprgbuff="0x400" progwithcode="TRUE" size="0x10000"/>
-<prog_flash blocksz="0x10000" location="0x1a010000" maxprgbuff="0x400" progwithcode="TRUE" size="0x70000"/>
-<prog_flash blocksz="0x2000" location="0x1b000000" maxprgbuff="0x400" progwithcode="TRUE" size="0x10000"/>
-<prog_flash blocksz="0x10000" location="0x1b010000" maxprgbuff="0x400" progwithcode="TRUE" size="0x70000"/>
+<memoryInstance derived_from="Flash" id="MFlash64" location="0x0" size="0x10000"/>
+<memoryInstance derived_from="RAM" id="RamLoc8" location="0x10000000" size="0x2000"/>
+<memoryInstance derived_from="RAM" id="RamUsb2" location="0x20004000" size="0x800"/>
+<memoryInstance derived_from="RAM" id="RamPeriph2" location="0x20000000" size="0x800"/>
+<prog_flash blocksz="0x1000" location="0x0" maxprgbuff="0x400" progwithcode="TRUE" size="0x10000"/>
<peripheralInstance derived_from="V7M_MPU" id="MPU" location="0xe000ed90"/>
<peripheralInstance derived_from="V7M_NVIC" id="NVIC" location="0xe000e000"/>
<peripheralInstance derived_from="V7M_DCR" id="DCR" location="0xe000edf0"/>
<peripheralInstance derived_from="V7M_ITM" id="ITM" location="0xe0000000"/>
-<peripheralInstance derived_from="SCT" id="SCT" location="0x40000000"/>
-<peripheralInstance derived_from="GPDMA" id="GPDMA" location="0x40002000"/>
-<peripheralInstance derived_from="SDMMC" id="SDMMC" location="0x40004000"/>
-<peripheralInstance derived_from="EMC" id="EMC" location="0x40005000"/>
-<peripheralInstance derived_from="USB0" id="USB0" location="0x40006000"/>
-<peripheralInstance derived_from="USB1" id="USB1" location="0x40007000"/>
-<peripheralInstance derived_from="LCD" id="LCD" location="0x40008000"/>
-<peripheralInstance derived_from="ETHERNET" id="ETHERNET" location="0x40010000"/>
-<peripheralInstance derived_from="ATIMER" id="ATIMER" location="0x40040000"/>
-<peripheralInstance derived_from="REGFILE" id="REGFILE" location="0x40041000"/>
-<peripheralInstance derived_from="PMC" id="PMC" location="0x40042000"/>
-<peripheralInstance derived_from="CREG" id="CREG" location="0x40043000"/>
-<peripheralInstance derived_from="EVENTROUTER" id="EVENTROUTER" location="0x40044000"/>
-<peripheralInstance derived_from="RTC" id="RTC" location="0x40046000"/>
-<peripheralInstance derived_from="CGU" id="CGU" location="0x40050000"/>
-<peripheralInstance derived_from="CCU1" id="CCU1" location="0x40051000"/>
-<peripheralInstance derived_from="CCU2" id="CCU2" location="0x40052000"/>
-<peripheralInstance derived_from="RGU" id="RGU" location="0x40053000"/>
-<peripheralInstance derived_from="WWDT" id="WWDT" location="0x40080000"/>
-<peripheralInstance derived_from="USART0" id="USART0" location="0x40081000"/>
-<peripheralInstance derived_from="USART2" id="USART2" location="0x400c1000"/>
-<peripheralInstance derived_from="USART3" id="USART3" location="0x400c2000"/>
-<peripheralInstance derived_from="UART1" id="UART1" location="0x40082000"/>
-<peripheralInstance derived_from="SSP0" id="SSP0" location="0x40083000"/>
-<peripheralInstance derived_from="SSP1" id="SSP1" location="0x400c5000"/>
-<peripheralInstance derived_from="TIMER0" id="TIMER0" location="0x40084000"/>
-<peripheralInstance derived_from="TIMER1" id="TIMER1" location="0x40085000"/>
-<peripheralInstance derived_from="TIMER2" id="TIMER2" location="0x400c3000"/>
-<peripheralInstance derived_from="TIMER3" id="TIMER3" location="0x400c4000"/>
-<peripheralInstance derived_from="SCU" id="SCU" location="0x40086000"/>
-<peripheralInstance derived_from="GPIO-PIN-INT" id="GPIO-PIN-INT" location="0x40087000"/>
-<peripheralInstance derived_from="GPIO-GROUP-INT0" id="GPIO-GROUP-INT0" location="0x40088000"/>
-<peripheralInstance derived_from="GPIO-GROUP-INT1" id="GPIO-GROUP-INT1" location="0x40089000"/>
-<peripheralInstance derived_from="MCPWM" id="MCPWM" location="0x400a0000"/>
-<peripheralInstance derived_from="I2C0" id="I2C0" location="0x400a1000"/>
-<peripheralInstance derived_from="I2C1" id="I2C1" location="0x400e0000"/>
-<peripheralInstance derived_from="I2S0" id="I2S0" location="0x400a2000"/>
-<peripheralInstance derived_from="I2S1" id="I2S1" location="0x400a3000"/>
-<peripheralInstance derived_from="C-CAN1" id="C-CAN1" location="0x400a4000"/>
-<peripheralInstance derived_from="RITIMER" id="RITIMER" location="0x400c0000"/>
-<peripheralInstance derived_from="QEI" id="QEI" location="0x400c6000"/>
-<peripheralInstance derived_from="GIMA" id="GIMA" location="0x400c7000"/>
-<peripheralInstance derived_from="DAC" id="DAC" location="0x400e1000"/>
-<peripheralInstance derived_from="C-CAN0" id="C-CAN0" location="0x400e2000"/>
-<peripheralInstance derived_from="ADC0" id="ADC0" location="0x400e3000"/>
-<peripheralInstance derived_from="ADC1" id="ADC1" location="0x400e4000"/>
-<peripheralInstance derived_from="GPIO-PORT" id="GPIO-PORT" location="0x400f4000"/>
+<peripheralInstance derived_from="I2C" id="I2C" location="0x40000000"/>
+<peripheralInstance derived_from="WWDT" id="WWDT" location="0x40004000"/>
+<peripheralInstance derived_from="USART" id="USART" location="0x40008000"/>
+<peripheralInstance derived_from="CT16B0" id="CT16B0" location="0x4000c000"/>
+<peripheralInstance derived_from="CT16B1" id="CT16B1" location="0x40010000"/>
+<peripheralInstance derived_from="CT32B0" id="CT32B0" location="0x40014000"/>
+<peripheralInstance derived_from="CT32B1" id="CT32B1" location="0x40018000"/>
+<peripheralInstance derived_from="ADC" id="ADC" location="0x4001c000"/>
+<peripheralInstance derived_from="PMU" id="PMU" location="0x40038000"/>
+<peripheralInstance derived_from="FLASHCTRL" id="FLASHCTRL" location="0x4003c000"/>
+<peripheralInstance derived_from="SSP0" id="SSP0" location="0x40040000"/>
+<peripheralInstance derived_from="IOCON" id="IOCON" location="0x40044000"/>
+<peripheralInstance derived_from="SYSCON" id="SYSCON" location="0x40048000"/>
+<peripheralInstance derived_from="GPIO-PIN-INT" id="GPIO-PIN-INT" location="0x4004c000"/>
+<peripheralInstance derived_from="SSP1" id="SSP1" location="0x40058000"/>
+<peripheralInstance derived_from="GPIO-GROUP-INT0" id="GPIO-GROUP-INT0" location="0x4005c000"/>
+<peripheralInstance derived_from="GPIO-GROUP-INT1" id="GPIO-GROUP-INT1" location="0x40060000"/>
+<peripheralInstance derived_from="RITIMER" id="RITIMER" location="0x40064000"/>
+<peripheralInstance derived_from="USB" id="USB" location="0x40080000"/>
+<peripheralInstance derived_from="GPIO-PORT" id="GPIO-PORT" location="0x50000000"/>
</chip>
-<processor><name gcc_name="cortex-m4">Cortex-M4</name>
+<processor><name gcc_name="cortex-m3">Cortex-M3</name>
<family>Cortex-M</family>
</processor>
-<link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/>
+<link href="nxp_lpc13Uxx_peripheral.xme" show="embed" type="simple"/>
</info>
</infoList>
</TargetConfig>
diff --git a/demos/device/keyboard/main.c b/demos/device/keyboard/main.c
index 0648b1e1d..76c6383f5 100644
--- a/demos/device/keyboard/main.c
+++ b/demos/device/keyboard/main.c
@@ -14,6 +14,8 @@
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
#endif
+void print_greeting(void);
+
int main(void)
{
uint32_t current_tick = system_ticks;
@@ -21,6 +23,7 @@ int main(void)
board_init();
tusb_init();
+ print_greeting();
while (1)
{
if (current_tick + 1000 < system_ticks)
@@ -32,19 +35,17 @@ int main(void)
board_leds(led_on_mask, 1 - led_on_mask);
led_on_mask = 1 - led_on_mask; // toggle
- #if !(defined TUSB_CFG_DEVICE_CDC) && 0
if (usb_isConfigured())
{
- #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
- uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA};
- tusb_hid_keyboard_sendKeys(0x00, keys, 1);
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ uint8_t keys[6] = {0x04}; // A character
+ tusbd_hid_keyboard_send_report(0x00, keys, 1);
#endif
- #ifdef TUSB_CFG_DEVICE_HID_MOUSE
+ #if TUSB_CFG_DEVICE_HID_MOUSE
tusb_hid_mouse_send(0, 10, 10);
#endif
}
- #endif
}
#if defined TUSB_CFG_DEVICE_CDC && 0
@@ -59,7 +60,7 @@ int main(void)
case '1' :
{
uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA + 'e' - 'a'};
- tusb_hid_keyboard_sendKeys(0x08, keys, 1); // windows + E --> open explorer
+ tusbd_hid_keyboard_send_report(0x08, keys, 1); // windows + E --> open explorer
}
break;
#endif
@@ -83,3 +84,17 @@ int main(void)
return 0;
}
+
+//--------------------------------------------------------------------+
+// HELPER FUNCTION
+//--------------------------------------------------------------------+
+void print_greeting(void)
+{
+ printf("\r\n\
+--------------------------------------------------------------------\r\n\
+- Device Demo (a tinyusb example)\r\n\
+- if you find any bugs or get any questions, feel free to file an\r\n\
+- issue at https://github.com/hathach/tinyusb\r\n\
+--------------------------------------------------------------------\r\n\r\n"
+ );
+}
diff --git a/tinyusb/class/cdc.c b/tinyusb/class/cdc.c
index d929d3efe..18029acf3 100644
--- a/tinyusb/class/cdc.c
+++ b/tinyusb/class/cdc.c
@@ -233,7 +233,7 @@ ErrorCode_t CDC_BulkIn_Hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event)
uint16_t count;
count = fifo_read_n(&ffTX, buffer, CDC_DATA_EP_MAXPACKET_SIZE);
- USBD_API->hw->WriteEP(hUsb, CDC_DATA_EP_IN, buffer, count); // write data to EP
+ ROM_API->hw->WriteEP(hUsb, CDC_DATA_EP_IN, buffer, count); // write data to EP
}
return LPC_OK;
@@ -251,7 +251,7 @@ ErrorCode_t CDC_BulkOut_Hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event)
uint16_t count, i;
uint8_t buffer[CDC_DATA_EP_MAXPACKET_SIZE];
- count = USBD_API->hw->ReadEP(hUsb, CDC_DATA_EP_OUT, buffer);
+ count = ROM_API->hw->ReadEP(hUsb, CDC_DATA_EP_OUT, buffer);
for (i=0; icore->RegisterEpHandler (hUsb , ((CDC_DATA_EP_IN & 0x0F) << 1) +1 , CDC_BulkIn_Hdlr , NULL), TUSB_ERROR_FAILED );
- ASSERT ( LPC_OK == USBD_API->core->RegisterEpHandler (hUsb , (CDC_DATA_EP_OUT & 0x0F) << 1 , CDC_BulkOut_Hdlr , NULL), TUSB_ERROR_FAILED );
+ ASSERT ( LPC_OK == ROM_API->core->RegisterEpHandler (hUsb , ((CDC_DATA_EP_IN & 0x0F) << 1) +1 , CDC_BulkIn_Hdlr , NULL), TUSB_ERROR_FAILED );
+ ASSERT ( LPC_OK == ROM_API->core->RegisterEpHandler (hUsb , (CDC_DATA_EP_OUT & 0x0F) << 1 , CDC_BulkOut_Hdlr , NULL), TUSB_ERROR_FAILED );
- ASSERT ( LPC_OK == USBD_API->cdc->init(hUsb, &cdc_param, &g_hCdc), TUSB_ERROR_FAILED);
+ ASSERT ( LPC_OK == ROM_API->cdc->init(hUsb, &cdc_param, &g_hCdc), TUSB_ERROR_FAILED);
/* update memory variables */
*mem_base = cdc_param.mem_base;
@@ -310,7 +310,7 @@ 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)
{
uint8_t dummy=0;
- USBD_API->hw->WriteEP(hUsb, CDC_DATA_EP_IN, &dummy, 1); // initial packet for IN endpoint, will not work if omitted
+ ROM_API->hw->WriteEP(hUsb, CDC_DATA_EP_IN, &dummy, 1); // initial packet for IN endpoint, will not work if omitted
// FIXME abstract to hal
#if MCU == MCU_LPC11UXX
diff --git a/tinyusb/class/hid.c b/tinyusb/class/hid.c
index 372861caa..2308e24ac 100644
--- a/tinyusb/class/hid.c
+++ b/tinyusb/class/hid.c
@@ -134,7 +134,7 @@ ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
{
memset(&hid_keyboard_report, 0, sizeof(tusb_keyboard_report_t));
}
- USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(tusb_keyboard_report_t));
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(tusb_keyboard_report_t));
bKeyChanged = false;
break;
#endif
@@ -145,7 +145,7 @@ ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
{
memset(&hid_mouse_report, 0, sizeof(tusb_mouse_report_t));
}
- USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(tusb_mouse_report_t));
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(tusb_mouse_report_t));
bMouseChanged = false;
break;
#endif
@@ -170,7 +170,7 @@ ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
// not used yet
// uint8_t outreport[8];
// USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
- // USBD_API->hw->ReadEP(hUsb, pHidCtrl->epout_adr, outreport);
+ // ROM_API->hw->ReadEP(hUsb, pHidCtrl->epout_adr, outreport);
}
return LPC_OK;
}
@@ -207,7 +207,7 @@ tusb_error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c
ASSERT( (pIntfDesc != NULL) && (pIntfDesc->bInterfaceClass == USB_DEVICE_CLASS_HUMAN_INTERFACE), ERR_FAILED);
- ASSERT( LPC_OK == USBD_API->hid->init(hUsb, &hid_param), TUSB_ERROR_FAILED );
+ ASSERT( LPC_OK == ROM_API->hid->init(hUsb, &hid_param), TUSB_ERROR_FAILED );
/* update memory variables */
*mem_base += (*mem_size - hid_param.mem_size);
@@ -224,11 +224,11 @@ tusb_error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c
tusb_error_t tusb_hid_configured(USBD_HANDLE_T hUsb)
{
#ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
- USBD_API->hw->WriteEP(hUsb , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(tusb_keyboard_report_t) ); // initial packet for IN endpoint , will not work if omitted
+ ROM_API->hw->WriteEP(hUsb , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(tusb_keyboard_report_t) ); // initial packet for IN endpoint , will not work if omitted
#endif
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
- USBD_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(tusb_mouse_report_t) ); // initial packet for IN endpoint, will not work if omitted
+ ROM_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(tusb_mouse_report_t) ); // initial packet for IN endpoint, will not work if omitted
#endif
return TUSB_ERROR_NONE;
diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h
index 43af4d7cd..3e7d86a18 100644
--- a/tinyusb/class/hid.h
+++ b/tinyusb/class/hid.h
@@ -69,6 +69,12 @@ enum {
HID_DESC_TYPE_PHYSICAL = 0x23
};
+enum {
+ HID_REQUEST_REPORT_INPUT = 1,
+ HID_REQUEST_REPORT_OUTPUT,
+ HID_REQUEST_REPORT_FEATURE
+};
+
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index 02f1974aa..91c31e04a 100644
--- a/tinyusb/class/hid_device.c
+++ b/tinyusb/class/hid_device.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if (MODE_DEVICE_SUPPORTED && defined HOST_CLASS_HID)
+#if (MODE_DEVICE_SUPPORTED && DEVICE_CLASS_HID)
#define _TINY_USB_SOURCE_FILE_
//--------------------------------------------------------------------+
@@ -58,5 +58,221 @@
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+tusb_keyboard_report_t hid_keyboard_report;
+static volatile bool bKeyChanged = false;
+#endif
+
+#if TUSB_CFG_DEVICE_HID_MOUSE
+tusb_mouse_report_t hid_mouse_report;
+static volatile bool bMouseChanged = false;
+#endif
+
+ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength)
+{
+ USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*) hHid;
+
+ /* ReportID = SetupPacket.wValue.WB.L; */
+ if (pSetup->wValue.WB.H == HID_REQUEST_REPORT_INPUT)
+ return (ERR_USBD_STALL); /* Not Supported */
+
+ switch (pHidCtrl->protocol)
+ {
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ case HID_PROTOCOL_KEYBOARD:
+ *pBuffer = (uint8_t*) &hid_keyboard_report;
+ *plength = sizeof(tusb_keyboard_report_t);
+
+ if (!bKeyChanged)
+ {
+ memset(pBuffer, 0, *plength);
+ }
+ bKeyChanged = false;
+ break;
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ case HID_PROTOCOL_MOUSE:
+ *pBuffer = (uint8_t*) &hid_mouse_report;
+ *plength = sizeof(tusb_mouse_report_t);
+
+ if (!bMouseChanged)
+ {
+ memset(pBuffer, 0, *plength);
+ }
+ bMouseChanged = false;
+ break;
+ #endif
+
+ default:
+ break;
+ }
+
+ return (LPC_OK);
+}
+
+ErrorCode_t HID_SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length)
+{
+ /* we will reuse standard EP0Buf */
+ if (length == 0)
+ return LPC_OK;
+
+ /* ReportID = SetupPacket.wValue.WB.L; */
+ if (pSetup->wValue.WB.H != HID_REQUEST_REPORT_OUTPUT)
+ return (ERR_USBD_STALL); /* Not Supported */
+
+ return (LPC_OK);
+}
+
+ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
+{
+ if (USB_EVT_IN == event)
+ {
+ USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
+ switch(pHidCtrl->protocol)
+ {
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ case HID_PROTOCOL_KEYBOARD:
+ if (!bKeyChanged)
+ {
+ memset(&hid_keyboard_report, 0, sizeof(tusb_keyboard_report_t));
+ }
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(tusb_keyboard_report_t));
+ bKeyChanged = false;
+ break;
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ case HID_PROTOCOL_MOUSE:
+ if (!bMouseChanged)
+ {
+ memset(&hid_mouse_report, 0, sizeof(tusb_mouse_report_t));
+ }
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(tusb_mouse_report_t));
+ bMouseChanged = false;
+ break;
+ #endif
+
+ default:
+ break;
+ }
+ }
+
+ return LPC_OK;
+}
+
+ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
+{
+ if (USB_EVT_OUT == event)
+ {
+ // not used yet
+ // uint8_t outreport[8];
+ // USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
+ // ROM_API->hw->ReadEP(hUsb, pHidCtrl->epout_adr, outreport);
+ }
+ return LPC_OK;
+}
+
+//--------------------------------------------------------------------+
+// CLASS-USBH API (don't require to verify parameters)
+//--------------------------------------------------------------------+
+tusb_error_t hidd_init(USBD_HANDLE_T hUsb, tusb_descriptor_interface_t const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size)
+{
+ USB_HID_REPORT_T reports_data =
+ {
+ .desc = (uint8_t*) pHIDReportDesc,
+ .len = ReportDescLength,
+ .idle_time = 0,
+ };
+
+ USBD_HID_INIT_PARAM_T hid_param =
+ {
+ .mem_base = *mem_base,
+ .mem_size = *mem_size,
+
+ .intf_desc = (uint8_t*)pIntfDesc,
+ .report_data = &reports_data,
+ .max_reports = 1,
+
+ /* user defined functions */
+ .HID_GetReport = HID_GetReport,
+ .HID_SetReport = HID_SetReport,
+ .HID_EpIn_Hdlr = HID_EpIn_Hdlr,
+ .HID_EpOut_Hdlr = HID_EpOut_Hdlr
+ };
+
+ ASSERT( (pIntfDesc != NULL) && (pIntfDesc->bInterfaceClass == USB_DEVICE_CLASS_HUMAN_INTERFACE), ERR_FAILED);
+
+ ASSERT( LPC_OK == ROM_API->hid->init(hUsb, &hid_param), TUSB_ERROR_FAILED );
+
+ /* update memory variables */
+ *mem_base += (*mem_size - hid_param.mem_size);
+ *mem_size = hid_param.mem_size;
+
+ return TUSB_ERROR_NONE;
+}
+
+tusb_error_t hidd_configured(USBD_HANDLE_T hUsb)
+{
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ ROM_API->hw->WriteEP(hUsb , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(tusb_keyboard_report_t) ); // initial packet for IN endpoint , will not work if omitted
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ ROM_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(tusb_mouse_report_t) ); // initial packet for IN endpoint, will not work if omitted
+ #endif
+
+ return TUSB_ERROR_NONE;
+}
+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+tusb_error_t tusbd_hid_keyboard_send_report(uint8_t modifier, uint8_t keycodes[], uint8_t numkey)
+{
+// uint32_t start_time = systickGetSecondsActive();
+// while (bKeyChanged) // TODO blocking while previous key has yet sent - can use fifo to improve this
+// {
+// ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Keyboard Timeout");
+// }
+
+ if (bKeyChanged)
+ {
+ return TUSB_ERROR_FAILED;
+ }
+
+ ASSERT(keycodes && numkey && numkey <=6, ERR_FAILED);
+
+ hid_keyboard_report.modifier = modifier;
+ memset(hid_keyboard_report.keycode, 0, 6);
+ memcpy(hid_keyboard_report.keycode, keycodes, numkey);
+
+ bKeyChanged = true;
+
+ return TUSB_ERROR_NONE;
+}
+#endif
+
+#if TUSB_CFG_DEVICE_HID_MOUSE
+tusb_error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y)
+{
+// uint32_t start_time = systickGetSecondsActive();
+// while (bMouseChanged) // TODO Block while previous key hasn't been sent - can use fifo to improve this
+// {
+// ASSERT_MESSAGE(systickGetSecondsActive() - start_time < 5, ERR_FAILED, "HID Mouse Timeout");
+// }
+
+ if (bMouseChanged)
+ {
+ return TUSB_ERROR_FAILED;
+ }
+
+ hid_mouse_report.buttons = buttons;
+ hid_mouse_report.x = x;
+ hid_mouse_report.y = y;
+
+ bMouseChanged = true;
+
+ return TUSB_ERROR_NONE;
+}
+#endif
#endif
diff --git a/tinyusb/class/hid_device.h b/tinyusb/class/hid_device.h
index f797007b0..f01685e25 100644
--- a/tinyusb/class/hid_device.h
+++ b/tinyusb/class/hid_device.h
@@ -53,50 +53,29 @@
#define _TUSB_HID_DEVICE_H_
#include "common/common.h"
+#include "device/usbd.h"
#include "hid.h"
#ifdef __cplusplus
extern "C" {
#endif
-#ifdef DEVICE_ROMDRIVER
-/** \brief Initialize HID driver
- *
- * \param[in] para1
- * \param[out] para2
- * \return Error Code of the \ref TUSB_ERROR enum
- * \note
- */
-tusb_error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size);
-
-/** \brief Notify HID class that usb is configured
- *
- * \param[in] para1
- * \param[out] para2
- * \return Error Code of the \ref TUSB_ERROR enum
- * \note
- */
-tusb_error_t tusb_hid_configured(USBD_HANDLE_T hUsb);
-
-/** \brief Used by Application to send Keycode to Host
- *
- * \param[in] para1
- * \param[out] para2
- * \return Error Code of the \ref TUSB_ERROR enum
- * \note
- */
-tusb_error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey);
-
-/** \brief
- *
- * \param[in] para1
- * \param[out] para2
- * \return Error Code of the \ref TUSB_ERROR enum
- * \note
- */
+//--------------------------------------------------------------------+
+// KEYBOARD Application API
+//--------------------------------------------------------------------+
+tusb_error_t tusbd_hid_keyboard_send_report(uint8_t modifier, uint8_t keycodes[], uint8_t numkey);
tusb_error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y);
-#endif /* ROM DRIVRER */
+//--------------------------------------------------------------------+
+// USBD-CLASS DRIVER API
+//--------------------------------------------------------------------+
+#ifdef _TINY_USB_SOURCE_FILE_
+#include "device/romdriver/mw_usbd_rom_api.h" // TODO remove rom driver dependency
+
+tusb_error_t hidd_init(USBD_HANDLE_T hUsb, tusb_descriptor_interface_t const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size);
+tusb_error_t hidd_configured(USBD_HANDLE_T hUsb);
+
+#endif
#ifdef __cplusplus
}
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index 0cced3226..4ba1556dd 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -181,7 +181,7 @@ tusb_interface_status_t tusbh_hid_mouse_status(uint8_t dev_addr, uint8_t instanc
#endif
//--------------------------------------------------------------------+
-// CLASS-USBD API (don't require to verify parameters)
+// CLASS-USBH API (don't require to verify parameters)
//--------------------------------------------------------------------+
void hidh_init(void)
{
diff --git a/tinyusb/device/dcd.c b/tinyusb/device/dcd.c
index c0115c4e5..638ecdfe9 100644
--- a/tinyusb/device/dcd.c
+++ b/tinyusb/device/dcd.c
@@ -37,7 +37,7 @@
#include "dcd.h"
-#ifdef TUSB_CFG_DEVICE
+#if 0
#include "descriptors.h" // TODO refractor later
@@ -109,7 +109,7 @@ tusb_error_t dcd_init(uint8_t coreid)
};
/* USB hardware core initialization */
- ASSERT(LPC_OK == USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param), TUSB_ERROR_FAILED);
+ ASSERT(LPC_OK == ROM_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param), TUSB_ERROR_FAILED);
membase += (memsize - usb_param.mem_size);
memsize = usb_param.mem_size;
@@ -135,7 +135,7 @@ tusb_error_t dcd_init(uint8_t coreid)
hal_interrupt_enable(); /* Enable the USB interrupt */
/* Perform USB soft connect */
- USBD_API->hw->Connect(g_hUsb, 1);
+ ROM_API->hw->Connect(g_hUsb, 1);
#endif
return TUSB_ERROR_NONE;
diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h
index be139b713..c4b98d990 100644
--- a/tinyusb/device/dcd.h
+++ b/tinyusb/device/dcd.h
@@ -56,6 +56,9 @@
#endif
#include "common/common.h"
+#include "dcd_nxp_romdriver.h"
+
+#define ROM_API ( * (*((USBD_API_T***) 0x1FFF1FF8)) ) // TODO remove rom API dependency
tusb_error_t dcd_init(void) ATTR_WARN_UNUSED_RESULT;
tusb_error_t dcd_controller_reset(uint8_t coreid) ATTR_WARN_UNUSED_RESULT;
diff --git a/tinyusb/device/dcd_nxp_romdriver.c b/tinyusb/device/dcd_nxp_romdriver.c
index 8587a66f3..34dfa5e35 100644
--- a/tinyusb/device/dcd_nxp_romdriver.c
+++ b/tinyusb/device/dcd_nxp_romdriver.c
@@ -51,11 +51,23 @@
#include "tusb_descriptors.h"
-#define USBD_API ((USBD_API_T*) DEVICE_ROM_DRIVER_ADDR)
+
#define USB_ROM_SIZE (1024*2) // TODO dcd abstract later
uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM;
USBD_HANDLE_T g_hUsb;
+typedef struct {
+ volatile uint8_t state;
+}usbd_info_t; // TODO rename
+
+usbd_info_t usbd_info; // TODO rename
+
+typedef struct {
+ void (* const init) (void);
+ void (* const configured) (void);
+ void (* const unmounted) (void);
+}device_class_driver_t;
+
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -74,10 +86,10 @@ ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
if (pCtrl->config_value)
{
-// usbd_info.state = TUSB_DEVICE_STATE_CONFIGURED;
+ usbd_info.state = TUSB_DEVICE_STATE_CONFIGURED;
#if defined(DEVICE_CLASS_HID)
-// ASSERT( TUSB_ERROR_NONE == tusb_hid_configured(hUsb), ERR_FAILED );
+ ASSERT( TUSB_ERROR_NONE == hidd_configured(hUsb), ERR_FAILED );
#endif
#ifdef TUSB_CFG_DEVICE_CDC
@@ -91,7 +103,7 @@ ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb)
{
-// usbd_info.state = TUSB_DEVICE_STATE_UNPLUG;
+ usbd_info.state = TUSB_DEVICE_STATE_UNPLUG;
return LPC_OK;
}
@@ -122,7 +134,7 @@ tusb_error_t dcd_init(void)
};
/* USB hardware core initialization */
- ASSERT(LPC_OK == USBD_API->hw->Init(&g_hUsb, &desc_core, &usb_param), TUSB_ERROR_FAILED);
+ ASSERT_INT(LPC_OK, ROM_API->hw->Init(&g_hUsb, &desc_core, &usb_param), TUSB_ERROR_FAILED);
// TODO need to confirm the mem_size is reduced by the number of byte used
membase += (memsize - usb_param.mem_size);
@@ -130,7 +142,7 @@ tusb_error_t dcd_init(void)
#if TUSB_CFG_DEVICE_HID_KEYBOARD
- ASSERT_STATUS( tusb_hid_init(g_hUsb , &app_desc_configuration.keyboard_interface,
+ ASSERT_STATUS( hidd_init(g_hUsb , &app_desc_configuration.keyboard_interface,
keyboard_report_descriptor, app_desc_configuration.keyboard_hid.wReportLength,
&membase , &memsize) );
#endif
@@ -141,10 +153,16 @@ tusb_error_t dcd_init(void)
&membase , &memsize) );
#endif
+ ROM_API->hw->Connect(g_hUsb, 1);
return TUSB_ERROR_NONE;
}
+bool usb_isConfigured(void)
+{
+ return usbd_info.state == TUSB_DEVICE_STATE_CONFIGURED;
+}
+
tusb_error_t dcd_controller_reset(uint8_t coreid)
{
//TODO merge with hcd_controller_reset
@@ -154,12 +172,12 @@ tusb_error_t dcd_controller_reset(uint8_t coreid)
void dcd_controller_connect(uint8_t coreid)
{
-// USBD_API->hw->Connect(g_hUsb, 1);
+// ROM_API->hw->Connect(g_hUsb, 1);
}
void dcd_isr(uint8_t coreid)
{
-// USBD_API->hw->ISR(g_hUsb);
+// ROM_API->hw->ISR(g_hUsb);
}
#endif
diff --git a/tinyusb/device/dcd_nxp_romdriver.h b/tinyusb/device/dcd_nxp_romdriver.h
index c185bab07..616240151 100644
--- a/tinyusb/device/dcd_nxp_romdriver.h
+++ b/tinyusb/device/dcd_nxp_romdriver.h
@@ -54,6 +54,8 @@
#if (MCU == MCU_LPC18XX) || (MCU == MCU_LPC43XX)
#include "dcd_lpc18xx_lpc43xx.h"
+#elif (MCU == MCU_LPC13UXX)
+ #include "dcd_lpc13xx.h"
#else
#error forgot something, thach ?
#endif
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index cbbc28995..efcf29ced 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -54,17 +54,7 @@
// volatile uint8_t state;
//
//};
-typedef struct {
- volatile uint8_t state;
-}usbd_info_t; // TODO rename
-usbd_info_t usbd_info; // TODO rename
-
-typedef struct {
- void (* const init) (void);
- void (* const configured) (void);
- void (* const unmounted) (void);
-}device_class_driver_t;
//--------------------------------------------------------------------+
diff --git a/tinyusb/hal/hal_lpc43xx.c b/tinyusb/hal/hal_lpc43xx.c
index e700041b1..1284391e5 100644
--- a/tinyusb/hal/hal_lpc43xx.c
+++ b/tinyusb/hal/hal_lpc43xx.c
@@ -70,7 +70,7 @@ tusb_error_t hal_init(void)
LPC_USB0->USBMODE_H = LPC43XX_USBMODE_HOST | (LPC43XX_USBMODE_VBUS_HIGH << 5);
#else // TODO OTG
// dcd_controller_reset(0);
-// LPC_USB0->USBMODE_D = LPC43XX_USBMODE_DEVICE;
+ LPC_USB0->USBMODE_D = LPC43XX_USBMODE_DEVICE;
dcd_controller_connect(0);
#endif
@@ -92,7 +92,7 @@ tusb_error_t hal_init(void)
LPC_USB1->USBMODE_H = LPC43XX_USBMODE_HOST | (LPC43XX_USBMODE_VBUS_HIGH << 5);
#else // TODO OTG
// dcd_controller_reset(1);
-// LPC_USB0->USBMODE_D = LPC43XX_USBMODE_DEVICE;
+ LPC_USB0->USBMODE_D = LPC43XX_USBMODE_DEVICE;
dcd_controller_connect(1);
#endif
diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h
index 11f961d2c..fefe4a2d7 100644
--- a/tinyusb/tusb_option.h
+++ b/tinyusb/tusb_option.h
@@ -156,13 +156,16 @@
//--------------------------------------------------------------------+
// DEVICE OPTIONS
//--------------------------------------------------------------------+
-//#if MODE_DEVICE_SUPPORTED
+#if MODE_DEVICE_SUPPORTED
#if !TUSB_CFG_DEVICE_USE_ROM_DRIVER
#error only rom driver is supported now
#endif
-#define DEVICE_CLASS_HID ( (defined TUSB_CFG_DEVICE_HID_KEYBOARD) || (defined TUSB_CFG_DEVICE_HID_MOUSE) )
+#define DEVICE_CLASS_HID ( TUSB_CFG_DEVICE_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_MOUSE + TUSB_CFG_DEVICE_HID_GENERIC )
+
+
+#endif
// TODO Device APP
#define USB_MAX_IF_NUM 8
@@ -187,7 +190,7 @@
#define CDC_NOTIFICATION_EP_MAXPACKETSIZE 8
#define CDC_DATA_EP_MAXPACKET_SIZE 16
-//#endif
+
#ifdef __cplusplus
}