mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
add TUH_EPBUF_DEF for cdc host
This commit is contained in:
parent
f7efcf3c47
commit
67e92e6688
@ -28,22 +28,8 @@
|
||||
#include "bsp/board_api.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define CDC_STACK_SZIE 2048
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
|
||||
#define CDC_STACK_SZIE (3*configMINIMAL_STACK_SIZE/2)
|
||||
#endif
|
||||
|
||||
|
@ -31,22 +31,8 @@
|
||||
#include "tusb.h"
|
||||
|
||||
#if TUSB_MCU_VENDOR_ESPRESSIF
|
||||
// ESP-IDF need "freertos/" prefix in include path.
|
||||
// CFG_TUSB_OS_INC_PATH should be defined accordingly.
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define USBH_STACK_SIZE 4096
|
||||
#else
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
|
||||
// Increase stack size when debug log is enabled
|
||||
#define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
|
||||
#endif
|
||||
|
@ -35,10 +35,6 @@
|
||||
#include "driver/uart.h"
|
||||
#include "esp_private/periph_ctrl.h"
|
||||
|
||||
// Note; current code use UART0 can cause device to reset while monitoring
|
||||
#define USE_UART 0
|
||||
#define UART_ID UART_NUM_0
|
||||
|
||||
#ifdef NEOPIXEL_PIN
|
||||
#include "led_strip.h"
|
||||
static led_strip_handle_t led_strip;
|
||||
@ -57,19 +53,6 @@ static bool usb_init(void);
|
||||
|
||||
// Initialize on-board peripherals : led, button, uart and USB
|
||||
void board_init(void) {
|
||||
#if USE_UART
|
||||
// uart init
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
|
||||
};
|
||||
uart_driver_install(UART_ID, 1024, 0, 0, NULL, 0);
|
||||
uart_param_config(UART_ID, &uart_config);
|
||||
#endif
|
||||
|
||||
#ifdef NEOPIXEL_PIN
|
||||
#ifdef NEOPIXEL_POWER_PIN
|
||||
gpio_reset_pin(NEOPIXEL_POWER_PIN);
|
||||
@ -145,23 +128,26 @@ uint32_t board_button_read(void) {
|
||||
|
||||
// Get characters from UART
|
||||
int board_uart_read(uint8_t* buf, int len) {
|
||||
#if USE_UART
|
||||
return uart_read_bytes(UART_ID, buf, len, 0);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
for (int i=0; i<len; i++) {
|
||||
int c = getchar();
|
||||
if (c == EOF) {
|
||||
return i;
|
||||
}
|
||||
buf[i] = (uint8_t) c;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// Send characters to UART
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
(void) buf;
|
||||
(void) len;
|
||||
return 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
putchar(((char*) buf)[i]);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int board_getchar(void) {
|
||||
uint8_t c = 0;
|
||||
return board_uart_read(&c, 1) > 0 ? (int) c : (-1);
|
||||
return getchar();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -73,15 +73,17 @@ typedef struct {
|
||||
tu_edpt_stream_t rx;
|
||||
|
||||
uint8_t tx_ff_buf[CFG_TUH_CDC_TX_BUFSIZE];
|
||||
CFG_TUH_MEM_ALIGN uint8_t tx_ep_buf[CFG_TUH_CDC_TX_EPSIZE];
|
||||
|
||||
uint8_t rx_ff_buf[CFG_TUH_CDC_TX_BUFSIZE];
|
||||
CFG_TUH_MEM_ALIGN uint8_t rx_ep_buf[CFG_TUH_CDC_TX_EPSIZE];
|
||||
} stream;
|
||||
} cdch_interface_t;
|
||||
|
||||
CFG_TUH_MEM_SECTION
|
||||
typedef struct {
|
||||
TUH_EPBUF_DEF(tx_ep_buf, CFG_TUH_CDC_TX_EPSIZE);
|
||||
TUH_EPBUF_DEF(rx_ep_buf, CFG_TUH_CDC_TX_EPSIZE);
|
||||
} cdch_epbuf_t;
|
||||
|
||||
static cdch_interface_t cdch_data[CFG_TUH_CDC];
|
||||
CFG_TUH_MEM_SECTION static cdch_epbuf_t cdch_epbuf[CFG_TUH_CDC];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Serial Driver
|
||||
@ -626,13 +628,14 @@ bool cdch_init(void) {
|
||||
tu_memclr(cdch_data, sizeof(cdch_data));
|
||||
for (size_t i = 0; i < CFG_TUH_CDC; i++) {
|
||||
cdch_interface_t* p_cdc = &cdch_data[i];
|
||||
cdch_epbuf_t* epbuf = &cdch_epbuf[i];
|
||||
tu_edpt_stream_init(&p_cdc->stream.tx, true, true, false,
|
||||
p_cdc->stream.tx_ff_buf, CFG_TUH_CDC_TX_BUFSIZE,
|
||||
p_cdc->stream.tx_ep_buf, CFG_TUH_CDC_TX_EPSIZE);
|
||||
epbuf->tx_ep_buf, CFG_TUH_CDC_TX_EPSIZE);
|
||||
|
||||
tu_edpt_stream_init(&p_cdc->stream.rx, true, false, false,
|
||||
p_cdc->stream.rx_ff_buf, CFG_TUH_CDC_RX_BUFSIZE,
|
||||
p_cdc->stream.rx_ep_buf, CFG_TUH_CDC_RX_EPSIZE);
|
||||
epbuf->rx_ep_buf, CFG_TUH_CDC_RX_EPSIZE);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -654,7 +657,9 @@ void cdch_close(uint8_t daddr) {
|
||||
TU_LOG_DRV(" CDCh close addr = %u index = %u\r\n", daddr, idx);
|
||||
|
||||
// Invoke application callback
|
||||
if (tuh_cdc_umount_cb) tuh_cdc_umount_cb(idx);
|
||||
if (tuh_cdc_umount_cb) {
|
||||
tuh_cdc_umount_cb(idx);
|
||||
}
|
||||
|
||||
p_cdc->daddr = 0;
|
||||
p_cdc->bInterfaceNumber = 0;
|
||||
@ -675,7 +680,9 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
|
||||
if ( ep_addr == p_cdc->stream.tx.ep_addr ) {
|
||||
// invoke tx complete callback to possibly refill tx fifo
|
||||
if (tuh_cdc_tx_complete_cb) tuh_cdc_tx_complete_cb(idx);
|
||||
if (tuh_cdc_tx_complete_cb) {
|
||||
tuh_cdc_tx_complete_cb(idx);
|
||||
}
|
||||
|
||||
if ( 0 == tu_edpt_stream_write_xfer(daddr, &p_cdc->stream.tx) ) {
|
||||
// If there is no data left, a ZLP should be sent if:
|
||||
@ -695,7 +702,9 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
}
|
||||
|
||||
// invoke receive callback
|
||||
if (tuh_cdc_rx_cb) tuh_cdc_rx_cb(idx);
|
||||
if (tuh_cdc_rx_cb) {
|
||||
tuh_cdc_rx_cb(idx);
|
||||
}
|
||||
|
||||
// prepare for next transfer if needed
|
||||
tu_edpt_stream_read_xfer(daddr, &p_cdc->stream.rx);
|
||||
@ -738,9 +747,8 @@ bool cdch_open(uint8_t rhport, uint8_t daddr, tusb_desc_interface_t const *itf_d
|
||||
if (TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
|
||||
CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass) {
|
||||
return acm_open(daddr, itf_desc, max_len);
|
||||
}
|
||||
else if (SERIAL_DRIVER_COUNT > 1 &&
|
||||
TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass) {
|
||||
} else if (SERIAL_DRIVER_COUNT > 1 &&
|
||||
TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass) {
|
||||
uint16_t vid, pid;
|
||||
TU_VERIFY(tuh_vid_pid_get(daddr, &vid, &pid));
|
||||
|
||||
@ -760,7 +768,9 @@ bool cdch_open(uint8_t rhport, uint8_t daddr, tusb_desc_interface_t const *itf_d
|
||||
static void set_config_complete(cdch_interface_t * p_cdc, uint8_t idx, uint8_t itf_num) {
|
||||
TU_LOG_DRV("CDCh Set Configure complete\r\n");
|
||||
p_cdc->mounted = true;
|
||||
if (tuh_cdc_mount_cb) tuh_cdc_mount_cb(idx);
|
||||
if (tuh_cdc_mount_cb) {
|
||||
tuh_cdc_mount_cb(idx);
|
||||
}
|
||||
|
||||
// Prepare for incoming data
|
||||
tu_edpt_stream_read_xfer(p_cdc->daddr, &p_cdc->stream.rx);
|
||||
|
@ -89,8 +89,7 @@ bool tuh_cdc_get_dtr(uint8_t idx);
|
||||
bool tuh_cdc_get_rts(uint8_t idx);
|
||||
|
||||
// Check if interface is connected (DTR active)
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool tuh_cdc_connected(uint8_t idx)
|
||||
{
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool tuh_cdc_connected(uint8_t idx) {
|
||||
return tuh_cdc_get_dtr(idx);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user