Mistake on this page?
Report an issue in GitHub or email us
static_pinmap.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef STATIC_PINMAP_H
18 #define STATIC_PINMAP_H
19 
20 #include "PinNames.h"
21 #include "spi_api.h"
22 #include "pwmout_api.h"
23 #include "analogin_api.h"
24 #include "analogout_api.h"
25 #include "i2c_api.h"
26 #include "serial_api.h"
27 #include "qspi_api.h"
28 #include "ospi_api.h"
29 #include "can_api.h"
30 #include <mstd_cstddef>
31 
32 #if STATIC_PINMAP_READY
33 #include "PeripheralPinMaps.h"
34 
35 
36 #if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM)
37 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
38 {
39  for (const PinMap &pinmap : PINMAP_PWM) {
40  if (pinmap.pin == pin) {
41  return {pin, pinmap.peripheral, pinmap.function};
42  }
43  }
44  return {NC, (int) NC, (int) NC};
45 }
46 #endif // DEVICE_PWMOUT
47 
48 #if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN)
49 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
50 {
51  for (const PinMap &pinmap : PINMAP_ANALOGIN) {
52  if (pinmap.pin == pin) {
53  return {pin, pinmap.peripheral, pinmap.function};
54  }
55  }
56 
57 #if PINMAP_ANALOGIN_INTERNAL
58  for (const PinMap &pinmap : PINMAP_ANALOGIN_INTERNAL) {
59  if (pinmap.pin == pin) {
60  return {pin, pinmap.peripheral, pinmap.function};
61  }
62  }
63 #endif
64 
65  return {NC, (int) NC, (int) NC};
66 }
67 #endif // DEVICE_ANALOGIN
68 
69 #if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT)
70 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
71 {
72  for (const PinMap &pinmap : PINMAP_ANALOGOUT) {
73  if (pinmap.pin == pin) {
74  return {pin, pinmap.peripheral, pinmap.function};
75  }
76  }
77  return {NC, (int) NC, (int) NC};
78 }
79 #endif // DEVICE_ANALOGOUT
80 
81 #if defined(DEVICE_I2C) && defined(PINMAP_I2C_SDA) && defined(PINMAP_I2C_SCL)
82 MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
83 {
84  const PinMap *sda_map = nullptr;
85  for (const PinMap &pinmap : PINMAP_I2C_SDA) {
86  if (pinmap.pin == sda) {
87  sda_map = &pinmap;
88  break;
89  }
90  }
91 
92  const PinMap *scl_map = nullptr;
93  for (const PinMap &pinmap : PINMAP_I2C_SCL) {
94  if (pinmap.pin == scl) {
95  scl_map = &pinmap;
96  break;
97  }
98  }
99 
100  if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
101  return {(int) NC, NC, (int) NC, NC, (int) NC};
102  }
103 
104  return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
105 }
106 #endif //DEVICE_I2C
107 
108 #if defined(DEVICE_SERIAL) && defined(PINMAP_UART_TX) && defined(PINMAP_UART_RX)
109 MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
110 {
111  const PinMap *tx_map = nullptr;
112  for (const PinMap &pinmap : PINMAP_UART_TX) {
113  if (pinmap.pin == tx) {
114  tx_map = &pinmap;
115  break;
116  }
117  }
118 
119  const PinMap *rx_map = nullptr;
120  for (const PinMap &pinmap : PINMAP_UART_RX) {
121  if (pinmap.pin == rx) {
122  rx_map = &pinmap;
123  break;
124  }
125  }
126 
127  if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
128  return {(int) NC, NC, (int) NC, NC, (int) NC, false};
129  }
130 
131  if (tx_map->pin == STDIO_UART_TX && rx_map->pin == STDIO_UART_RX) {
132  return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true};
133  } else {
134  return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false};
135  }
136 }
137 
138 #if defined(DEVICE_SERIAL_FC) && defined(PINMAP_UART_RTS) && defined(PINMAP_UART_CTS)
139 MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
140 {
141  const PinMap *rts_map = nullptr;
142  for (const PinMap &pinmap : PINMAP_UART_RTS) {
143  if (pinmap.pin == rxflow) {
144  rts_map = &pinmap;
145  break;
146  }
147  }
148 
149  const PinMap *cts_map = nullptr;
150  for (const PinMap &pinmap : PINMAP_UART_CTS) {
151  if (pinmap.pin == txflow) {
152  cts_map = &pinmap;
153  break;
154  }
155  }
156 
157  if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
158  return {(int) NC, NC, (int) NC, NC, (int) NC};
159  }
160 
161  return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
162 }
163 #endif // DEVICE_SERIAL_FC
164 #endif // DEVICE_SERIAL
165 
166 #if defined(DEVICE_SPI) && defined(PINMAP_SPI_MOSI) && defined(PINMAP_SPI_MISO) && defined(PINMAP_SPI_SCLK) && defined(PINMAP_SPI_SSEL)
167 MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
168 {
169  const PinMap *mosi_map = nullptr;
170  for (const PinMap &pinmap : PINMAP_SPI_MOSI) {
171  if (pinmap.pin == mosi) {
172  mosi_map = &pinmap;
173  break;
174  }
175  }
176 
177  const PinMap *miso_map = nullptr;
178  for (const PinMap &pinmap : PINMAP_SPI_MISO) {
179  if (pinmap.pin == miso) {
180  miso_map = &pinmap;
181  break;
182  }
183  }
184 
185  const PinMap *sclk_map = nullptr;
186  for (const PinMap &pinmap : PINMAP_SPI_SCLK) {
187  if (pinmap.pin == sclk) {
188  sclk_map = &pinmap;
189  break;
190  }
191  }
192 
193  const PinMap *ssel_map = nullptr;
194  for (const PinMap &pinmap : PINMAP_SPI_SSEL) {
195  if (pinmap.pin == ssel) {
196  ssel_map = &pinmap;
197  break;
198  }
199  }
200 
201  if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) ||
202  (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) ||
203  (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) {
204  return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
205  }
206 
207  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};
208 }
209 #endif // DEVICE_SPI
210 
211 #if defined(DEVICE_CAN) && defined(PINMAP_CAN_RD) && defined(PINMAP_CAN_TD)
212 MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
213 {
214  const PinMap *rd_map = nullptr;
215  for (const PinMap &pinmap : PINMAP_CAN_RD) {
216  if (pinmap.pin == rd) {
217  rd_map = &pinmap;
218  break;
219  }
220  }
221 
222  const PinMap *td_map = nullptr;
223  for (const PinMap &pinmap : PINMAP_CAN_TD) {
224  if (pinmap.pin == td) {
225  td_map = &pinmap;
226  break;
227  }
228  }
229 
230  if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
231  return {(int) NC, NC, (int) NC, NC, (int) NC};
232  }
233 
234  return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
235 }
236 #endif //DEVICE_CAN
237 
238 #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)
239 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 {
241  const PinMap *data0_map = nullptr;
242  for (const PinMap &pinmap : PINMAP_QSPI_DATA0) {
243  if (pinmap.pin == data0) {
244  data0_map = &pinmap;
245  break;
246  }
247  }
248 
249  const PinMap *data1_map = nullptr;
250  for (const PinMap &pinmap : PINMAP_QSPI_DATA1) {
251  if (pinmap.pin == data1) {
252  data1_map = &pinmap;
253  break;
254  }
255  }
256 
257  const PinMap *data2_map = nullptr;
258  for (const PinMap &pinmap : PINMAP_QSPI_DATA2) {
259  if (pinmap.pin == data2) {
260  data2_map = &pinmap;
261  break;
262  }
263  }
264 
265  const PinMap *data3_map = nullptr;
266  for (const PinMap &pinmap : PINMAP_QSPI_DATA3) {
267  if (pinmap.pin == data3) {
268  data3_map = &pinmap;
269  break;
270  }
271  }
272 
273  const PinMap *sclk_map = nullptr;
274  for (const PinMap &pinmap : PINMAP_QSPI_SCLK) {
275  if (pinmap.pin == sclk) {
276  sclk_map = &pinmap;
277  break;
278  }
279  }
280 
281  const PinMap *ssel_map = nullptr;
282  for (const PinMap &pinmap : PINMAP_QSPI_SSEL) {
283  if (pinmap.pin == ssel) {
284  ssel_map = &pinmap;
285  break;
286  }
287  }
288 
289  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) {
290  return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
291  }
292 
293  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};
294 }
295 #endif //DEVICE_QSPI
296 
297 #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)
298 MSTD_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)
299 {
300  const PinMap *data0_map = nullptr;
301  for (const PinMap &pinmap : PINMAP_OSPI_DATA0) {
302  if (pinmap.pin == data0) {
303  data0_map = &pinmap;
304  break;
305  }
306  }
307 
308  const PinMap *data1_map = nullptr;
309  for (const PinMap &pinmap : PINMAP_OSPI_DATA1) {
310  if (pinmap.pin == data1) {
311  data1_map = &pinmap;
312  break;
313  }
314  }
315 
316  const PinMap *data2_map = nullptr;
317  for (const PinMap &pinmap : PINMAP_OSPI_DATA2) {
318  if (pinmap.pin == data2) {
319  data2_map = &pinmap;
320  break;
321  }
322  }
323 
324  const PinMap *data3_map = nullptr;
325  for (const PinMap &pinmap : PINMAP_OSPI_DATA3) {
326  if (pinmap.pin == data3) {
327  data3_map = &pinmap;
328  break;
329  }
330  }
331 
332  const PinMap *data4_map = nullptr;
333  for (const PinMap &pinmap : PINMAP_OSPI_DATA4) {
334  if (pinmap.pin == data4) {
335  data4_map = &pinmap;
336  break;
337  }
338  }
339 
340  const PinMap *data5_map = nullptr;
341  for (const PinMap &pinmap : PINMAP_OSPI_DATA5) {
342  if (pinmap.pin == data5) {
343  data5_map = &pinmap;
344  break;
345  }
346  }
347 
348  const PinMap *data6_map = nullptr;
349  for (const PinMap &pinmap : PINMAP_OSPI_DATA6) {
350  if (pinmap.pin == data6) {
351  data6_map = &pinmap;
352  break;
353  }
354  }
355 
356  const PinMap *data7_map = nullptr;
357  for (const PinMap &pinmap : PINMAP_OSPI_DATA7) {
358  if (pinmap.pin == data7) {
359  data7_map = &pinmap;
360  break;
361  }
362  }
363 
364  const PinMap *sclk_map = nullptr;
365  for (const PinMap &pinmap : PINMAP_OSPI_SCLK) {
366  if (pinmap.pin == sclk) {
367  sclk_map = &pinmap;
368  break;
369  }
370  }
371 
372  const PinMap *ssel_map = nullptr;
373  for (const PinMap &pinmap : PINMAP_OSPI_SSEL) {
374  if (pinmap.pin == ssel) {
375  ssel_map = &pinmap;
376  break;
377  }
378  }
379 
380  const PinMap *dqs_map = nullptr;
381  for (const PinMap &pinmap : PINMAP_OSPI_DQS) {
382  if (pinmap.pin == dqs) {
383  dqs_map = &pinmap;
384  break;
385  }
386  }
387 
388 
389  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) {
390  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};
391  }
392 
393  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};
394 }
395 #endif //DEVICE_OSPI
396 
397 #else // STATIC_PINMAP_READY
398 
399 #if DEVICE_PWMOUT
400 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
401 {
402  return {pin, (int) NC, (int) NC};
403 }
404 #endif // DEVICE_PWMOUT
405 
406 #if DEVICE_ANALOGIN
407 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
408 {
409  return {pin, (int) NC, (int) NC};
410 }
411 #endif // DEVICE_ANALOGIN
412 
413 #if DEVICE_ANALOGOUT
414 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
415 {
416  return {pin, (int) NC, (int) NC};
417 }
418 #endif // DEVICE_ANALOGOUT
419 
420 #if DEVICE_I2C
421 MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
422 {
423  return {(int) NC, sda, (int) NC, scl, (int) NC};
424 }
425 #endif //DEVICE_I2C
426 
427 #if DEVICE_SERIAL
428 MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
429 {
430  return {(int) NC, tx, (int) NC, rx, (int) NC, false};
431 }
432 
433 #if DEVICE_SERIAL_FC
434 MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
435 {
436  return {(int) NC, txflow, (int) NC, rxflow, (int) NC};
437 }
438 #endif // DEVICE_SERIAL_FC
439 #endif // DEVICE_SERIAL
440 
441 #if DEVICE_SPI
442 MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
443 {
444  return {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC};
445 }
446 #endif // DEVICE_SERIAL
447 
448 #if DEVICE_CAN
449 MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
450 {
451  return {(int) NC, rd, (int) NC, td, (int) NC};
452 }
453 #endif //DEVICE_CAN
454 
455 #if DEVICE_QSPI
456 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)
457 {
458  return {(int) NC, data0, (int) NC, data1, (int) NC, data2, (int) NC, data3, (int) NC, sclk, (int) NC, ssel, (int) NC};
459 }
460 #endif //DEVICE_QSPI
461 
462 #if DEVICE_OSPI
463 MSTD_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)
464 {
465  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};
466 }
467 #endif //DEVICE_OSPI
468 
469 #endif // STATIC_PINMAP_READY
470 
471 #endif // STATIC_PINMAP_H
Definition: pinmap.h:31
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.