Skip to content

Commit 4786812

Browse files
committed
FW cleanup
Firmware cleanup and update
1 parent cfd0370 commit 4786812

File tree

2 files changed

+449
-459
lines changed

2 files changed

+449
-459
lines changed

firmware/SpdReaderWriter.ino

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
#include <EEPROM.h>
1717
#include "SpdReaderWriterSettings.h" // Settings
1818

19-
#define VERSION 20221011 // Version number (YYYYMMDD)
19+
#define VERSION 20221110 // Version number (YYYYMMDD)
2020

2121
// RSWP RAM support bitmasks
2222
#define DDR5 (1 << 5) // Offline mode control
2323
#define DDR4 (1 << 4) // VHV control
2424
#define DDR3 (1 << 3) // VHV+SA1 controls
2525

2626
// SPD5 hub registers
27-
#pragma region SPD5 hub registers
2827
#define MEMREG 0b11111 // SPD5 internal register bitmask
2928
#define MR0 0x00 // Device Type; Most Significant Byte
3029
#define MR1 0x01 // Device Type; Least Significant Byte
@@ -44,17 +43,13 @@
4443
#define MR48 0x30 // Device Status
4544
#define MR51 0x33 // TS Temperature Status
4645
#define MR52 0x34 // Hub, Thermal and NVM Error Status
47-
#pragma endregion
4846

4947
// EEPROM page commands
50-
#pragma region EEPROM page commands
5148
#define SPA0 0x6C // Set EE Page Address to 0 (offsets 00h to FFh) ( 0-255) (DDR4)
5249
#define SPA1 0x6E // Set EE Page Address to 1 (offsets 100h to 1FFh) (256-511) (DDR4)
5350
#define RPA 0x6D // Read EE Page Address (DDR4)
54-
#pragma endregion
5551

5652
// EEPROM RSWP commands
57-
#pragma region EEPROM RSWP commands
5853
#define RPS0 0x63 // Read SWP0 status (offsets 00h to 7Fh) ( 0-127) (DDR4/DDR3/DDR2)
5954
#define RPS1 0x69 // Read SWP1 status (offsets 80h to FFh) (128-255) (DDR4)
6055
#define RPS2 0x6B // Read SWP2 status (offsets 100h to 17Fh) (256-383) (DDR4)
@@ -66,13 +61,11 @@
6661
#define SWP3 0x60 // Set RSWP for block 3 (offsets 180h to 1FFh) (384-511) (DDR4) *
6762

6863
#define CWP 0x66 // Clear RSWP (DDR4/DDR3/DDR2) *
69-
#pragma endregion
7064

7165
// EEPROM PSWP commands
7266
#define PWPB 0b0110 // PSWP Device Type Identifier Control Code (bits 7-4) (DDR3/DDR2)
7367

7468
// EEPROM temperature sensor register commands
75-
#pragma region EEPROM temperature sensor register commands
7669
#define TSRB 0b0011 // Device select code to access Temperature Sensor registers (bits 7-4)
7770
#define TS00 0x00 // Capability Register [RO]
7871
#define TS01 0x01 // Configuration Register [R/W]
@@ -82,13 +75,11 @@
8275
#define TS05 0x05 // Temperature Data Register [RO]
8376
#define TS06 0x06 // Manufacturer ID Register [RO]
8477
#define TS07 0x07 // Device ID/Revision Register [RO]
85-
#pragma endregion
8678

8779
// EEPROM data
8880
#define DNC 0x00 // "Do not care" byte
8981

9082
// Device commands
91-
#pragma region Command
9283
#define READBYTE 'r' // Read
9384
#define WRITEBYTE 'w' // Write byte
9485
#define WRITEPAGE 'g' // Write page
@@ -106,7 +97,6 @@
10697
#define DDR4DETECT '4' // DDR4 detection test
10798
#define DDR5DETECT '5' // DDR5 detection test
10899
#define FACTORYRESET '-' // Factory reset device settings
109-
#pragma endregion
110100

111101
// Device pin names (SpdReaderWriterDll.Pin.Name class)
112102
#define OFFLINE_MODE_SWITCH (uint8_t) 0 // Pin to toggle SPD5 offline mode
@@ -163,7 +153,7 @@ const int pins[] = { OFF_EN, SA1_EN, HV_EN };
163153
void setup() {
164154

165155
// Config pin controls
166-
for (int i = 0; i <= sizeof(pins[0]); i++) {
156+
for (uint8_t i = 0; i <= sizeof(pins[0]); i++) {
167157
pinMode(pins[i], OUTPUT);
168158
}
169159

@@ -452,7 +442,7 @@ void cmdName() {
452442
// Set name
453443
else if (buffer[0] > 0 && buffer[0] <= NAMELENGTH) {
454444
// prepare name buffer
455-
byte name[buffer[0] + 1];
445+
char name[buffer[0] + 1];
456446
// read name and put it into buffer
457447
PORT.readBytes(name, buffer[0]);
458448
// set last byte to \0 where the string ends
@@ -497,7 +487,7 @@ void cmdI2CClock() {
497487
}
498488
}
499489

500-
bool cmdFactoryReset() {
490+
void cmdFactoryReset() {
501491
PORT.write(factoryReset() ? SUCCESS : ERROR);
502492
}
503493

@@ -976,6 +966,8 @@ bool saveSettings(byte name, byte value) {
976966

977967
byte currentSettings = EEPROM.read(DEVICESETTINGS);
978968
EEPROM.update(DEVICESETTINGS, bitWrite(currentSettings, name, value));
969+
970+
return getSettings(name) == value;
979971
}
980972

981973

@@ -1054,7 +1046,7 @@ bool getConfigPin(uint8_t pin) {
10541046

10551047
// Reset config pins
10561048
void resetPins() {
1057-
for (int i = 0; i <= sizeof(pins[0]); i++) {
1049+
for (uint8_t i = 0; i <= sizeof(pins[0]); i++) {
10581050
setConfigPin(pins[i], OFF);
10591051
}
10601052
}

0 commit comments

Comments
 (0)