Skip to content

Commit fe63e30

Browse files
committed
Add FT9xx for cdc_dual_ports
Fix handling of interrupt endpoints. i.e. no ZLPs. Fix the assignation of endpoint types. Add button support for MM900evx boards. On board support do not block for UART input.
1 parent 7d8d3ec commit fe63e30

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

examples/device/cdc_dual_ports/src/usb_descriptors.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ enum
111111
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
112112
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
113113
// e.g EP1 OUT & EP1 IN cannot exist together
114-
#define EPNUM_CDC_NOTIF 0x81
115-
#define EPNUM_CDC_OUT 0x02
116-
#define EPNUM_CDC_IN 0x83
114+
#define EPNUM_CDC_0_NOTIF 0x81
115+
#define EPNUM_CDC_0_OUT 0x02
116+
#define EPNUM_CDC_0_IN 0x83
117117

118-
#define EPNUM_MSC_OUT 0x04
119-
#define EPNUM_MSC_IN 0x85
118+
#define EPNUM_CDC_1_NOTIF 0x84
119+
#define EPNUM_CDC_1_OUT 0x05
120+
#define EPNUM_CDC_1_IN 0x86
120121

121122
#else
122123
#define EPNUM_CDC_0_NOTIF 0x81

hw/bsp/brtmm90x/boards/mm900evxb/board.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
// LED is connected to pins 4 (signal) and 2 (GND) of CN2.
4343
#define GPIO_LED 36
44+
// Button is connected to pins 6 (signal) and 2 (GND) of CN2.
45+
#define GPIO_BUTTON 37
4446

4547
// Remote wakeup is wired to pin 40 of CN1.
4648
#define GPIO_REMOTE_WAKEUP_PIN 18

hw/bsp/brtmm90x/family.c

+25-6
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ void board_pm_ISR(void);
4949
void board_init(void)
5050
{
5151
sys_reset_all();
52+
5253
// Enable the UART Device.
5354
sys_enable(sys_device_uart0);
5455
// Set UART0 GPIO functions to UART0_TXD and UART0_RXD.
56+
#ifdef GPIO_UART0_TX
5557
gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */
58+
#endif
59+
#ifdef GPIO_UART0_RX
5660
gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */
61+
#endif
5762
uart_open(UART0, /* Device */
5863
1, /* Prescaler = 1 */
5964
UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
@@ -65,11 +70,17 @@ void board_init(void)
6570
board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));
6671

6772
#ifdef GPIO_LED
68-
gpio_function(GPIO_LED, pad_func_0); /* CN2 connector pin 4 */
73+
gpio_function(GPIO_LED, pad_func_0);
6974
gpio_idrive(GPIO_LED, pad_drive_12mA);
7075
gpio_dir(GPIO_LED, pad_dir_output);
7176
#endif
7277

78+
#ifdef GPIO_BUTTON
79+
gpio_function(GPIO_BUTTON, pad_func_0);
80+
gpio_pull(GPIO_BUTTON, pad_pull_pullup);
81+
gpio_dir(GPIO_BUTTON, pad_dir_input);
82+
#endif
83+
7384
sys_enable(sys_device_timer_wdt);
7485
/* Timer A = 1ms */
7586
timer_prescaler(timer_select_a, 1000);
@@ -171,9 +182,7 @@ int8_t board_ft9xx_vbus(void)
171182
// Turn LED on or off
172183
void board_led_write(bool state)
173184
{
174-
#if 0
175-
gpio_write(GPIO_ETH_LED0, state);
176-
#else
185+
#ifdef GPIO_LED
177186
gpio_write(GPIO_LED, state);
178187
#endif
179188
}
@@ -182,13 +191,23 @@ void board_led_write(bool state)
182191
// a '1' means active (pressed), a '0' means inactive.
183192
uint32_t board_button_read(void)
184193
{
185-
return 0;
194+
uint32_t state = 0;
195+
#ifdef GPIO_BUTTON
196+
state = gpio_read(GPIO_BUTTON);
197+
state = !state;
198+
#endif
199+
return state;
186200
}
187201

188202
// Get characters from UART
189203
int board_uart_read(uint8_t *buf, int len)
190204
{
191-
int r = uart_readn(UART0, (uint8_t *)buf, len);
205+
int r = 0;
206+
207+
if (uart_rx_has_data(UART0))
208+
{
209+
r = uart_readn(UART0, (uint8_t *)buf, len);
210+
}
192211

193212
return r;
194213
}

src/portable/bridgetek/ft9xx/dcd_ft9xx.c

+19-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
// Board code will determine the state of VBUS from USB host.
5050
extern int8_t board_ft9xx_vbus(void);
51+
extern int board_uart_write(void const *buf, int len);
5152

5253
// Static array to store an incoming SETUP request for processing by tinyusb.
5354
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN
@@ -154,17 +155,24 @@ static uint16_t _ft9xx_edpt_xfer_in(uint8_t ep_number, uint8_t *buffer, uint16_t
154155
}
155156
else
156157
{
157-
uint8_t sr_reg;
158158
// If there is data to transmit then wait until the IN buffer
159159
// for the endpoint is empty.
160-
do
160+
// This does not apply to interrupt endpoints.
161+
if (ep_xfer[ep_number].type != TUSB_XFER_INTERRUPT)
161162
{
162-
sr_reg = USBD_EP_SR_REG(ep_number);
163-
} while (sr_reg & MASK_USBD_EPxSR_INPRDY);
164-
163+
uint8_t sr_reg;
164+
do
165+
{
166+
sr_reg = USBD_EP_SR_REG(ep_number);
167+
} while (sr_reg & MASK_USBD_EPxSR_INPRDY);
168+
}
165169
}
166170

167-
xfer_bytes = _ft9xx_dusb_in(ep_number, (uint8_t *)buffer, xfer_bytes);
171+
// Do not send a ZLP for interrupt endpoints.
172+
if ((ep_xfer[ep_number].type != TUSB_XFER_INTERRUPT) || (xfer_bytes > 0))
173+
{
174+
xfer_bytes = _ft9xx_dusb_in(ep_number, (uint8_t *)buffer, xfer_bytes);
175+
}
168176

169177
if (ep_number == USBD_EP_0)
170178
{
@@ -749,19 +757,19 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *ep_desc)
749757
}
750758

751759
// Set the type of this endpoint in the control register.
752-
if (ep_type == USBD_EP_BULK)
760+
if (ep_type == TUSB_XFER_BULK)
753761
ep_reg_data |= (USBD_EP_DIS_BULK << BIT_USBD_EP_CONTROL_DIS);
754-
else if (ep_type == USBD_EP_INT)
762+
else if (ep_type == TUSB_XFER_INTERRUPT)
755763
ep_reg_data |= (USBD_EP_DIS_INT << BIT_USBD_EP_CONTROL_DIS);
756-
else if (ep_type == USBD_EP_ISOC)
764+
else if (ep_type == TUSB_XFER_ISOCHRONOUS)
757765
ep_reg_data |= (USBD_EP_DIS_ISO << BIT_USBD_EP_CONTROL_DIS);
758766
// Set the direction of this endpoint in the control register.
759767
if (ep_dir == USBD_DIR_IN)
760768
ep_reg_data |= MASK_USBD_EPxCR_DIR;
761769
// Do not perform double buffering.
762770
//if (<double buffering flag> != USBD_DB_OFF)
763771
//ep_reg_data |= MASK_USBD_EPxCR_DB;
764-
// Set the control endpoint for this endpoint.
772+
// Set the control register for this endpoint.
765773
USBD_EP_CR_REG(ep_number) = ep_reg_data;
766774
TU_LOG2("FT9xx endpoint setting %x\r\n", ep_reg_data);
767775
}
@@ -858,6 +866,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
858866

859867
// Transfer incoming data from an OUT packet to the buffer.
860868
xfer_bytes = _ft9xx_edpt_xfer_out(ep_number, buffer, total_bytes);
869+
861870
// Report completion of the transfer.
862871
dcd_event_xfer_complete(BOARD_TUD_RHPORT, ep_number /*| TUSB_DIR_OUT_MASK */, xfer_bytes, XFER_RESULT_SUCCESS, false);
863872
}

0 commit comments

Comments
 (0)