2828#include "debug_uart.h"
2929#include "ch32v30x.h"
3030
31- #include "../board.h"
31+ #include "bsp/board.h"
32+ #include "board.h"
3233
3334//--------------------------------------------------------------------+
3435// Forward USB interrupt events to TinyUSB IRQ Handler
3536//--------------------------------------------------------------------+
3637
37- void USBHS_IRQHandler (void ) __attribute__((naked ));
38- void USBHS_IRQHandler (void ) {
39- __asm volatile ("call USBHS_IRQHandler_impl; mret" );
38+ void USBHS_IRQHandler (void ) __attribute__((naked ));
39+ void USBHS_IRQHandler (void )
40+ {
41+ __asm volatile ("call USBHS_IRQHandler_impl; mret" );
4042}
4143
42- __attribute__ ((used )) void USBHS_IRQHandler_impl (void ) {
43- tud_int_handler (0 );
44+ __attribute__ ((used )) void USBHS_IRQHandler_impl (void )
45+ {
46+ tud_int_handler (0 );
4447}
4548
4649//--------------------------------------------------------------------+
@@ -49,21 +52,20 @@ __attribute__ ((used)) void USBHS_IRQHandler_impl(void) {
4952
5053uint32_t SysTick_Config (uint32_t ticks )
5154{
52- NVIC_EnableIRQ (SysTicK_IRQn );
53- SysTick -> CTLR = 0 ;
54- SysTick -> SR = 0 ;
55- SysTick -> CNT = 0 ;
56- SysTick -> CMP = ticks - 1 ;
57- SysTick -> CTLR = 0xF ;
58- return 0 ;
55+ NVIC_EnableIRQ (SysTicK_IRQn );
56+ SysTick -> CTLR = 0 ;
57+ SysTick -> SR = 0 ;
58+ SysTick -> CNT = 0 ;
59+ SysTick -> CMP = ticks - 1 ;
60+ SysTick -> CTLR = 0xF ;
61+ return 0 ;
5962}
6063
6164void board_init (void ) {
6265
6366 /* Disable interrupts during init */
6467 __disable_irq ();
6568
66-
6769#if CFG_TUSB_OS == OPT_OS_NONE
6870 SysTick_Config (SystemCoreClock / 1000 );
6971#endif
@@ -79,11 +81,19 @@ void board_init(void) {
7981
8082 GPIO_InitTypeDef GPIO_InitStructure = {0 };
8183
82- RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC , ENABLE );
83- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_0 ;
84+ // LED
85+ LED_CLOCK_EN ();
86+ GPIO_InitStructure .GPIO_Pin = LED_PIN ;
8487 GPIO_InitStructure .GPIO_Mode = GPIO_Mode_Out_OD ;
8588 GPIO_InitStructure .GPIO_Speed = GPIO_Speed_50MHz ;
86- GPIO_Init (GPIOC , & GPIO_InitStructure );
89+ GPIO_Init (LED_PORT , & GPIO_InitStructure );
90+
91+ // Button
92+ BUTTON_CLOCK_EN ();
93+ GPIO_InitStructure .GPIO_Pin = BUTTON_PIN ;
94+ GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IPU ;
95+ GPIO_InitStructure .GPIO_Speed = GPIO_Speed_50MHz ;
96+ GPIO_Init (BUTTON_PORT , & GPIO_InitStructure );
8797
8898 /* Enable interrupts globally */
8999 __enable_irq ();
@@ -114,26 +124,29 @@ uint32_t board_millis(void) { return system_ticks; }
114124// Board porting API
115125//--------------------------------------------------------------------+
116126
117- void board_led_write (bool state ) {
118- (void ) state ;
119-
120- GPIO_WriteBit (GPIOC , GPIO_Pin_0 , state );
127+ void board_led_write (bool state )
128+ {
129+ GPIO_WriteBit (LED_PORT , LED_PIN , state );
121130}
122131
123- uint32_t board_button_read (void ) {
124- return false;
132+ uint32_t board_button_read (void )
133+ {
134+ return BUTTON_STATE_ACTIVE == GPIO_ReadInputDataBit (BUTTON_PORT , BUTTON_PIN );
125135}
126136
127- int board_uart_read (uint8_t * buf , int len ) {
128- (void )buf ;
129- (void )len ;
137+ int board_uart_read (uint8_t * buf , int len )
138+ {
139+ (void ) buf ;
140+ (void ) len ;
130141 return 0 ;
131142}
132143
133- int board_uart_write (void const * buf , int len ) {
144+ int board_uart_write (void const * buf , int len )
145+ {
134146 int txsize = len ;
135- while (txsize -- ) {
136- uart_write (* (uint8_t const * )buf );
147+ while ( txsize -- )
148+ {
149+ uart_write (* (uint8_t const * ) buf );
137150 buf ++ ;
138151 }
139152 return len ;
0 commit comments