57 return (
int)(((double)GetAnalogValue(vcc) * INT_MAX) / (
double)vcc);
61 notifyList.push_back(h);
67 if(pinOfPort !=
nullptr) {
71 *pinOfPort &= 0xff - mask;
73 if(pinRegOfPort !=
nullptr)
74 pinRegOfPort->hardwareChange(*pinOfPort);
77 std::vector<HasPinNotifyFunction*>::iterator ii;
78 std::vector<HasPinNotifyFunction*>::iterator ee = notifyList.end();
80 for(ii = notifyList.begin(); ii != ee; ii++) {
81 (*ii)->PinStateHasChanged(
this);
86 if(connectedTo ==
nullptr) {
91 return connectedTo->CalcNet();
97 pinRegOfPort =
nullptr;
98 connectedTo =
nullptr;
127 pinRegOfPort =
nullptr;
128 connectedTo =
nullptr;
136 UnRegisterNet(connectedTo);
139 Pin::Pin(
unsigned char *parentPin,
unsigned char _mask) {
140 pinOfPort = parentPin;
141 pinRegOfPort =
nullptr;
143 connectedTo =
nullptr;
150 pinRegOfPort =
nullptr;
151 connectedTo =
nullptr;
161 pinRegOfPort =
nullptr;
162 connectedTo =
nullptr;
163 analogVal.setA(analog);
169 UnRegisterNet(connectedTo);
174 if(connectedTo == n && connectedTo !=
nullptr)
175 connectedTo->Delete(
this);
176 connectedTo =
nullptr;
179 Pin::operator char()
const {
181 case SHORTED:
return 'S';
182 case HIGH:
return 'H';
183 case PULLUP:
return 'h';
184 case TRISTATE:
return 't';
185 case PULLDOWN:
return 'l';
186 case LOW:
return 'L';
187 case ANALOG:
return 'a';
188 case ANALOG_SHORTED:
return 'A';
193 Pin::operator bool()
const {
198 if((outState==TRISTATE) || (outState==PULLUP)) {
207 if(outState==ANALOG) {
208 if(analogVal.analogValid())
257 outState = ANALOG_SHORTED;
268 analogVal.setA(value);
281 if(outState == SHORTED)
283 if(outState == ANALOG_SHORTED)
284 return Pin(ANALOG_SHORTED);
285 if((outState == ANALOG) && (p.
outState != TRISTATE))
286 return Pin(ANALOG_SHORTED);
303 if(outState == PULLDOWN)
304 return Pin(TRISTATE);
317 if(outState == PULLUP)
318 return Pin(TRISTATE);
319 return Pin(PULLDOWN);
329 if(outState != TRISTATE)
330 return Pin(ANALOG_SHORTED);
336 return Pin(ANALOG_SHORTED);
339 return Pin(TRISTATE);
344 bool input = (bool)*pin;
348 return Pin(TRISTATE);
364 UnRegisterNet(connectedTo);
369 PVOE = PVOV = PVOEwDDR = 0;
374 assert(regCount < (
sizeof(DDOV) * 8));
382 DDOV &= ~(1 << index);
389 DDOE &= ~(1 << index);
396 PVOV &= ~(1 << index);
403 PVOE &= ~(1 << index);
408 PVOEwDDR |= 1 << index;
410 PVOEwDDR &= ~(1 << index);
417 PUOV &= ~(1 << index);
424 PUOE &= ~(1 << index);
428 unsigned char ddov = DDOE & DDOV;
429 unsigned char pvov = PVOE & PVOV;
430 unsigned char pvovwddr = PVOEwDDR & PVOV;
431 bool resultingDDR = (!DDOE && ddr) || (DDOE && ddov);
432 bool resultingPort = (!(PVOE || PVOEwDDR) && port) || (PVOE && pvov) || (PVOEwDDR && pvovwddr && ddr);
433 bool pu = !pud && !ddr && port;
434 bool resultingPU = (!PUOE && pu) || (PUOE && PUOV);
virtual ~PortPin()
pin destructor, breaks save connection to other pins, if necessary
int GetAnalog(void)
Get analog value as integer from 0 to INT_MAX (for backward compatibility, will be deprecated later) ...
virtual ~Pin()
pin destructor, breaks save connection to other pins, if necessary
PortPin(void)
common constructor, initial output state is tristate
float getA(float vcc)
calculate real voltage potential, needs value of Vcc potential
virtual Pin operator+=(const Pin &p)
calculate common state from connected other pin to this pin
Pin class, handles input and output to external parts.
digital state, Vcc potential
Pin & SetAnalogValue(float value)
Sets the pin to an real analog value.
void SetPVOE(bool val, int index=0)
set port override enable
void SetPVOV(bool val, int index=0)
set port override value
float aValue
analog value from setA method or constructor (not checked to valid range!)
virtual Pin & operator=(char)
set output stage to (digital) state, set value for ANALOG state separately
virtual Pin operator+(const Pin &p)
calculate common state from 2 connected pins
int dState
digital state and validity of aValue
T_Pinstate
Possible PIN states.
digital state, ground potential
T_Pinstate outState
discrete value of output stage
virtual Pin GetPin()
"cast method" to get back a Pin instance
bool CalcPinOverride(bool ddr, bool port, bool pud)
calculate pin outState with override functionality
bool CalcPin(void)
Update input values from output values.
void ResetOverride(void)
reset override states
valid analog value between ground and Vcc (and included)
int RegisterAlternateUse(void)
register an alternate function to pin
void RegisterCallback(HasPinNotifyFunction *)
void SetPUOE(bool val, int index=0)
set pullup override enable
virtual void UnRegisterNet(Net *n)
deletes Net instance registration for pin
floating potential, not connected or tristate, assumed as FLOATING_POTENTIAL
virtual void RegisterNet(Net *n)
registers Net instance on pin
Pin(void)
common constructor, initial output state is tristate
virtual void SetInState(const Pin &p)
handles the input value from net
void SetDDOV(bool val, int index=0)
set data direction override value
void SetDDOE(bool val, int index=0)
set data direction override enable
#define REL_FLOATING_POTENTIAL
void SetPUOV(bool val, int index=0)
set pullup override value
void SetPVOE_WithDDR(bool val, int index=0)
set port override enable, if DDR is set
AnalogValue analogVal
"real" analog voltage value
Connect Pins to each other and transfers a output change from a pin to input values for all pins...