|
| 1 | +/* |
| 2 | + * This file is part of the Arduino_ThreadsafeIO library. |
| 3 | + * Copyright (c) 2021 Arduino SA. |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2.1 of the License, or (at your option) any later version. |
| 9 | + * This library is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | + * Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public |
| 15 | + * License along with this library; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + */ |
| 18 | + |
| 19 | +/************************************************************************************** |
| 20 | + * INCLUDE |
| 21 | + **************************************************************************************/ |
| 22 | + |
| 23 | +#include "BusDeviceCreator.h" |
| 24 | + |
| 25 | +/************************************************************************************** |
| 26 | + * NAMESPACE |
| 27 | + **************************************************************************************/ |
| 28 | + |
| 29 | +namespace impl |
| 30 | +{ |
| 31 | + |
| 32 | +/************************************************************************************** |
| 33 | + * PUBLIC MEMBER FUNCTIONS |
| 34 | + **************************************************************************************/ |
| 35 | + |
| 36 | +SpiBusDevice create(arduino::SPIClass & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol) |
| 37 | +{ |
| 38 | + return SpiBusDevice(SpiBusDeviceConfig{spi, |
| 39 | + spi_settings, |
| 40 | + cs_pin, |
| 41 | + fill_symbol |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +SpiBusDevice BusDeviceCreator::create(arduino::SPIClass & spi, int const cs_pin, uint32_t const spi_clock, BitOrder const spi_bit_order, SPIMode const spi_bit_mode, byte const fill_symbol) |
| 46 | +{ |
| 47 | + return SpiBusDevice(SpiBusDeviceConfig{spi, |
| 48 | + SPISettings(spi_clock, spi_bit_order, spi_bit_mode), |
| 49 | + cs_pin, |
| 50 | + fill_symbol |
| 51 | + }); |
| 52 | +} |
| 53 | + |
| 54 | +SpiBusDevice BusDeviceCreator::create(arduino::SPIClass & spi, SpiBusDeviceConfig::SpiSelectFunc spi_select, SpiBusDeviceConfig::SpiDeselectFunc spi_deselect, SPISettings const & spi_settings, byte const fill_symbol) |
| 55 | +{ |
| 56 | + return SpiBusDevice(SpiBusDeviceConfig{spi, spi_settings, spi_select, spi_deselect, fill_symbol}); |
| 57 | +} |
| 58 | + |
| 59 | +WireBusDevice BusDeviceCreator::create(arduino::HardwareI2C & wire, byte const slave_addr) |
| 60 | +{ |
| 61 | + return create(wire, slave_addr, true, true); |
| 62 | +} |
| 63 | + |
| 64 | +WireBusDevice BusDeviceCreator::create(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart) |
| 65 | +{ |
| 66 | + return create(wire, slave_addr, restart, true); |
| 67 | +} |
| 68 | + |
| 69 | +WireBusDevice BusDeviceCreator::create(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart, bool const stop) |
| 70 | +{ |
| 71 | + return WireBusDevice(WireBusDeviceConfig{wire, slave_addr, restart, stop}); |
| 72 | +} |
| 73 | + |
| 74 | +/************************************************************************************** |
| 75 | + * NAMESPACE |
| 76 | + **************************************************************************************/ |
| 77 | + |
| 78 | +} /* namespace impl */ |
| 79 | + |
| 80 | +/************************************************************************************** |
| 81 | + * GLOBAL VARIABLES |
| 82 | + **************************************************************************************/ |
| 83 | + |
| 84 | +impl::BusDeviceCreator BusDeviceCreator; |
0 commit comments