DigitalIn
General
The classes DigitalInPolling, DebouncedDigitalInPolling and DigitalInInt have as main goal the handling of a digital input signal form a normal GPIO or an ExternalInterrupt input. To configure a inverted input, please do that by calling the setInverted function, alternativly you can set the inverted flag in the constructor. These classss dependent on a semf-supplied interface class Gpio, which links the hardware input pin of the microcontroller and the semf library.
DigitalInPolling
Initialization
For using a normal GPIO as input (without external interrupt handling) you can setup a DigitalInPolling object
// Inclusion of the predeclared and predefined class in the project. #include "HardwareAbstraction/Stm32/stm32l0gpio.h" #include "HardwareAbstraction/Stm32/stm32l0systick.h" #include "Components/Input/digitalinpolling.h" #include "Components/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); semf::Stm32L0Systick systick; // Configure a timebase on basis of 1ms systick timer and enable it semf::TimeBase timebase1ms(systick, true); timebase1ms.add(digInPin);
Usage
changedToHigh and changedToLow signals must be connected to their corresponding slots. Checking the state of the the digital pin can be manually done all the time.
void inputChangedToHighSlot() { // do something } void inputChangedToLowSlot() { // do something } digInPin.changedToHigh.connect(inputChangedToHighSlot); digInPin.changedToLowconnect(inputChangedToLowSlot); // Check manually if (digInPin.state() == semf::DigitalIn::State::LOW) { // do something }
DebouncedDigitalInPolling
Often digital inputs, e.g. buttons, have to be bedounced for a certain time. This can be easily done by using a DebouncedDigitalInPolling object. It can be used same as the base class 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 "HardwareAbstraction/Stm32/stm32l0gpio.h" #include "HardwareAbstraction/Stm32/stm32l0systick.h" #include "Components/Input/debounceddigitalinpolling.h" #include "Components/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); semf::Stm32L0Systick systick; // Configure a timebase on basis of 1ms systick timer and enable it semf::TimeBase timebase1ms(systick, true); timebase1ms.add(digInPin);
Usage
The Usage is analog to DigitalInPolling.
DigitalInInt
For using an GPIO as input, triggered by an external interrupt, DigitalInputInt is the bect choice. For external interrupt driven inputs no timer is neccessary.
Initialization
// Inclusion of the predeclared and predefined class in the project. #include "HardwareAbstraction/Stm32/stm32l0gpio.h" #include "HardwareAbstraction/Stm32/stm32l0externalinterrupt.h" #include "Components/Input/digitalinint.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);
Usage
The Usage is analog to DigitalInPolling.