Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Chip-Select Pins to Be Used by More than One Sensor. #383

Open
wants to merge 4 commits into
base: v3.01-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Hardware/IoPorts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ bool IoPort::Allocate(const char *pn, const StringRef& reply, PinUsedBy neededFo
if (lp != NoLogicalPin) // if not assigning "nil"
{
bool doSetMode = true;
if (portUsedBy[lp] == PinUsedBy::unused || (portUsedBy[lp] == PinUsedBy::temporaryInput && neededFor != PinUsedBy::temporaryInput))
if (portUsedBy[lp] == PinUsedBy::unused || (portUsedBy[lp] == PinUsedBy::temporaryInput && neededFor != PinUsedBy::temporaryInput) || (portUsedBy[lp] == PinUsedBy::chipSelect && neededFor == PinUsedBy::chipSelect))
{
portUsedBy[lp] = neededFor;
}
Expand All @@ -248,7 +248,14 @@ bool IoPort::Allocate(const char *pn, const StringRef& reply, PinUsedBy neededFo
}
logicalPin = lp;
hardwareInvert = hwInvert;
isSharedInput = (neededFor == PinUsedBy::temporaryInput);
if (neededFor == PinUsedBy::temporaryInput || neededFor == PinUsedBy::chipSelect)
{
isSharedInput = true;
}
else
{
isSharedInput = false;
}
SetInvert(inverted);

if (doSetMode && !SetMode(access))
Expand Down
7 changes: 6 additions & 1 deletion src/Heating/Sensors/CurrentLoopTemperatureSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ GCodeResult CurrentLoopTemperatureSensor::Configure(GCodeBuffer& gb, const Strin
else
{
CopyBasicDetails(reply);
reply.catf(", temperature range %.1f to %.1fC", (double)tempAt4mA, (double)tempAt20mA);
reply.catf(", channel: %d", (int)chipChannel);
if (isDifferential)
{
reply.copy(", differential mode");
}
reply.catf(", temperature range %.1f to %.1fC", (double)minLinearAdcTemp, (double)tempAt20mA);
}
return GCodeResult::ok;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Heating/Sensors/SensorWithPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ SensorWithPort::~SensorWithPort() noexcept
}

// Try to configure the port. Return true if the port is valid at the end, else return false and set the error message in 'reply'. Set 'seen' if we saw the P parameter.
bool SensorWithPort::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, bool& seen)
bool SensorWithPort::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, PinUsedBy usedBy, bool& seen)
{
if (gb.Seen('P'))
{
seen = true;
return port.AssignPort(gb, reply, PinUsedBy::sensor, access);
return port.AssignPort(gb, reply, usedBy, access);
}
if (port.IsValid())
{
Expand All @@ -34,6 +34,11 @@ bool SensorWithPort::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinA
return false;
}

bool SensorWithPort::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, bool& seen)
{
return ConfigurePort(gb, reply, access, PinUsedBy::sensor, seen);
}

// Copy the basic details to the reply buffer. This hides the version in the base class.
void SensorWithPort::CopyBasicDetails(const StringRef& reply) const noexcept
{
Expand Down
1 change: 1 addition & 0 deletions src/Heating/Sensors/SensorWithPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SensorWithPort : public TemperatureSensor
~SensorWithPort() noexcept;

// Try to configure the port
bool ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, PinUsedBy usedBy, bool& seen);
bool ConfigurePort(GCodeBuffer& gb, const StringRef& reply, PinAccess access, bool& seen);

// Copy the basic details to the reply buffer. This hides the version in the base class.
Expand Down
2 changes: 1 addition & 1 deletion src/Heating/Sensors/SpiTemperatureSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SpiTemperatureSensor::SpiTemperatureSensor(unsigned int sensorNum, const char *n

bool SpiTemperatureSensor::ConfigurePort(GCodeBuffer& gb, const StringRef& reply, bool& seen)
{
const bool ret = SensorWithPort::ConfigurePort(gb, reply, PinAccess::write1, seen);
const bool ret = SensorWithPort::ConfigurePort(gb, reply, PinAccess::write1, PinUsedBy::chipSelect, seen);
device.csPin = port.GetPin();
return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion src/RepRapFirmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ enum class PinUsedBy : uint8_t
gpout,
filamentMonitor,
temporaryInput,
sensor
sensor,
chipSelect
};

#include "Configuration.h"
Expand Down