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

GpioPorts.h « GPIO « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30d5a0742623b0b3119257c7af77d114cd96afbc (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
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * GpioPorts.h
 *
 *  Created on: 11 Feb 2020
 *      Author: David
 */

#ifndef SRC_GPIO_GPIOPORTS_H_
#define SRC_GPIO_GPIOPORTS_H_

#include <RepRapFirmware.h>
#include <Hardware/IoPorts.h>
#include <GCodes/GCodeResult.h>
#include <ObjectModel/ObjectModel.h>

#if SUPPORT_CAN_EXPANSION
# include <RemoteInputHandle.h>
#endif

class GpInputPort INHERIT_OBJECT_MODEL
{
public:
	GpInputPort() noexcept :
#if SUPPORT_CAN_EXPANSION
		boardAddress (CanId::MasterAddress),
#endif
		currentState(false) { }
	GpInputPort(const GpInputPort&) = delete;

	bool GetState() const noexcept;
	bool IsUnused() const noexcept;

#if SUPPORT_CAN_EXPANSION
	void SetState(CanAddress src, bool b) noexcept { if (src == boardAddress) { currentState = b; } }
#endif

	GCodeResult Configure(uint32_t gpinNumber, GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);

protected:
	DECLARE_OBJECT_MODEL

private:
	IoPort port;									// will be initialised by PwmPort default constructor
#if SUPPORT_CAN_EXPANSION
	RemoteInputHandle handle;
	CanAddress boardAddress;
#endif
	bool currentState;
};

class GpOutputPort
{
public:
	GpOutputPort() noexcept
#if SUPPORT_CAN_EXPANSION
		: boardAddress(CanId::MasterAddress)
#endif
	{ }

	GpOutputPort(const GpOutputPort&) = delete;

	GCodeResult WriteAnalog(uint32_t gpioPortNumber, bool isServo, float pwm, const GCodeBuffer& gb, const StringRef& reply) const noexcept;
	GCodeResult Configure(uint32_t gpioNumber, bool isServo, GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException);

#ifdef PCCB
	void Assign(const char *pinName) noexcept;
#endif

private:
	PwmPort port;									// will be initialised by PwmPort default constructor
#if SUPPORT_CAN_EXPANSION
	CanAddress boardAddress;
#endif
};

#endif /* SRC_GPIO_GPIOPORTS_H_ */