Skip to content

Commit fa22634

Browse files
ananglcarlescufi
authored andcommitted
drivers: pinctrl: nrf: Add support for SPI and TWI peripherals
Add support for configuring pins of the following nRF peripherals: SPI, SPIM, SPIS, TWI, and TWIM. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 70fb312 commit fa22634

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

drivers/pinctrl/pinctrl_nrf.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ BUILD_ASSERT(((NRF_DRIVE_S0S1 == NRF_GPIO_PIN_S0S1) &&
3333
#define NRF_PSEL_UART(reg, line) ((NRF_UARTE_Type *)reg)->PSEL.line
3434
#endif
3535

36+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spi)
37+
#define NRF_PSEL_SPIM(reg, line) ((NRF_SPI_Type *)reg)->PSEL##line
38+
#elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spim)
39+
#define NRF_PSEL_SPIM(reg, line) ((NRF_SPIM_Type *)reg)->PSEL.line
40+
#endif
41+
42+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spis)
43+
#if defined(NRF51)
44+
#define NRF_PSEL_SPIS(reg, line) ((NRF_SPIS_Type *)reg)->PSEL##line
45+
#else
46+
#define NRF_PSEL_SPIS(reg, line) ((NRF_SPIS_Type *)reg)->PSEL.line
47+
#endif
48+
#endif /* DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_spis) */
49+
50+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_twi)
51+
#define NRF_PSEL_TWIM(reg, line) ((NRF_TWI_Type *)reg)->PSEL##line
52+
#elif DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_twim)
53+
#define NRF_PSEL_TWIM(reg, line) ((NRF_TWIM_Type *)reg)->PSEL.line
54+
#endif
55+
3656
/**
3757
* @brief Configure pin settings.
3858
*
@@ -83,6 +103,57 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
83103
NRF_GPIO_PIN_INPUT_CONNECT);
84104
break;
85105
#endif /* defined(NRF_PSEL_UART) */
106+
#if defined(NRF_PSEL_SPIM)
107+
case NRF_FUN_SPIM_SCK:
108+
NRF_PSEL_SPIM(reg, SCK) = NRF_GET_PIN(pins[i]);
109+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_OUTPUT,
110+
NRF_GPIO_PIN_INPUT_CONNECT);
111+
break;
112+
case NRF_FUN_SPIM_MOSI:
113+
NRF_PSEL_SPIM(reg, MOSI) = NRF_GET_PIN(pins[i]);
114+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_OUTPUT,
115+
NRF_GPIO_PIN_INPUT_DISCONNECT);
116+
break;
117+
case NRF_FUN_SPIM_MISO:
118+
NRF_PSEL_SPIM(reg, MISO) = NRF_GET_PIN(pins[i]);
119+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
120+
NRF_GPIO_PIN_INPUT_CONNECT);
121+
break;
122+
#endif /* defined(NRF_PSEL_SPIM) */
123+
#if defined(NRF_PSEL_SPIS)
124+
case NRF_FUN_SPIS_SCK:
125+
NRF_PSEL_SPIS(reg, SCK) = NRF_GET_PIN(pins[i]);
126+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
127+
NRF_GPIO_PIN_INPUT_CONNECT);
128+
break;
129+
case NRF_FUN_SPIS_MOSI:
130+
NRF_PSEL_SPIS(reg, MOSI) = NRF_GET_PIN(pins[i]);
131+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
132+
NRF_GPIO_PIN_INPUT_CONNECT);
133+
break;
134+
case NRF_FUN_SPIS_MISO:
135+
NRF_PSEL_SPIS(reg, MISO) = NRF_GET_PIN(pins[i]);
136+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
137+
NRF_GPIO_PIN_INPUT_DISCONNECT);
138+
break;
139+
case NRF_FUN_SPIS_CSN:
140+
NRF_PSEL_SPIS(reg, CSN) = NRF_GET_PIN(pins[i]);
141+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
142+
NRF_GPIO_PIN_INPUT_CONNECT);
143+
break;
144+
#endif /* defined(NRF_PSEL_SPIS) */
145+
#if defined(NRF_PSEL_TWIM)
146+
case NRF_FUN_TWIM_SCL:
147+
NRF_PSEL_TWIM(reg, SCL) = NRF_GET_PIN(pins[i]);
148+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
149+
NRF_GPIO_PIN_INPUT_CONNECT);
150+
break;
151+
case NRF_FUN_TWIM_SDA:
152+
NRF_PSEL_TWIM(reg, SDA) = NRF_GET_PIN(pins[i]);
153+
nrf_pin_configure(pins[i], NRF_GPIO_PIN_DIR_INPUT,
154+
NRF_GPIO_PIN_INPUT_CONNECT);
155+
break;
156+
#endif /* defined(NRF_PSEL_TWIM) */
86157
default:
87158
return -ENOTSUP;
88159
}

include/dt-bindings/pinctrl/nrf-pinctrl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@
5959
#define NRF_FUN_UART_RTS 2U
6060
/** UART CTS */
6161
#define NRF_FUN_UART_CTS 3U
62+
/** SPI master SCK */
63+
#define NRF_FUN_SPIM_SCK 4U
64+
/** SPI master MOSI */
65+
#define NRF_FUN_SPIM_MOSI 5U
66+
/** SPI master MISO */
67+
#define NRF_FUN_SPIM_MISO 6U
68+
/** SPI slave SCK */
69+
#define NRF_FUN_SPIS_SCK 7U
70+
/** SPI slave MOSI */
71+
#define NRF_FUN_SPIS_MOSI 8U
72+
/** SPI slave MISO */
73+
#define NRF_FUN_SPIS_MISO 9U
74+
/** SPI slave CSN */
75+
#define NRF_FUN_SPIS_CSN 10U
76+
/** TWI master SCL */
77+
#define NRF_FUN_TWIM_SCL 11U
78+
/** TWI master SDA */
79+
#define NRF_FUN_TWIM_SDA 12U
6280

6381
/** @} */
6482

0 commit comments

Comments
 (0)