semf
DigitalIn

General

The classes semf::DigitalInPolling, semf::DebouncedDigitalInPolling and semf::DigitalInInt handle and process the digital input signal from a normal semf::Gpio or an semf::ExternalInterrupt input. To configure an inverted input, call the setInverted() function. Alternativly you can set the inverted flag in the constructor. These classss dependend on a semf supplied interface class semf::Gpio which links the hardware input pin of the microcontroller and the semf library. All three implementations are based on the interface semf::app::DigitalIn.

The class triggers two signals after changing the digital input: changedToHigh and changedToLow. The hardware semf::Gpio pins can easily be configured either by using the vendors hardware configuration tool e.g. stm-cube or by calling the hardware functions for setting the pin.

DigitalInPolling

Initialization

To use a normal GPIO as input (without external interrupt handling) you can set up a semf::DigitalInPolling object. Take care, that the tick() function is called periodically e.g. by a semf::app::TimeBase.

// Inclusion of the predeclared and predefined class in the project.
#include "semf/hardwareabstraction/stm32l0/stm32l0gpio.h"
#include "semf/hardwareabstraction/stm32l0/stm32l0systick.h"
#include "semf/utils/system/timebase.h"
// Microcontroller pin definitions are stored in 'main.h'.
#include "main.h"
semf::Stm32L0Gpio gpio1(GPIOA, GPIO_PIN_1);
semf::DigitalInPolling digInPin(gpio1, false);
// Configure a timebase on basis of 1ms systick timer and enable it
semf::TimeBase timebase1ms(semf::Stm32F4SysTick::instance(), true);
timebase1ms.add(digInPin);
Class for reading a digital input in polling mode.
A TimeBase is the bridge between e.g. a hardware timer (interrupt service routine) and TickReceiver o...
Definition: timebase.h:24

Usage

changedToHigh and changedToLow signals must be connected to their corresponding slots. Checking the state of the the digital pin can be done manually at any point in time.

void onInputChangedToHigh()
{
// do something
}
void onInputChangedToLow()
{
// do something
}
semf::StaticSlot<> onInputChangedToHighSlot(onInputChangedToHigh);
semf::StaticSlot<> onInputChangedToLowSlot(onInputChangedToLow);
digInPin.changedToHigh.connect(onInputChangedToHighSlot);
digInPin.changedToLowconnect(onInputChangedToLowSlot);
// Check manually
if (digInPin.state() == semf::DigitalIn::State::Low)
{
// do something
}
StaticSlot for lightweight signal/slot implementation. This StaticSlot ist for connecting a signal to...
Definition: staticslot.h:27

DebouncedDigitalInPolling

Often digital inputs, e.g. buttons, have to be debounced for a certain time. This can easily be done by using a semf::DebouncedDigitalInPolling object. It can be used same as the base class semf::DigitalInPolling with the extra feature of setting a debounced low and high time for signal excecution.

Initialization

// Inclusion of the predeclared and predefined class in the project.
#include "semf/hardwareabstraction/stm32l0/stm32l0gpio.h"
#include "semf/hardwareabstraction/stm32l0/stm32l0systick.h"
#include "semf/input/digitanin/debounceddigitalinpolling.h"
#include "semf/utils/system/timebase.h"
// Microcontroller pin definitions are stored in 'main.h'.
#include "main.h"
semf::Stm32L0Gpio gpio1(GPIOA, GPIO_PIN_1);
// debounced low time: 100ms
// debounced high time: 20ms
semf::DebouncedDigitalInPolling digInPin(gpio1, 100, 20, false);
// Configure a timebase on basis of 1ms systick timer and enable it
semf::TimeBase timebase1ms(semf::Stm32F4SysTick::instance(), true);
timebase1ms.add(digInPin);
Class for reading and debouncing a digital input (e.g. used for buttons or relays inputs)....

Usage

The Usage is analog to semf::DigitalInPolling.

DigitalInInt

Take care that the external interrupt is configured correctly. For using a semf::Gpio as input triggered by an semf::ExternalInterrupt semf::DigitalInInt is the best choice. For external interrupt driven inputs no timer is neccessary.

Initialization

// Inclusion of the predeclared and predefined class in the project.
#include "semf/hardwareabstraction/stm32l0/stm32l0gpio.h"
#include "semf/hardwareabstraction/stm32l0/stm32l0externalinterrupt.h"
// Microcontroller pin definitions are stored in 'main.h'.
#include "main.h"
semf::Stm32L0Gpio gpio1(GPIOA, GPIO_PIN_1);
semf::Stm32L0ExternalInterrupt exti1(GPIO_PIN_1);
semf::DigitalInInt digInPin(gpio1, exti1, false);
Class for reading a digital input in interrupt mode.
Definition: digitalinint.h:25

Usage

The Usage is analog to semf::DigitalInPolling.