17#ifndef STATIC_PINMAP_H
18#define STATIC_PINMAP_H
20#include "hal/PinNameAliases.h"
23#include "pwmout_api.h"
24#include "analogin_api.h"
25#include "analogout_api.h"
27#include "serial_api.h"
31#include <mstd_cstddef>
33#if STATIC_PINMAP_READY
34#include "PeripheralPinMaps.h"
37#if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM)
38MSTD_CONSTEXPR_FN_14
PinMap get_pwm_pinmap(
const PinName pin)
40 for (
const PinMap &pinmap : PINMAP_PWM) {
41 if (pinmap.pin == pin) {
42 return {pin, pinmap.peripheral, pinmap.function};
45 return {NC, (int) NC, (
int) NC};
49#if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN)
50MSTD_CONSTEXPR_FN_14
PinMap get_analogin_pinmap(
const PinName pin)
52 for (
const PinMap &pinmap : PINMAP_ANALOGIN) {
53 if (pinmap.pin == pin) {
54 return {pin, pinmap.peripheral, pinmap.function};
58#if PINMAP_ANALOGIN_INTERNAL
59 for (
const PinMap &pinmap : PINMAP_ANALOGIN_INTERNAL) {
60 if (pinmap.pin == pin) {
61 return {pin, pinmap.peripheral, pinmap.function};
66 return {NC, (int) NC, (
int) NC};
70#if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT)
71MSTD_CONSTEXPR_FN_14
PinMap get_analogout_pinmap(
const PinName pin)
73 for (
const PinMap &pinmap : PINMAP_ANALOGOUT) {
74 if (pinmap.pin == pin) {
75 return {pin, pinmap.peripheral, pinmap.function};
78 return {NC, (int) NC, (
int) NC};
82#if defined(DEVICE_I2C) && defined(PINMAP_I2C_SDA) && defined(PINMAP_I2C_SCL)
83MSTD_CONSTEXPR_FN_14
i2c_pinmap_t get_i2c_pinmap(
const PinName sda,
const PinName scl)
85 const PinMap *sda_map =
nullptr;
86 for (
const PinMap &pinmap : PINMAP_I2C_SDA) {
87 if (pinmap.pin == sda) {
93 const PinMap *scl_map =
nullptr;
94 for (
const PinMap &pinmap : PINMAP_I2C_SCL) {
95 if (pinmap.pin == scl) {
101 if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
102 return {(int) NC, NC, (
int) NC, NC, (int) NC};
105 return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
109#if defined(DEVICE_SERIAL) && defined(PINMAP_UART_TX) && defined(PINMAP_UART_RX)
110MSTD_CONSTEXPR_FN_14
serial_pinmap_t get_uart_pinmap(
const PinName tx,
const PinName rx)
112 const PinMap *tx_map =
nullptr;
113 for (
const PinMap &pinmap : PINMAP_UART_TX) {
114 if (pinmap.pin == tx) {
120 const PinMap *rx_map =
nullptr;
121 for (
const PinMap &pinmap : PINMAP_UART_RX) {
122 if (pinmap.pin == rx) {
128 if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
129 return {(int) NC, NC, (
int) NC, NC, (int) NC,
false};
132 if (tx_map->pin == CONSOLE_TX && rx_map->pin == CONSOLE_RX) {
133 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function,
true};
135 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function,
false};
139#if defined(DEVICE_SERIAL_FC) && defined(PINMAP_UART_RTS) && defined(PINMAP_UART_CTS)
140MSTD_CONSTEXPR_FN_14
serial_fc_pinmap_t get_uart_fc_pinmap(
const PinName rxflow,
const PinName txflow)
142 const PinMap *rts_map =
nullptr;
143 for (
const PinMap &pinmap : PINMAP_UART_RTS) {
144 if (pinmap.pin == rxflow) {
150 const PinMap *cts_map =
nullptr;
151 for (
const PinMap &pinmap : PINMAP_UART_CTS) {
152 if (pinmap.pin == txflow) {
158 if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
159 return {(int) NC, NC, (
int) NC, NC, (int) NC};
162 return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
167#if defined(DEVICE_SPI) && defined(PINMAP_SPI_MOSI) && defined(PINMAP_SPI_MISO) && defined(PINMAP_SPI_SCLK) && defined(PINMAP_SPI_SSEL)
168MSTD_CONSTEXPR_FN_14
spi_pinmap_t get_spi_pinmap(
const PinName mosi,
const PinName miso,
const PinName sclk,
const PinName ssel = NC)
170 const PinMap *mosi_map =
nullptr;
171 for (
const PinMap &pinmap : PINMAP_SPI_MOSI) {
172 if (pinmap.pin == mosi) {
178 const PinMap *miso_map =
nullptr;
179 for (
const PinMap &pinmap : PINMAP_SPI_MISO) {
180 if (pinmap.pin == miso) {
186 const PinMap *sclk_map =
nullptr;
187 for (
const PinMap &pinmap : PINMAP_SPI_SCLK) {
188 if (pinmap.pin == sclk) {
194 const PinMap *ssel_map =
nullptr;
195 for (
const PinMap &pinmap : PINMAP_SPI_SSEL) {
196 if (pinmap.pin == ssel) {
202 if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) ||
203 (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) ||
204 (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) {
205 return {(int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC};
208 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};
212#if defined(DEVICE_CAN) && defined(PINMAP_CAN_RD) && defined(PINMAP_CAN_TD)
213MSTD_CONSTEXPR_FN_14
can_pinmap_t get_can_pinmap(
const PinName rd,
const PinName td)
215 const PinMap *rd_map =
nullptr;
216 for (
const PinMap &pinmap : PINMAP_CAN_RD) {
217 if (pinmap.pin == rd) {
223 const PinMap *td_map =
nullptr;
224 for (
const PinMap &pinmap : PINMAP_CAN_TD) {
225 if (pinmap.pin == td) {
231 if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
232 return {(int) NC, NC, (
int) NC, NC, (int) NC};
235 return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
239#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)
240MSTD_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)
242 const PinMap *data0_map =
nullptr;
243 for (
const PinMap &pinmap : PINMAP_QSPI_DATA0) {
244 if (pinmap.pin == data0) {
250 const PinMap *data1_map =
nullptr;
251 for (
const PinMap &pinmap : PINMAP_QSPI_DATA1) {
252 if (pinmap.pin == data1) {
258 const PinMap *data2_map =
nullptr;
259 for (
const PinMap &pinmap : PINMAP_QSPI_DATA2) {
260 if (pinmap.pin == data2) {
266 const PinMap *data3_map =
nullptr;
267 for (
const PinMap &pinmap : PINMAP_QSPI_DATA3) {
268 if (pinmap.pin == data3) {
274 const PinMap *sclk_map =
nullptr;
275 for (
const PinMap &pinmap : PINMAP_QSPI_SCLK) {
276 if (pinmap.pin == sclk) {
282 const PinMap *ssel_map =
nullptr;
283 for (
const PinMap &pinmap : PINMAP_QSPI_SSEL) {
284 if (pinmap.pin == ssel) {
290 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) {
291 return {(int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC};
294 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};
298#if defined(DEVICE_OSPI) && defined(PINMAP_OSPI_DATA0) && defined(PINMAP_OSPI_DATA1) && defined(PINMAP_OSPI_DATA2) && defined(PINMAP_OSPI_DATA3) && defined(PINMAP_OSPI_DATA4) && defined(PINMAP_OSPI_DATA5) && defined(PINMAP_OSPI_DATA6) && defined(PINMAP_OSPI_DATA7) && defined(PINMAP_OSPI_SCLK) && defined(PINMAP_OSPI_SSEL) && defined(PINMAP_OSPI_DQS)
299MSTD_CONSTEXPR_FN_14 ospi_pinmap_t get_ospi_pinmap(
const PinName data0,
const PinName data1,
const PinName data2,
const PinName data3,
const PinName data4,
const PinName data5,
const PinName data6,
const PinName data7,
const PinName sclk,
const PinName ssel,
const PinName dqs)
301 const PinMap *data0_map =
nullptr;
302 for (
const PinMap &pinmap : PINMAP_OSPI_DATA0) {
303 if (pinmap.pin == data0) {
309 const PinMap *data1_map =
nullptr;
310 for (
const PinMap &pinmap : PINMAP_OSPI_DATA1) {
311 if (pinmap.pin == data1) {
317 const PinMap *data2_map =
nullptr;
318 for (
const PinMap &pinmap : PINMAP_OSPI_DATA2) {
319 if (pinmap.pin == data2) {
325 const PinMap *data3_map =
nullptr;
326 for (
const PinMap &pinmap : PINMAP_OSPI_DATA3) {
327 if (pinmap.pin == data3) {
333 const PinMap *data4_map =
nullptr;
334 for (
const PinMap &pinmap : PINMAP_OSPI_DATA4) {
335 if (pinmap.pin == data4) {
341 const PinMap *data5_map =
nullptr;
342 for (
const PinMap &pinmap : PINMAP_OSPI_DATA5) {
343 if (pinmap.pin == data5) {
349 const PinMap *data6_map =
nullptr;
350 for (
const PinMap &pinmap : PINMAP_OSPI_DATA6) {
351 if (pinmap.pin == data6) {
357 const PinMap *data7_map =
nullptr;
358 for (
const PinMap &pinmap : PINMAP_OSPI_DATA7) {
359 if (pinmap.pin == data7) {
365 const PinMap *sclk_map =
nullptr;
366 for (
const PinMap &pinmap : PINMAP_OSPI_SCLK) {
367 if (pinmap.pin == sclk) {
373 const PinMap *ssel_map =
nullptr;
374 for (
const PinMap &pinmap : PINMAP_OSPI_SSEL) {
375 if (pinmap.pin == ssel) {
381 const PinMap *dqs_map =
nullptr;
382 for (
const PinMap &pinmap : PINMAP_OSPI_DQS) {
383 if (pinmap.pin == dqs) {
390 if (!data0_map || !data1_map || !data2_map || !data3_map || !data4_map || !data5_map || !data6_map || !data7_map || !sclk_map || !ssel_map || !dqs_map || data0_map->peripheral != data1_map->peripheral || data0_map->peripheral != data2_map->peripheral || data0_map->peripheral != data3_map->peripheral || data0_map->peripheral != data4_map->peripheral || data0_map->peripheral != data5_map->peripheral || data0_map->peripheral != data6_map->peripheral || data0_map->peripheral != data7_map->peripheral || data0_map->peripheral != sclk_map->peripheral || data0_map->peripheral != ssel_map->peripheral || data0_map->peripheral != dqs_map->peripheral) {
391 return {(int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC, NC, (
int) NC, NC, (int) NC};
394 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, data4_map->pin, data4_map->function, data5_map->pin, data5_map->function, data6_map->pin, data6_map->function, data7_map->pin, data7_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function, dqs_map->pin, dqs_map->function};
401MSTD_CONSTEXPR_FN_14
PinMap get_pwm_pinmap(
const PinName pin)
403 return {pin, (int) NC, (
int) NC};
408MSTD_CONSTEXPR_FN_14
PinMap get_analogin_pinmap(
const PinName pin)
410 return {pin, (int) NC, (
int) NC};
415MSTD_CONSTEXPR_FN_14
PinMap get_analogout_pinmap(
const PinName pin)
417 return {pin, (int) NC, (
int) NC};
422MSTD_CONSTEXPR_FN_14
i2c_pinmap_t get_i2c_pinmap(
const PinName sda,
const PinName scl)
424 return {(int) NC, sda, (
int) NC, scl, (int) NC};
429MSTD_CONSTEXPR_FN_14
serial_pinmap_t get_uart_pinmap(
const PinName tx,
const PinName rx)
431 return {(int) NC, tx, (
int) NC, rx, (int) NC,
false};
435MSTD_CONSTEXPR_FN_14
serial_fc_pinmap_t get_uart_fc_pinmap(
const PinName rxflow,
const PinName txflow)
437 return {(int) NC, txflow, (
int) NC, rxflow, (int) NC};
443MSTD_CONSTEXPR_FN_14
spi_pinmap_t get_spi_pinmap(
const PinName mosi,
const PinName miso,
const PinName sclk,
const PinName ssel)
445 return {(int) NC, mosi, (
int) NC, miso, (int) NC, sclk, (
int) NC, ssel, (int) NC};
450MSTD_CONSTEXPR_FN_14
can_pinmap_t get_can_pinmap(
const PinName rd,
const PinName td)
452 return {(int) NC, rd, (
int) NC, td, (int) NC};
457MSTD_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)
459 return {(int) NC, data0, (
int) NC, data1, (int) NC, data2, (
int) NC, data3, (int) NC, sclk, (
int) NC, ssel, (int) NC};
464MSTD_CONSTEXPR_FN_14 ospi_pinmap_t get_ospi_pinmap(
const PinName data0,
const PinName data1,
const PinName data2,
const PinName data3,
const PinName data4,
const PinName data5,
const PinName data6,
const PinName data7,
const PinName sclk,
const PinName ssel,
const PinName dqs)
466 return {(int) NC, data0, (
int) NC, data1, (int) NC, data2, (
int) NC, data3, (int) NC, data4, (
int) NC, data5, (int) NC, data6, (
int) NC, data7, (int) NC, sclk, (
int) NC, ssel, (int) NC, dqs, (
int) NC};