mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
#pragma once
|
|
//
|
|
// FILE: FRAM.h
|
|
// AUTHOR: Rob Tillaart
|
|
// VERSION: 0.3.3
|
|
// DATE: 2018-01-24
|
|
// PURPOSE: Arduino library for I2C FRAM
|
|
// URL: https://github.com/RobTillaart/FRAM_I2C
|
|
//
|
|
|
|
|
|
#include "Arduino.h"
|
|
#include "Wire.h"
|
|
|
|
|
|
#define FRAM_LIB_VERSION (F("0.3.3"))
|
|
|
|
|
|
#define FRAM_OK 0
|
|
#define FRAM_ERROR_ADDR -10
|
|
#define FRAM_ERROR_I2C -11
|
|
#define FRAM_ERROR_CONNECT -12
|
|
|
|
|
|
class FRAM
|
|
{
|
|
public:
|
|
FRAM(TwoWire *wire = &Wire);
|
|
|
|
#if defined (ESP8266) || defined(ESP32)
|
|
// address and writeProtectPin is optional
|
|
int begin(uint8_t sda, uint8_t scl, const uint8_t address = 0x50, int8_t writeProtectPin = -1);
|
|
#endif
|
|
// address and writeProtectPin is optional
|
|
int begin(const uint8_t address = 0x50, int8_t writeProtectPin = -1);
|
|
bool isConnected();
|
|
|
|
void write8(uint16_t memaddr, uint8_t value);
|
|
void write16(uint16_t memaddr, uint16_t value);
|
|
void write32(uint16_t memaddr, uint32_t value);
|
|
void write(uint16_t memaddr, uint8_t * obj, uint16_t size);
|
|
|
|
uint8_t read8(uint16_t memaddr);
|
|
uint16_t read16(uint16_t memaddr);
|
|
uint32_t read32(uint16_t memaddr);
|
|
void read(uint16_t memaddr, uint8_t * obj, uint16_t size);
|
|
|
|
// works only if pin is defined in begin.
|
|
bool setWriteProtect(bool b);
|
|
bool getWriteProtect();
|
|
|
|
// meta info
|
|
uint16_t getManufacturerID(); // Fujitsu = 0x000A
|
|
uint16_t getProductID(); // Proprietary
|
|
uint16_t getSize(); // Returns kiloBYTE
|
|
uint32_t getSizeBytes() { return getSize() * 1024UL; };
|
|
|
|
|
|
private:
|
|
uint8_t _address;
|
|
|
|
// default no pin = -1 ==> no write protect.
|
|
int8_t _writeProtectPin = -1;
|
|
|
|
uint16_t getMetaData(uint8_t id);
|
|
void writeBlock(uint16_t memaddr, uint8_t * obj, uint8_t size);
|
|
void readBlock(uint16_t memaddr, uint8_t * obj, uint8_t size);
|
|
|
|
TwoWire* _wire;
|
|
};
|
|
|
|
|
|
// -- END OF FILE --
|
|
|