More configurable board options

This commit is contained in:
Gordon McNab 2022-11-30 16:18:07 +00:00
parent d3c4f66d35
commit 8cce9385e2
2 changed files with 80 additions and 50 deletions

View File

@ -35,23 +35,47 @@
extern "C" { extern "C" {
#endif #endif
#include <tinyprintf.h>
// UART to use on this board.
#ifndef BOARD_UART
#define BOARD_UART UART0
#endif
// UART is on connector CN1. // UART is on connector CN1.
#define GPIO_UART0_TX 48 // Pin 4 of CN1. #ifndef BOARD_GPIO_UART0_TX
#define GPIO_UART0_RX 49 // Pin 6 of CN1. #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 4 (signal) and 2 (GND) of CN2. // LED is connected to pins 17 (signal) and 15 (GND) of CN1.
#define GPIO_LED 36 #ifndef BOARD_GPIO_LED
// Button is connected to pins 6 (signal) and 2 (GND) of CN2. #define BOARD_GPIO_LED 35
#define GPIO_BUTTON 37 #endif
#ifndef BOARD_GPIO_LED_STATE_ON
// Remote wakeup is wired to pin 40 of CN1. #define BOARD_GPIO_LED_STATE_ON 1
#define GPIO_REMOTE_WAKEUP_PIN 18 #endif
// Button is connected to pins 13 (signal) and 15 (GND) of CN1.
// USB VBus signal is connected directly to the FT900. #ifndef BOARD_GPIO_BUTTON
#define USBD_VBUS_DTC_PIN 3 #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
// Enable the Remote Wakeup signalling. // Enable the Remote Wakeup signalling.
#define GPIO_REMOTE_WAKEUP // 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 #ifdef __cplusplus
} }

View File

@ -35,7 +35,7 @@ int8_t board_ft9xx_vbus(void); // Board specific implementation of VBUS detectio
extern void ft9xx_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management extern void ft9xx_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
#endif #endif
#ifdef GPIO_REMOTE_WAKEUP #ifdef BOARD_GPIO_REMOTE_WAKEUP
void gpio_ISR(void); void gpio_ISR(void);
#endif #endif
void timer_ISR(void); void timer_ISR(void);
@ -52,14 +52,14 @@ void board_init(void)
// Enable the UART Device. // Enable the UART Device.
sys_enable(sys_device_uart0); sys_enable(sys_device_uart0);
// Set UART0 GPIO functions to UART0_TXD and UART0_RXD. // Set BOARD_UART GPIO function pins for TXD and RXD.
#ifdef GPIO_UART0_TX #ifdef BOARD_GPIO_UART_TX
gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */ gpio_function(BOARD_GPIO_UART_TX, pad_uart0_txd); /* UART0 TXD */
#endif #endif
#ifdef GPIO_UART0_RX #ifdef BOARD_GPIO_UART_RX
gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */ gpio_function(BOARD_GPIO_UART_RX, pad_uart0_rxd); /* UART0 RXD */
#endif #endif
uart_open(UART0, /* Device */ uart_open(BOARD_UART, /* Device */
1, /* Prescaler = 1 */ 1, /* Prescaler = 1 */
UART_DIVIDER_19200_BAUD, /* Divider = 1302 */ UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
uart_data_bits_8, /* No. Data Bits */ uart_data_bits_8, /* No. Data Bits */
@ -69,16 +69,17 @@ void board_init(void)
// Use sizeof to avoid pulling in strlen unnecessarily. // Use sizeof to avoid pulling in strlen unnecessarily.
board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG)); board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));
#ifdef GPIO_LED #ifdef BOARD_GPIO_LED
gpio_function(GPIO_LED, pad_func_0); gpio_function(BOARD_GPIO_LED, pad_func_0);
gpio_idrive(GPIO_LED, pad_drive_12mA); gpio_idrive(BOARD_GPIO_LED, pad_drive_12mA);
gpio_dir(GPIO_LED, pad_dir_output); gpio_dir(BOARD_GPIO_LED, pad_dir_output);
#endif #endif
#ifdef GPIO_BUTTON #ifdef BOARD_GPIO_BUTTON
gpio_function(GPIO_BUTTON, pad_func_0); gpio_function(BOARD_GPIO_BUTTON, pad_func_0);
gpio_pull(GPIO_BUTTON, pad_pull_pullup); // Pull up if active low. Down if active high.
gpio_dir(GPIO_BUTTON, pad_dir_input); 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 #endif
sys_enable(sys_device_timer_wdt); sys_enable(sys_device_timer_wdt);
@ -91,26 +92,26 @@ void board_init(void)
// Setup VBUS detect GPIO. If the device is connected then this // Setup VBUS detect GPIO. If the device is connected then this
// will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG. // will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
gpio_interrupt_disable(USBD_VBUS_DTC_PIN); gpio_interrupt_disable(BOARD_USBD_VBUS_DTC_PIN);
gpio_function(USBD_VBUS_DTC_PIN, pad_vbus_dtc); gpio_function(BOARD_USBD_VBUS_DTC_PIN, pad_vbus_dtc);
gpio_pull(USBD_VBUS_DTC_PIN, pad_pull_pulldown); gpio_pull(BOARD_USBD_VBUS_DTC_PIN, pad_pull_pulldown);
gpio_dir(USBD_VBUS_DTC_PIN, pad_dir_input); gpio_dir(BOARD_USBD_VBUS_DTC_PIN, pad_dir_input);
interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR); interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR);
#ifdef GPIO_REMOTE_WAKEUP #ifdef BOARD_GPIO_REMOTE_WAKEUP
//Configuring GPIO pin to wakeup. // Configuring GPIO pin to wakeup.
// Set up the wakeup pin. // Set up the wakeup pin.
gpio_dir(GPIO_REMOTE_WAKEUP_PIN, pad_dir_input); gpio_dir(BOARD_GPIO_REMOTE_WAKEUP, pad_dir_input);
gpio_pull(GPIO_REMOTE_WAKEUP_PIN, pad_pull_pullup); gpio_pull(BOARD_GPIO_REMOTE_WAKEUP, pad_pull_pullup);
// Attach an interrupt handler. // Attach an interrupt handler.
interrupt_attach(interrupt_gpio, (uint8_t)interrupt_gpio, gpio_ISR); 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 #endif
uart_disable_interrupt(UART0, uart_interrupt_tx); uart_disable_interrupt(BOARD_UART, uart_interrupt_tx);
uart_disable_interrupt(UART0, uart_interrupt_rx); uart_disable_interrupt(BOARD_UART, uart_interrupt_rx);
// Enable all peripheral interrupts. // Enable all peripheral interrupts.
interrupt_enable_globally(); interrupt_enable_globally();
@ -126,10 +127,10 @@ void timer_ISR(void)
} }
} }
#ifdef GPIO_REMOTE_WAKEUP #ifdef BOARD_GPIO_REMOTE_WAKEUP
void gpio_ISR(void) void gpio_ISR(void)
{ {
if (gpio_is_interrupted(GPIO_REMOTE_WAKEUP_PIN)) if (gpio_is_interrupted(BOARD_GPIO_REMOTE_WAKEUP))
{ {
} }
} }
@ -171,7 +172,7 @@ void board_pm_ISR(void)
#if CFG_TUD_ENABLED #if CFG_TUD_ENABLED
int8_t board_ft9xx_vbus(void) int8_t board_ft9xx_vbus(void)
{ {
return gpio_read(USBD_VBUS_DTC_PIN); return gpio_read(BOARD_USBD_VBUS_DTC_PIN);
} }
#endif #endif
@ -182,8 +183,8 @@ int8_t board_ft9xx_vbus(void)
// Turn LED on or off // Turn LED on or off
void board_led_write(bool state) void board_led_write(bool state)
{ {
#ifdef GPIO_LED #ifdef BOARD_GPIO_LED
gpio_write(GPIO_LED, state); gpio_write(BOARD_GPIO_LED, (state == 0)?(BOARD_GPIO_LED_STATE_ON?0:1):BOARD_GPIO_LED_STATE_ON);
#endif #endif
} }
@ -192,9 +193,8 @@ void board_led_write(bool state)
uint32_t board_button_read(void) uint32_t board_button_read(void)
{ {
uint32_t state = 0; uint32_t state = 0;
#ifdef GPIO_BUTTON #ifdef BOARD_GPIO_BUTTON
state = gpio_read(GPIO_BUTTON); state = (gpio_read(BOARD_GPIO_BUTTON) == BOARD_GPIO_BUTTON_STATE_ACTIVE)?1:0;
state = !state;
#endif #endif
return state; return state;
} }
@ -204,10 +204,12 @@ int board_uart_read(uint8_t *buf, int len)
{ {
int r = 0; int r = 0;
if (uart_rx_has_data(UART0)) #ifdef BOARD_UART
if (uart_rx_has_data(BOARD_UART))
{ {
r = uart_readn(UART0, (uint8_t *)buf, len); r = uart_readn(BOARD_UART, (uint8_t *)buf, len);
} }
#endif
return r; return r;
} }
@ -215,10 +217,14 @@ int board_uart_read(uint8_t *buf, int len)
// Send characters to UART // Send characters to UART
int board_uart_write(void const *buf, int len) int board_uart_write(void const *buf, int len)
{ {
int r = 0;
#ifdef BOARD_UART
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter. #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 #pragma GCC diagnostic pop
#endif
return r; return r;
} }