Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct structure of configuration #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ DigitalInput::InputConfiguration const* DigitalInput::getConfiguration(uint8_t h
enum DigitalInputId
{
/* 0 */ EVAL_DI_1,
/* 1 */ EVAL_SW3,

/* xx */ NUMBER_OF_INTERNAL_DIGITAL_INPUTS,

// TODO: dynamic inputs here
/* yy */ // MyDynamicInput,

NUMBER_OF_EXTERNAL_DIGITAL_INPUTS,
TOTAL_NUMBER_OF_DIGITAL_INPUTS = NUMBER_OF_EXTERNAL_DIGITAL_INPUTS,
PORT_UNAVAILABLE = TOTAL_NUMBER_OF_DIGITAL_INPUTS
/* 1 */ EVAL_SW3,
// TODO: other internal inputs go here
// update LAST_INTERNAL_DIGITAL_INPUT when adding a new internal input
LAST_INTERNAL_DIGITAL_INPUT = EVAL_SW3,
// TODO: dynamic inputs go here
// update LAST_DYNAMIC_DIGITAL_INPUT when adding a new external input
/* yy */ // MyFirstDynamicInput,
LAST_DYNAMIC_DIGITAL_INPUT = LAST_INTERNAL_DIGITAL_INPUT,
PORT_UNAVAILABLE
};
#endif /* #if (BSP_INPUT_PIN_CONFIGURATION == 1) */
20 changes: 17 additions & 3 deletions libs/bsp/bspInputManager/include/inputManager/DigitalInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef GUARD_CF7B03E0_39CD_48FA_AEF0_45E4BC276713
#define GUARD_CF7B03E0_39CD_48FA_AEF0_45E4BC276713

#include "estd/static_assert.h"
#include "estd/uncopyable.h"
#include "io/DynamicClientCfg.h"
#include "io/Io.h"
Expand All @@ -20,6 +21,19 @@ class DigitalInput
#endif
#include "bsp/io/input/inputConfiguration.h"

static uint16_t const TOTAL_NUMBER_OF_DIGITAL_INPUTS
= static_cast<uint16_t>(DigitalInputId::PORT_UNAVAILABLE);
static uint16_t const NUMBER_OF_EXTERNAL_DIGITAL_INPUTS = static_cast<uint16_t>(
DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT - DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT);
static uint16_t const NUMBER_OF_INTERNAL_DIGITAL_INPUTS
= TOTAL_NUMBER_OF_DIGITAL_INPUTS - NUMBER_OF_EXTERNAL_DIGITAL_INPUTS;

// Make sure inputConfiguration has the correct structure
ESTD_STATIC_ASSERT(
DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT >= DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT);
ESTD_STATIC_ASSERT(
DigitalInputId::PORT_UNAVAILABLE == DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT + 1);

// Api for all DynamicClients
class IDynamicInputClient
{
Expand Down Expand Up @@ -90,12 +104,12 @@ class DigitalInput

using dynamicClientType = uint16_t;

static uint8_t const InputAnzahlDynamic
static uint16_t const InputNumberDynamic
= ((NUMBER_OF_EXTERNAL_DIGITAL_INPUTS > 0)
? static_cast<uint8_t>(NUMBER_OF_EXTERNAL_DIGITAL_INPUTS)
? NUMBER_OF_EXTERNAL_DIGITAL_INPUTS
: 1U);

static dynamicClient<dynamicClientType, IDynamicInputClient, 4, InputAnzahlDynamic>
static dynamicClient<dynamicClientType, IDynamicInputClient, 4, InputNumberDynamic>
dynamicInputCfg;
#if (INPUTDIGITAL_DEBOUNCE_ACTIVE == 1)
static DebounceConfiguration debounced[NUMBER_OF_DIGITAL_INPUTS];
Expand Down
42 changes: 22 additions & 20 deletions libs/bsp/bspInputManager/src/inputManager/DigitalInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dynamicClient<
DigitalInput::dynamicClientType,
DigitalInput::IDynamicInputClient,
4,
DigitalInput::InputAnzahlDynamic>
DigitalInput::InputNumberDynamic>
DigitalInput::dynamicInputCfg;

void DigitalInput::init(uint8_t const hw, bool const doSetup)
Expand All @@ -34,7 +34,7 @@ void DigitalInput::init(uint8_t const hw, bool const doSetup)
}
if (true == doSetup)
{
for (int32_t i = 0; i < NUMBER_OF_INTERNAL_DIGITAL_INPUTS; i++)
for (uint16_t i = 0; i < NUMBER_OF_INTERNAL_DIGITAL_INPUTS; i++)
{
(void)Io::setDefaultConfiguration(
static_cast<uint16_t>(sfpDigitalInputConfiguration[i].ioNumber));
Expand Down Expand Up @@ -92,34 +92,35 @@ bsp::BspReturnCode DigitalInput::get(DigitalInputId const channel, bool& result)
return bsp::BSP_ERROR;
}

if (channel < NUMBER_OF_INTERNAL_DIGITAL_INPUTS)
const uint16_t tmpChannel = static_cast<uint16_t>(channel);

// Internal channel
if ((NUMBER_OF_INTERNAL_DIGITAL_INPUTS > 0)
&& (channel <= DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT))
{
if (Io::PORT_UNAVAILABLE == sfpDigitalInputConfiguration[channel].ioNumber)
if (Io::PORT_UNAVAILABLE == sfpDigitalInputConfiguration[tmpChannel].ioNumber)
{
return bsp::BSP_NOT_SUPPORTED;
}
#if (INPUTDIGITAL_DEBOUNCE_ACTIVE == 1)
result = debounced[channel].vol != 0U;
#else
result = Io::getPin(static_cast<uint16_t>(sfpDigitalInputConfiguration[channel].ioNumber));
result = Io::getPin(static_cast<uint16_t>(sfpDigitalInputConfiguration[tmpChannel].ioNumber));
#endif

if (sfpDigitalInputConfiguration[channel].isInverted)
if (sfpDigitalInputConfiguration[tmpChannel].isInverted)
{
result = !result;
}
return bsp::BSP_OK;
}
else if (channel == NUMBER_OF_INTERNAL_DIGITAL_INPUTS)
{
return bsp::BSP_ERROR;
}
else if (channel < TOTAL_NUMBER_OF_DIGITAL_INPUTS)
else if ((channel > DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT)
&& (channel <= DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT))
{
// dynamic instance
dynamicClientType const dynamicChannel
= static_cast<dynamicClientType>(channel - NUMBER_OF_INTERNAL_DIGITAL_INPUTS - 1);
if (dynamicChannel < InputAnzahlDynamic)
= static_cast<dynamicClientType>(tmpChannel - NUMBER_OF_INTERNAL_DIGITAL_INPUTS);
if (dynamicChannel < InputNumberDynamic)
{
if (dynamicInputCfg.getClientValid(dynamicChannel) == true)
{
Expand All @@ -145,12 +146,12 @@ bsp::BspReturnCode DigitalInput::get(DigitalInputId const channel, bool& result)
bsp::BspReturnCode DigitalInput::setDynamicClient(
uint16_t const inputNumber, uint16_t const clientInputNumber, IDynamicInputClient* const client)
{
// range of outputNumber check
if ((inputNumber > static_cast<uint16_t>(NUMBER_OF_INTERNAL_DIGITAL_INPUTS))
&& (inputNumber < static_cast<uint16_t>(TOTAL_NUMBER_OF_DIGITAL_INPUTS)))
// range of input check
if ((inputNumber > static_cast<uint16_t>(DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT))
&& (inputNumber <= static_cast<uint16_t>(DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT)))
{
dynamicClientType const dynamicChannel
= inputNumber - static_cast<uint16_t>(NUMBER_OF_INTERNAL_DIGITAL_INPUTS) - 1U;
= static_cast<dynamicClientType>(inputNumber - NUMBER_OF_INTERNAL_DIGITAL_INPUTS);
interrupts::SuspendResumeAllInterruptsLock fLock;
fLock.suspend();
if (dynamicInputCfg.setDynamicClient(dynamicChannel, clientInputNumber, client) == true)
Expand All @@ -172,11 +173,12 @@ bsp::BspReturnCode DigitalInput::setDynamicClient(

bsp::BspReturnCode DigitalInput::clrDynamicClient(uint16_t const inputNumber)
{
if ((inputNumber > static_cast<uint16_t>(NUMBER_OF_INTERNAL_DIGITAL_INPUTS))
&& (inputNumber < static_cast<uint16_t>(TOTAL_NUMBER_OF_DIGITAL_INPUTS)))
// range of input check
if ((inputNumber > static_cast<uint16_t>(DigitalInputId::LAST_INTERNAL_DIGITAL_INPUT))
&& (inputNumber <= static_cast<uint16_t>(DigitalInputId::LAST_DYNAMIC_DIGITAL_INPUT)))
{
dynamicClientType const dynamicChannel
= inputNumber - static_cast<uint16_t>(NUMBER_OF_INTERNAL_DIGITAL_INPUTS) - 1U;
= static_cast<dynamicClientType>(inputNumber - NUMBER_OF_INTERNAL_DIGITAL_INPUTS);
interrupts::SuspendResumeAllInterruptsLock fLock;
fLock.suspend();
if (dynamicInputCfg.clearDynamicClient(dynamicChannel) == true)
Expand Down
12 changes: 4 additions & 8 deletions libs/bsp/bspInputManager/src/inputManager/DigitalInputTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ void DigitalInputTester::executeCommand(::util::command::CommandContext& context
::util::format::SharedStringWriter out(context);
(void)out.printf(
"All digital inputs: %d \r\n", DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS);
for (uint16_t i = 0U;
i < static_cast<uint16_t>(DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS);
++i)
for (uint16_t i = 0U; i < DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS; ++i)
{
bool temp;
bsp::BspReturnCode const ret
Expand All @@ -45,9 +43,9 @@ void DigitalInputTester::executeCommand(::util::command::CommandContext& context
break;
case 2: // "get"
{
uint32_t const inputNo = context.scanIntToken<uint32_t>();
uint16_t const inputNo = context.scanIntToken<uint16_t>();
(void)context.check(
inputNo < static_cast<uint32_t>(DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS));
inputNo < DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS);
if (context.checkEol())
{
::util::format::SharedStringWriter out(context);
Expand All @@ -70,9 +68,7 @@ void DigitalInputTester::executeCommand(::util::command::CommandContext& context
{
::util::format::SharedStringWriter out(context);
(void)out.printf("#");
for (uint32_t i = 0U;
i < static_cast<uint32_t>(DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS);
++i)
for (uint16_t i = 0U; i < DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS; ++i)
{
bool temp;
bsp::BspReturnCode const ret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ enum DigitalInputId
{
InternalInput1,
InternalInput2,
NUMBER_OF_INTERNAL_DIGITAL_INPUTS,
LAST_INTERNAL_DIGITAL_INPUT = InternalInput2,
ExternalInput1,
ExternalInput2,
NUMBER_OF_EXTERNAL_DIGITAL_INPUTS,
TOTAL_NUMBER_OF_DIGITAL_INPUTS = NUMBER_OF_EXTERNAL_DIGITAL_INPUTS,
PORT_UNAVAILABLE = TOTAL_NUMBER_OF_DIGITAL_INPUTS
LAST_DYNAMIC_DIGITAL_INPUT = ExternalInput2,
PORT_UNAVAILABLE
};
Loading