simulavr  1.1.0
Pin Class Reference

Pin class, handles input and output to external parts. More...

#include <pin.h>

Inheritance diagram for Pin:

Public Types

enum  T_Pinstate {
  LOW, HIGH, SHORTED, PULLUP,
  TRISTATE, PULLDOWN, ANALOG, ANALOG_SHORTED
}
 Possible PIN states. More...
 

Public Member Functions

 Pin (void)
 common constructor, initial output state is tristate More...
 
 Pin (const Pin &p)
 copy constructor, copy values but no refs to Net or HWPort More...
 
 Pin (T_Pinstate ps)
 copy constructor from pin state More...
 
 Pin (unsigned char *parentPin, unsigned char mask)
 constructor for a port pin, only used in UI part! More...
 
 Pin (float analog)
 constructor for analog pin More...
 
virtual ~Pin ()
 pin destructor, breaks save connection to other pins, if necessary More...
 
 operator char () const
 return char representation for output stage More...
 
virtual Pinoperator= (char)
 set output stage to (digital) state, set value for ANALOG state separately More...
 
virtual operator bool () const
 return boolean state of output stage More...
 
virtual Pin operator+ (const Pin &p)
 calculate common state from 2 connected pins More...
 
virtual Pin operator+= (const Pin &p)
 calculate common state from connected other pin to this pin More...
 
virtual void SetInState (const Pin &p)
 handles the input value from net More...
 
virtual void RegisterNet (Net *n)
 registers Net instance on pin More...
 
virtual void UnRegisterNet (Net *n)
 deletes Net instance registration for pin More...
 
virtual Pin GetPin (void)
 "cast method" to get back a Pin instance More...
 
int GetAnalog (void)
 Get analog value as integer from 0 to INT_MAX (for backward compatibility, will be deprecated later) More...
 
float GetRawAnalog (void) const
 get back raw analog value (just variable content!) More...
 
float GetAnalogValue (float vcc)
 Returns real analog input value of pin. More...
 
PinSetAnalogValue (float value)
 Sets the pin to an real analog value. More...
 
void SetRawAnalog (float value)
 
void RegisterCallback (HasPinNotifyFunction *)
 
bool CalcPin (void)
 Update input values from output values. More...
 
bool isPortPin (void)
 True, if it's a port pin. More...
 
bool isConnected (void)
 True, if it's connected to other pins. More...
 
bool hasListener (void)
 True, if there change listeners. More...
 

Public Attributes

T_Pinstate outState
 discrete value of output stage More...
 
std::vector< HasPinNotifyFunction * > notifyList
 listeners for change of input value More...
 

Protected Attributes

unsigned char * pinOfPort
 points to HWPort::pin or nullptr More...
 
IOReg< HWPort > * pinRegOfPort
 points to PIN io register of port or nullptr More...
 
unsigned char mask
 byte mask for HWPort::pin More...
 
AnalogValue analogVal
 "real" analog voltage value More...
 
NetconnectedTo
 the connection to other pins (nullptr, if not connected) More...
 

Friends

class HWPort
 
class Net
 

Detailed Description

Pin class, handles input and output to external parts.

This isn't a simple electrical point with a electrical potential. Pin class simulates mostly complete Input/Output circuit. So you have a output stage and a input state. Such a pin is connected by a net (see Net class) with other pins. Attention! The variable outState isn't the electrical state of a pin, it's only the state of the output stage. Only in case of no connected Net instance (aka no physical connection to other sink / source) it's also the real pin state!

Definition at line 98 of file pin.h.

Member Enumeration Documentation

◆ T_Pinstate

Possible PIN states.

This are the discrete states of output stage and input value.

Warning
Please do not change the order of these values without thinking twice, as for example the simulavr VPI interface depends on this/exports this to verilog.
Enumerator
LOW 
HIGH 
SHORTED 
PULLUP 
TRISTATE 
PULLDOWN 
ANALOG 
ANALOG_SHORTED 

Definition at line 115 of file pin.h.

Constructor & Destructor Documentation

◆ Pin() [1/5]

Pin::Pin ( void  )

common constructor, initial output state is tristate

Definition at line 125 of file pin.cpp.

◆ Pin() [2/5]

Pin::Pin ( const Pin p)

copy constructor, copy values but no refs to Net or HWPort

Definition at line 148 of file pin.cpp.

References analogVal, and outState.

◆ Pin() [3/5]

Pin::Pin ( T_Pinstate  ps)

copy constructor from pin state

Definition at line 95 of file pin.cpp.

References AnalogValue::ST_FLOATING, AnalogValue::ST_GND, and AnalogValue::ST_VCC.

◆ Pin() [4/5]

Pin::Pin ( unsigned char *  parentPin,
unsigned char  mask 
)

constructor for a port pin, only used in UI part!

Definition at line 139 of file pin.cpp.

◆ Pin() [5/5]

Pin::Pin ( float  analog)

constructor for analog pin

Definition at line 158 of file pin.cpp.

◆ ~Pin()

Pin::~Pin ( )
virtual

pin destructor, breaks save connection to other pins, if necessary

Definition at line 134 of file pin.cpp.

Member Function Documentation

◆ CalcPin()

bool Pin::CalcPin ( void  )

Update input values from output values.

If there is no connection to other pins, then it will reflect the own output value to own input value. Otherwise it calls Net::CalcNet method

Definition at line 85 of file pin.cpp.

◆ GetAnalog()

int Pin::GetAnalog ( void  )

Get analog value as integer from 0 to INT_MAX (for backward compatibility, will be deprecated later)

Definition at line 54 of file pin.cpp.

◆ GetAnalogValue()

◆ GetPin()

virtual Pin Pin::GetPin ( void  )
inlinevirtual

"cast method" to get back a Pin instance

Reimplemented in OpenDrain.

Definition at line 147 of file pin.h.

Referenced by PinMonitor::PinMonitor().

◆ GetRawAnalog()

float Pin::GetRawAnalog ( void  ) const
inline

◆ hasListener()

bool Pin::hasListener ( void  )
inline

True, if there change listeners.

Definition at line 161 of file pin.h.

◆ isConnected()

bool Pin::isConnected ( void  )
inline

True, if it's connected to other pins.

Definition at line 160 of file pin.h.

◆ isPortPin()

bool Pin::isPortPin ( void  )
inline

True, if it's a port pin.

Definition at line 159 of file pin.h.

◆ operator bool()

Pin::operator bool ( ) const
virtual

return boolean state of output stage

Definition at line 193 of file pin.cpp.

References AnalogValue::ST_FLOATING, AnalogValue::ST_GND, and AnalogValue::ST_VCC.

◆ operator char()

Pin::operator char ( ) const

return char representation for output stage

Definition at line 179 of file pin.cpp.

◆ operator+()

Pin Pin::operator+ ( const Pin p)
virtual

calculate common state from 2 connected pins

Definition at line 280 of file pin.cpp.

References outState.

◆ operator+=()

Pin Pin::operator+= ( const Pin p)
virtual

calculate common state from connected other pin to this pin

Definition at line 275 of file pin.cpp.

◆ operator=()

Pin & Pin::operator= ( char  c)
virtual

set output stage to (digital) state, set value for ANALOG state separately

Definition at line 219 of file pin.cpp.

References AnalogValue::ST_FLOATING, AnalogValue::ST_GND, and AnalogValue::ST_VCC.

◆ RegisterCallback()

◆ RegisterNet()

void Pin::RegisterNet ( Net n)
virtual

registers Net instance on pin

Definition at line 168 of file pin.cpp.

Referenced by Net::Add().

◆ SetAnalogValue()

Pin & Pin::SetAnalogValue ( float  value)

Sets the pin to an real analog value.

Definition at line 267 of file pin.cpp.

Referenced by AdcAnalogPin::setAnalogValue().

◆ SetInState()

void Pin::SetInState ( const Pin p)
virtual

handles the input value from net

Reimplemented in ExtAnalogPin, and ExtPin.

Definition at line 64 of file pin.cpp.

References analogVal.

Referenced by avr_set_pin_tf(), and Net::CalcNet().

◆ SetRawAnalog()

void Pin::SetRawAnalog ( float  value)
inline

Definition at line 152 of file pin.h.

References AnalogValue::setA().

◆ UnRegisterNet()

void Pin::UnRegisterNet ( Net n)
virtual

deletes Net instance registration for pin

Definition at line 173 of file pin.cpp.

Friends And Related Function Documentation

◆ HWPort

friend class HWPort
friend

Definition at line 163 of file pin.h.

◆ Net

friend class Net
friend

Definition at line 164 of file pin.h.

Member Data Documentation

◆ analogVal

AnalogValue Pin::analogVal
protected

"real" analog voltage value

Definition at line 104 of file pin.h.

Referenced by Pin(), and SetInState().

◆ connectedTo

Net* Pin::connectedTo
protected

the connection to other pins (nullptr, if not connected)

Definition at line 106 of file pin.h.

◆ mask

unsigned char Pin::mask
protected

byte mask for HWPort::pin

Definition at line 103 of file pin.h.

Referenced by HWPort::HWPort().

◆ notifyList

std::vector<HasPinNotifyFunction*> Pin::notifyList

listeners for change of input value

Definition at line 127 of file pin.h.

◆ outState

T_Pinstate Pin::outState

discrete value of output stage

Definition at line 126 of file pin.h.

Referenced by avr_get_pin_tf(), operator+(), and Pin().

◆ pinOfPort

unsigned char* Pin::pinOfPort
protected

points to HWPort::pin or nullptr

Definition at line 101 of file pin.h.

Referenced by HWPort::HWPort().

◆ pinRegOfPort

IOReg<HWPort>* Pin::pinRegOfPort
protected

points to PIN io register of port or nullptr

Definition at line 102 of file pin.h.

Referenced by HWPort::HWPort().


The documentation for this class was generated from the following files: