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

IoPorts.h « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67d90b45e0022cb1ff6c4a72b7faeec37401b7d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * IoPort.h
 *
 *  Created on: 30 Sep 2017
 *      Author: David
 */

#ifndef SRC_IOPORTS_H_
#define SRC_IOPORTS_H_

#include "RepRapFirmware.h"

// Logical pins used fore general output, servos, CCN and laser control
typedef uint16_t LogicalPin;								// Type used to represent logical pin numbers
constexpr LogicalPin NoLogicalPin = 0xFFFFu;

// 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_ */