Skip to content

Commit

Permalink
Add debug option for dumping the first 128 bytes of the SAO EEPROM
Browse files Browse the repository at this point in the history
  • Loading branch information
renzenicolai committed May 1, 2023
1 parent d9ae922 commit d21f9a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions main/include/sao_eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct __attribute__((__packed__)) _sao_driver_ntag_data {
#define SAO_DRIVER_APP_NAME "app"
// data is a string containing the slug name of the app, null terminated

void dump_eeprom_contents();
esp_err_t sao_identify(SAO* sao);
esp_err_t sao_write_raw(size_t offset, uint8_t* buffer, size_t buffer_length);
esp_err_t sao_format(const char* name, const char* driver, const uint8_t* driver_data, uint8_t driver_data_length, const char* driver2,
Expand Down
5 changes: 4 additions & 1 deletion main/menus/sao.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void menu_sao(xQueueHandle button_queue) {

display_flush();

if (xQueueReceive(button_queue, &buttonMessage, 200 / portTICK_PERIOD_MS) == pdTRUE) {
if (xQueueReceive(button_queue, &buttonMessage, 500 / portTICK_PERIOD_MS) == pdTRUE) {
uint8_t pin = buttonMessage.input;
bool value = buttonMessage.state;
if (value) {
Expand All @@ -394,6 +394,9 @@ void menu_sao(xQueueHandle button_queue) {
case RP2040_INPUT_BUTTON_BACK:
exit = true;
break;
case RP2040_INPUT_BUTTON_SELECT:
dump_eeprom_contents();
break;
case RP2040_INPUT_BUTTON_ACCEPT:
if ((sao.type == SAO_BINARY) && (strncmp(sao.driver, "badgeteam_app_link", strlen("badgeteam_app_link")) == 0)) {
if (!sao_is_app_installed((char*) sao.driver_data)) {
Expand Down
15 changes: 15 additions & 0 deletions main/sao_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ static const char* TAG = "SAO";

EEPROM sao_eeprom = {.i2c_bus = 0, .i2c_address = 0x50};

void dump_eeprom_contents() {
uint8_t buffer[128] = {0};
if (eeprom_read(&sao_eeprom, 0, buffer, sizeof(buffer)) != ESP_OK) {
printf("Failed to read EEPROM contents\n");
} else {
for (int i = 0; i < sizeof(buffer); i++) {
if (i % 16 == 0) {
printf("\n");
}
printf("%02x ", buffer[i]);
}
}
printf("\n");
}

esp_err_t sao_identify(SAO* sao) {
if (sao == NULL) return ESP_FAIL;
memset(sao, 0, sizeof(SAO));
Expand Down

0 comments on commit d21f9a6

Please sign in to comment.