Merge branch 'master' of https://github.com/hathach/tinyusb into stm32f4
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
void print_greeting(void);
|
||||
void led_blinking_task(void);
|
||||
|
||||
extern void virtual_com_task(void);
|
||||
@@ -56,13 +55,13 @@ extern void usb_hid_task(void);
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
print_greeting();
|
||||
|
||||
tusb_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
tusb_task();
|
||||
// tinyusb device task
|
||||
tud_task();
|
||||
|
||||
led_blinking_task();
|
||||
|
||||
@@ -84,9 +83,9 @@ int main(void)
|
||||
#if CFG_TUD_CDC
|
||||
void virtual_com_task(void)
|
||||
{
|
||||
// connected and there are data available
|
||||
if ( tud_cdc_connected() )
|
||||
{
|
||||
// connected and there are data available
|
||||
if ( tud_cdc_available() )
|
||||
{
|
||||
uint8_t buf[64];
|
||||
@@ -94,10 +93,15 @@ void virtual_com_task(void)
|
||||
// read and echo back
|
||||
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
||||
|
||||
tud_cdc_write(buf, count);
|
||||
}
|
||||
for(uint32_t i=0; i<count; i++)
|
||||
{
|
||||
tud_cdc_write_char(buf[i]);
|
||||
|
||||
tud_cdc_write_flush();
|
||||
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
|
||||
}
|
||||
|
||||
tud_cdc_write_flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +112,8 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
// connected
|
||||
if ( dtr && rts )
|
||||
{
|
||||
// print greeting
|
||||
tud_cdc_write_str("tinyusb usb cdc\n");
|
||||
// print initial message when connected
|
||||
tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device example\r\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -187,6 +191,7 @@ void tud_umount_cb(void)
|
||||
|
||||
void tud_cdc_rx_cb(uint8_t itf)
|
||||
{
|
||||
(void) itf;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -200,31 +205,6 @@ void led_blinking_task(void)
|
||||
if ( !tu_timeout_expired(&tm) ) return; // not enough time
|
||||
tu_timeout_reset(&tm);
|
||||
|
||||
board_led_control(BOARD_LED0, led_state);
|
||||
board_led_control(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HELPER FUNCTION
|
||||
//--------------------------------------------------------------------+
|
||||
void print_greeting(void)
|
||||
{
|
||||
char const * const rtos_name[] =
|
||||
{
|
||||
[OPT_OS_NONE] = "None",
|
||||
[OPT_OS_FREERTOS] = "FreeRTOS",
|
||||
};
|
||||
|
||||
printf("\n--------------------------------------------------------------------\n");
|
||||
printf("- Device Demo (a tinyusb example)\n");
|
||||
printf("- if you find any bugs or get any questions, feel free to file an\n");
|
||||
printf("- issue at https://github.com/hathach/tinyusb\n");
|
||||
printf("--------------------------------------------------------------------\n\n");
|
||||
|
||||
printf("This DEVICE demo is configured to support:");
|
||||
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
|
||||
if (CFG_TUD_CDC ) puts(" - Communication Device Class");
|
||||
if (CFG_TUD_MSC ) puts(" - Mass Storage");
|
||||
if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
|
||||
if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
|
||||
// Some MCU doesn't have enough 8KB SRAM to store the whole disk
|
||||
// We will use Flash as read-only disk
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC13XX
|
||||
#define DISK_READONLY
|
||||
#endif
|
||||
|
||||
#define README_CONTENTS \
|
||||
"This is tinyusb's MassStorage Class demo.\r\n\r\n\
|
||||
If you find any bugs or get any questions, feel free to file an\r\n\
|
||||
@@ -52,7 +58,10 @@ enum
|
||||
DISK_BLOCK_SIZE = 512
|
||||
};
|
||||
|
||||
uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
|
||||
#ifdef DISK_READONLY
|
||||
const
|
||||
#endif
|
||||
uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
|
||||
{
|
||||
//------------- Boot Sector -------------//
|
||||
// byte_per_sector = DISK_BLOCK_SIZE; fat12_sector_num_16 = DISK_BLOCK_NUM;
|
||||
@@ -99,7 +108,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
uint8_t* addr = msc_device_ramdisk[lba] + offset;
|
||||
uint8_t const* addr = msc_disk[lba] + offset;
|
||||
memcpy(buffer, addr, bufsize);
|
||||
|
||||
return bufsize;
|
||||
@@ -111,8 +120,12 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
|
||||
{
|
||||
(void) lun;
|
||||
|
||||
uint8_t* addr = msc_device_ramdisk[lba] + offset;
|
||||
#ifndef DISK_READONLY
|
||||
uint8_t* addr = msc_disk[lba] + offset;
|
||||
memcpy(addr, buffer, bufsize);
|
||||
#else
|
||||
(void) lba; (void) offset; (void) buffer;
|
||||
#endif
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@
|
||||
#ifndef _TUSB_CONFIG_H_
|
||||
#define _TUSB_CONFIG_H_
|
||||
|
||||
#include "tusb_option.h"
|
||||
#include "bsp/board.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -52,10 +49,15 @@
|
||||
|
||||
// defined by compiler flags for flexibility
|
||||
#ifndef CFG_TUSB_MCU
|
||||
#error CFG_TUSB_MCU should be defined using compiler flags
|
||||
#error CFG_TUSB_MCU must be defined
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
|
||||
#else
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
||||
#endif
|
||||
|
||||
#define CFG_TUSB_DEBUG 2
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
|
||||
@@ -88,12 +90,22 @@
|
||||
*/
|
||||
#define CFG_TUD_DESC_AUTO 1
|
||||
|
||||
/* USB VID/PID if not defined, tinyusb to use default value
|
||||
/* If USB VID/PID is not defined, tinyusb will use default value
|
||||
* Note: different class combination e.g CDC and (CDC + MSC) should have different
|
||||
* PID since Host OS will "remembered" device driver after the first plug */
|
||||
// #define CFG_TUD_DESC_VID 0xCAFE
|
||||
// #define CFG_TUD_DESC_PID 0x0001
|
||||
|
||||
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
|
||||
// Therefor we need to force endpoint number to correct type on lpc17xx
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
|
||||
#define CFG_TUD_DESC_CDC_EPNUM_NOTIF 1
|
||||
#define CFG_TUD_DESC_CDC_EPNUM 2
|
||||
#define CFG_TUD_DESC_MSC_EPNUM 5
|
||||
#define CFG_TUD_DESC_HID_KEYBOARD_EPNUM 4
|
||||
#define CFG_TUD_DESC_HID_MOUSE_EPNUM 7
|
||||
#endif
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_CDC 1
|
||||
#define CFG_TUD_MSC 0
|
||||
@@ -109,7 +121,6 @@
|
||||
#define CFG_TUD_HID_KEYBOARD_BOOT 1
|
||||
#define CFG_TUD_HID_MOUSE_BOOT 1
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// CDC
|
||||
//--------------------------------------------------------------------
|
||||
@@ -121,7 +132,6 @@
|
||||
//--------------------------------------------------------------------
|
||||
// MSC
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
// Number of supported Logical Unit Number (At least 1)
|
||||
#define CFG_TUD_MSC_MAXLUN 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user