eBoard ①⑧⑨
Written for SIA 2017/2018
eagle_PinCtrl.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_PINCTRL
2  #define EAGLE_EBOARD_HELPLIB_PINCTRL
3 
12 //=====================================================================================================================================================
13 // Pin control
14 //=====================================================================================================================================================
15 
16  //-------------------------------------------------------------------------------------------------------------------------------------------------
17  // variables
18  //-------------------------------------------------------------------------------------------------------------------------------------------------
19 
22 
23  //-------------------------------------------------------------------------------------------------------------------------------------------------
24  // PWM
25  //-------------------------------------------------------------------------------------------------------------------------------------------------
26 
34  inline void writePWM (optVAL_t val);
35 
37  inline void writePWM(optVAL_t val){
38  val = min(val,0xFF); val = max(0x0,val);
39  _pwmValue = val;
40  }
42 
43  //-------------------------------------------------------------------------------------------------------------------------------------------------
44  // write
45  //-------------------------------------------------------------------------------------------------------------------------------------------------
46 
56  inline void writePin(optVAL_t idx,bool val);
57 
59  inline void writePin(optVAL_t idx,bool val){
60  #if EBOARD_SHIFT_REGISTER > 0x0
61  if(idx>0x63) {
62  idx -= 0x64;
63  shiftSingle(idx,val);
64  return;
65  }
66  #endif
67  #if EBOARD_CHECK_PINS > 0x0
68  checkIdx(idx);
69  if(!checkPin(idx))
70  #endif
71  setPin(idx);
72  digitalWrite(idx,val);
73  }
74 
75  //-------------------------------------------------------------------------------------------------------------------------------------------------
76  // read1
77  //-------------------------------------------------------------------------------------------------------------------------------------------------
78 
80 
90  inline optVAL_t readPin(optVAL_t idx,bool dig = true);
91 
93  inline optVAL_t readPin(optVAL_t idx,bool dig){
94  #if EBOARD_CHECK_PINS > 0x0
95  if(dig) checkIdx(idx);
96  #if defined (__AVR_ATmega2560__)
97  else if (idx<0||idx>0xF){ //use I2C? change => Wire
98  #else
99  else if (idx<0||idx>0x7){ //use I2C? change => Wire
100  #endif
101  #if EBOARD_DEBUG_MODE > 0x0
102  assert(false);
103  #endif
104  return 0;
105  }
106  if(dig && !checkPin(idx,INPUT))
107  #endif
108  setPin(idx,INPUT);
109 
110  return((dig)? digitalRead(idx) : analogRead(idx));
111  }
113 #endif
void writePWM(optVAL_t val)
write a clamped pwm value to an output pin
void checkIdx(optVAL_t idx)
[DEBUG_MODE] used to check if a pin index is in bounds
void setPin(optVAL_t idx, optVAL_t mode=OUTPUT)
[COPY&PASTE] set a pin to a certain mode => checkPin() will return true then
void writePin(optVAL_t idx, bool val)
write a boolean state to an output pin
optVAL_t _pwmValue
Definition: eagle_PinCtrl.h:21
optVAL_t readPin(optVAL_t idx, bool dig=true)
read a digital state from an INPUTpin
optVAL_t _OpwmValue
Definition: eagle_PinCtrl.h:21
void shiftSingle(optVAL_t idx, bool val)
[SHIFT] Changes a single output Pin
int optVAL_t
Definition: eBoard.h:137