Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_compat.c Source File

mbed_compat.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 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 
00018 #include "analogin_api.h"
00019 #include "i2c_api.h"
00020 #include "spi_api.h"
00021 #include "gpio_api.h"
00022 #include "mbed_toolchain.h"
00023 
00024 // To be re-implemented in the target layer if required
00025 MBED_WEAK void gpio_free(gpio_t *obj)
00026 {
00027     // Do nothing
00028 }
00029 
00030 #if DEVICE_I2C
00031 // To be re-implemented in the target layer if required
00032 MBED_WEAK void i2c_free(i2c_t *obj)
00033 {
00034     // Do nothing
00035 }
00036 #endif
00037 
00038 #if DEVICE_ANALOGIN
00039 // To be re-implemented in the target layer if required
00040 MBED_WEAK void analogin_free(analogin_t *obj)
00041 {
00042     // Do nothing
00043 }
00044 #endif
00045 
00046 #if DEVICE_SPI
00047 // Default SPI capabilities. If specific target has different capabilities this function needs to be re-implemented.
00048 MBED_WEAK void spi_get_capabilities(PinName ssel, bool slave, spi_capabilities_t *cap)
00049 {
00050     if (slave) {
00051         cap->minimum_frequency = 200000;            // 200 kHz
00052         cap->maximum_frequency = 2000000;           // 2 MHz
00053         cap->word_length = 0x00008080;              // 8 and 16 bit symbols
00054         cap->support_slave_mode = false;            // to be determined later based on ssel
00055         cap->hw_cs_handle = false;                  // irrelevant in slave mode
00056         cap->slave_delay_between_symbols_ns = 2500; // 2.5 us
00057         cap->clk_modes = 0x0f;                      // all clock modes
00058 #if DEVICE_SPI_ASYNCH
00059         cap->async_mode = true;
00060 #else
00061         cap->async_mode = false;
00062 #endif
00063     } else {
00064         cap->minimum_frequency = 200000;          // 200 kHz
00065         cap->maximum_frequency = 2000000;         // 2 MHz
00066         cap->word_length = 0x00008080;            // 8 and 16 bit symbols
00067         cap->support_slave_mode = false;          // to be determined later based on ssel
00068         cap->hw_cs_handle = false;                // to be determined later based on ssel
00069         cap->slave_delay_between_symbols_ns = 0;  // irrelevant in master mode
00070         cap->clk_modes = 0x0f;                    // all clock modes
00071 #if DEVICE_SPI_ASYNCH
00072         cap->async_mode = true;
00073 #else
00074         cap->async_mode = false;
00075 #endif
00076     }
00077 
00078     // check if given ssel pin is in the cs pinmap
00079     const PinMap *cs_pins = spi_master_cs_pinmap();
00080     PinName pin = NC;
00081     while (cs_pins->pin != NC) {
00082         if (cs_pins->pin == ssel) {
00083 #if DEVICE_SPISLAVE
00084             cap->support_slave_mode = true;
00085 #endif
00086             cap->hw_cs_handle = true;
00087             break;
00088         }
00089         cs_pins++;
00090     }
00091 }
00092 
00093 #endif