@@ -54,6 +54,14 @@ void USB0_IRQHandler(void)
54
54
#define LED_PIN_FUNCTION kPORT_MuxAsGpio
55
55
#define LED_STATE_ON 0
56
56
57
+ // Button
58
+ #define BUTTON_PORT GPIOC
59
+ #define BUTTON_PIN_CLOCK kCLOCK_PortC
60
+ #define BUTTON_PIN_PORT PORTC
61
+ #define BUTTON_PIN 9U
62
+ #define BUTTON_PIN_FUNCTION kPORT_MuxAsGpio
63
+ #define BUTTON_STATE_ACTIVE 0
64
+
57
65
// UART
58
66
#define UART_PORT UART0
59
67
#define UART_PIN_CLOCK kCLOCK_PortA
@@ -84,7 +92,19 @@ void board_init(void)
84
92
PORT_SetPinMux (LED_PIN_PORT , LED_PIN , LED_PIN_FUNCTION );
85
93
gpio_pin_config_t led_config = { kGPIO_DigitalOutput , 0 };
86
94
GPIO_PinInit (LED_PORT , LED_PIN , & led_config );
87
- board_led_write (true);
95
+ board_led_write (false);
96
+
97
+ #if defined(BUTTON_PORT ) && defined(BUTTON_PIN )
98
+ // Button
99
+ CLOCK_EnableClock (BUTTON_PIN_CLOCK );
100
+ port_pin_config_t button_port = {
101
+ .pullSelect = kPORT_PullUp ,
102
+ .mux = BUTTON_PIN_FUNCTION ,
103
+ };
104
+ PORT_SetPinConfig (BUTTON_PIN_PORT , BUTTON_PIN , & button_port );
105
+ gpio_pin_config_t button_config = { kGPIO_DigitalInput , 0 };
106
+ GPIO_PinInit (BUTTON_PORT , BUTTON_PIN , & button_config );
107
+ #endif
88
108
89
109
// UART
90
110
CLOCK_EnableClock (UART_PIN_CLOCK );
@@ -119,6 +139,9 @@ void board_led_write(bool state)
119
139
120
140
uint32_t board_button_read (void )
121
141
{
142
+ #if defined(BUTTON_PORT ) && defined(BUTTON_PIN )
143
+ return BUTTON_STATE_ACTIVE == GPIO_ReadPinInput (BUTTON_PORT , BUTTON_PIN );
144
+ #endif
122
145
return 0 ;
123
146
}
124
147
0 commit comments