Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers static_pinmap.h Source File

static_pinmap.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018-2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef STATIC_PINMAP_H
00018 #define STATIC_PINMAP_H
00019 
00020 #include "PinNames.h"
00021 #include "spi_api.h"
00022 #include "pwmout_api.h"
00023 #include "analogin_api.h"
00024 #include "analogout_api.h"
00025 #include "i2c_api.h"
00026 #include "serial_api.h"
00027 #include "qspi_api.h"
00028 #include "can_api.h"
00029 #include <mstd_cstddef>
00030 
00031 #if STATIC_PINMAP_READY
00032 #include "PeripheralPinMaps.h"
00033 
00034 
00035 #if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM)
00036 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
00037 {
00038     for (const PinMap &pinmap : PINMAP_PWM) {
00039         if (pinmap.pin == pin) {
00040             return {pin, pinmap.peripheral, pinmap.function};
00041         }
00042     }
00043     return {NC, (int) NC, (int) NC};
00044 }
00045 #endif // DEVICE_PWMOUT
00046 
00047 #if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN)
00048 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
00049 {
00050     for (const PinMap &pinmap : PINMAP_ANALOGIN) {
00051         if (pinmap.pin == pin) {
00052             return {pin, pinmap.peripheral, pinmap.function};
00053         }
00054     }
00055 
00056 #if PINMAP_ANALOGIN_INTERNAL
00057     for (const PinMap &pinmap : PINMAP_ANALOGIN_INTERNAL) {
00058         if (pinmap.pin == pin) {
00059             return {pin, pinmap.peripheral, pinmap.function};
00060         }
00061     }
00062 #endif
00063 
00064     return {NC, (int) NC, (int) NC};
00065 }
00066 #endif // DEVICE_ANALOGIN
00067 
00068 #if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT)
00069 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
00070 {
00071     for (const PinMap &pinmap : PINMAP_ANALOGOUT) {
00072         if (pinmap.pin == pin) {
00073             return {pin, pinmap.peripheral, pinmap.function};
00074         }
00075     }
00076     return {NC, (int) NC, (int) NC};
00077 }
00078 #endif // DEVICE_ANALOGOUT
00079 
00080 #if defined(DEVICE_I2C) && defined(PINMAP_I2C_SDA) && defined(PINMAP_I2C_SCL)
00081 MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
00082 {
00083     const PinMap *sda_map = nullptr;
00084     for (const PinMap &pinmap : PINMAP_I2C_SDA) {
00085         if (pinmap.pin == sda) {
00086             sda_map = &pinmap;
00087             break;
00088         }
00089     }
00090 
00091     const PinMap *scl_map = nullptr;
00092     for (const PinMap &pinmap : PINMAP_I2C_SCL) {
00093         if (pinmap.pin == scl) {
00094             scl_map = &pinmap;
00095             break;
00096         }
00097     }
00098 
00099     if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
00100         return {(int) NC, NC, (int) NC, NC, (int) NC};
00101     }
00102 
00103     return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
00104 }
00105 #endif //DEVICE_I2C
00106 
00107 #if defined(DEVICE_SERIAL) && defined(PINMAP_UART_TX) && defined(PINMAP_UART_RX)
00108 MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
00109 {
00110     const PinMap *tx_map = nullptr;
00111     for (const PinMap &pinmap : PINMAP_UART_TX) {
00112         if (pinmap.pin == tx) {
00113             tx_map = &pinmap;
00114             break;
00115         }
00116     }
00117 
00118     const PinMap *rx_map = nullptr;
00119     for (const PinMap &pinmap : PINMAP_UART_RX) {
00120         if (pinmap.pin == rx) {
00121             rx_map = &pinmap;
00122             break;
00123         }
00124     }
00125 
00126     if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
00127         return {(int) NC, NC, (int) NC, NC, (int) NC, false};
00128     }
00129 
00130     if (tx_map->pin == STDIO_UART_TX && rx_map->pin == STDIO_UART_RX) {
00131         return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true};
00132     } else {
00133         return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false};
00134     }
00135 }
00136 
00137 #if defined(DEVICE_SERIAL_FC) && defined(PINMAP_UART_RTS) && defined(PINMAP_UART_CTS)
00138 MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
00139 {
00140     const PinMap *rts_map = nullptr;
00141     for (const PinMap &pinmap : PINMAP_UART_RTS) {
00142         if (pinmap.pin == rxflow) {
00143             rts_map = &pinmap;
00144             break;
00145         }
00146     }
00147 
00148     const PinMap *cts_map = nullptr;
00149     for (const PinMap &pinmap : PINMAP_UART_CTS) {
00150         if (pinmap.pin == txflow) {
00151             cts_map = &pinmap;
00152             break;
00153         }
00154     }
00155 
00156     if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
00157         return {(int) NC, NC, (int) NC, NC, (int) NC};
00158     }
00159 
00160     return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
00161 }
00162 #endif // DEVICE_SERIAL_FC
00163 #endif // DEVICE_SERIAL
00164 
00165 #if defined(DEVICE_SPI) && defined(PINMAP_SPI_MOSI) && defined(PINMAP_SPI_MISO) && defined(PINMAP_SPI_SCLK) && defined(PINMAP_SPI_SSEL)
00166 MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
00167 {
00168     const PinMap *mosi_map = nullptr;
00169     for (const PinMap &pinmap : PINMAP_SPI_MOSI) {
00170         if (pinmap.pin == mosi) {
00171             mosi_map = &pinmap;
00172             break;
00173         }
00174     }
00175 
00176     const PinMap *miso_map = nullptr;
00177     for (const PinMap &pinmap : PINMAP_SPI_MISO) {
00178         if (pinmap.pin == miso) {
00179             miso_map = &pinmap;
00180             break;
00181         }
00182     }
00183 
00184     const PinMap *sclk_map = nullptr;
00185     for (const PinMap &pinmap : PINMAP_SPI_SCLK) {
00186         if (pinmap.pin == sclk) {
00187             sclk_map = &pinmap;
00188             break;
00189         }
00190     }
00191 
00192     const PinMap *ssel_map = nullptr;
00193     for (const PinMap &pinmap : PINMAP_SPI_SSEL) {
00194         if (pinmap.pin == ssel) {
00195             ssel_map = &pinmap;
00196             break;
00197         }
00198     }
00199 
00200     if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) ||
00201             (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) ||
00202             (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) {
00203         return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
00204     }
00205 
00206     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};
00207 }
00208 #endif // DEVICE_SPI
00209 
00210 #if defined(DEVICE_CAN) && defined(PINMAP_CAN_RD) && defined(PINMAP_CAN_TD)
00211 MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
00212 {
00213     const PinMap *rd_map = nullptr;
00214     for (const PinMap &pinmap : PINMAP_CAN_RD) {
00215         if (pinmap.pin == rd) {
00216             rd_map = &pinmap;
00217             break;
00218         }
00219     }
00220 
00221     const PinMap *td_map = nullptr;
00222     for (const PinMap &pinmap : PINMAP_CAN_TD) {
00223         if (pinmap.pin == td) {
00224             td_map = &pinmap;
00225             break;
00226         }
00227     }
00228 
00229     if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
00230         return {(int) NC, NC, (int) NC, NC, (int) NC};
00231     }
00232 
00233     return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
00234 }
00235 #endif //DEVICE_CAN
00236 
00237 #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)
00238 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)
00239 {
00240     const PinMap *data0_map = nullptr;
00241     for (const PinMap &pinmap : PINMAP_QSPI_DATA0) {
00242         if (pinmap.pin == data0) {
00243             data0_map = &pinmap;
00244             break;
00245         }
00246     }
00247 
00248     const PinMap *data1_map = nullptr;
00249     for (const PinMap &pinmap : PINMAP_QSPI_DATA1) {
00250         if (pinmap.pin == data1) {
00251             data1_map = &pinmap;
00252             break;
00253         }
00254     }
00255 
00256     const PinMap *data2_map = nullptr;
00257     for (const PinMap &pinmap : PINMAP_QSPI_DATA2) {
00258         if (pinmap.pin == data2) {
00259             data2_map = &pinmap;
00260             break;
00261         }
00262     }
00263 
00264     const PinMap *data3_map = nullptr;
00265     for (const PinMap &pinmap : PINMAP_QSPI_DATA3) {
00266         if (pinmap.pin == data3) {
00267             data3_map = &pinmap;
00268             break;
00269         }
00270     }
00271 
00272     const PinMap *sclk_map = nullptr;
00273     for (const PinMap &pinmap : PINMAP_QSPI_SCLK) {
00274         if (pinmap.pin == sclk) {
00275             sclk_map = &pinmap;
00276             break;
00277         }
00278     }
00279 
00280     const PinMap *ssel_map = nullptr;
00281     for (const PinMap &pinmap : PINMAP_QSPI_SSEL) {
00282         if (pinmap.pin == ssel) {
00283             ssel_map = &pinmap;
00284             break;
00285         }
00286     }
00287 
00288     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) {
00289         return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
00290     }
00291 
00292     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};
00293 }
00294 #endif //DEVICE_QSPI
00295 
00296 #else // STATIC_PINMAP_READY
00297 
00298 #if DEVICE_PWMOUT
00299 MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
00300 {
00301     return {pin, (int) NC, (int) NC};
00302 }
00303 #endif // DEVICE_PWMOUT
00304 
00305 #if DEVICE_ANALOGIN
00306 MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
00307 {
00308     return {pin, (int) NC, (int) NC};
00309 }
00310 #endif // DEVICE_ANALOGIN
00311 
00312 #if DEVICE_ANALOGOUT
00313 MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
00314 {
00315     return {pin, (int) NC, (int) NC};
00316 }
00317 #endif // DEVICE_ANALOGOUT
00318 
00319 #if DEVICE_I2C
00320 MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
00321 {
00322     return {(int) NC, sda, (int) NC, scl, (int) NC};
00323 }
00324 #endif //DEVICE_I2C
00325 
00326 #if DEVICE_SERIAL
00327 MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
00328 {
00329     return {(int) NC, tx, (int) NC, rx, (int) NC, false};
00330 }
00331 
00332 #if DEVICE_SERIAL_FC
00333 MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
00334 {
00335     return {(int) NC, txflow, (int) NC, rxflow, (int) NC};
00336 }
00337 #endif // DEVICE_SERIAL_FC
00338 #endif // DEVICE_SERIAL
00339 
00340 #if DEVICE_SPI
00341 MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
00342 {
00343     return {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC};
00344 }
00345 #endif // DEVICE_SERIAL
00346 
00347 #if DEVICE_CAN
00348 MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
00349 {
00350     return {(int) NC, rd, (int) NC, td, (int) NC};
00351 }
00352 #endif //DEVICE_CAN
00353 
00354 #if DEVICE_QSPI
00355 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)
00356 {
00357     return {(int) NC, data0, (int) NC, data1, (int) NC, data2, (int) NC, data3, (int) NC, sclk, (int) NC, ssel, (int) NC};
00358 }
00359 #endif //DEVICE_QSPI
00360 
00361 #endif // STATIC_PINMAP_READY
00362 
00363 #endif // STATIC_PINMAP_H