|
16 | 16 | #include <EEPROM.h> |
17 | 17 | #include "SpdReaderWriterSettings.h" // Settings |
18 | 18 |
|
19 | | -#define VERSION 20221011 // Version number (YYYYMMDD) |
| 19 | +#define VERSION 20221110 // Version number (YYYYMMDD) |
20 | 20 |
|
21 | 21 | // RSWP RAM support bitmasks |
22 | 22 | #define DDR5 (1 << 5) // Offline mode control |
23 | 23 | #define DDR4 (1 << 4) // VHV control |
24 | 24 | #define DDR3 (1 << 3) // VHV+SA1 controls |
25 | 25 |
|
26 | 26 | // SPD5 hub registers |
27 | | -#pragma region SPD5 hub registers |
28 | 27 | #define MEMREG 0b11111 // SPD5 internal register bitmask |
29 | 28 | #define MR0 0x00 // Device Type; Most Significant Byte |
30 | 29 | #define MR1 0x01 // Device Type; Least Significant Byte |
|
44 | 43 | #define MR48 0x30 // Device Status |
45 | 44 | #define MR51 0x33 // TS Temperature Status |
46 | 45 | #define MR52 0x34 // Hub, Thermal and NVM Error Status |
47 | | -#pragma endregion |
48 | 46 |
|
49 | 47 | // EEPROM page commands |
50 | | -#pragma region EEPROM page commands |
51 | 48 | #define SPA0 0x6C // Set EE Page Address to 0 (offsets 00h to FFh) ( 0-255) (DDR4) |
52 | 49 | #define SPA1 0x6E // Set EE Page Address to 1 (offsets 100h to 1FFh) (256-511) (DDR4) |
53 | 50 | #define RPA 0x6D // Read EE Page Address (DDR4) |
54 | | -#pragma endregion |
55 | 51 |
|
56 | 52 | // EEPROM RSWP commands |
57 | | -#pragma region EEPROM RSWP commands |
58 | 53 | #define RPS0 0x63 // Read SWP0 status (offsets 00h to 7Fh) ( 0-127) (DDR4/DDR3/DDR2) |
59 | 54 | #define RPS1 0x69 // Read SWP1 status (offsets 80h to FFh) (128-255) (DDR4) |
60 | 55 | #define RPS2 0x6B // Read SWP2 status (offsets 100h to 17Fh) (256-383) (DDR4) |
|
66 | 61 | #define SWP3 0x60 // Set RSWP for block 3 (offsets 180h to 1FFh) (384-511) (DDR4) * |
67 | 62 |
|
68 | 63 | #define CWP 0x66 // Clear RSWP (DDR4/DDR3/DDR2) * |
69 | | -#pragma endregion |
70 | 64 |
|
71 | 65 | // EEPROM PSWP commands |
72 | 66 | #define PWPB 0b0110 // PSWP Device Type Identifier Control Code (bits 7-4) (DDR3/DDR2) |
73 | 67 |
|
74 | 68 | // EEPROM temperature sensor register commands |
75 | | -#pragma region EEPROM temperature sensor register commands |
76 | 69 | #define TSRB 0b0011 // Device select code to access Temperature Sensor registers (bits 7-4) |
77 | 70 | #define TS00 0x00 // Capability Register [RO] |
78 | 71 | #define TS01 0x01 // Configuration Register [R/W] |
|
82 | 75 | #define TS05 0x05 // Temperature Data Register [RO] |
83 | 76 | #define TS06 0x06 // Manufacturer ID Register [RO] |
84 | 77 | #define TS07 0x07 // Device ID/Revision Register [RO] |
85 | | -#pragma endregion |
86 | 78 |
|
87 | 79 | // EEPROM data |
88 | 80 | #define DNC 0x00 // "Do not care" byte |
89 | 81 |
|
90 | 82 | // Device commands |
91 | | -#pragma region Command |
92 | 83 | #define READBYTE 'r' // Read |
93 | 84 | #define WRITEBYTE 'w' // Write byte |
94 | 85 | #define WRITEPAGE 'g' // Write page |
|
106 | 97 | #define DDR4DETECT '4' // DDR4 detection test |
107 | 98 | #define DDR5DETECT '5' // DDR5 detection test |
108 | 99 | #define FACTORYRESET '-' // Factory reset device settings |
109 | | -#pragma endregion |
110 | 100 |
|
111 | 101 | // Device pin names (SpdReaderWriterDll.Pin.Name class) |
112 | 102 | #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 }; |
163 | 153 | void setup() { |
164 | 154 |
|
165 | 155 | // Config pin controls |
166 | | - for (int i = 0; i <= sizeof(pins[0]); i++) { |
| 156 | + for (uint8_t i = 0; i <= sizeof(pins[0]); i++) { |
167 | 157 | pinMode(pins[i], OUTPUT); |
168 | 158 | } |
169 | 159 |
|
@@ -452,7 +442,7 @@ void cmdName() { |
452 | 442 | // Set name |
453 | 443 | else if (buffer[0] > 0 && buffer[0] <= NAMELENGTH) { |
454 | 444 | // prepare name buffer |
455 | | - byte name[buffer[0] + 1]; |
| 445 | + char name[buffer[0] + 1]; |
456 | 446 | // read name and put it into buffer |
457 | 447 | PORT.readBytes(name, buffer[0]); |
458 | 448 | // set last byte to \0 where the string ends |
@@ -497,7 +487,7 @@ void cmdI2CClock() { |
497 | 487 | } |
498 | 488 | } |
499 | 489 |
|
500 | | -bool cmdFactoryReset() { |
| 490 | +void cmdFactoryReset() { |
501 | 491 | PORT.write(factoryReset() ? SUCCESS : ERROR); |
502 | 492 | } |
503 | 493 |
|
@@ -976,6 +966,8 @@ bool saveSettings(byte name, byte value) { |
976 | 966 |
|
977 | 967 | byte currentSettings = EEPROM.read(DEVICESETTINGS); |
978 | 968 | EEPROM.update(DEVICESETTINGS, bitWrite(currentSettings, name, value)); |
| 969 | + |
| 970 | + return getSettings(name) == value; |
979 | 971 | } |
980 | 972 |
|
981 | 973 |
|
@@ -1054,7 +1046,7 @@ bool getConfigPin(uint8_t pin) { |
1054 | 1046 |
|
1055 | 1047 | // Reset config pins |
1056 | 1048 | void resetPins() { |
1057 | | - for (int i = 0; i <= sizeof(pins[0]); i++) { |
| 1049 | + for (uint8_t i = 0; i <= sizeof(pins[0]); i++) { |
1058 | 1050 | setConfigPin(pins[i], OFF); |
1059 | 1051 | } |
1060 | 1052 | } |
|
0 commit comments