10
10
11
11
int pinctrl_configure_pins (const pinctrl_soc_pin_t * pins , uint8_t pin_cnt , uintptr_t reg )
12
12
{
13
- #ifdef CONFIG_UART_GECKO
14
- struct soc_gpio_pin rxpin = {0 };
15
- struct soc_gpio_pin txpin = {0 };
16
13
USART_TypeDef * base = (USART_TypeDef * )reg ;
17
- uint8_t loc ;
18
14
int usart_num = USART_NUM (base );
15
+ uint8_t loc ;
16
+
17
+ #ifdef CONFIG_SPI_GECKO
18
+ struct soc_gpio_pin spi_pin_cfg = {0 , 0 , 0 , 0 };
19
+ #endif /* CONFIG_SPI_GECKO */
20
+
21
+ #ifdef CONFIG_UART_GECKO
22
+ struct soc_gpio_pin rxpin = {0 , 0 , 0 , 0 };
23
+ struct soc_gpio_pin txpin = {0 , 0 , 0 , 0 };
19
24
#endif /* CONFIG_UART_GECKO */
20
25
21
26
for (uint8_t i = 0U ; i < pin_cnt ; i ++ ) {
@@ -27,20 +32,20 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
27
32
rxpin .mode = gpioModeInput ;
28
33
rxpin .out = 1 ;
29
34
GPIO_PinModeSet (rxpin .port , rxpin .pin , rxpin .mode ,
30
- rxpin .out );
35
+ rxpin .out );
31
36
break ;
32
37
case GECKO_FUN_UART_TX :
33
38
txpin .port = GECKO_GET_PORT (pins [i ]);
34
39
txpin .pin = GECKO_GET_PIN (pins [i ]);
35
40
txpin .mode = gpioModePushPull ;
36
41
txpin .out = 1 ;
37
42
GPIO_PinModeSet (txpin .port , txpin .pin , txpin .mode ,
38
- txpin .out );
43
+ txpin .out );
39
44
break ;
40
45
case GECKO_FUN_UART_LOC :
41
46
loc = GECKO_GET_LOC (pins [i ]);
42
47
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
43
- /* For SOCs with configurable pin locations (set in SOC Kconfig) */
48
+ /* For SOCs with configurable pin_cfg locations (set in SOC Kconfig) */
44
49
base -> ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN ;
45
50
base -> ROUTELOC0 = (loc << _USART_ROUTELOC0_TXLOC_SHIFT ) |
46
51
(loc << _USART_ROUTELOC0_RXLOC_SHIFT );
@@ -94,9 +99,46 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintp
94
99
#endif /* UART_GECKO_HW_FLOW_CONTROL */
95
100
break ;
96
101
#endif /* CONFIG_UART_GECKO */
102
+ #ifdef CONFIG_SPI_GECKO
103
+ case GECKO_FUN_SPI_SCK :
104
+ spi_pin_cfg .port = GECKO_GET_PORT (pins [i ]);
105
+ spi_pin_cfg .pin = GECKO_GET_PIN (pins [i ]);
106
+ spi_pin_cfg .mode = gpioModePushPull ;
107
+ spi_pin_cfg .out = 1 ;
108
+ GPIO -> USARTROUTE [usart_num ].ROUTEEN |= GPIO_USART_ROUTEEN_CLKPEN ;
109
+ GPIO -> USARTROUTE [usart_num ].CLKROUTE =
110
+ (spi_pin_cfg .pin << _GPIO_USART_CLKROUTE_PIN_SHIFT ) |
111
+ (spi_pin_cfg .port << _GPIO_USART_CLKROUTE_PORT_SHIFT );
112
+ break ;
113
+ case GECKO_FUN_SPI_MOSI :
114
+ spi_pin_cfg .port = GECKO_GET_PORT (pins [i ]);
115
+ spi_pin_cfg .pin = GECKO_GET_PIN (pins [i ]);
116
+ spi_pin_cfg .mode = gpioModePushPull ;
117
+ spi_pin_cfg .out = 1 ;
118
+ GPIO -> USARTROUTE [usart_num ].ROUTEEN |= GPIO_USART_ROUTEEN_TXPEN ;
119
+ GPIO -> USARTROUTE [usart_num ].TXROUTE =
120
+ (spi_pin_cfg .pin << _GPIO_USART_TXROUTE_PIN_SHIFT ) |
121
+ (spi_pin_cfg .port << _GPIO_USART_TXROUTE_PORT_SHIFT );
122
+ break ;
123
+ case GECKO_FUN_SPI_MISO :
124
+ spi_pin_cfg .port = GECKO_GET_PORT (pins [i ]);
125
+ spi_pin_cfg .pin = GECKO_GET_PIN (pins [i ]);
126
+ spi_pin_cfg .mode = gpioModeInput ;
127
+ spi_pin_cfg .out = 1 ;
128
+ GPIO -> USARTROUTE [usart_num ].ROUTEEN |= GPIO_USART_ROUTEEN_RXPEN ;
129
+ GPIO -> USARTROUTE [usart_num ].RXROUTE =
130
+ (spi_pin_cfg .pin << _GPIO_USART_RXROUTE_PIN_SHIFT ) |
131
+ (spi_pin_cfg .port << _GPIO_USART_RXROUTE_PORT_SHIFT );
132
+ break ;
133
+ #endif /* CONFIG_SPI_GECKO */
134
+
97
135
default :
98
136
return - ENOTSUP ;
99
137
}
138
+ #ifdef CONFIG_SPI_GECKO
139
+ GPIO_PinModeSet (spi_pin_cfg .port , spi_pin_cfg .pin ,
140
+ spi_pin_cfg .mode , spi_pin_cfg .out );
141
+ #endif /* CONFIG_SPI_GECKO */
100
142
}
101
143
102
144
return 0 ;
0 commit comments