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 "can_api.h"
29 #include <mstd_cstddef>
30 
31 #if STATIC_PINMAP_READY
32 #include "PeripheralPinMaps.h"
33 
34 
35 #if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM)
36 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
37 {
38  for (const PinMap &pinmap : PINMAP_PWM) {
39  if (pinmap.pin == pin) {
40  return {pin, pinmap.peripheral, pinmap.function};
41  }
42  }
43  return {NC, (int) NC, (int) NC};
44 }
45 #endif // DEVICE_PWMOUT
46 
47 #if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN)
48 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
49 {
50  for (const PinMap &pinmap : PINMAP_ANALOGIN) {
51  if (pinmap.pin == pin) {
52  return {pin, pinmap.peripheral, pinmap.function};
53  }
54  }
55 
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};
60  }
61  }
62 #endif
63 
64  return {NC, (int) NC, (int) NC};
65 }
66 #endif // DEVICE_ANALOGIN
67 
68 #if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT)
69 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
70 {
71  for (const PinMap &pinmap : PINMAP_ANALOGOUT) {
72  if (pinmap.pin == pin) {
73  return {pin, pinmap.peripheral, pinmap.function};
74  }
75  }
76  return {NC, (int) NC, (int) NC};
77 }
78 #endif // DEVICE_ANALOGOUT
79 
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)
82 {
83  const PinMap *sda_map = nullptr;
84  for (const PinMap &pinmap : PINMAP_I2C_SDA) {
85  if (pinmap.pin == sda) {
86  sda_map = &pinmap;
87  break;
88  }
89  }
90 
91  const PinMap *scl_map = nullptr;
92  for (const PinMap &pinmap : PINMAP_I2C_SCL) {
93  if (pinmap.pin == scl) {
94  scl_map = &pinmap;
95  break;
96  }
97  }
98 
99  if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
100  return {(int) NC, NC, (int) NC, NC, (int) NC};
101  }
102 
103  return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
104 }
105 #endif //DEVICE_I2C
106 
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)
109 {
110  const PinMap *tx_map = nullptr;
111  for (const PinMap &pinmap : PINMAP_UART_TX) {
112  if (pinmap.pin == tx) {
113  tx_map = &pinmap;
114  break;
115  }
116  }
117 
118  const PinMap *rx_map = nullptr;
119  for (const PinMap &pinmap : PINMAP_UART_RX) {
120  if (pinmap.pin == rx) {
121  rx_map = &pinmap;
122  break;
123  }
124  }
125 
126  if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
127  return {(int) NC, NC, (int) NC, NC, (int) NC, false};
128  }
129 
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};
132  } else {
133  return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false};
134  }
135 }
136 
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)
139 {
140  const PinMap *rts_map = nullptr;
141  for (const PinMap &pinmap : PINMAP_UART_RTS) {
142  if (pinmap.pin == rxflow) {
143  rts_map = &pinmap;
144  break;
145  }
146  }
147 
148  const PinMap *cts_map = nullptr;
149  for (const PinMap &pinmap : PINMAP_UART_CTS) {
150  if (pinmap.pin == txflow) {
151  cts_map = &pinmap;
152  break;
153  }
154  }
155 
156  if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
157  return {(int) NC, NC, (int) NC, NC, (int) NC};
158  }
159 
160  return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
161 }
162 #endif // DEVICE_SERIAL_FC
163 #endif // DEVICE_SERIAL
164 
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)
167 {
168  const PinMap *mosi_map = nullptr;
169  for (const PinMap &pinmap : PINMAP_SPI_MOSI) {
170  if (pinmap.pin == mosi) {
171  mosi_map = &pinmap;
172  break;
173  }
174  }
175 
176  const PinMap *miso_map = nullptr;
177  for (const PinMap &pinmap : PINMAP_SPI_MISO) {
178  if (pinmap.pin == miso) {
179  miso_map = &pinmap;
180  break;
181  }
182  }
183 
184  const PinMap *sclk_map = nullptr;
185  for (const PinMap &pinmap : PINMAP_SPI_SCLK) {
186  if (pinmap.pin == sclk) {
187  sclk_map = &pinmap;
188  break;
189  }
190  }
191 
192  const PinMap *ssel_map = nullptr;
193  for (const PinMap &pinmap : PINMAP_SPI_SSEL) {
194  if (pinmap.pin == ssel) {
195  ssel_map = &pinmap;
196  break;
197  }
198  }
199 
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};
204  }
205 
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};
207 }
208 #endif // DEVICE_SPI
209 
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)
212 {
213  const PinMap *rd_map = nullptr;
214  for (const PinMap &pinmap : PINMAP_CAN_RD) {
215  if (pinmap.pin == rd) {
216  rd_map = &pinmap;
217  break;
218  }
219  }
220 
221  const PinMap *td_map = nullptr;
222  for (const PinMap &pinmap : PINMAP_CAN_TD) {
223  if (pinmap.pin == td) {
224  td_map = &pinmap;
225  break;
226  }
227  }
228 
229  if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
230  return {(int) NC, NC, (int) NC, NC, (int) NC};
231  }
232 
233  return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
234 }
235 #endif //DEVICE_CAN
236 
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)
239 {
240  const PinMap *data0_map = nullptr;
241  for (const PinMap &pinmap : PINMAP_QSPI_DATA0) {
242  if (pinmap.pin == data0) {
243  data0_map = &pinmap;
244  break;
245  }
246  }
247 
248  const PinMap *data1_map = nullptr;
249  for (const PinMap &pinmap : PINMAP_QSPI_DATA1) {
250  if (pinmap.pin == data1) {
251  data1_map = &pinmap;
252  break;
253  }
254  }
255 
256  const PinMap *data2_map = nullptr;
257  for (const PinMap &pinmap : PINMAP_QSPI_DATA2) {
258  if (pinmap.pin == data2) {
259  data2_map = &pinmap;
260  break;
261  }
262  }
263 
264  const PinMap *data3_map = nullptr;
265  for (const PinMap &pinmap : PINMAP_QSPI_DATA3) {
266  if (pinmap.pin == data3) {
267  data3_map = &pinmap;
268  break;
269  }
270  }
271 
272  const PinMap *sclk_map = nullptr;
273  for (const PinMap &pinmap : PINMAP_QSPI_SCLK) {
274  if (pinmap.pin == sclk) {
275  sclk_map = &pinmap;
276  break;
277  }
278  }
279 
280  const PinMap *ssel_map = nullptr;
281  for (const PinMap &pinmap : PINMAP_QSPI_SSEL) {
282  if (pinmap.pin == ssel) {
283  ssel_map = &pinmap;
284  break;
285  }
286  }
287 
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};
290  }
291 
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};
293 }
294 #endif //DEVICE_QSPI
295 
296 #else // STATIC_PINMAP_READY
297 
298 #if DEVICE_PWMOUT
299 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
300 {
301  return {pin, (int) NC, (int) NC};
302 }
303 #endif // DEVICE_PWMOUT
304 
305 #if DEVICE_ANALOGIN
306 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
307 {
308  return {pin, (int) NC, (int) NC};
309 }
310 #endif // DEVICE_ANALOGIN
311 
312 #if DEVICE_ANALOGOUT
313 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
314 {
315  return {pin, (int) NC, (int) NC};
316 }
317 #endif // DEVICE_ANALOGOUT
318 
319 #if DEVICE_I2C
320 MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
321 {
322  return {(int) NC, sda, (int) NC, scl, (int) NC};
323 }
324 #endif //DEVICE_I2C
325 
326 #if DEVICE_SERIAL
327 MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
328 {
329  return {(int) NC, tx, (int) NC, rx, (int) NC, false};
330 }
331 
332 #if DEVICE_SERIAL_FC
333 MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
334 {
335  return {(int) NC, txflow, (int) NC, rxflow, (int) NC};
336 }
337 #endif // DEVICE_SERIAL_FC
338 #endif // DEVICE_SERIAL
339 
340 #if DEVICE_SPI
341 MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
342 {
343  return {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC};
344 }
345 #endif // DEVICE_SERIAL
346 
347 #if DEVICE_CAN
348 MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
349 {
350  return {(int) NC, rd, (int) NC, td, (int) NC};
351 }
352 #endif //DEVICE_CAN
353 
354 #if DEVICE_QSPI
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)
356 {
357  return {(int) NC, data0, (int) NC, data1, (int) NC, data2, (int) NC, data3, (int) NC, sclk, (int) NC, ssel, (int) NC};
358 }
359 #endif //DEVICE_QSPI
360 
361 #endif // STATIC_PINMAP_READY
362 
363 #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.