14
14
#endif
15
15
16
16
// Initialize the GPIO for the LED
17
- void pico_led_init (void ) {
17
+ static void pico_led_init (void ) {
18
18
#ifdef PICO_DEFAULT_LED_PIN
19
19
// A device like Pico that uses a GPIO for the LED will define PICO_DEFAULT_LED_PIN
20
20
// so we can use normal GPIO functionality to turn the led on and off
@@ -24,23 +24,44 @@ void pico_led_init(void) {
24
24
}
25
25
26
26
// Turn the LED on or off
27
- void pico_set_led (bool led_on ) {
27
+ static void pico_set_led (bool led_on ) {
28
28
#if defined(PICO_DEFAULT_LED_PIN )
29
29
// Just set the GPIO on or off
30
30
gpio_put (PICO_DEFAULT_LED_PIN , led_on );
31
31
#endif
32
32
}
33
33
34
+ enum qspi_gpio {
35
+ // arbitrarily choose PAD register bank to set the order
36
+ QSPI_GPIO_SCLK = 0 ,
37
+ QSPI_GPIO_SD0 = 1 ,
38
+ QSPI_GPIO_SD1 = 2 ,
39
+ QSPI_GPIO_SD2 = 3 ,
40
+ QSPI_GPIO_SD3 = 4 ,
41
+ QSPI_GPIO_SS = 5 ,
42
+ };
43
+
44
+ // curiously the IO and PAD register banks for the QSPI GPIOs are not in the same order
45
+ // This look up table will map the PAD offset to the IO offset for the same pin
46
+ static const uint QSPI_GPIO_PAD_TO_IO_OFFSET [] = {
47
+ 0 , // SCLK
48
+ 2 , // SD0
49
+ 3 , // SD1
50
+ 4 , // SD2
51
+ 5 , // SD3
52
+ 1 , // SS
53
+ };
54
+
34
55
// Set function for QSPI GPIO pin
35
- void qspi_gpio_set_function (uint gpio , gpio_function_t fn ) {
56
+ static void qspi_gpio_set_function (enum qspi_gpio gpio , gpio_function_t fn ) {
36
57
// Set input enable on, output disable off
37
58
hw_write_masked (& pads_qspi_hw -> io [gpio ],
38
59
PADS_QSPI_GPIO_QSPI_SD2_IE_BITS ,
39
60
PADS_QSPI_GPIO_QSPI_SD2_IE_BITS | PADS_QSPI_GPIO_QSPI_SD2_OD_BITS
40
61
);
41
62
// Zero all fields apart from fsel; we want this IO to do what the peripheral tells it.
42
63
// This doesn't affect e.g. pullup/pulldown, as these are in pad controls.
43
- io_qspi_hw -> io [gpio ].ctrl = fn << IO_QSPI_GPIO_QSPI_SD2_CTRL_FUNCSEL_LSB ;
64
+ io_qspi_hw -> io [QSPI_GPIO_PAD_TO_IO_OFFSET [ gpio ] ].ctrl = fn << IO_QSPI_GPIO_QSPI_SD2_CTRL_FUNCSEL_LSB ;
44
65
45
66
// Remove pad isolation now that the correct peripheral is in control of the pad
46
67
hw_clear_bits (& pads_qspi_hw -> io [gpio ], PADS_QSPI_GPIO_QSPI_SD2_ISO_BITS );
@@ -49,9 +70,9 @@ void qspi_gpio_set_function(uint gpio, gpio_function_t fn) {
49
70
int main () {
50
71
pico_led_init ();
51
72
52
- // SD2 is QSPI GPIO 3 , SD3 is QSPI GPIO 4
53
- qspi_gpio_set_function (3 , GPIO_FUNC_UART_AUX );
54
- qspi_gpio_set_function (4 , GPIO_FUNC_UART_AUX );
73
+ // SD2 is UART0 TX , SD3 is UART0 RX (same as the ROM UART bootloader)
74
+ qspi_gpio_set_function (QSPI_GPIO_SD2 , GPIO_FUNC_UART_AUX );
75
+ qspi_gpio_set_function (QSPI_GPIO_SD3 , GPIO_FUNC_UART_AUX );
55
76
56
77
uart_init (uart0 , 1000000 );
57
78
0 commit comments