17 #ifndef STATIC_PINMAP_H 18 #define STATIC_PINMAP_H 22 #include "pwmout_api.h" 23 #include "analogin_api.h" 24 #include "analogout_api.h" 26 #include "serial_api.h" 29 #include <mstd_cstddef> 31 #if STATIC_PINMAP_READY 32 #include "PeripheralPinMaps.h" 35 #if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM) 36 MSTD_CONSTEXPR_FN_14
PinMap get_pwm_pinmap(
const PinName pin)
38 for (
const PinMap &pinmap : PINMAP_PWM) {
39 if (pinmap.pin == pin) {
40 return {pin, pinmap.peripheral, pinmap.function};
43 return {NC, (int) NC, (
int) NC};
45 #endif // DEVICE_PWMOUT 47 #if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN) 48 MSTD_CONSTEXPR_FN_14
PinMap get_analogin_pinmap(
const PinName pin)
50 for (
const PinMap &pinmap : PINMAP_ANALOGIN) {
51 if (pinmap.pin == pin) {
52 return {pin, pinmap.peripheral, pinmap.function};
56 #if PINMAP_ANALOGIN_INTERNAL 57 for (
const PinMap &pinmap : PINMAP_ANALOGIN_INTERNAL) {
58 if (pinmap.pin == pin) {
59 return {pin, pinmap.peripheral, pinmap.function};
64 return {NC, (int) NC, (
int) NC};
66 #endif // DEVICE_ANALOGIN 68 #if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT) 69 MSTD_CONSTEXPR_FN_14
PinMap get_analogout_pinmap(
const PinName pin)
71 for (
const PinMap &pinmap : PINMAP_ANALOGOUT) {
72 if (pinmap.pin == pin) {
73 return {pin, pinmap.peripheral, pinmap.function};
76 return {NC, (int) NC, (
int) NC};
78 #endif // DEVICE_ANALOGOUT 80 #if defined(DEVICE_I2C) && defined(PINMAP_I2C_SDA) && defined(PINMAP_I2C_SCL) 81 MSTD_CONSTEXPR_FN_14
i2c_pinmap_t get_i2c_pinmap(
const PinName sda,
const PinName scl)
83 const PinMap *sda_map =
nullptr;
84 for (
const PinMap &pinmap : PINMAP_I2C_SDA) {
85 if (pinmap.pin == sda) {
91 const PinMap *scl_map =
nullptr;
92 for (
const PinMap &pinmap : PINMAP_I2C_SCL) {
93 if (pinmap.pin == scl) {
99 if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
100 return {(int) NC, NC, (
int) NC, NC, (int) NC};
103 return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
107 #if defined(DEVICE_SERIAL) && defined(PINMAP_UART_TX) && defined(PINMAP_UART_RX) 108 MSTD_CONSTEXPR_FN_14
serial_pinmap_t get_uart_pinmap(
const PinName tx,
const PinName rx)
110 const PinMap *tx_map =
nullptr;
111 for (
const PinMap &pinmap : PINMAP_UART_TX) {
112 if (pinmap.pin == tx) {
118 const PinMap *rx_map =
nullptr;
119 for (
const PinMap &pinmap : PINMAP_UART_RX) {
120 if (pinmap.pin == rx) {
126 if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
127 return {(int) NC, NC, (
int) NC, NC, (int) NC,
false};
130 if (tx_map->pin == STDIO_UART_TX && rx_map->pin == STDIO_UART_RX) {
131 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function,
true};
133 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function,
false};
137 #if defined(DEVICE_SERIAL_FC) && defined(PINMAP_UART_RTS) && defined(PINMAP_UART_CTS) 138 MSTD_CONSTEXPR_FN_14
serial_fc_pinmap_t get_uart_fc_pinmap(
const PinName rxflow,
const PinName txflow)
140 const PinMap *rts_map =
nullptr;
141 for (
const PinMap &pinmap : PINMAP_UART_RTS) {
142 if (pinmap.pin == rxflow) {
148 const PinMap *cts_map =
nullptr;
149 for (
const PinMap &pinmap : PINMAP_UART_CTS) {
150 if (pinmap.pin == txflow) {
156 if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
157 return {(int) NC, NC, (
int) NC, NC, (int) NC};
160 return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
162 #endif // DEVICE_SERIAL_FC 163 #endif // DEVICE_SERIAL 165 #if defined(DEVICE_SPI) && defined(PINMAP_SPI_MOSI) && defined(PINMAP_SPI_MISO) && defined(PINMAP_SPI_SCLK) && defined(PINMAP_SPI_SSEL) 166 MSTD_CONSTEXPR_FN_14
spi_pinmap_t get_spi_pinmap(
const PinName mosi,
const PinName miso,
const PinName sclk,
const PinName ssel)
168 const PinMap *mosi_map =
nullptr;
169 for (
const PinMap &pinmap : PINMAP_SPI_MOSI) {
170 if (pinmap.pin == mosi) {
176 const PinMap *miso_map =
nullptr;
177 for (
const PinMap &pinmap : PINMAP_SPI_MISO) {
178 if (pinmap.pin == miso) {
184 const PinMap *sclk_map =
nullptr;
185 for (
const PinMap &pinmap : PINMAP_SPI_SCLK) {
186 if (pinmap.pin == sclk) {
192 const PinMap *ssel_map =
nullptr;
193 for (
const PinMap &pinmap : PINMAP_SPI_SSEL) {
194 if (pinmap.pin == ssel) {
200 if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) ||
201 (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) ||
202 (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) {
203 return {(int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC};
206 return {mosi_map->peripheral, mosi_map->pin, mosi_map->function, miso_map->pin, miso_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function};
210 #if defined(DEVICE_CAN) && defined(PINMAP_CAN_RD) && defined(PINMAP_CAN_TD) 211 MSTD_CONSTEXPR_FN_14
can_pinmap_t get_can_pinmap(
const PinName rd,
const PinName td)
213 const PinMap *rd_map =
nullptr;
214 for (
const PinMap &pinmap : PINMAP_CAN_RD) {
215 if (pinmap.pin == rd) {
221 const PinMap *td_map =
nullptr;
222 for (
const PinMap &pinmap : PINMAP_CAN_TD) {
223 if (pinmap.pin == td) {
229 if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
230 return {(int) NC, NC, (
int) NC, NC, (int) NC};
233 return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
237 #if defined(DEVICE_QSPI) && defined(PINMAP_QSPI_DATA0) && defined(PINMAP_QSPI_DATA1) && defined(PINMAP_QSPI_DATA2) && defined(PINMAP_QSPI_DATA3) && defined(PINMAP_QSPI_SCLK) && defined(PINMAP_QSPI_SSEL) 238 MSTD_CONSTEXPR_FN_14
qspi_pinmap_t get_qspi_pinmap(
const PinName data0,
const PinName data1,
const PinName data2,
const PinName data3,
const PinName sclk,
const PinName ssel)
240 const PinMap *data0_map =
nullptr;
241 for (
const PinMap &pinmap : PINMAP_QSPI_DATA0) {
242 if (pinmap.pin == data0) {
248 const PinMap *data1_map =
nullptr;
249 for (
const PinMap &pinmap : PINMAP_QSPI_DATA1) {
250 if (pinmap.pin == data1) {
256 const PinMap *data2_map =
nullptr;
257 for (
const PinMap &pinmap : PINMAP_QSPI_DATA2) {
258 if (pinmap.pin == data2) {
264 const PinMap *data3_map =
nullptr;
265 for (
const PinMap &pinmap : PINMAP_QSPI_DATA3) {
266 if (pinmap.pin == data3) {
272 const PinMap *sclk_map =
nullptr;
273 for (
const PinMap &pinmap : PINMAP_QSPI_SCLK) {
274 if (pinmap.pin == sclk) {
280 const PinMap *ssel_map =
nullptr;
281 for (
const PinMap &pinmap : PINMAP_QSPI_SSEL) {
282 if (pinmap.pin == ssel) {
288 if (!data0_map || !data1_map || !data2_map || !data3_map || !sclk_map || !ssel_map || data0_map->peripheral != data1_map->peripheral || data0_map->peripheral != data2_map->peripheral || data0_map->peripheral != data3_map->peripheral || data0_map->peripheral != sclk_map->peripheral || data0_map->peripheral != ssel_map->peripheral) {
289 return {(int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC};
292 return {data0_map->peripheral, data0_map->pin, data0_map->function, data1_map->pin, data1_map->function, data2_map->pin, data2_map->function, data3_map->pin, data3_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function};
296 #else // STATIC_PINMAP_READY 299 MSTD_CONSTEXPR_FN_14
PinMap get_pwm_pinmap(
const PinName pin)
301 return {pin, (int) NC, (
int) NC};
303 #endif // DEVICE_PWMOUT 306 MSTD_CONSTEXPR_FN_14
PinMap get_analogin_pinmap(
const PinName pin)
308 return {pin, (int) NC, (
int) NC};
310 #endif // DEVICE_ANALOGIN 313 MSTD_CONSTEXPR_FN_14
PinMap get_analogout_pinmap(
const PinName pin)
315 return {pin, (int) NC, (
int) NC};
317 #endif // DEVICE_ANALOGOUT 320 MSTD_CONSTEXPR_FN_14
i2c_pinmap_t get_i2c_pinmap(
const PinName sda,
const PinName scl)
322 return {(int) NC, sda, (
int) NC, scl, (int) NC};
327 MSTD_CONSTEXPR_FN_14
serial_pinmap_t get_uart_pinmap(
const PinName tx,
const PinName rx)
329 return {(int) NC, tx, (
int) NC, rx, (int) NC,
false};
333 MSTD_CONSTEXPR_FN_14
serial_fc_pinmap_t get_uart_fc_pinmap(
const PinName rxflow,
const PinName txflow)
335 return {(int) NC, txflow, (
int) NC, rxflow, (int) NC};
337 #endif // DEVICE_SERIAL_FC 338 #endif // DEVICE_SERIAL 341 MSTD_CONSTEXPR_FN_14
spi_pinmap_t get_spi_pinmap(
const PinName mosi,
const PinName miso,
const PinName sclk,
const PinName ssel)
343 return {(int) NC, mosi, (
int) NC, miso, (int) NC, sclk, (
int) NC, ssel, (int) NC};
345 #endif // DEVICE_SERIAL 348 MSTD_CONSTEXPR_FN_14
can_pinmap_t get_can_pinmap(
const PinName rd,
const PinName td)
350 return {(int) NC, rd, (
int) NC, td, (int) NC};
355 MSTD_CONSTEXPR_FN_14
qspi_pinmap_t get_qspi_pinmap(
const PinName data0,
const PinName data1,
const PinName data2,
const PinName data3,
const PinName sclk,
const PinName ssel)
357 return {(int) NC, data0, (
int) NC, data1, (int) NC, data2, (
int) NC, data3, (int) NC, sclk, (
int) NC, ssel, (int) NC};
361 #endif // STATIC_PINMAP_READY 363 #endif // STATIC_PINMAP_H