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
path: root/src
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2022-02-17 13:48:15 +0300
committerDavid Crocker <dcrocker@eschertech.com>2022-02-17 13:48:15 +0300
commit3604365ba2911b07b8bef17c93cf3d75fff9317f (patch)
treeea660876808ffe2165e399ed82893707a46a0a2f /src
parent9eaf29caa032334bcc7d602a00d5062554cc9183 (diff)
Reduced code size for Duet 2 build
Diffstat (limited to 'src')
-rw-r--r--src/GCodes/GCodes2.cpp134
-rw-r--r--src/libc/memcmp.c16
-rw-r--r--src/libc/readme-libc.txt2
-rw-r--r--src/libc/strptime.cpp9
4 files changed, 67 insertions, 94 deletions
diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp
index 43b7dcc0..f4055731 100644
--- a/src/GCodes/GCodes2.cpp
+++ b/src/GCodes/GCodes2.cpp
@@ -3255,6 +3255,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
case 556: // Axis compensation (we support only X, Y, Z)
{
bool seen = false;
+ Move& move = reprap.GetMove();
if (gb.Seen('S'))
{
@@ -3265,7 +3266,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
{
if (gb.Seen(axisLetters[axis]))
{
- reprap.GetMove().SetAxisCompensation(axis, gb.GetFValue() / value);
+ move.SetAxisCompensation(axis, gb.GetFValue() / value);
seen = true;
}
}
@@ -3274,15 +3275,15 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
if (gb.Seen('P'))
{
- reprap.GetMove().SetXYCompensation(gb.GetIValue() <= 0);
+ move.SetXYCompensation(gb.GetIValue() <= 0);
seen = true;
}
if (!seen)
{
reply.printf("Axis compensations - %s: %.5f, YZ: %.5f, ZX: %.5f",
- reprap.GetMove().IsXYCompensated() ? "XY" : "YX",
- (double)reprap.GetMove().AxisCompensation(X_AXIS), (double)reprap.GetMove().AxisCompensation(Y_AXIS), (double)reprap.GetMove().AxisCompensation(Z_AXIS));
+ move.IsXYCompensated() ? "XY" : "YX",
+ (double)move.AxisCompensation(X_AXIS), (double)move.AxisCompensation(Y_AXIS), (double)move.AxisCompensation(Z_AXIS));
}
break;
}
@@ -3795,11 +3796,11 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
}
if (changed || changedMode)
{
- if (reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
+ if (move.GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
{
ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // make sure the limits are reflected in the user position
}
- reprap.GetMove().SetNewPosition(moveState.coords, true);
+ move.SetNewPosition(moveState.coords, true);
SetAllAxesNotHomed();
reprap.MoveUpdated();
}
@@ -3829,62 +3830,42 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
{
return false;
}
+ if (gb.Seen('S'))
{
+ const unsigned int mode = gb.GetLimitedUIValue('S', 3);
Move& move = reprap.GetMove();
const KinematicsType oldK = move.GetKinematics().GetKinematicsType(); // get the current kinematics type so we can tell whether it changed
- bool seen = false;
- if (gb.Seen('S'))
+ // Switch to the correct CoreXY mode
+ switch (mode)
{
- // Switch to the correct CoreXY mode
- const int mode = gb.GetIValue();
- switch (mode)
- {
- case 0:
- move.SetKinematics(KinematicsType::cartesian);
- break;
-
- case 1:
- move.SetKinematics(KinematicsType::coreXY);
- break;
+ case 0:
+ default: // to keep Eclipse happy
+ move.SetKinematics(KinematicsType::cartesian);
+ break;
- case 2:
- move.SetKinematics(KinematicsType::coreXZ);
- break;
+ case 1:
+ move.SetKinematics(KinematicsType::coreXY);
+ break;
- default:
- reply.printf("Mode %d is not valid", mode);
- result = GCodeResult::error;
- break;
- }
- seen = true;
+ case 2:
+ move.SetKinematics(KinematicsType::coreXZ);
+ break;
}
- if (result == GCodeResult::ok)
+ // We changed something, so reset the positions and set all axes not homed
+ if (move.GetKinematics().GetKinematicsType() != oldK)
{
- if (gb.Seen('X') || gb.Seen('Y') || gb.Seen('Z'))
- {
- reply.copy("M667 XYZ parameters are no longer supported, use M669 matrix parameters instead");
- result = GCodeResult::error;
- }
-
- if (seen)
- {
- // We changed something, so reset the positions and set all axes not homed
- if (move.GetKinematics().GetKinematicsType() != oldK)
- {
- move.GetKinematics().GetAssumedInitialPosition(numVisibleAxes, moveState.coords);
- ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition);
- }
- if (reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
- {
- ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // make sure the limits are reflected in the user position
- }
- reprap.GetMove().SetNewPosition(moveState.coords, true);
- SetAllAxesNotHomed();
- reprap.MoveUpdated();
- }
+ move.GetKinematics().GetAssumedInitialPosition(numVisibleAxes, moveState.coords);
+ ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition);
}
+ if (move.GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
+ {
+ ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // make sure the limits are reflected in the user position
+ }
+ move.SetNewPosition(moveState.coords, true);
+ SetAllAxesNotHomed();
+ reprap.MoveUpdated();
}
break;
@@ -3900,8 +3881,8 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
bool seen = false;
if (gb.Seen('K'))
{
- const int nk = gb.GetIValue();
- if (nk < 0 || nk >= (int)KinematicsType::unknown || !move.SetKinematics(static_cast<KinematicsType>(nk)))
+ const unsigned int nk = gb.GetUIValue();
+ if (nk >= (unsigned int)KinematicsType::unknown || !move.SetKinematics(static_cast<KinematicsType>(nk)))
{
reply.printf("Unknown kinematics type %d", nk);
result = GCodeResult::error;
@@ -3924,11 +3905,11 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
move.GetKinematics().GetAssumedInitialPosition(numVisibleAxes, moveState.coords);
ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition);
}
- if (reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
+ if (move.GetKinematics().LimitPosition(moveState.coords, nullptr, numVisibleAxes, axesVirtuallyHomed, false, false) != LimitPositionResult::ok)
{
ToolOffsetInverseTransform(moveState.coords, moveState.currentUserPosition); // make sure the limits are reflected in the user position
}
- reprap.GetMove().SetNewPosition(moveState.coords, true);
+ move.SetNewPosition(moveState.coords, true);
SetAllAxesNotHomed();
reprap.MoveUpdated();
}
@@ -3966,7 +3947,8 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
}
else if (LockMovementAndWaitForStandstill(gb))
{
- if (reprap.GetMove().GetNumProbedProbePoints() < 2)
+ Move& move = reprap.GetMove();
+ if (move.GetNumProbedProbePoints() < 2)
{
reply.copy("Insufficient probe points");
result = GCodeResult::error;
@@ -3991,8 +3973,8 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
// Get the coordinates of the first two G30 points and calculate how far off the axis is
float x1, y1, x2, y2;
- const float z1 = reprap.GetMove().GetProbeCoordinates(0, x1, y1, true);
- const float z2 = reprap.GetMove().GetProbeCoordinates(1, x2, y2, true);
+ const float z1 = move.GetProbeCoordinates(0, x1, y1, true);
+ const float z2 = move.GetProbeCoordinates(1, x2, y2, true);
const float a1 = (x1 == x2) ? y1 : x1;
const float a2 = (x1 == x2) ? y2 : x2;
@@ -4008,11 +3990,11 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
reply.printf("%c axis is off by %.2f deg", axisLetters[axisToUse], (double)correctionAngle);
HandleReply(gb, GCodeResult::notFinished, reply.c_str());
}
- else if (reprap.GetMove().GetNumProbedProbePoints() >= 4)
+ else if (move.GetNumProbedProbePoints() >= 4)
{
// At least four G30 points are given. This lets us figure out how far off the centre of the axis is
- const float z3 = reprap.GetMove().GetProbeCoordinates(2, x1, y1, true);
- const float z4 = reprap.GetMove().GetProbeCoordinates(3, x2, y2, true);
+ const float z3 = move.GetProbeCoordinates(2, x1, y1, true);
+ const float z4 = move.GetProbeCoordinates(3, x2, y2, true);
const float a3 = (x1 == x2) ? y1 : x1;
const float a4 = (x1 == x2) ? y2 : x2;
@@ -4058,7 +4040,8 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
case 674: // Set Z to center point
if (LockMovementAndWaitForStandstill(gb))
{
- if (reprap.GetMove().GetNumProbedProbePoints() < 2)
+ Move& move = reprap.GetMove();
+ if (move.GetNumProbedProbePoints() < 2)
{
reply.copy("Insufficient probe points");
result = GCodeResult::error;
@@ -4071,18 +4054,18 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
else
{
float x, y;
- const float z1 = reprap.GetMove().GetProbeCoordinates(0, x, y, true);
- const float z2 = reprap.GetMove().GetProbeCoordinates(1, x, y, true);
+ const float z1 = move.GetProbeCoordinates(0, x, y, true);
+ const float z2 = move.GetProbeCoordinates(1, x, y, true);
const float offset = gb.Seen('P') ? gb.GetFValue() : 0.0;
currentUserPosition[Z_AXIS] -= (z1 + z2) / 2.0 + offset;
ToolOffsetTransform(currentUserPosition, moveState.coords);
- if (reprap.GetMove().GetKinematics().LimitPosition(moveState.coords, numVisibleAxes, LowestNBits<AxesBitmap>(numVisibleAxes), false)) // pretend that all axes are homed
+ if (move.GetKinematics().LimitPosition(moveState.coords, numVisibleAxes, LowestNBits<AxesBitmap>(numVisibleAxes), false)) // pretend that all axes are homed
{
ToolOffsetInverseTransform(moveState.coords, currentUserPosition); // make sure the limits are reflected in the user position
}
- reprap.GetMove().SetNewPosition(moveState.coords, true);
- axesHomed |= reprap.GetMove().GetKinematics().AxesAssumedHomed(MakeBitmap<AxesBitmap>(Z_AXIS));
+ move.SetNewPosition(moveState.coords, true);
+ axesHomed |= move.GetKinematics().AxesAssumedHomed(MakeBitmap<AxesBitmap>(Z_AXIS));
reply.printf("Probe points at %.2f %.2f, setting new Z to %.2f", (double)z1, (double)z2, (double)currentUserPosition[Z_AXIS]);
}
@@ -4678,7 +4661,7 @@ GCodeResult GCodes::TryMacroFile(GCodeBuffer& gb) noexcept
return GCodeResult::warningNotSupported;
}
-bool GCodes::HandleTcode(GCodeBuffer& gb, const StringRef& reply)
+bool GCodes::HandleTcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException)
{
if (gb.LatestMachineState().runningM502)
{
@@ -4700,18 +4683,9 @@ bool GCodes::HandleTcode(GCodeBuffer& gb, const StringRef& reply)
}
else if (gb.Seen('R'))
{
- const unsigned int rpNumber = gb.GetIValue();
- if (rpNumber < ARRAY_SIZE(numberedRestorePoints))
- {
- seen = true;
- toolNum = numberedRestorePoints[rpNumber].toolNumber;
- }
- else
- {
- UnlockAll(gb);
- HandleReply(gb, GCodeResult::error, "T: bad restore point number");
- return true; // bad restore point number so ignore the T command
- }
+ const unsigned int rpNumber = gb.GetLimitedUIValue('R', ARRAY_SIZE(numberedRestorePoints));
+ seen = true;
+ toolNum = numberedRestorePoints[rpNumber].toolNumber;
}
if (seen)
diff --git a/src/libc/memcmp.c b/src/libc/memcmp.c
index 342fb9fb..a842d927 100644
--- a/src/libc/memcmp.c
+++ b/src/libc/memcmp.c
@@ -54,14 +54,14 @@ memcmp (const void *m1,
while (n--)
{
if (*s1 != *s2)
- {
- return *s1 - *s2;
- }
+ {
+ return *s1 - *s2;
+ }
s1++;
s2++;
}
return 0;
-#else
+#else
unsigned char *s1 = (unsigned char *) m1;
unsigned char *s2 = (unsigned char *) m2;
unsigned long *a1;
@@ -72,14 +72,14 @@ memcmp (const void *m1,
not turn up in inner loops. */
if (!TOO_SMALL(n) && !UNALIGNED(s1,s2))
{
- /* Otherwise, load and compare the blocks of memory one
+ /* Otherwise, load and compare the blocks of memory one
word at a time. */
a1 = (unsigned long*) s1;
a2 = (unsigned long*) s2;
while (n >= LBLOCKSIZE)
{
- if (*a1 != *a2)
- break;
+ if (*a1 != *a2)
+ break;
a1++;
a2++;
n -= LBLOCKSIZE;
@@ -94,7 +94,7 @@ memcmp (const void *m1,
while (n--)
{
if (*s1 != *s2)
- return *s1 - *s2;
+ return *s1 - *s2;
s1++;
s2++;
}
diff --git a/src/libc/readme-libc.txt b/src/libc/readme-libc.txt
index f60e3ac1..eb404b97 100644
--- a/src/libc/readme-libc.txt
+++ b/src/libc/readme-libc.txt
@@ -5,7 +5,7 @@ On ARM Cortex M7 processors, accesses to strongly-ordered memory such as our "no
Unfortunately, newlib (the standard C library) isn't compiled with -fno-unaligned-access, and memcpy in particular sometimes does unaligned accesses.
To fix this, we include our own copy of memcpy here. Similarly for other memory-related functions that might be used to access DMA buffers.
-strptime.c in this folder is a cut-down version that doesn't need a locale, saving about 360 bytes of RAM. This is sufficient for RepRapFirmware because we don't
+strptime.cpp in this folder is a cut-down version that doesn't need a locale, saving about 360 bytes of RAM. This is sufficient for RepRapFirmware because we don't
need to recognise month or day names.
DC 2020-01-10
diff --git a/src/libc/strptime.cpp b/src/libc/strptime.cpp
index a22288c5..1633795b 100644
--- a/src/libc/strptime.cpp
+++ b/src/libc/strptime.cpp
@@ -51,7 +51,7 @@
#include <General/SafeStrtod.h>
-static constexpr int _DAYS_BEFORE_MONTH[12] =
+static constexpr int16_t _DAYS_BEFORE_MONTH[12] =
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
#define SET_MDAY 1
@@ -90,12 +90,11 @@ static int first_day (int year) noexcept
#undef isspace_l
#define isspace_l(_c, _l) isspace(_c)
#define strtol_l(_b, _s, _n, _l) StrToI32(_b, _s)
-#define strptime_l(_b, _f, _t, _l) strptime_dc(_b, _f, _t)
const char *SafeStrptime(const char *_ecv_array buf, const char *_ecv_array format, struct tm *timeptr) noexcept
{
char c;
- int ymd = 0;
+ uint8_t ymd = 0;
for (; (c = *format) != '\0'; ++format)
{
@@ -255,7 +254,7 @@ const char *SafeStrptime(const char *_ecv_array buf, const char *_ecv_array form
}
else
{
- int leap = is_leap_year (timeptr->tm_year + tm_year_base);
+ const int leap = is_leap_year (timeptr->tm_year + tm_year_base);
int i;
for (i = 2; i < 12; ++i)
{
@@ -282,7 +281,7 @@ const char *SafeStrptime(const char *_ecv_array buf, const char *_ecv_array form
if ((ymd & (SET_YEAR | SET_YDAY | SET_WDAY)) == (SET_YEAR | SET_YDAY))
{
/* fill in tm_wday */
- int fday = first_day (timeptr->tm_year + tm_year_base);
+ const int fday = first_day (timeptr->tm_year + tm_year_base);
timeptr->tm_wday = (fday + timeptr->tm_yday) % 7;
}