Skip to content

Commit

Permalink
Merge pull request #11 from 1a2m3/20211228
Browse files Browse the repository at this point in the history
20211228 update
  • Loading branch information
1a2m3 authored Dec 29, 2021
2 parents cd46df9 + f022e09 commit f876afd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 45 deletions.
42 changes: 16 additions & 26 deletions firmware/SpdReaderWriter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <EEPROM.h>
#include "SpdReaderWriterSettings.h" // Settings

#define VERSION 20211208 // Version number (YYYYMMDD)
#define VERSION 20211228 // Version number (YYYYMMDD)

// RSWP RAM support bitmasks
#define DDR5 (1 << 5) // Offline mode control
Expand Down Expand Up @@ -166,12 +166,6 @@ void setup() {
// Perform initial device RSWP support test
rswpSupport = rswpSupportTest();

// Check saved i2c clock and set mode accordingly
if (getI2cClockMode()) {
i2cClock = 400000;
}
Wire.setClock(i2cClock);

// Reset EEPROM page address
setPageAddress(0);

Expand All @@ -181,6 +175,12 @@ void setup() {

// Wait for serial port connection or initialization
while (!PORT) {}

// Check saved i2c clock and set mode accordingly
if (getI2cClockMode()) {
i2cClock = 400000;
}
Wire.setClock(i2cClock);

// Send a welcome byte when the device is ready
cmdTest();
Expand Down Expand Up @@ -382,7 +382,13 @@ void cmdRswpReport() {
}

void cmdRetestRswp() {
// Slow down I2C bus clock for accurate results
if (getI2cClockMode()) {
Wire.setClock(100000);
}
PORT.write(rswpSupportTest());

Wire.setClock(getI2cClockMode() ? 400000 : 100000);
}

void cmdDdr4Detect() {
Expand Down Expand Up @@ -733,12 +739,7 @@ byte rswpSupportTest() {
if (!scanBus()) {
// No I2C devices
return ZERO;
}

// Slow down I2C bus clock for accurate results
if (getI2cClockMode()) {
Wire.setClock(100000);
}
}

// RSWP DDR5 test
if (ddr5SetOfflineMode(ON)) {
Expand All @@ -755,10 +756,7 @@ byte rswpSupportTest() {
}
}

resetPins();

// Restore I2C clock
setI2cClockMode(getI2cClockMode());
resetPins();

return rswpSupport;
}
Expand Down Expand Up @@ -833,8 +831,6 @@ uint8_t getPageAddress(bool lowLevel = false) {
return eepromPageAddress;
}

//#ifdef __AVR__

uint8_t status = ERROR;

// Send start condition
Expand Down Expand Up @@ -876,11 +872,6 @@ uint8_t getPageAddress(bool lowLevel = false) {
case 0x48: return 1;
default: return status;
}

//#endif

// Non-AVR response
return ERROR;
}

// Sets page address to access lower or upper 256 bytes of DDR4 SPD
Expand Down Expand Up @@ -974,8 +965,7 @@ bool saveSettings(byte name, byte value) {
// Set I2C bus clock mode
bool setI2cClockMode(bool mode) {
saveSettings(CLOCKMODE, mode ? FASTMODE : STDMODE);
i2cClock = mode ? 400000 : 100000;
Wire.setClock(i2cClock);
Wire.setClock(mode ? 400000 : 100000);

return getI2cClockMode() == mode;
}
Expand Down
9 changes: 7 additions & 2 deletions src/SpdReaderWriterDll/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,12 @@ private bool ConnectPrivate() {
}

if (!_isValid) {
throw new Exception("Invalid device");
try {
DisposePrivate();
}
finally {
throw new Exception("Invalid device");
}
}
}
catch (Exception ex) {
Expand Down Expand Up @@ -951,7 +956,7 @@ private int GetFirmwareVersionPrivate() {
if (IsConnected) {
_version = Int32.Parse(
Encoding.Default.GetString(
ExecuteCommand(new[] { GETVERSION }, (uint)Settings.MINVERSION.ToString().Length)
ExecuteCommand(new[] { GETVERSION }, 8)
)
);
}
Expand Down
17 changes: 0 additions & 17 deletions src/SpdReaderWriterDll/Settings.cs

This file was deleted.

0 comments on commit f876afd

Please sign in to comment.