Class Pin

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class Pin : public SignalHook

MCU pin model.

Pin represents a external pad of the MCU used for GPIO. The pin has two electrical states given by the external circuit and the internal circuit (the GPIO port), which are resolved into a single electrical state. In case of conflict, the SHORTED state is set. Analog voltage levels are relative to VCC, hence limited to the range [0.0, 1.0].

Public Types

enum State

Pin state enum. All the possible logical/analog electrical states that the pin can take.

Values:

enumerator State_Floating
enumerator State_PullUp
enumerator State_PullDown
enumerator State_Analog
enumerator State_High
enumerator State_Low
enumerator State_Shorted
enum SignalId

Signal IDs raised by the pin. For all signals, the index is set to the pin ID.

Values:

enumerator Signal_StateChange

Signal raised for any change of the resolved state. data is set to the new state (one of State enum values)

enumerator Signal_DigitalChange

Signal raised for any change of the resolved digital state. data is set to the new digital state (0 or 1).

enumerator Signal_VoltageChange

Signal raised for any change to the analog value, including when induced by a digital state change. data is set to the analog value (double, in range [0;1])

Public Functions

explicit Pin(pin_id_t id)

Build a pin.

Parameters:

id – Identifier for the pin which should be unique

void set_external_state(State state, double voltage = 0.0)

Set the external electrical state of the pin.

Note

The voltage value is used only when state is Analog, and contrained to the range [0.0; 1.0].

Parameters:
  • state – new external electrical state

  • voltage – new voltage value, relative to VCC.

void set_gpio_state(State state)

Set the electrical state of the pin as controlled by the GPIO port.

Parameters:

state – new internal electrical state

inline pin_id_t id() const
Returns:

the identifier of the pin

inline State state() const
Returns:

the resolved state

bool digital_state() const

Returns the electrical state expressed as a boolean state. If the state is digital, it returns true if the state is high or false if it’s low. In other states, true is returned if the voltage is greater than 0.5.

Returns:

the resolved state

inline double voltage() const
Returns:

the pin voltage value

inline DataSignal &signal()
Returns:

the signal raising the state/value changes

virtual void raised(const signal_data_t &sigdata, int hooktag) override

Callback override for receiving signal changes

Public Static Functions

static const char *StateName(State state)

Map the state to its name, for debug and logging purpose.

Parameters:

state

Returns:

name of the state

struct state_t

Public Members

State state
double level