library to access typical i2c device

Committer:
j_rocket_boy
Date:
Wed Jul 11 16:27:47 2018 +0000
Revision:
3:648d68018302
Parent:
1:e7e87f75c0d5
modify license year

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j_rocket_boy 1:e7e87f75c0d5 1 // -*- coding: utf-8 -*-
j_rocket_boy 1:e7e87f75c0d5 2 /**
j_rocket_boy 1:e7e87f75c0d5 3 @file i2c_general_io.h
j_rocket_boy 1:e7e87f75c0d5 4 @brief This is a library for accessing registers of a typical i2c sensor to set or read measurement value.
j_rocket_boy 1:e7e87f75c0d5 5
j_rocket_boy 1:e7e87f75c0d5 6 @author D.Nakayama
j_rocket_boy 1:e7e87f75c0d5 7 @version 1.0
j_rocket_boy 1:e7e87f75c0d5 8 @date 2018-07-08 D.Nakayama Written for C++/mbed.
j_rocket_boy 1:e7e87f75c0d5 9
j_rocket_boy 1:e7e87f75c0d5 10
j_rocket_boy 1:e7e87f75c0d5 11 @see
j_rocket_boy 3:648d68018302 12 Copyright (C) 2018 D.Nakayama.
j_rocket_boy 1:e7e87f75c0d5 13 Released under the MIT license.
j_rocket_boy 1:e7e87f75c0d5 14 http://opensource.org/licenses/mit-license.php
j_rocket_boy 1:e7e87f75c0d5 15
j_rocket_boy 0:712b59c07bd3 16 */
j_rocket_boy 0:712b59c07bd3 17
j_rocket_boy 0:712b59c07bd3 18 #ifndef INCLUDED_i2c_genela_io_h_
j_rocket_boy 0:712b59c07bd3 19 #define INCLUDED_i2c_genela_io_h_
j_rocket_boy 0:712b59c07bd3 20 #include "mbed.h"
j_rocket_boy 0:712b59c07bd3 21
j_rocket_boy 1:e7e87f75c0d5 22 /**
j_rocket_boy 1:e7e87f75c0d5 23 @class GEN_I2C
j_rocket_boy 1:e7e87f75c0d5 24 @brief Class for accessing a typical sensor with i2c
j_rocket_boy 1:e7e87f75c0d5 25 */
j_rocket_boy 0:712b59c07bd3 26 class GEN_I2C{
j_rocket_boy 0:712b59c07bd3 27
j_rocket_boy 0:712b59c07bd3 28 public:
j_rocket_boy 0:712b59c07bd3 29
j_rocket_boy 1:e7e87f75c0d5 30 /**
j_rocket_boy 1:e7e87f75c0d5 31 @brief Create a new i2c sensor.
j_rocket_boy 1:e7e87f75c0d5 32 @param sda SDA pin name (Defined in PinName.h)
j_rocket_boy 1:e7e87f75c0d5 33 @param sck SCK pin name (Defined in PinName.h)
j_rocket_boy 1:e7e87f75c0d5 34 */
j_rocket_boy 0:712b59c07bd3 35 GEN_I2C(PinName sda, PinName sck);
j_rocket_boy 1:e7e87f75c0d5 36 /**
j_rocket_boy 1:e7e87f75c0d5 37 @brief Create a new i2c sensor.
j_rocket_boy 1:e7e87f75c0d5 38 @param &i2c_obj i2c name
j_rocket_boy 1:e7e87f75c0d5 39 */
j_rocket_boy 0:712b59c07bd3 40 GEN_I2C(I2C &i2c_obj);
j_rocket_boy 0:712b59c07bd3 41
j_rocket_boy 1:e7e87f75c0d5 42 /**
j_rocket_boy 1:e7e87f75c0d5 43 @brief Disable the i2c sensor.
j_rocket_boy 1:e7e87f75c0d5 44 @param No parameters.
j_rocket_boy 1:e7e87f75c0d5 45 */
j_rocket_boy 0:712b59c07bd3 46 virtual ~GEN_I2C();
j_rocket_boy 0:712b59c07bd3 47
j_rocket_boy 0:712b59c07bd3 48
j_rocket_boy 0:712b59c07bd3 49 //multi bytes func
j_rocket_boy 1:e7e87f75c0d5 50 /**
j_rocket_boy 1:e7e87f75c0d5 51 @brief multible read register.
j_rocket_boy 1:e7e87f75c0d5 52 @param[in] Device_add Device i2c address(8bit)
j_rocket_boy 1:e7e87f75c0d5 53 @param[in] reg_add register address(8bit)
j_rocket_boy 1:e7e87f75c0d5 54 @param[out] *data read data array
j_rocket_boy 1:e7e87f75c0d5 55 @param[in] n Number of register reads
j_rocket_boy 1:e7e87f75c0d5 56 @return int read result(define mbed(i2c))
j_rocket_boy 1:e7e87f75c0d5 57 */
j_rocket_boy 1:e7e87f75c0d5 58 virtual int read_reg(char Device_add, char reg_add, char *data, int n);
j_rocket_boy 0:712b59c07bd3 59
j_rocket_boy 0:712b59c07bd3 60 //single byte func
j_rocket_boy 1:e7e87f75c0d5 61 /**
j_rocket_boy 1:e7e87f75c0d5 62 @brief single read register.
j_rocket_boy 1:e7e87f75c0d5 63 @param[in] Device_add Device i2c address(8bit)
j_rocket_boy 1:e7e87f75c0d5 64 @param[in] reg_add register address(8bit)
j_rocket_boy 1:e7e87f75c0d5 65 @return char read data
j_rocket_boy 1:e7e87f75c0d5 66 */
j_rocket_boy 1:e7e87f75c0d5 67 virtual char read_reg(char Device_add, char reg_add);
j_rocket_boy 1:e7e87f75c0d5 68
j_rocket_boy 1:e7e87f75c0d5 69 /**
j_rocket_boy 1:e7e87f75c0d5 70 @brief single write register.
j_rocket_boy 1:e7e87f75c0d5 71 @param[in] Device_add Device i2c address(8bit)
j_rocket_boy 1:e7e87f75c0d5 72 @param[in] reg_add register address(8bit)
j_rocket_boy 1:e7e87f75c0d5 73 @param[in] data write data
j_rocket_boy 1:e7e87f75c0d5 74 @return int write result(define mbed(i2c))
j_rocket_boy 1:e7e87f75c0d5 75 */
j_rocket_boy 1:e7e87f75c0d5 76 virtual int write_reg(char Device_add, char reg_add, char data);
j_rocket_boy 0:712b59c07bd3 77
j_rocket_boy 0:712b59c07bd3 78 private:
j_rocket_boy 0:712b59c07bd3 79 I2C *i2c_p;
j_rocket_boy 0:712b59c07bd3 80 I2C &i2c;
j_rocket_boy 0:712b59c07bd3 81
j_rocket_boy 0:712b59c07bd3 82 };
j_rocket_boy 0:712b59c07bd3 83
j_rocket_boy 0:712b59c07bd3 84 #endif