Embedded Artistry Framework
Embedded Systems C++ Framework
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | List of all members
embvm::led::gpio< TActiveHigh > Class Template Referencefinal

This class manages a GPIO object which is attached to an LED. More...

#include <led.hpp>

Inheritance diagram for embvm::led::gpio< TActiveHigh >:
Inheritance graph

Public Member Functions

 gpio (embvm::gpio::output &g) noexcept
 Default constructor. More...
 
 gpio (embvm::gpio::output &g, const char *name) noexcept
 Construct an led::gpio() with a C-string name. More...
 
 gpio (embvm::gpio::output &g, const std::string &name) noexcept
 Construct an led::gpio() with a std::string name. More...
 
 gpio (embvm::gpio::output &g, const std::string_view &name) noexcept
 Construct an led::gpio() with a std::string_view name. More...
 
 ~gpio () final=default
 Default destructor. More...
 
void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void on () noexcept final
 Turn on the LED. More...
 
void off () noexcept final
 Turn off the LED. More...
 
void toggle () noexcept final
 Toggle the LED state. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop the driver. More...
 
void restart () noexcept
 Restart the driver. More...
 
type_safe::boolean started () const noexcept
 Check if the driver has been started. More...
 
constexpr embvm::DriverType_t DriverType () const noexcept
 Returns the registered type ID of the driver. More...
 
constexpr const std::string_view & name () const noexcept
 Provides a string_view reference of the driver name. More...
 
constexpr const char * name_cstr () const noexcept
 Provides a c-string version of the driver name. More...
 
virtual DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 LED Driver Type ID. More...
 

Protected Attributes

type_safe::boolean started_ = false
 Tracks the driver state. More...
 
const std::string_view name_
 Name of the driver instance. More...
 
const embvm::DriverType_t type_
 Type ID of the driver instance. More...
 

Private Attributes

embvm::gpio::outputg_
 The GPIO output object which this LED driver is managing. More...
 
bool on_ = false
 State of the LED, required to implement toggle(). More...
 

Detailed Description

template<bool TActiveHigh = true>
class embvm::led::gpio< TActiveHigh >

This class manages a GPIO object which is attached to an LED.

This class provides a specialization of the led::base() object. The led::gpio() class manages a embvm::gpio::output object that is connected to an LED in hardware. All interactions with the LED are forwarded to the embvm::gpio::output.

This class is used in the same way as led::base(). The only additonal requirement is that it must be initialized with a embvm::gpio::output object. This driver assumes that is is the sole owner of the embvm::gpio::output object after creation. If other code messes with the embvm::gpio::output state outside of this interface, proper functioning is no longer guaranteed.

Template Parameters
TActiveHighIf true, the LED turns on when the GPIO is set high. If false, the LED turns on when the GPIO is set low.

Constructor & Destructor Documentation

◆ gpio() [1/4]

template<bool TActiveHigh = true>
embvm::led::gpio< TActiveHigh >::gpio ( embvm::gpio< TActiveHigh >::output &  g)
inlineexplicitnoexcept

Default constructor.

Initializes the led::gpio() instance with a GPIO output object to manage.

Parameters
gThe embvm::gpio::output object which the LED driver will manage.

◆ gpio() [2/4]

template<bool TActiveHigh = true>
embvm::led::gpio< TActiveHigh >::gpio ( embvm::gpio< TActiveHigh >::output &  g,
const char *  name 
)
inlineexplicitnoexcept

Construct an led::gpio() with a C-string name.

Initializes the led::gpio() instance with a GPIO output object to manage and uses the specified name.

Parameters
gThe embvm::gpio::output object which the LED driver will manage.
nameThe name of the LED instance.

◆ gpio() [3/4]

template<bool TActiveHigh = true>
embvm::led::gpio< TActiveHigh >::gpio ( embvm::gpio< TActiveHigh >::output &  g,
const std::string &  name 
)
inlineexplicitnoexcept

Construct an led::gpio() with a std::string name.

Initializes the led::gpio() instance with a GPIO output object to manage and uses the specified name.

Parameters
gThe embvm::gpio::output object which the LED driver will manage.
nameThe name of the LED instance.

◆ gpio() [4/4]

template<bool TActiveHigh = true>
embvm::led::gpio< TActiveHigh >::gpio ( embvm::gpio< TActiveHigh >::output &  g,
const std::string_view &  name 
)
inlineexplicitnoexcept

Construct an led::gpio() with a std::string_view name.

Initializes the led::gpio() instance with a GPIO output object to manage and uses the specified name.

Parameters
gThe embvm::gpio::output object which the LED driver will manage.
nameThe name of the LED instance. led::base() uses a std::string_view, so the std::string must remain valid

◆ ~gpio()

template<bool TActiveHigh = true>
embvm::led::gpio< TActiveHigh >::~gpio ( )
finaldefault

Default destructor.

Member Function Documentation

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
inlinenoexceptinherited

Returns the registered type ID of the driver.

When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.

The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ off()

template<bool TActiveHigh = true>
void embvm::led::gpio< TActiveHigh >::off ( )
inlinefinalvirtualnoexcept

Turn off the LED.

Postcondition
LED is turned off.

Implements embvm::led::base.

Referenced by NRF52DKHWPlatform::leds_off(), and NRF52DongleHWPlatform::leds_off().

◆ on()

template<bool TActiveHigh = true>
void embvm::led::gpio< TActiveHigh >::on ( )
inlinefinalvirtualnoexcept

Turn on the LED.

Postcondition
LED is turned on.

Implements embvm::led::base.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ restart()

void embvm::DriverBase::restart ( )
inlinenoexceptinherited

Restart the driver.

Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.

References embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ start()

void embvm::DriverBase::start ( )
inlinenoexceptinherited

◆ start_()

template<bool TActiveHigh = true>
void embvm::led::gpio< TActiveHigh >::start_ ( )
inlinefinalvirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::led::base.

References embvm::led::base::off().

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ stop()

void embvm::DriverBase::stop ( )
inlinenoexceptinherited

◆ stop_()

template<bool TActiveHigh = true>
void embvm::led::gpio< TActiveHigh >::stop_ ( )
inlinefinalvirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::led::base.

◆ toggle()

template<bool TActiveHigh = true>
void embvm::led::gpio< TActiveHigh >::toggle ( )
inlinefinalvirtualnoexcept

Toggle the LED state.

If the LED is on, turn it off. If the LED is off, turn it on. The logic for implementing toggle is left to the base class, as there may be efficient options that depend on the specific implementation.

Derived classes must implement the toggle() function.

Postcondition
If the LED was off, the LED is now on. If the LED was on, LED is now off.

Implements embvm::led::base.

References embvm::led::base::off(), and embvm::led::base::on().

Referenced by BlinkySimulatorHWPlatform::init_().

◆ type()

static constexpr embvm::DriverType embvm::led::base::type ( )
inlinestaticnoexceptinherited

LED Driver Type ID.

Returns
LED type ID.

References embvm::LED.

Member Data Documentation

◆ g_

template<bool TActiveHigh = true>
embvm::gpio::output& embvm::led::gpio< TActiveHigh >::g_
private

The GPIO output object which this LED driver is managing.

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ on_

template<bool TActiveHigh = true>
bool embvm::led::gpio< TActiveHigh >::on_ = false
private

State of the LED, required to implement toggle().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
protectedinherited

Tracks the driver state.

True if the driver has been started, false if it has been stopped or not yet started.

Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().


The documentation for this class was generated from the following file: