Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hardware/IoPorts.h')
-rw-r--r--src/Hardware/IoPorts.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Hardware/IoPorts.h b/src/Hardware/IoPorts.h
new file mode 100644
index 00000000..9570e72c
--- /dev/null
+++ b/src/Hardware/IoPorts.h
@@ -0,0 +1,59 @@
+/*
+ * IoPort.h
+ *
+ * Created on: 30 Sep 2017
+ * Author: David
+ */
+
+#ifndef SRC_IOPORTS_H_
+#define SRC_IOPORTS_H_
+
+#include "RepRapFirmware.h"
+
+// Enumeration to describe what we want to do with a logical pin
+enum class PinAccess : int
+{
+ read,
+ write,
+ pwm,
+ servo
+};
+
+// Class to represent a port
+class IoPort
+{
+public:
+ IoPort();
+ void Clear();
+ bool Set(LogicalPin lp, PinAccess access, bool pInvert);
+
+ LogicalPin GetLogicalPin() const { return logicalPort; }
+ LogicalPin GetLogicalPin(bool& pInvert) const { pInvert = invert; return logicalPort; }
+ void WriteDigital(bool high) const { if (pin != NoPin) { WriteDigital(pin, (invert) ? !high : high); } }
+
+ // Low level port access
+ static void SetPinMode(Pin p, PinMode mode);
+ static bool ReadPin(Pin p);
+ static void WriteDigital(Pin p, bool high);
+ static void WriteAnalog(Pin p, float pwm, uint16_t frequency);
+
+protected:
+ LogicalPin logicalPort;
+ Pin pin;
+ bool invert;
+};
+
+// Class to represent a PWM output port
+class PwmPort : public IoPort
+{
+public:
+ PwmPort();
+ void SetFrequency(float freq);
+ float GetFrequency() const { return (float)frequency; }
+ void WriteAnalog(float pwm) const;
+
+private:
+ uint16_t frequency;
+};
+
+#endif /* SRC_PORT_H_ */