Skip to content

Instantly share code, notes, and snippets.

@Zyr00
Last active July 8, 2022 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zyr00/95591c62896efd708ae4b4b9a2284244 to your computer and use it in GitHub Desktop.
Save Zyr00/95591c62896efd708ae4b4b9a2284244 to your computer and use it in GitHub Desktop.
Set mangoh yellow nfc slave address back to default of 0x66
#include <linux/i2c.h>
#include <linux/i2c-help.h>
#include <sys/ioctl.h>
#include "legato.h"
#define ADAPTER "/dev/i2c-8"
#define BAD_ADDRESS 0x00
#define GOOD_ADDRESS 0x55
int open_nfc_file(uint8_t address)
{
int file = open(ADAPTER, O_RDWD);
if (file < 0)
{
LE_ERROR("Failed to open adapter.");
goto exit;
}
if (ioctl(file, I2C_SLAVE_FORCE, address) < 0)
LE_ERROR("Failed i2c transaction: %m");
exit:
return file;
}
COMPONENT_INIT
{
LE_INFO("Starting...");
int file = open_nfc_file(BAD_ADDRESS);
if (file < 0)
exit(-1);
char unsigned buf[17];
buf[0] = 0x00;
buf[1] = GOOD_ADDRESS << 1; // This set the address back to 0x55
buf[2] = 0x00;
buf[3] = 0x00;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
buf[7] = 0x00;
buf[8] = 0x00;
buf[9] = 0x00;
buf[10] = 0x00;
buf[11] = 0x00;
buf[12] = 0x00;
buf[13] = 0xE1;
buf[14] = 0x10;
buf[15] = 0x6D;
buf[16] = 0x00;
int res = write(file, buf, 17);
LE_ERROR_IF(res == -1, "ERROR: %m");
LE_INFO_IF(res != -1, "%m);
close(file);
}