m24lr64e: Initial Implementation

This module was developed and tested on the Grove NFC Tag.  It is an
8KB EEPROM accessable (with various protection capabilites) via I2C
and NFC capable devices.

The code was based on the Seeed Studio example code with some help
from the datasheet.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-06-01 17:14:07 -06:00 committed by Mihai Tudor Panu
parent 6740932c47
commit 5733918a2f
9 changed files with 778 additions and 0 deletions

View File

@ -122,6 +122,7 @@ add_executable (ht9170-example ht9170.cxx)
add_executable (h3lis331dl-example h3lis331dl.cxx)
add_executable (ad8232-example ad8232.cxx)
add_executable (grovescam-example grovescam.cxx)
add_executable (m24lr64e-example m24lr64e.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -222,6 +223,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/ht9170)
include_directories (${PROJECT_SOURCE_DIR}/src/h3lis331dl)
include_directories (${PROJECT_SOURCE_DIR}/src/ad8232)
include_directories (${PROJECT_SOURCE_DIR}/src/grovescam)
include_directories (${PROJECT_SOURCE_DIR}/src/m24lr64e)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -345,3 +347,4 @@ target_link_libraries (ht9170-example ht9170 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (h3lis331dl-example h3lis331dl ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (ad8232-example ad8232 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovescam-example grovescam ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (m24lr64e-example m24lr64e ${CMAKE_THREAD_LIBS_INIT})

65
examples/c++/m24lr64e.cxx Normal file
View File

@ -0,0 +1,65 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "m24lr64e.h"
using namespace std;
using namespace upm;
int main(int argc, char **argv)
{
//! [Interesting]
// Instantiate an M24LR64E on I2C bus 0
upm::M24LR64E *nfcTag = new upm::M24LR64E(M24LR64E_I2C_BUS);
// This example accesses the device in the 'user' (default) mode,
// reads the last byte of data in the EEPROM, inverts it, writes
// it back, and then re-reads it.
// Read the last byte of the EEPROM area
int addr = M24LR64E::EEPROM_I2C_LENGTH - 1;
printf("Address: %d\n", addr);
uint8_t byte = nfcTag->readByte(addr);
printf("Read byte: %02x\n", byte);
// Now change it to it's opposite and write it
byte = ~byte;
nfcTag->writeByte(addr, byte);
printf("Wrote inverted byte: %02x\n", byte);
// Now read it back.
byte = nfcTag->readByte(addr);
printf("Read byte: %02x\n", byte);
//! [Interesting]
cout << "Exiting..." << endl;
delete nfcTag;
return 0;
}

View File

@ -0,0 +1,59 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var nfcTagObj = require('jsupm_m24lr64e');
// Instantiate a M24LR64E Grove NFC Tag Module on UART 0
var nfcTag = new nfcTagObj.M24LR64E(nfcTagObj.M24LR64E_I2C_BUS);
// This example accesses the device in the 'user' (default) mode,
// reads the last byte of data in the EEPROM, inverts it, writes
// it back, and then re-reads it.
// Read the last byte of the EEPROM area
var addr = (nfcTagObj.M24LR64E.EEPROM_I2C_LENGTH - 1);
console.log("Address: " + addr);
var byte = nfcTag.readByte(addr);
console.log("Read byte: " + byte.toString(16));
// Now change it to it's opposite and write it
byte = (~byte & 0xff);
nfcTag.writeByte(addr, byte);
console.log("Wrote inverted byte: " + byte.toString(16));
// Now read it back.
byte = nfcTag.readByte(addr);
console.log("Read byte: " + byte.toString(16));
// clean up
nfcTag = null;
nfcTagObj.cleanUp();
nfcTagObj = null;
console.log("Exiting...");
process.exit(0);

View File

@ -0,0 +1,49 @@
#!/usr/bin/python
# Author: Jon Trulson <jtrulson@ics.com>
# Copyright (c) 2015 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import sys
import pyupm_m24lr64e as nfcTagObj
# Instantiate a M24LR64E Grove NFC Tag Module on UART 0
nfcTag = nfcTagObj.M24LR64E(nfcTagObj.M24LR64E_I2C_BUS)
# This example accesses the device in the 'user' (default) mode,
# reads the last byte of data in the EEPROM, inverts it, writes
# it back, and then re-reads it.
# Read the last byte of the EEPROM area
addr = (nfcTagObj.M24LR64E.EEPROM_I2C_LENGTH - 1)
print "Address: ", addr
byte = nfcTag.readByte(addr)
print "Read byte: ", format(byte, '02x')
# Now change it to it's opposite and write it
byte = (~byte & 0xff)
nfcTag.writeByte(addr, byte)
print "Wrote inverted byte: ", format(byte, '02x')
# Now read it back.
byte = nfcTag.readByte(addr)
print "Read byte: ", format(byte, '02x')

View File

@ -0,0 +1,5 @@
set (libname "m24lr64e")
set (libdescription "upm m24lr64e grove NFC tag")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,10 @@
%module jsupm_m24lr64e
%include "../upm.i"
%include "stdint.i"
%{
#include "m24lr64e.h"
%}
%include "m24lr64e.h"

290
src/m24lr64e/m24lr64e.cxx Normal file
View File

@ -0,0 +1,290 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <math.h>
#include <iostream>
#include <string>
#include "m24lr64e.h"
using namespace upm;
using namespace std;
M24LR64E::M24LR64E(int bus, AccessMode mode):
m_i2c(bus)
{
if (mode == USER_MODE)
m_addr = M24LR64E_DEFAULT_I2C_ADDR;
else
m_addr = M24LR64E_DEFAULT_I2C_ADDR_E2;
mraa_result_t rv;
if ( (rv = m_i2c.address(m_addr)) != MRAA_SUCCESS)
{
cerr << "M24LR64E: Could not initialize i2c address. " << endl;
mraa_result_print(rv);
return;
}
}
M24LR64E::~M24LR64E()
{
}
bool M24LR64E::submitPasswd(uint32_t passwd)
{
// this device actually uses two bytes to address a register
const int pktLen = 11;
uint8_t buf[pktLen];
buf[0] = 0x09;
buf[1] = 0x00;
buf[2] = ((passwd >> 24) & 0xff);
buf[3] = ((passwd >> 16) & 0xff);
buf[4] = ((passwd >> 8) & 0xff);
buf[5] = (passwd & 0xff);
buf[6] = 0x09;
// the password is written twice
buf[7] = ((passwd >> 24) & 0xff);
buf[8] = ((passwd >> 16) & 0xff);
buf[9] = ((passwd >> 8) & 0xff);
buf[10] = (passwd & 0xff);
if (m_i2c.write(buf, pktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
return false;
}
return true;
}
bool M24LR64E::writePasswd(uint32_t passwd)
{
const int pktLen = 11;
uint8_t buf[pktLen];
buf[0] = 0x09;
buf[1] = 0x00;
buf[2] = ((passwd >> 24) & 0xff);
buf[3] = ((passwd >> 16) & 0xff);
buf[4] = ((passwd >> 8) & 0xff);
buf[5] = (passwd & 0xff);
buf[6] = 0x07;
// the password is written twice
buf[7] = ((passwd >> 24) & 0xff);
buf[8] = ((passwd >> 16) & 0xff);
buf[9] = ((passwd >> 8) & 0xff);
buf[10] = (passwd & 0xff);
if (m_i2c.write(buf, pktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
return false;
}
return true;
}
void M24LR64E::sectorProtectConfig(unsigned int sectorNumber,
bool protectEnable,
SectorAccessRight accessRight,
SectorSelectPassWd passwd)
{
if(!protectEnable) {
EEPROM_Write_Byte(sectorNumber,0x0);
} else {
EEPROM_Write_Byte(sectorNumber,
protectEnable | (accessRight<<1) |(passwd<<2));
}
}
void M24LR64E::clearSectorProtect(void)
{
uint8_t buf[64]={0x0};
EEPROM_Write_Bytes(0, buf, 64);
}
void M24LR64E::sectorWriteLockBit(unsigned int sectorNumber,
bool sockEnable)
{
unsigned int sectorAddress = SECTOR_SECURITY_STATUS_BASE_ADDR
+ (sectorNumber/8);
uint8_t sectorBit = sectorNumber % 8;
uint8_t preStatus = EEPROM_Read_Byte(sectorAddress);
bool status = (preStatus >> sectorBit) & 0x01;
if(status != sockEnable) {
if(status == true) {
writeByte(sectorAddress,preStatus&(~(1<<sectorBit)));
} else {
writeByte(sectorAddress,preStatus|(1<<sectorBit));
}
}
}
uint8_t M24LR64E::getDSFID()
{
return EEPROM_Read_Byte(DSFID_ADDR);
}
uint8_t M24LR64E::getAFI()
{
return EEPROM_Read_Byte(AFI_ADDR);
}
void M24LR64E::getUID(uint8_t* buf)
{
EEPROM_Read_Bytes(UID_ADDR,buf,UID_LENGTH);
}
uint32_t M24LR64E::getMemorySize()
{
uint32_t volume = 0x0;
volume = EEPROM_Read_Byte(MEM_SIZE_ADDR);
volume = volume<<8|EEPROM_Read_Byte(MEM_SIZE_ADDR+1);
volume = volume<<8|EEPROM_Read_Byte(MEM_SIZE_ADDR+2);
return volume;
}
void M24LR64E::clearMemory()
{
for(int i = 0; i < EEPROM_I2C_LENGTH; i++){
writeByte(i,0x0);
}
}
void M24LR64E::writeByte(unsigned int address, uint8_t data)
{
EEPROM_Write_Byte(address, data);
}
void M24LR64E::writeBytes(unsigned int address, uint8_t* buf, unsigned int len)
{
EEPROM_Write_Bytes(address, buf, len);
}
uint8_t M24LR64E::readByte(unsigned int address)
{
return EEPROM_Read_Byte(address);
}
void M24LR64E::readBytes(unsigned int address, uint8_t* buf, unsigned int len)
{
EEPROM_Read_Bytes(address, buf, len);
}
void M24LR64E::EEPROM_Write_Byte(unsigned int address, uint8_t data)
{
const int pktLen = 3;
uint8_t buf[pktLen];
buf[0] = ((address >> 8) & 0xff);
buf[1] = (address & 0xff);
buf[2] = data;
if (m_i2c.write(buf, pktLen))
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
usleep(I2C_WRITE_TIME * 1000);
}
void M24LR64E::EEPROM_Write_Bytes(unsigned int address, uint8_t* data,
unsigned int len)
{
const int pktLen = 2 + len;
uint8_t buf[pktLen];
buf[0] = ((address >> 8) & 0xff);
buf[1] = (address & 0xff);
for (int i=0; i<len; i++)
buf[2+i] = data[i];
if (m_i2c.write(buf, pktLen))
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
usleep(I2C_WRITE_TIME * 1000);
}
uint8_t M24LR64E::EEPROM_Read_Byte(unsigned int address)
{
const int apktLen = 2;
uint8_t abuf[apktLen];
abuf[0] = ((address >> 8) & 0xff);
abuf[1] = (address & 0xff);
if (m_i2c.write(abuf, apktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
return 0x00;
}
const int pktLen = 1;
uint8_t buf[apktLen];
buf[0] = 0;
if (m_i2c.read(buf, pktLen) != pktLen)
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": read failed" << endl;
return 0x00;
}
return buf[0];
}
unsigned int M24LR64E::EEPROM_Read_Bytes(unsigned int address,
uint8_t* buf, unsigned int len)
{
const int apktLen = 2;
uint8_t abuf[apktLen];
abuf[0] = ((address >> 8) & 0xff);
abuf[1] = (address & 0xff);
if (m_i2c.write(abuf, apktLen))
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": write failed" << endl;
return false;
}
int rv = m_i2c.read(buf, len);
if (rv != len)
{
cerr << __FUNCTION__ << "@" << __LINE__ << ": read failed" << endl;
}
return rv;
}

282
src/m24lr64e/m24lr64e.h Normal file
View File

@ -0,0 +1,282 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
*
* This code was adapted from the Seeed Studio code at:
* https://github.com/Seeed-Studio/NFC_Tag_M24LR6E
*
* Copyright (c) 2014 seeed technology inc.
* Website : www.seeed.cc
* Author : lawliet zou
* Create Time: March 2014
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/i2c.hpp>
#define M24LR64E_I2C_BUS 0
#define M24LR64E_DEFAULT_I2C_ADDR 0x53
#define M24LR64E_DEFAULT_I2C_ADDR_E2 (M24LR64E_DEFAULT_I2C_ADDR | 0x04)
namespace upm {
/**
* @brief Grove NFC Tag
* @defgroup m24lr64e libupm-m24lr64e
* @ingroup seeed i2c other
*/
/**
* @library m24lr64e
* @sensor m24lr64e
* @comname Grove NFC Tag
* @type other
* @man seeed
* @web http://www.seeedstudio.com/wiki/Grove_-_NFC_Tag
* @con i2c
*
* @brief C++ API for the M24LR64E based Grove NFC Tag
*
* The Grove NFC tag is, in essence, an 8KB EEPROM that can be written
* to or read from using I2C and NFC equipped devices.
*
* The USER mode (default) allows read and write access to all 8KB
* of space, provided the sector security status (SSS) allows it.
* The ROOT mode allows modification of the SSS data and other
* information, provided the proper password is submitted. The
* default password for a new tag is 0x00000000. See the data sheet
* for much more detailed information.
*
* The Seeed Studio wiki page for this device includes a link to an
* Android application that can be used to also read and write the
* device via NFC, as well as set the NFC passwords, which cannot be
* done via I2C.
*
* @snippet m24lr64e.cxx Interesting
*/
class M24LR64E {
public:
static const int EEPROM_I2C_LENGTH = 8192;
static const int PASSWORD_LENGTH = 4;
static const int SECTOR_SECURITY_STATUS_BASE_ADDR = 0x800; // 2048
static const uint8_t LOCK_PROTECT_BIT = 0x01;
static const uint8_t WRITE_READ_PROTECT_BIT = 0x02;
static const uint8_t PASSWORD_CTRL_BIT = 0x04;
static const int UID_LENGTH = 8; // bytes
static const unsigned int I2C_WRITE_TIME = 5; // 5ms
/**
* M24LR64E addresses, accessable only in root mode
*/
typedef enum {
I2C_PASSWORD_ADDR = 2304,
RF_PASSWORD_1_ADDR = 2308, // RF pwds not available in
RF_PASSWORD_2_ADDR = 2312, // i2c access modes
RF_PASSWORD_3_ADDR = 2316,
DSFID_ADDR = 2320, // 1 byte
AFI_ADDR = 2321, // 1 byte
RESV_ADDR = 2322, // 1 bytes
CONFIG_ADDR = 2323, // 1 bytes
UID_ADDR = 2324, // 8 bytes
MEM_SIZE_ADDR = 2332, // 3 bytes
IC_REF_ADDR = 2335, // 1 byte
PROG_COMP_ENERGY_HARVEST_ADDR = 2339 // 1 byte
} M24LR64E_ADDR_T;
enum AccessMode {
USER_MODE = 0x0, // offer simple read/write access right
ROOT_MODE = 0x1 // offer password change access right
};
enum SectorAccessRight {
// **********************************
// * submit passWd * no submit *
//b2,b1 * Read * Write * Read * Write *
// 00 * 1 1 1 0 *
// 01 * 1 1 1 1 *
// 10 * 1 1 0 0 *
// 11 * 0 1 0 0 *
// **********************************
Access_1110 = 0,
Access_1111 = 1,
Access_1100 = 2,
Access_0111 = 3,
};
enum SectorSelectPassWd {
//00 => no passwd protect
//01 => passWd 1
//10 => passWd 2
//11 => passwd 3
noPasswd = 0,
passwd_1 = 1,
passwd_2 = 2,
passwd_3 = 3,
};
/**
* m24lr64e constructor
*
* @param bus i2c bus to use
* @param mode the access mode (user or root) to use
*/
M24LR64E(int bus, AccessMode mode = USER_MODE);
/**
* M24LR64E Destructor
*/
~M24LR64E();
/**
* submit an i2c access password
*
* @param passwd the 4-byte access password
*/
bool submitPasswd(uint32_t passwd);
/**
* write a new i2c password
*
* @param passwd the 4-byte access password
*/
bool writePasswd(uint32_t passwd);
/**
* Set the protection bit for a sector. Must be in ROOT mode
*
* @param sectorNumber the sector whose protection you are modifying
* @param protectEnable true if you are enabling protection
* @param accessRight the access rights to set
* @param passwd the password number to enable, if any
*/
void sectorProtectConfig(unsigned int sectorNumber,
bool protectEnable,
SectorAccessRight accessRight,
SectorSelectPassWd passwd);
/**
* Clear the sector protection bits. Must be in ROOT mode.
*/
void clearSectorProtect(void);
/**
* Set or clear the Sector Security Status Lock bit for a sector.
* Must be in ROOT mode.
*
* @param sectorNumber the sector who's SSS you want to modify
* @param sockEnable true r false to set or clear the bit
*/
void sectorWriteLockBit(unsigned int sectorNumber,
bool sockEnable);
/**
* return the Data Storage Familiy Identifier
* Must be in ROOT mode.
*
* @return the DSFID
*/
uint8_t getDSFID();
/**
* return the Application Family Identifier
* Must be in ROOT mode.
*
* @return the AFI
*/
uint8_t getAFI();
/**
* return the Unique ID.
* Must be in ROOT mode.
*
* @param buf buffer to hold returned UID. Must be UID_LENGTH bytes.
*/
void getUID(uint8_t* buf);
/**
* return the memory size
* Must be in ROOT mode.
*
* @return the amount of memory present
*/
uint32_t getMemorySize();
/**
* set all memory to 0, if permissions allow
*/
void clearMemory();
/**
* write a byte to EEPROM
*
* @param address address to write to
* @param data data to write
*/
void writeByte(unsigned int address, uint8_t data);
/**
* write bytes to EEPROM
*
* @param address address to write to
* @param data data to write
* @param data length of data buffer
*/
void writeBytes(unsigned int address, uint8_t* buf, unsigned int len);
/**
* read a byte from EEPROM
*
* @param address address to read from
* @return data value read
*/
uint8_t readByte(unsigned int address);
/**
* read multiple bytes from EEPROM
*
* @param address address to read from
* @param buffer buffer to store data
* @param len number of bytes to read
*/
void readBytes(unsigned int address, uint8_t* buf, unsigned int len);
protected:
mraa::I2c m_i2c;
void EEPROM_Write_Byte(unsigned int address, uint8_t data);
void EEPROM_Write_Bytes(unsigned int address, uint8_t* data,
unsigned int len);
uint8_t EEPROM_Read_Byte(unsigned int address);
unsigned int EEPROM_Read_Bytes(unsigned int address,
uint8_t* buf, unsigned int len);
private:
uint8_t m_addr;
};
}

View File

@ -0,0 +1,15 @@
%module pyupm_m24lr64e
%include "../upm.i"
%include "stdint.i"
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "m24lr64e_doc.i"
#endif
%include "m24lr64e.h"
%{
#include "m24lr64e.h"
%}