Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Badge addon id firmware for STM32
/**
STM32 Fake EEPROM Firmware
Copyright (C) 2020, Uri Shaked. Released under the MIT license.
*/
#include <Wire.h>
#define EEPROM_ADDR 0x50
byte addrReg = 0;
const byte descriptor[] = {
'L', 'I', 'F', 'E', // Magic
4, // Device name length
5, // Driver name length
0, // Driver data buffer length
0, // Reversed,
'T', 'e', 's', 't', // Device name
't', 'e', 's', 't', '1' // driver name
};
void receiveEvent(int count) {
addrReg = Wire.read();
}
void requestEvent() {
if (addrReg < sizeof(descriptor)) {
Wire.write(&descriptor[addrReg], sizeof(descriptor) - addrReg);
}
}
void setup() {
Wire.begin(EEPROM_ADDR);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment