#include <string>
#include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
+#include "PinNames.h"
+
+namespace mbed {
+ class PwmOut;
+ class InterruptIn;
+}
class Pin {
public:
Pin* from_string(std::string value);
inline bool connected(){
- return this->pin < 32;
+ return this->valid;
+ }
+
+ inline bool equals(const Pin& other) const {
+ return (this->pin == other.pin) && (this->port == other.port);
}
inline Pin* as_output(){
- if (this->pin < 32)
+ if (this->valid)
this->port->FIODIR |= 1<<this->pin;
return this;
}
inline Pin* as_input(){
- if (this->pin < 32)
+ if (this->valid)
this->port->FIODIR &= ~(1<<this->pin);
return this;
}
Pin* pull_none(void);
- inline bool get(){
- if (this->pin >= 32) return false;
+ inline bool get() const{
+ if (!this->valid) return false;
return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
}
inline void set(bool value)
{
- if (this->pin >= 32) return;
+ if (!this->valid) return;
if ( this->inverting ^ value )
this->port->FIOSET = 1 << this->pin;
else
this->port->FIOCLR = 1 << this->pin;
}
+ mbed::PwmOut *hardware_pwm();
+
+ mbed::InterruptIn *interrupt_pin();
+
+ bool is_inverting() const { return inverting; }
+ void set_inverting(bool f) { inverting= f; }
+
+ // these should be private, and use getters
LPC_GPIO_TypeDef* port;
- bool inverting;
- char port_number;
+
unsigned char pin;
+ char port_number;
+
+ private:
+ struct {
+ bool inverting:1;
+ bool valid:1;
+ };
};