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

Pins_Pccb.cpp « Pccb « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5fa45a32e9be3c1fd5fa56241a49d7421a7bd8df (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
/*
 * Pins_DuetNG.cpp
 *
 *  Created on: 31 Mar 2019
 *      Author: David
 */

#include "RepRapFirmware.h"

// Hardware-dependent pins functions

// Return a pointer to the pin description entry. Declared in and called from CoreN2G.
const PinDescriptionBase *AppGetPinDescription(Pin p) noexcept
{
	return (p < ARRAY_SIZE(PinTable)) ? &PinTable[p] : nullptr;
}

// Function to look up a pin name and pass back the corresponding index into the pin table
// On this platform, the mapping from pin names to pins is fixed, so this is a simple lookup
bool LookupPinName(const char *pn, LogicalPin &lpin, bool &hardwareInverted) noexcept
{
	if (StringEqualsIgnoreCase(pn, NoPinName))
	{
		lpin = NoLogicalPin;
		hardwareInverted = false;
		return true;
	}

	for (size_t lp = 0; lp < ARRAY_SIZE(PinTable); ++lp)
	{
		const char *q = PinTable[lp].pinNames;
		if (q == nullptr)
		{
			continue;
		}
		while (*q != 0)
		{
			// Try the next alias in the list of names for this pin
			const char *p = pn;
			bool hwInverted = (*q == '!');
			if (hwInverted)
			{
				++q;
			}
			while (*q != ',' && *q != 0 && *p == *q)
			{
				++p;
				++q;
			}
			if (*p == 0 && (*q == 0 || *q == ','))
			{
				// Found a match
				lpin = (LogicalPin)lp;
				hardwareInverted = hwInverted;
				return true;
			}

			// Skip to the start of the next alias
			while (*q != 0 && *q != ',')
			{
				++q;
			}
			if (*q == ',')
			{
				++q;
			}
		}
	}
	return false;
}

// End