A I2C-Dev like library which can be used with different kinds of sensors.

Used in:

Committer:
joelvonrotz
Date:
Thu Jul 11 09:35:55 2019 +0000
Revision:
0:0af6c7cf0ed3
I2C Master library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joelvonrotz 0:0af6c7cf0ed3 1 /**
joelvonrotz 0:0af6c7cf0ed3 2 * @file i2c.h
joelvonrotz 0:0af6c7cf0ed3 3 * @author Joel von Rotz (joel.vonrotz@maxonmotor.com)
joelvonrotz 0:0af6c7cf0ed3 4 * @brief
joelvonrotz 0:0af6c7cf0ed3 5 * @version 0.1
joelvonrotz 0:0af6c7cf0ed3 6 * @date 2019-05-14
joelvonrotz 0:0af6c7cf0ed3 7 *
joelvonrotz 0:0af6c7cf0ed3 8 * @copyright Copyright (c) 2019, maxon motor ag, All Rights Reserved
joelvonrotz 0:0af6c7cf0ed3 9 *
joelvonrotz 0:0af6c7cf0ed3 10 */
joelvonrotz 0:0af6c7cf0ed3 11 #ifndef _I2C_H
joelvonrotz 0:0af6c7cf0ed3 12 #define _I2C_H
joelvonrotz 0:0af6c7cf0ed3 13 #include "mbed.h"
joelvonrotz 0:0af6c7cf0ed3 14
joelvonrotz 0:0af6c7cf0ed3 15 class I2C_Master
joelvonrotz 0:0af6c7cf0ed3 16 {
joelvonrotz 0:0af6c7cf0ed3 17 public:
joelvonrotz 0:0af6c7cf0ed3 18 I2C_Master(PinName sda, PinName scl, uint32_t frequency = 400000);
joelvonrotz 0:0af6c7cf0ed3 19 void i2c_write(uint8_t i2c_address, uint8_t slave_address, const uint8_t data);
joelvonrotz 0:0af6c7cf0ed3 20 void i2c_writeBits(uint8_t i2c_address, uint8_t slave_address, const uint8_t data, uint8_t mask);
joelvonrotz 0:0af6c7cf0ed3 21 uint8_t i2c_readBits(uint8_t i2c_address, uint8_t slave_address, uint8_t mask);
joelvonrotz 0:0af6c7cf0ed3 22 void i2c_readSeries(uint8_t i2c_address, uint8_t slave_address, uint8_t *data, uint8_t length);
joelvonrotz 0:0af6c7cf0ed3 23 uint8_t i2c_read(uint8_t i2c_address, uint8_t slave_address);
joelvonrotz 0:0af6c7cf0ed3 24
joelvonrotz 0:0af6c7cf0ed3 25 private:
joelvonrotz 0:0af6c7cf0ed3 26 I2C m_i2c_sensor;
joelvonrotz 0:0af6c7cf0ed3 27 uint32_t m_i2c_frequency;
joelvonrotz 0:0af6c7cf0ed3 28 };
joelvonrotz 0:0af6c7cf0ed3 29
joelvonrotz 0:0af6c7cf0ed3 30 #endif
joelvonrotz 0:0af6c7cf0ed3 31