Skip to content

Commit

Permalink
Correct structure of configuration
Browse files Browse the repository at this point in the history
* Fix TOTAL_NUMBER_OF_DIGITAL_INPUTS, NUMBER_OF_INTERNAL_DIGITAL_INPUTS
and NUMBER_OF_EXTERNAL_DIGITAL_INPUTS values to match the inputs in the
config enum
* Add estd_assert to verify the correct configuration

Change-Id: I5213105362a21e459b9af049fd402168d8aea226
  • Loading branch information
evengrinovich committed Feb 7, 2025
1 parent ec25295 commit bd192eb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
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) */
22 changes: 17 additions & 5 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,10 @@ class DigitalInput

using dynamicClientType = uint16_t;

static uint8_t const InputAnzahlDynamic
= ((NUMBER_OF_EXTERNAL_DIGITAL_INPUTS > 0)
? static_cast<uint8_t>(NUMBER_OF_EXTERNAL_DIGITAL_INPUTS)
: 1U);
static uint16_t const InputNumberDynamic
= ((NUMBER_OF_EXTERNAL_DIGITAL_INPUTS > 0) ? 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
44 changes: 24 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,37 @@ bsp::BspReturnCode DigitalInput::get(DigitalInputId const channel, bool& result)
return bsp::BSP_ERROR;
}

if (channel < NUMBER_OF_INTERNAL_DIGITAL_INPUTS)
uint16_t const 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 +148,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 +175,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
13 changes: 4 additions & 9 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,8 @@ void DigitalInputTester::executeCommand(::util::command::CommandContext& context
break;
case 2: // "get"
{
uint32_t const inputNo = context.scanIntToken<uint32_t>();
(void)context.check(
inputNo < static_cast<uint32_t>(DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS));
uint16_t const inputNo = context.scanIntToken<uint16_t>();
(void)context.check(inputNo < DigitalInput::TOTAL_NUMBER_OF_DIGITAL_INPUTS);
if (context.checkEol())
{
::util::format::SharedStringWriter out(context);
Expand All @@ -70,9 +67,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
};

0 comments on commit bd192eb

Please sign in to comment.