Skip to content

Commit

Permalink
Merge pull request #1768 from ftdigdm/port-ft90x
Browse files Browse the repository at this point in the history
Port ft90x
  • Loading branch information
hathach committed Jan 30, 2023
2 parents 7166bb3 + 770de31 commit b03a688
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 147 deletions.
11 changes: 11 additions & 0 deletions examples/device/cdc_dual_ports/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ enum
#define EPNUM_CDC_1_OUT 0x05
#define EPNUM_CDC_1_IN 0x86

#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_CDC_0_NOTIF 0x81
#define EPNUM_CDC_0_OUT 0x02
#define EPNUM_CDC_0_IN 0x83

#define EPNUM_CDC_1_NOTIF 0x84
#define EPNUM_CDC_1_OUT 0x05
#define EPNUM_CDC_1_IN 0x86

#else
#define EPNUM_CDC_0_NOTIF 0x81
#define EPNUM_CDC_0_OUT 0x02
Expand Down
13 changes: 13 additions & 0 deletions examples/device/dynamic_configuration/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ enum
#define EPNUM_1_MSC_OUT 0x01
#define EPNUM_1_MSC_IN 0x82

#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_0_CDC_NOTIF 0x81
#define EPNUM_0_CDC_OUT 0x02
#define EPNUM_0_CDC_IN 0x83

#define EPNUM_0_MIDI_OUT 0x04
#define EPNUM_0_MIDI_IN 0x85

#define EPNUM_1_MSC_OUT 0x01
#define EPNUM_1_MSC_IN 0x82

#else
#define EPNUM_0_CDC_NOTIF 0x81
#define EPNUM_0_CDC_OUT 0x02
Expand Down
6 changes: 6 additions & 0 deletions examples/device/msc_dual_lun/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ enum
#define EPNUM_MSC_OUT 0x01
#define EPNUM_MSC_IN 0x82

#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_MSC_OUT 0x01
#define EPNUM_MSC_IN 0x82

#else
#define EPNUM_MSC_OUT 0x01
#define EPNUM_MSC_IN 0x81
Expand Down
6 changes: 6 additions & 0 deletions examples/device/uac2_headset/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ uint8_t const * tud_descriptor_device_cb(void)
#define EPNUM_AUDIO_IN 0x01
#define EPNUM_AUDIO_OUT 0x02

#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_AUDIO_IN 0x01
#define EPNUM_AUDIO_OUT 0x02

#else
#define EPNUM_AUDIO_IN 0x01
#define EPNUM_AUDIO_OUT 0x01
Expand Down
7 changes: 7 additions & 0 deletions examples/device/webusb_serial/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ enum
#define EPNUM_CDC_OUT 3
#define EPNUM_VENDOR_IN 4
#define EPNUM_VENDOR_OUT 5
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
// e.g EP1 OUT & EP1 IN cannot exist together
#define EPNUM_CDC_IN 2
#define EPNUM_CDC_OUT 3
#define EPNUM_VENDOR_IN 4
#define EPNUM_VENDOR_OUT 5
#else
#define EPNUM_CDC_IN 2
#define EPNUM_CDC_OUT 2
Expand Down
48 changes: 40 additions & 8 deletions hw/bsp/brtmm90x/boards/mm900evxb/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,53 @@
#ifndef BOARD_H_
#define BOARD_H_

// Note: This definition file covers all MM900EV1B, MM900EV2B, and MM900EV3B boards.
// Note: This definition file covers all MM900EV1B, MM900EV2B, MM900EV3B,
// MM900EV-Lite boards.
// Each of these boards has an FT900 device.

#ifdef __cplusplus
extern "C" {
#endif

#define GPIO_UART0_TX 48
#define GPIO_UART0_RX 49
#define GPIO_ETH_LED0 61
#define GPIO_ETH_LED1 62
#define GPIO_REMOTE_WAKEUP_PIN 18
#define USBD_VBUS_DTC_PIN 3
// UART to use on this board.
#ifndef BOARD_UART
#define BOARD_UART UART0
#endif

// UART is on connector CN1.
#ifndef BOARD_GPIO_UART0_TX
#define BOARD_GPIO_UART0_TX 48 // Pin 4 of CN1.
#endif
#ifndef BOARD_GPIO_UART0_RX
#define BOARD_GPIO_UART0_RX 49 // Pin 6 of CN1.
#endif

// LED is connected to pins 17 (signal) and 15 (GND) of CN1.
#ifndef BOARD_GPIO_LED
#define BOARD_GPIO_LED 35
#endif
#ifndef BOARD_GPIO_LED_STATE_ON
#define BOARD_GPIO_LED_STATE_ON 1
#endif
// Button is connected to pins 13 (signal) and 15 (GND) of CN1.
#ifndef BOARD_GPIO_BUTTON
#define BOARD_GPIO_BUTTON 56
#endif
// Button is pulled up and grounded for active.
#ifndef BOARD_GPIO_BUTTON_STATE_ACTIVE
#define BOARD_GPIO_BUTTON_STATE_ACTIVE 0
#endif

#define GPIO_REMOTE_WAKEUP
// Enable the Remote Wakeup signalling.
// Remote wakeup is wired to pin 40 of CN1.
#ifndef BOARD_GPIO_REMOTE_WAKEUP
#define BOARD_GPIO_REMOTE_WAKEUP 18
#endif

// USB VBus signal is connected directly to the FT900.
#ifndef BOARD_USBD_VBUS_DTC_PIN
#define BOARD_USBD_VBUS_DTC_PIN 3
#endif

#ifdef __cplusplus
}
Expand Down
110 changes: 76 additions & 34 deletions hw/bsp/brtmm90x/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
#include "bsp/board.h"
#include "board.h"

#include <registers/ft900_registers.h>
#include <ft900.h>
#include <registers/ft900_registers.h>

#if CFG_TUD_ENABLED
int8_t board_ft90x_vbus(void); // Board specific implementation of VBUS detection for USB device.
extern void ft90x_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
int8_t board_ft9xx_vbus(void); // Board specific implementation of VBUS detection for USB device.
extern void ft9xx_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
#endif

#ifdef GPIO_REMOTE_WAKEUP
#ifdef BOARD_GPIO_REMOTE_WAKEUP
void gpio_ISR(void);
#endif
void timer_ISR(void);
Expand All @@ -49,12 +49,17 @@ void board_pm_ISR(void);
void board_init(void)
{
sys_reset_all();

// Enable the UART Device.
sys_enable(sys_device_uart0);
// Set UART0 GPIO functions to UART0_TXD and UART0_RXD.
gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */
gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */
uart_open(UART0, /* Device */
// Set BOARD_UART GPIO function pins for TXD and RXD.
#ifdef BOARD_GPIO_UART_TX
gpio_function(BOARD_GPIO_UART_TX, pad_uart0_txd); /* UART0 TXD */
#endif
#ifdef BOARD_GPIO_UART_RX
gpio_function(BOARD_GPIO_UART_RX, pad_uart0_rxd); /* UART0 RXD */
#endif
uart_open(BOARD_UART, /* Device */
1, /* Prescaler = 1 */
UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
uart_data_bits_8, /* No. Data Bits */
Expand All @@ -64,12 +69,17 @@ void board_init(void)
// Use sizeof to avoid pulling in strlen unnecessarily.
board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));

#if 0
// Ethernet LEDs
gpio_function(GPIO_ETH_LED0, pad_gpio4); /* ETH LED0 */
gpio_dir(GPIO_ETH_LED0, pad_dir_open_drain);
gpio_function(GPIO_ETH_LED1, pad_gpio5); /* ETH LED1 */
gpio_dir(GPIO_ETH_LED1, pad_dir_output);
#ifdef BOARD_GPIO_LED
gpio_function(BOARD_GPIO_LED, pad_func_0);
gpio_idrive(BOARD_GPIO_LED, pad_drive_12mA);
gpio_dir(BOARD_GPIO_LED, pad_dir_output);
#endif

#ifdef BOARD_GPIO_BUTTON
gpio_function(BOARD_GPIO_BUTTON, pad_func_0);
// Pull up if active low. Down if active high.
gpio_pull(BOARD_GPIO_BUTTON, (BOARD_GPIO_BUTTON_STATE_ACTIVE == 0)?pad_pull_pullup:pad_pull_pulldown);
gpio_dir(BOARD_GPIO_BUTTON, pad_dir_input);
#endif

sys_enable(sys_device_timer_wdt);
Expand All @@ -82,26 +92,26 @@ void board_init(void)

// Setup VBUS detect GPIO. If the device is connected then this
// will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
gpio_interrupt_disable(USBD_VBUS_DTC_PIN);
gpio_function(USBD_VBUS_DTC_PIN, pad_vbus_dtc);
gpio_pull(USBD_VBUS_DTC_PIN, pad_pull_pulldown);
gpio_dir(USBD_VBUS_DTC_PIN, pad_dir_input);
gpio_interrupt_disable(BOARD_USBD_VBUS_DTC_PIN);
gpio_function(BOARD_USBD_VBUS_DTC_PIN, pad_vbus_dtc);
gpio_pull(BOARD_USBD_VBUS_DTC_PIN, pad_pull_pulldown);
gpio_dir(BOARD_USBD_VBUS_DTC_PIN, pad_dir_input);

interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR);

#ifdef GPIO_REMOTE_WAKEUP
//Configuring GPIO pin to wakeup.
#ifdef BOARD_GPIO_REMOTE_WAKEUP
// Configuring GPIO pin to wakeup.
// Set up the wakeup pin.
gpio_dir(GPIO_REMOTE_WAKEUP_PIN, pad_dir_input);
gpio_pull(GPIO_REMOTE_WAKEUP_PIN, pad_pull_pullup);
gpio_dir(BOARD_GPIO_REMOTE_WAKEUP, pad_dir_input);
gpio_pull(BOARD_GPIO_REMOTE_WAKEUP, pad_pull_pullup);

// Attach an interrupt handler.
interrupt_attach(interrupt_gpio, (uint8_t)interrupt_gpio, gpio_ISR);
gpio_interrupt_enable(GPIO_REMOTE_WAKEUP_PIN, gpio_int_edge_falling);
gpio_interrupt_enable(BOARD_GPIO_REMOTE_WAKEUP, gpio_int_edge_falling);
#endif

uart_disable_interrupt(UART0, uart_interrupt_tx);
uart_disable_interrupt(UART0, uart_interrupt_rx);
uart_disable_interrupt(BOARD_UART, uart_interrupt_tx);
uart_disable_interrupt(BOARD_UART, uart_interrupt_rx);

// Enable all peripheral interrupts.
interrupt_enable_globally();
Expand All @@ -117,10 +127,10 @@ void timer_ISR(void)
}
}

#ifdef GPIO_REMOTE_WAKEUP
#ifdef BOARD_GPIO_REMOTE_WAKEUP
void gpio_ISR(void)
{
if (gpio_is_interrupted(GPIO_REMOTE_WAKEUP_PIN))
if (gpio_is_interrupted(BOARD_GPIO_REMOTE_WAKEUP))
{
}
}
Expand Down Expand Up @@ -153,16 +163,16 @@ void board_pm_ISR(void)
)
{
#if CFG_TUD_ENABLED
ft90x_usbd_pm_ISR(pmcfg);
ft9xx_usbd_pm_ISR(pmcfg);
#endif
}
#endif
}

#if CFG_TUD_ENABLED
int8_t board_ft90x_vbus(void)
int8_t board_ft9xx_vbus(void)
{
return gpio_read(USBD_VBUS_DTC_PIN);
return gpio_read(BOARD_USBD_VBUS_DTC_PIN);
}
#endif

Expand All @@ -173,31 +183,48 @@ int8_t board_ft90x_vbus(void)
// Turn LED on or off
void board_led_write(bool state)
{
gpio_write(GPIO_ETH_LED0, state);
#ifdef BOARD_GPIO_LED
gpio_write(BOARD_GPIO_LED, (state == 0)?(BOARD_GPIO_LED_STATE_ON?0:1):BOARD_GPIO_LED_STATE_ON);
#endif
}

// Get the current state of button
// a '1' means active (pressed), a '0' means inactive.
uint32_t board_button_read(void)
{
return 0;
uint32_t state = 0;
#ifdef BOARD_GPIO_BUTTON
state = (gpio_read(BOARD_GPIO_BUTTON) == BOARD_GPIO_BUTTON_STATE_ACTIVE)?1:0;
#endif
return state;
}

// Get characters from UART
int board_uart_read(uint8_t *buf, int len)
{
int r = uart_readn(UART0, (uint8_t *)buf, len);
int r = 0;

#ifdef BOARD_UART
if (uart_rx_has_data(BOARD_UART))
{
r = uart_readn(BOARD_UART, (uint8_t *)buf, len);
}
#endif

return r;
}

// Send characters to UART
int board_uart_write(void const *buf, int len)
{
int r = 0;

#ifdef BOARD_UART
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter.
int r = uart_writen(UART0, (uint8_t *)((const void *)buf), len);
r = uart_writen(BOARD_UART, (uint8_t *)((const void *)buf), len);
#pragma GCC diagnostic pop
#endif

return r;
}
Expand All @@ -213,3 +240,18 @@ uint32_t board_millis(void)

return safe_ms;
}

// Restart the program
// Called in the event of a watchdog timeout
void chip_reboot(void)
{
// SOFT reset
__asm__("call 0");
#if 0
// HARD reset
// Initiates data transfer from Flash Memory to Data Memory (DBG_CMDF2D3)
// followed by a system reboot
dbg_memory_copy(0xfe, 0, 0, 255);
#endif
}

Loading

0 comments on commit b03a688

Please sign in to comment.