-
-
Save awfulwoman/b48a4f208d151d7dab540066b80a19a2 to your computer and use it in GitHub Desktop.
Emulate Dell chargers with ESP-01 module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Example-Code that emulates a DS2502 - 1kbit EEPROM as a dell power supply | |
* | |
* Tested with | |
* - dell notebook https://forum.pjrc.com/threads/33640-Teensy-2-OneWire-Slave | |
* - DS9490R-Master, atmega328@16MHz as Slave | |
* - Arduino ProMini clone | |
* - esp8266 | |
* | |
* OneWire messaging starts when AC adapter is plugged to notebook, | |
* try to use parasite powering but unfortunately it doesn't provide enough power, | |
* so You need DC-DC converter to power MCU | |
* | |
* thanks to Nik / ploys for supplying traces of real data-traffic to figure out communication: | |
* - reset and presence detection normal | |
* - cmd from master: 0xCC -> skip rom, so there is only ONE device allowed on the bus | |
* - cmd from master: 0xF0 -> read memory | |
* - address request from master: 0x0008 | |
* - master listens for data, gets CRC of seconds cmd and address first, then listens for 3 bytes, does not listen any further | |
*/ | |
#include <Arduino.h> | |
#include "OneWireHub.h" | |
#include "DS2502.h" | |
// Valid for GPIO2 on ESP01 module | |
constexpr uint8_t pin_onewire { 2 }; | |
constexpr uint8_t charger130W[4] = {0x31, 0x33, 0x30}; //130W (=second digit of each hex-number) | |
constexpr uint8_t charger090W[4] = {0x30, 0x39, 0x30}; //90W | |
constexpr uint8_t charger065W[4] = {0x30, 0x36, 0x36}; //66W | |
// https://github.com/garyStofer/DS2502_DELL_PS/blob/master/DS2502_DELL_PS.ino | |
// constexpr const char* chargerEEPROMStr_90W = "DELL00AC090195046CN09T"; | |
// https://nickschicht.wordpress.com/2009/07/15/dell-power-supply-fault/ | |
constexpr const char* chargerEEPROMStr_90W = "DELL00AC090195046CN0C80234866161R23H8A03\x4D\x7C"; | |
constexpr const char* chargerEEPROMStr_65W = "DELL00AC065195033CN05U0927161552F31B8A03\xBC\x8F"; | |
// https://github.com/KivApple/dell-charger-emulator | |
constexpr const char* chargerEEPROMStr_45W = "DELL00AC045195023CN0CDF577243865Q27F2A05\x3D\x94"; | |
// I made this up | |
constexpr const char* chargerEEPROMStr_130W = "DELL00AC130195067CN0CDF577243865Q27F2233\x9D\x72"; | |
auto hub = OneWireHub(pin_onewire); | |
auto dellCH = DS2502( 0x28, 0x0D, 0x01, 0x08, 0x0B, 0x02, 0x0A); // address does not matter, laptop uses skipRom -> note that therefore only one slave device is allowed on the bus | |
// Assumes that serialStr is at least 40 bytes. | |
void crc(const char* serialStr, uint8_t* crc_l, uint8_t* crc_h) { | |
uint32_t crc = 0; | |
for (int offset = 0; offset < 40; offset++) { | |
uint8_t byte = serialStr[offset]; | |
crc ^= byte; | |
for (int i = 0; i<8; i++) { | |
if (crc & 1) | |
crc = (crc>>1) ^ 0xA001; | |
else | |
crc >>= 1; | |
} | |
} | |
*crc_l = crc & 0xFF; | |
*crc_h = (crc >> 8) & 0xFF; | |
} | |
void setup() | |
{ | |
//Serial.begin(115200); | |
//Serial.println("OneWire-Hub DS2502 aka Dell Charger"); | |
//uint8_t crc_l, crc_h; | |
//crc(chargerEEPROMStr_90W, &crc_l, &crc_h); | |
//Serial.printf("CRC(90W)= %02X %02X !!!\n", crc_l, crc_h); | |
// Setup OneWire | |
hub.attach(dellCH); | |
dellCH.writeMemory((uint8_t*)chargerEEPROMStr_130W, 42, 0); | |
//dellCH.writeMemory(charger130W, sizeof(charger130W), 0x08); | |
} | |
void loop() | |
{ | |
// following function must be called periodically | |
hub.poll(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment