Small tidy up for waveshare openh743i BSP.

This commit is contained in:
Ben Evans 2021-07-27 12:07:19 +10:00
parent d058645f97
commit 0953be9d7f
1 changed files with 17 additions and 5 deletions

View File

@ -100,6 +100,7 @@
#define OTG_FS_VBUS_SENSE 1 #define OTG_FS_VBUS_SENSE 1
#define OTG_HS_VBUS_SENSE 0 #define OTG_HS_VBUS_SENSE 0
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM // MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -107,6 +108,7 @@
UART_HandleTypeDef uartHandle; UART_HandleTypeDef uartHandle;
TIM_HandleTypeDef tim2Handle; TIM_HandleTypeDef tim2Handle;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler // Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -125,6 +127,7 @@ void OTG_HS_IRQHandler(void)
tud_int_handler(1); tud_int_handler(1);
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// RCC Clock // RCC Clock
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -230,17 +233,19 @@ static void init_timer(void)
return; return;
} }
//Custom board delay implementation using timer ticks
// Custom board delay implementation using timer ticks
static inline void timer_board_delay(uint32_t ms) static inline void timer_board_delay(uint32_t ms)
{ {
uint32_t startMs = __HAL_TIM_GET_COUNTER(&tim2Handle); uint32_t startMs = __HAL_TIM_GET_COUNTER(&tim2Handle);
while ((__HAL_TIM_GET_COUNTER(&tim2Handle) - startMs) < ms) while ((__HAL_TIM_GET_COUNTER(&tim2Handle) - startMs) < ms)
{ {
asm("nop"); asm("nop"); //do nothing
} }
} }
//Board initialisation
void board_init(void) void board_init(void)
{ {
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
@ -418,11 +423,11 @@ void board_init(void)
#endif // rhport = 1 #endif // rhport = 1
//Disable the timer use for delays //Disable the timer used for delays
HAL_TIM_Base_Stop(&tim2Handle); HAL_TIM_Base_Stop(&tim2Handle);
__HAL_RCC_TIM2_CLK_DISABLE(); __HAL_RCC_TIM2_CLK_DISABLE();
// 1ms tick timer // Configure systick 1ms tick timer
SysTick_Config(SystemCoreClock / 1000); SysTick_Config(SystemCoreClock / 1000);
//Enable systick //Enable systick
@ -431,20 +436,22 @@ void board_init(void)
return; return;
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void board_led_write(bool state) void board_led_write(bool state)
{ {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON)); HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
} }
uint32_t board_button_read(void) uint32_t board_button_read(void)
{ {
return (BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) ? 1 : 0; return (BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) ? 1 : 0;
} }
int board_uart_read(uint8_t *buf, int len) int board_uart_read(uint8_t *buf, int len)
{ {
(void)buf; (void)buf;
@ -452,12 +459,14 @@ int board_uart_read(uint8_t *buf, int len)
return 0; return 0;
} }
int board_uart_write(void const *buf, int len) int board_uart_write(void const *buf, int len)
{ {
HAL_UART_Transmit(&uartHandle, (uint8_t *)buf, len, 0xffff); HAL_UART_Transmit(&uartHandle, (uint8_t *)buf, len, 0xffff);
return len; return len;
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler(void) void SysTick_Handler(void)
@ -465,17 +474,20 @@ void SysTick_Handler(void)
system_ticks++; system_ticks++;
} }
uint32_t board_millis(void) uint32_t board_millis(void)
{ {
return system_ticks; return system_ticks;
} }
#endif #endif
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
asm("bkpt"); asm("bkpt");
} }
// Required by __libc_init_array in startup code if we are compiling using // Required by __libc_init_array in startup code if we are compiling using
// -nostdlib/-nostartfiles. // -nostdlib/-nostartfiles.
void _init(void) void _init(void)