Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DynamicPinList.cpp Source File

DynamicPinList.cpp

00001 /*
00002  * Copyright (c) 2019, Arm Limited and affiliates.
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 "DynamicPinList.h"
00019 
00020 DynamicPinList::DynamicPinList()
00021 {
00022 
00023 }
00024 
00025 DynamicPinList::DynamicPinList(const PinList *pin_list)
00026 {
00027     for (uint32_t i = 0; i < pin_list->count; i++) {
00028         _pins.push_back(pin_list->pins[i]);
00029     }
00030 }
00031 
00032 DynamicPinList::DynamicPinList(const DynamicPinList &other)
00033 {
00034     _pins = other._pins;
00035 }
00036 
00037 void DynamicPinList::add(PinName pin)
00038 {
00039     _pins.push_back(pin);
00040 }
00041 
00042 bool DynamicPinList::has_pin(PinName pin) const
00043 {
00044     for (uint32_t i = 0; i < _pins.size(); i++) {
00045         if (pin == _pins[i]) {
00046             return true;
00047         }
00048     }
00049     return false;
00050 }
00051 
00052 void DynamicPinList::clear()
00053 {
00054     _pins.clear();
00055 }
00056 
00057 uint32_t DynamicPinList::count() const
00058 {
00059     return _pins.size();
00060 }
00061 
00062 PinName DynamicPinList::get(uint32_t index) const
00063 {
00064     return index < _pins.size() ? _pins[index] : NC;
00065 }
00066 
00067 int DynamicPinList::index(PinName pin) const
00068 {
00069     for (uint32_t i = 0; i < _pins.size(); i++) {
00070         if (pin == _pins[i]) {
00071             return i;
00072         }
00073     }
00074     return -1;
00075 }