/****************************************************************************** * * Author : Konstantin Chizhov * Date : 2013 * All rights reserved. * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************************** * modified: layout // a.b. * modified /impl/iopin.h included here // a.b. ****************************************************************************** * why PORT and CONFIGPORT ? ******************************************************************************/ #pragma once #include "static_assert.h" #include namespace Mcucpp { namespace IO { template //**************************** class TPin { STATIC_ASSERT(PIN < PORT::Width); /*********** * this class represents one pin in an IO port. It is fully static *****************************************************************/ public: using Port = PORT ; using ConfigPort = CONFIG_PORT ; using DataT = typename ConfigPort::DataT; // a.b. using Speed = typename ConfigPort::Speed ; using PullMode = typename ConfigPort::PullMode ; using DriverType = typename ConfigPort::DriverType ; using Configuration = typename ConfigPort::Configuration ; static const unsigned Number = PIN; static const bool Inverted = false; static void Set() { Set(true); } static void Set(bool val) { if(val) PORT:: template Set <1u << PIN>(); else PORT:: template Clear <1u << PIN>(); } static void SetDir(uint8_t val) { if(val) SetDirWrite(); else SetDirRead(); } static void Clear () { Set (false); } static void Toggle () { PORT:: Toggle (1u << PIN); } static void SetDirRead () { PORT:: template SetPinConfiguration < PIN>(PORT::In ); } static void SetDirWrite () { ConfigPort:: template SetPinConfiguration < PIN>(PORT::Out); } static void SetDriverType (DriverType driverType) { ConfigPort:: SetDriverType (1u << PIN, driverType); } static void SetPullUp (PullMode pullMode) { ConfigPort:: SetPullUp (1u << PIN, pullMode ); } static void SetSpeed (Speed speed) { ConfigPort:: SetSpeed (1u << PIN, speed ); } static void AltFuncNumber (uint8_t funcNumber) { ConfigPort:: AltFuncNumber (1u << PIN, funcNumber); } static bool IsSet () { return (PORT:: PinRead() & (DataT) (1u << PIN)) != 0; } static void WaitForSet () { while ( IsSet()==0 ) {} } static void WaitForClear () { while ( IsSet() ) {} } static void SetConfiguration(Configuration config) { ConfigPort:: template SetPinConfiguration < PIN>(config);} template //***************************** static void SetConfiguration() { ConfigPort:: template SetConfiguration <1u << PIN, config>(); } }; //.TPin template //**************************** class TInvertedPin : public TPin { //****************** public: static const bool Inverted = true; static void Set () { Set (true); } static void Set (bool val) { if(val) PORT:: template Clear <1u << PIN>(); else PORT:: template Set <1u << PIN>(); } static void Clear() { Set (false); } }; } //.IO } //.Mcucpp /* obsolete ******************************************************************************/ // #include /* /impl/iopin.h // canibalised ****************************************************************************** namespace Mcucpp { namespace IO { template void TPin :: template void TPin :: template void TPin ::SetDirRead () template void TPin ::SetDirWrite () template void TPin ::SetConfiguration(Configuration configuration) template void TPin ::Set (bool val) template void TPin ::Toggle () template void TPin ::SetDir (uint8_t val) template void TPin ::SetDriverType (DriverType driverType) template void TPin ::SetPullUp (PullMode pullMode) template void TPin ::SetSpeed (Speed speed) template void TPin ::AltFuncNumber (uint8_t funcNumber) template bool TPin ::IsSet () template void TPin ::WaitForSet () template void TPin ::WaitForClear () template void TInvertedPin::Set () template void TInvertedPin::Clear () template void TInvertedPin::Set (bool val) } .IO } .Mcucpp ***************************************************************************************************************************************************/