Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Commit d16be9e

Browse files
committed
Fixed to fan handling, more noexcept
Fixed fan handling so that blip time doesn't get randomly extended Added missing noexcept specifiers, including to C functions because doing so eliminates exception table entries for client C++ functions
1 parent 64e172a commit d16be9e

22 files changed

+224
-184
lines changed

.cproject

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<listOptionValue builtIn="false" value="__SAM3X8E__"/>
6060
<listOptionValue builtIn="false" value="__RADDS__"/>
6161
<listOptionValue builtIn="false" value="RTOS"/>
62+
<listOptionValue builtIn="false" value="noexcept="/>
6263
</option>
6364
<option id="gnu.c.compiler.option.dialect.flags.1035432363" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>
6465
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.110609707" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
@@ -212,6 +213,7 @@
212213
<listOptionValue builtIn="false" value="__SAM4E8E__"/>
213214
<listOptionValue builtIn="false" value="RTOS"/>
214215
<listOptionValue builtIn="false" value="DUET_NG"/>
216+
<listOptionValue builtIn="false" value="noexcept="/>
215217
</option>
216218
<option id="gnu.c.compiler.option.dialect.std.1370424675" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
217219
<option id="gnu.c.compiler.option.dialect.flags.1078349416" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>
@@ -372,6 +374,7 @@
372374
<listOptionValue builtIn="false" value="__SAM4S8C__"/>
373375
<listOptionValue builtIn="false" value="RTOS"/>
374376
<listOptionValue builtIn="false" value="DUET_M"/>
377+
<listOptionValue builtIn="false" value="noexcept="/>
375378
</option>
376379
<option id="gnu.c.compiler.option.dialect.flags.1483343823" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>
377380
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.667707888" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
@@ -532,6 +535,7 @@
532535
<listOptionValue builtIn="false" value="RTOS"/>
533536
<listOptionValue builtIn="false" value="PCCB"/>
534537
<listOptionValue builtIn="false" value="PCCB_10"/>
538+
<listOptionValue builtIn="false" value="noexcept="/>
535539
</option>
536540
<option id="gnu.c.compiler.option.dialect.flags.2138987417" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>
537541
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1697017655" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
@@ -700,6 +704,7 @@
700704
<listOptionValue builtIn="false" value="__SAME70Q20B__"/>
701705
<listOptionValue builtIn="false" value="RTOS"/>
702706
<listOptionValue builtIn="false" value="DUET3_V06"/>
707+
<listOptionValue builtIn="false" value="noexcept="/>
703708
</option>
704709
<option id="gnu.c.compiler.option.dialect.std.1738681846" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
705710
<option id="gnu.c.compiler.option.dialect.flags.1952106689" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>
@@ -883,6 +888,7 @@
883888
<listOptionValue builtIn="false" value="__SAME70Q20B__"/>
884889
<listOptionValue builtIn="false" value="RTOS"/>
885890
<listOptionValue builtIn="false" value="DUET3_V06"/>
891+
<listOptionValue builtIn="false" value="noexcept="/>
886892
<listOptionValue builtIn="false" value="DEBUG"/>
887893
</option>
888894
<option id="gnu.c.compiler.option.dialect.std.1475182191" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
@@ -1065,6 +1071,7 @@
10651071
<listOptionValue builtIn="false" value="RTOS"/>
10661072
<listOptionValue builtIn="false" value="DUET3_V06"/>
10671073
<listOptionValue builtIn="false" value="USE_CAN0"/>
1074+
<listOptionValue builtIn="false" value="noexcept="/>
10681075
</option>
10691076
<option id="gnu.c.compiler.option.dialect.std.1589331260" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
10701077
<option id="gnu.c.compiler.option.dialect.flags.344980217" name="Other dialect flags" superClass="gnu.c.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=gnu99" valueType="string"/>

src/Display/ST7920/lcd7920.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Lcd7920 : public Print
4949
// Write a single character in the current font. Called by the 'print' functions.
5050
// c = character to write
5151
// Returns the number of characters written (1 if we wrote it, 0 otherwise)
52-
virtual size_t write(uint8_t c) noexcept; // write a character
52+
size_t write(uint8_t c) noexcept override; // write a character
5353

5454
// Write a space
5555
void WriteSpaces(PixelNumber numPixels) noexcept;

src/DuetNG/DueXn.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace DuetExpansion
6666
// ISR for when the SX1509B on the DueX indicates that the state of an input has changed.
6767
// Note, we must only wake up the DueX task if it is waiting on this specific interrupt.
6868
// Otherwise we might wake it prematurely when it is waiting for an I2C transaction to be completed.
69-
static void DueXIrq(CallbackParameter p)
69+
static void DueXIrq(CallbackParameter p) noexcept
7070
{
7171
inputsChanged = true;
7272
if (taskWaiting)
@@ -76,7 +76,7 @@ namespace DuetExpansion
7676
}
7777
}
7878

79-
extern "C" [[noreturn]] void DueXTask(void * pvParameters)
79+
extern "C" [[noreturn]] void DueXTask(void * pvParameters) noexcept
8080
{
8181
for (;;)
8282
{
@@ -98,7 +98,7 @@ namespace DuetExpansion
9898
}
9999

100100
// Identify which expansion board (if any) is attached and initialise it
101-
ExpansionBoardType DueXnInit()
101+
ExpansionBoardType DueXnInit() noexcept
102102
{
103103
I2C::Init(); // initialise I2C
104104
delay(200); // the SX1509B has an independent power on reset, so give it some time
@@ -142,7 +142,7 @@ namespace DuetExpansion
142142

143143
// Create the DueXn task and enable the associated interrupt from the DueXn.
144144
// This must be called after interrupt priorities have been configured, to comply with FreeRTOS constraints.
145-
void DueXnTaskInit()
145+
void DueXnTaskInit() noexcept
146146
{
147147
if (dueXnBoardType != ExpansionBoardType::none)
148148
{
@@ -158,7 +158,7 @@ namespace DuetExpansion
158158
}
159159

160160
// Look for an additional output pin expander
161-
void AdditionalOutputInit()
161+
void AdditionalOutputInit() noexcept
162162
{
163163
I2C::Init(); // initialise I2C
164164

@@ -181,7 +181,7 @@ namespace DuetExpansion
181181
}
182182

183183
// Return the name of the expansion board, or nullptr if no expansion board
184-
const char* _ecv_array null GetExpansionBoardName()
184+
const char* _ecv_array null GetExpansionBoardName() noexcept
185185
{
186186
switch(dueXnBoardType)
187187
{
@@ -197,13 +197,13 @@ namespace DuetExpansion
197197
}
198198

199199
// Return the name of the additional expansion board, or nullptr if no expansion board
200-
const char* _ecv_array null GetAdditionalExpansionBoardName()
200+
const char* _ecv_array null GetAdditionalExpansionBoardName() noexcept
201201
{
202202
return (additionalIoExpanderPresent) ? "SX1509B expander" : nullptr;
203203
}
204204

205205
// Set the I/O mode of a pin
206-
void SetPinMode(Pin pin, PinMode mode)
206+
void SetPinMode(Pin pin, PinMode mode) noexcept
207207
{
208208
if (pin >= DueXnExpansionStart && pin < DueXnExpansionStart + 16)
209209
{
@@ -247,7 +247,7 @@ namespace DuetExpansion
247247

248248
// Read a pin
249249
// We need to use the SX1509 interrupt to read the data register using interrupts, and just retrieve that value here.
250-
bool DigitalRead(Pin pin)
250+
bool DigitalRead(Pin pin) noexcept
251251
{
252252
if (pin >= DueXnExpansionStart && pin < DueXnExpansionStart + 16)
253253
{
@@ -281,7 +281,7 @@ namespace DuetExpansion
281281
}
282282

283283
// Write a pin
284-
void DigitalWrite(Pin pin, bool high)
284+
void DigitalWrite(Pin pin, bool high) noexcept
285285
{
286286
if (pin >= DueXnExpansionStart && pin < DueXnExpansionStart + 16)
287287
{
@@ -300,7 +300,7 @@ namespace DuetExpansion
300300
}
301301

302302
// Set the PWM value on this pin
303-
void AnalogOut(Pin pin, float pwm)
303+
void AnalogOut(Pin pin, float pwm) noexcept
304304
{
305305
if (pin >= DueXnExpansionStart && pin < DueXnExpansionStart + 16)
306306
{
@@ -320,12 +320,12 @@ namespace DuetExpansion
320320

321321
// Print diagnostic data
322322
// I2C error counts are now reported by Platform, so nothing to report here.
323-
void Diagnostics(MessageType mtype)
323+
void Diagnostics(MessageType mtype) noexcept
324324
{
325325
}
326326

327327
// Diagnose the SX1509 by setting all pins as inputs and reading them
328-
uint16_t DiagnosticRead()
328+
uint16_t DiagnosticRead() noexcept
329329
{
330330
dueXnExpander.pinModeMultiple(AllStopBitsX5 | AllGpioBits | AllFanBits, INPUT); // Initialise the endstop inputs and GPIO pins (no pullups because 5V-tolerant)
331331
delay(1);

src/DuetNG/DueXn.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ enum class ExpansionBoardType : uint8_t
2222

2323
namespace DuetExpansion
2424
{
25-
ExpansionBoardType DueXnInit(); // Look for a DueXn, initialise it and return which expansion board is attached
26-
void AdditionalOutputInit(); // Look for an additional output pin expander
27-
void DueXnTaskInit(); // Create the DueXn task and enable the associated interrupt from the DueXn
28-
const char* _ecv_array null GetExpansionBoardName(); // Return the name of the expansion board, or nullptr if no expansion board
29-
const char* _ecv_array null GetAdditionalExpansionBoardName(); // Return the name of the additional expansion board, or nullptr if no expansion board
30-
void SetPinMode(Pin pin, PinMode mode); // Set the I/O mode of a pin
31-
bool DigitalRead(Pin pin); // Read a pin
32-
void DigitalWrite(Pin pin, bool high); // Write a pin
33-
void AnalogOut(Pin pin, float pwm); // Set the PWM value on this pin
34-
uint16_t DiagnosticRead(); // Diagnose the SX1509 by setting all pins as inputs and reading them
35-
void Diagnostics(MessageType mtype); // Print diagnostic data
25+
ExpansionBoardType DueXnInit() noexcept; // Look for a DueXn, initialise it and return which expansion board is attached
26+
void AdditionalOutputInit() noexcept; // Look for an additional output pin expander
27+
void DueXnTaskInit() noexcept; // Create the DueXn task and enable the associated interrupt from the DueXn
28+
const char* _ecv_array null GetExpansionBoardName() noexcept; // Return the name of the expansion board, or nullptr if no expansion board
29+
const char* _ecv_array null GetAdditionalExpansionBoardName() noexcept; // Return the name of the additional expansion board, or nullptr if no expansion board
30+
void SetPinMode(Pin pin, PinMode mode) noexcept; // Set the I/O mode of a pin
31+
bool DigitalRead(Pin pin) noexcept; // Read a pin
32+
void DigitalWrite(Pin pin, bool high) noexcept; // Write a pin
33+
void AnalogOut(Pin pin, float pwm) noexcept; // Set the PWM value on this pin
34+
uint16_t DiagnosticRead() noexcept; // Diagnose the SX1509 by setting all pins as inputs and reading them
35+
void Diagnostics(MessageType mtype) noexcept; // Print diagnostic data
3636
};
3737

3838
#endif /* SRC_DUETNG_DUEXN_H_ */

src/DuetNG/Pins_DuetNG.h

+37-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ constexpr size_t NumFirmwareUpdateModules = 4; // 3 modules, plus one for manua
5353

5454
// The physical capabilities of the machine
5555

56+
#if SUPPORT_12864_LCD
57+
constexpr size_t NumDirectDrivers = 11; // The maximum number of drives supported directly by the electronics
58+
#else
5659
constexpr size_t NumDirectDrivers = 12; // The maximum number of drives supported directly by the electronics
60+
#endif
61+
5762
constexpr size_t MaxSmartDrivers = 10; // The maximum number of smart drivers
5863

5964
constexpr size_t MaxSensors = 32;
@@ -112,18 +117,27 @@ constexpr Pin ENABLE_PINS[NumDirectDrivers] =
112117
{
113118
PortDPin(14), PortCPin(9), PortCPin(10), PortCPin(17), PortCPin(25), // Duet
114119
PortDPin(23), PortDPin(24), PortDPin(25), PortDPin(26), PortBPin(14), // DueX5
115-
PortDPin(18), PortCPin(28) // CONN_LCD
120+
PortDPin(18), // CONN_LCD
121+
#if !SUPPORT_12864_LCD
122+
PortCPin(28)
123+
#endif
116124
};
117125
constexpr Pin STEP_PINS[NumDirectDrivers] =
118126
{
119127
PortDPin(6), PortDPin(7), PortDPin(8), PortDPin(5), PortDPin(4), // Duet
120128
PortDPin(2), PortDPin(1), PortDPin(0), PortDPin(3), PortDPin(27), // DueX5
121-
PortDPin(20), PortDPin(21) // CONN_LCD
129+
PortDPin(20), // CONN_LCD
130+
#if !SUPPORT_12864_LCD
131+
PortDPin(21)
132+
#endif
122133
};
123134
constexpr Pin DIRECTION_PINS[NumDirectDrivers] =
124135
{ PortDPin(11), PortDPin(12), PortDPin(13), PortAPin(1), PortDPin(9), // Duet
125136
PortDPin(28), PortDPin(22), PortDPin(16), PortDPin(17), PortCPin(0), // DueX5
126-
PortDPin(19), PortAPin(25) // CONN_LCD
137+
PortDPin(19), // CONN_LCD
138+
#if !SUPPORT_12864_LCD
139+
PortAPin(25)
140+
#endif
127141
};
128142

129143
// Pin assignments etc. using USART1 in SPI mode
@@ -187,6 +201,26 @@ constexpr Pin SdWriteProtectPins[NumSdCards] = { NoPin, NoPin };
187201
constexpr Pin SdSpiCSPins[1] = { PortCPin(24) };
188202
constexpr uint32_t ExpectedSdCardSpeed = 20000000;
189203

204+
#if SUPPORT_12864_LCD
205+
// The ST7920 datasheet specifies minimum clock cycle time 400ns @ Vdd=4.5V, min. clock width 200ns high and 20ns low.
206+
// This assumes that the Vih specification is met, which is 0.7 * Vcc = 3.5V @ Vcc=5V
207+
// The Duet Maestro level shifts all 3 LCD signals to 5V, so we meet the Vih specification and can reliably run at 2MHz.
208+
// For other electronics, there are reports that operation with 3.3V LCD signals may work if you reduce the clock frequency.
209+
constexpr uint32_t LcdSpiClockFrequency = 2000000; // 2.0MHz
210+
constexpr Pin LcdCSPin = PortDPin(21); //connlcd.10 --> gate -> exp2.4
211+
constexpr Pin LcdBeepPin = PortAPin(8); //connlcd.4 -> exp1.1
212+
constexpr Pin EncoderPinA = PortAPin(25); //connlcd.8 -> exp2.5
213+
constexpr Pin EncoderPinB = PortCPin(28); //connlcd.6 -> exp2.3
214+
constexpr Pin EncoderPinSw = PortAPin(7); //connsd.7 -> exp1.2
215+
//adittional spi wiring:
216+
//connsd.6 <- exp2.1
217+
//connsd.5 --> gate -> exp1.3
218+
// `-> -> exp2.6
219+
//connsd.4 --> gate -> exp1.5
220+
// `-> -> exp2.2
221+
//connsd.3 -> exp2.4
222+
#endif
223+
190224
// Enum to represent allowed types of pin access
191225
// We don't have a separate bit for servo, because Duet PWM-capable ports can be used for servos if they are on the Duet main board
192226
enum class PinCapability: uint8_t

0 commit comments

Comments
 (0)