Fujitsu MB85RCxx I2C FRAM access library

Dependents:   MB85RCxx_hello

Committer:
MACRUM
Date:
Sat Apr 22 12:30:56 2017 +0000
Revision:
1:b4cd8ba57300
Parent:
0:f7119e0aa405
Modified header info for doxygen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:f7119e0aa405 1 /**
MACRUM 0:f7119e0aa405 2 ******************************************************************************
MACRUM 0:f7119e0aa405 3 * @file MB85RCxx_I2C.h
MACRUM 0:f7119e0aa405 4 * @author Toyomasa Watarai
MACRUM 0:f7119e0aa405 5 * @version V1.0.0
MACRUM 0:f7119e0aa405 6 * @date 22 April 2017
MACRUM 0:f7119e0aa405 7 * @brief This file contains the class of an MB85RCxx FRAM library with I2C interface
MACRUM 0:f7119e0aa405 8 ******************************************************************************
MACRUM 0:f7119e0aa405 9 * @attention
MACRUM 0:f7119e0aa405 10 *
MACRUM 0:f7119e0aa405 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
MACRUM 0:f7119e0aa405 12 * of this software and associated documentation files (the "Software"), to deal
MACRUM 0:f7119e0aa405 13 * in the Software without restriction, including without limitation the rights
MACRUM 0:f7119e0aa405 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MACRUM 0:f7119e0aa405 15 * copies of the Software, and to permit persons to whom the Software is
MACRUM 0:f7119e0aa405 16 * furnished to do so, subject to the following conditions:
MACRUM 0:f7119e0aa405 17 *
MACRUM 0:f7119e0aa405 18 * The above copyright notice and this permission notice shall be included in
MACRUM 0:f7119e0aa405 19 * all copies or substantial portions of the Software.
MACRUM 0:f7119e0aa405 20 *
MACRUM 0:f7119e0aa405 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MACRUM 0:f7119e0aa405 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MACRUM 0:f7119e0aa405 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MACRUM 0:f7119e0aa405 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MACRUM 0:f7119e0aa405 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MACRUM 0:f7119e0aa405 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MACRUM 0:f7119e0aa405 27 * THE SOFTWARE.
MACRUM 0:f7119e0aa405 28 */
MACRUM 0:f7119e0aa405 29
MACRUM 0:f7119e0aa405 30 #ifndef MBED_MB85RCxx_I2C_H
MACRUM 0:f7119e0aa405 31 #define MBED_MB85RCxx_I2C_H
MACRUM 0:f7119e0aa405 32
MACRUM 1:b4cd8ba57300 33 #include "mbed.h"
MACRUM 0:f7119e0aa405 34
MACRUM 1:b4cd8ba57300 35 #define MB85_DENSITY_64K 0x3
MACRUM 1:b4cd8ba57300 36 #define MB85_DENSITY_256K 0x5
MACRUM 1:b4cd8ba57300 37 #define MB85_DENSITY_512K 0x6
MACRUM 1:b4cd8ba57300 38 #define MB85_DENSITY_1M 0x7
MACRUM 1:b4cd8ba57300 39 #define MB85_DENSITY_2M 0x8
MACRUM 1:b4cd8ba57300 40 #define MB85RC_I2C_ADDRESS 0xA0
MACRUM 1:b4cd8ba57300 41 #define I2C_WRITE 0
MACRUM 1:b4cd8ba57300 42 #define I2C_READ 1
MACRUM 1:b4cd8ba57300 43
MACRUM 1:b4cd8ba57300 44 /** Interface for accessing Fujitsu MB85RCxx FRAM
MACRUM 0:f7119e0aa405 45 *
MACRUM 0:f7119e0aa405 46 * @code
MACRUM 0:f7119e0aa405 47 * #include "mbed.h"
MACRUM 0:f7119e0aa405 48 * #include "MB85RCxx_I2C.h"
MACRUM 0:f7119e0aa405 49 *
MACRUM 0:f7119e0aa405 50 * Serial pc(USBTX, USBRX);
MACRUM 0:f7119e0aa405 51 *
MACRUM 0:f7119e0aa405 52 * #if defined(TARGET_LPC1768)
MACRUM 0:f7119e0aa405 53 * MB85RCxx_I2C fram(p28, p27);
MACRUM 0:f7119e0aa405 54 * #else
MACRUM 0:f7119e0aa405 55 * MB85RCxx_I2C fram(D14, D15);
MACRUM 0:f7119e0aa405 56 * #endif
MACRUM 0:f7119e0aa405 57 *
MACRUM 0:f7119e0aa405 58 * int main()
MACRUM 0:f7119e0aa405 59 * {
MACRUM 0:f7119e0aa405 60 * char buf[16];
MACRUM 0:f7119e0aa405 61 * uint32_t address;
MACRUM 0:f7119e0aa405 62 *
MACRUM 0:f7119e0aa405 63 * fram.fill(0, 0, 256);
MACRUM 0:f7119e0aa405 64 *
MACRUM 0:f7119e0aa405 65 * for (int i = 0; i < 16; i++) {
MACRUM 0:f7119e0aa405 66 * buf[i] = i;
MACRUM 0:f7119e0aa405 67 * }
MACRUM 0:f7119e0aa405 68 * fram.write(0, buf, 16);
MACRUM 0:f7119e0aa405 69 *
MACRUM 0:f7119e0aa405 70 * for (address = 0; address < 0x80; address += 16) {
MACRUM 0:f7119e0aa405 71 * fram.read(address, buf, 16);
MACRUM 0:f7119e0aa405 72 * pc.printf("%08X : ", address);
MACRUM 0:f7119e0aa405 73 * for (int i = 0; i < 16; i++) {
MACRUM 0:f7119e0aa405 74 * pc.printf("%02X ", buf[i]);
MACRUM 0:f7119e0aa405 75 * }
MACRUM 0:f7119e0aa405 76 * pc.printf("\n");
MACRUM 0:f7119e0aa405 77 * }
MACRUM 0:f7119e0aa405 78 * }
MACRUM 0:f7119e0aa405 79 *
MACRUM 0:f7119e0aa405 80 * @endcode
MACRUM 0:f7119e0aa405 81 */
MACRUM 0:f7119e0aa405 82
MACRUM 0:f7119e0aa405 83 /** MB85RCxx_I2C class
MACRUM 0:f7119e0aa405 84 *
MACRUM 0:f7119e0aa405 85 * MB85RCxx_I2C: A library to access Fujitsu MB85RCxx_I2C FRAM
MACRUM 0:f7119e0aa405 86 *
MACRUM 0:f7119e0aa405 87 */
MACRUM 0:f7119e0aa405 88 class MB85RCxx_I2C
MACRUM 0:f7119e0aa405 89 {
MACRUM 0:f7119e0aa405 90 public:
MACRUM 0:f7119e0aa405 91
MACRUM 0:f7119e0aa405 92 /** Create an MB85RCxx_I2C instance
MACRUM 0:f7119e0aa405 93 * which is connected to specified I2C pins with specified address
MACRUM 0:f7119e0aa405 94 *
MACRUM 0:f7119e0aa405 95 * @param sda I2C data line pin
MACRUM 0:f7119e0aa405 96 * @param scl I2C clock line pin
MACRUM 0:f7119e0aa405 97 * @param slave_adr (option) I2C slave address (default: 0xA0)
MACRUM 0:f7119e0aa405 98 */
MACRUM 0:f7119e0aa405 99 MB85RCxx_I2C(PinName sda, PinName scl, char slave_adr = MB85RC_I2C_ADDRESS);
MACRUM 0:f7119e0aa405 100
MACRUM 0:f7119e0aa405 101 /** Destructor of MB85RCxx_I2C
MACRUM 0:f7119e0aa405 102 */
MACRUM 0:f7119e0aa405 103 virtual ~MB85RCxx_I2C();
MACRUM 0:f7119e0aa405 104
MACRUM 0:f7119e0aa405 105 /** Read device ID from MB85RCxx FRAM
MACRUM 0:f7119e0aa405 106 *
MACRUM 0:f7119e0aa405 107 * @param device_id Pointer to the byte-array to read data in to
MACRUM 0:f7119e0aa405 108 *
MACRUM 0:f7119e0aa405 109 * @returns memory dencity
MACRUM 0:f7119e0aa405 110 */
MACRUM 0:f7119e0aa405 111 int read_device_id(char* device_id);
MACRUM 0:f7119e0aa405 112
MACRUM 0:f7119e0aa405 113 /** Read data from memory address
MACRUM 0:f7119e0aa405 114 *
MACRUM 0:f7119e0aa405 115 * @param address Memory address
MACRUM 0:f7119e0aa405 116 * @param data Pointer to the byte-array to read data in to
MACRUM 0:f7119e0aa405 117 * @param length Number of bytes to read
MACRUM 0:f7119e0aa405 118 *
MACRUM 0:f7119e0aa405 119 */
MACRUM 0:f7119e0aa405 120 void read(uint32_t address, char *data, uint32_t length);
MACRUM 0:f7119e0aa405 121
MACRUM 0:f7119e0aa405 122 /** Write data to memory address
MACRUM 0:f7119e0aa405 123 *
MACRUM 0:f7119e0aa405 124 * @param address Memory address
MACRUM 0:f7119e0aa405 125 * @param data Pointer to the byte-array data to write
MACRUM 0:f7119e0aa405 126 * @param length Number of bytes to write
MACRUM 0:f7119e0aa405 127 *
MACRUM 0:f7119e0aa405 128 */
MACRUM 0:f7119e0aa405 129 void write(uint32_t address, char *data, uint32_t length);
MACRUM 0:f7119e0aa405 130
MACRUM 0:f7119e0aa405 131 /** Write data to memory address
MACRUM 0:f7119e0aa405 132 *
MACRUM 0:f7119e0aa405 133 * @param address Memory address
MACRUM 0:f7119e0aa405 134 * @param data data to write out to memory
MACRUM 0:f7119e0aa405 135 *
MACRUM 0:f7119e0aa405 136 */
MACRUM 0:f7119e0aa405 137 void write(uint32_t address, char data);
MACRUM 0:f7119e0aa405 138
MACRUM 0:f7119e0aa405 139 /** Fill data to memory address
MACRUM 0:f7119e0aa405 140 *
MACRUM 0:f7119e0aa405 141 * @param address Memory address
MACRUM 0:f7119e0aa405 142 * @param data data to fill out to memory
MACRUM 0:f7119e0aa405 143 * @param length Number of bytes to write
MACRUM 0:f7119e0aa405 144 *
MACRUM 0:f7119e0aa405 145 */
MACRUM 0:f7119e0aa405 146 void fill(uint32_t address, uint8_t data, uint32_t length);
MACRUM 0:f7119e0aa405 147
MACRUM 0:f7119e0aa405 148 private:
MACRUM 0:f7119e0aa405 149 I2C *_i2c_p;
MACRUM 0:f7119e0aa405 150 I2C &_i2c;
MACRUM 0:f7119e0aa405 151 char _address;
MACRUM 0:f7119e0aa405 152 };
MACRUM 0:f7119e0aa405 153
MACRUM 0:f7119e0aa405 154 #endif