Class for making communication easier from code to i2c connected Rohm/Kionix sensors. Maybe could be used later also for abstracting Arduino/mbed os. Code ported from 'C'-library rohm-sensor-hal.

Dependents:   kionix-kx123-hello rohm-bh1790glc-hello simple-sensor-client rohm-SensorShield-example

Fork of rohm-sensor-hal by Rohm

Committer:
MikkoZ
Date:
Mon Oct 03 11:07:46 2016 +0000
Revision:
9:51c7b97b6a7d
Parent:
8:dea50f607a45
Child:
12:bc2446aabbfe
Doxygen documentation updated.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 8:dea50f607a45 1 /* Copyright 2016 Rohm Semiconductor
MikkoZ 8:dea50f607a45 2
MikkoZ 8:dea50f607a45 3 Licensed under the Apache License, Version 2.0 (the "License");
MikkoZ 8:dea50f607a45 4 you may not use this file except in compliance with the License.
MikkoZ 8:dea50f607a45 5 You may obtain a copy of the License at
MikkoZ 8:dea50f607a45 6
MikkoZ 8:dea50f607a45 7 http://www.apache.org/licenses/LICENSE-2.0
MikkoZ 8:dea50f607a45 8
MikkoZ 8:dea50f607a45 9 Unless required by applicable law or agreed to in writing, software
MikkoZ 8:dea50f607a45 10 distributed under the License is distributed on an "AS IS" BASIS,
MikkoZ 8:dea50f607a45 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikkoZ 8:dea50f607a45 12 See the License for the specific language governing permissions and
MikkoZ 8:dea50f607a45 13 limitations under the License.
MikkoZ 8:dea50f607a45 14 */
MikkoZ 8:dea50f607a45 15 #ifndef i2c_common_pp_h
MikkoZ 8:dea50f607a45 16 #define i2c_common_pp_h
MikkoZ 8:dea50f607a45 17
MikkoZ 8:dea50f607a45 18 #include "rohm_hal2.h" //types, DEBUG_print*, USE_*_HARDWARE_I2C
MikkoZ 8:dea50f607a45 19
MikkoZ 9:51c7b97b6a7d 20 /**
MikkoZ 9:51c7b97b6a7d 21 * RegisterWriter class for writing sensor registers via I2C object
MikkoZ 9:51c7b97b6a7d 22 */
MikkoZ 8:dea50f607a45 23 class RegisterWriter
MikkoZ 8:dea50f607a45 24 {
MikkoZ 8:dea50f607a45 25 public:
MikkoZ 8:dea50f607a45 26 /**
MikkoZ 9:51c7b97b6a7d 27 * Use pre-instantiated I2C instance for HAL.
MikkoZ 8:dea50f607a45 28 *
MikkoZ 8:dea50f607a45 29 * @param i2c_obj pre-instantiated i2c object.
MikkoZ 8:dea50f607a45 30 */
MikkoZ 8:dea50f607a45 31 RegisterWriter(I2C &i2c_obj);
MikkoZ 8:dea50f607a45 32
MikkoZ 8:dea50f607a45 33 /**
MikkoZ 8:dea50f607a45 34 * Create a i2c instance which is connected to specified I2C pins.
MikkoZ 8:dea50f607a45 35 *
MikkoZ 8:dea50f607a45 36 * @param sda SDA pin
MikkoZ 8:dea50f607a45 37 * @param sdl SCL pin
MikkoZ 8:dea50f607a45 38 */
MikkoZ 8:dea50f607a45 39 RegisterWriter(PinName sda = I2C_SDA, PinName scl = I2C_SCL);
MikkoZ 8:dea50f607a45 40
MikkoZ 8:dea50f607a45 41 ~RegisterWriter();
MikkoZ 8:dea50f607a45 42
MikkoZ 8:dea50f607a45 43 /**
MikkoZ 9:51c7b97b6a7d 44 * General read @buf_len value(s) to @*buf from sensor @reg in address @sad.
MikkoZ 9:51c7b97b6a7d 45 * @param sad Slave address of sensor
MikkoZ 9:51c7b97b6a7d 46 * @param reg Register of sensor
MikkoZ 9:51c7b97b6a7d 47 * @param *buf uint8_t[@buf_len] for read data
MikkoZ 9:51c7b97b6a7d 48 * @param buf_len amount of data to read from @reg
MikkoZ 8:dea50f607a45 49 */
MikkoZ 8:dea50f607a45 50 uint8_t read_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len);
MikkoZ 9:51c7b97b6a7d 51
MikkoZ 9:51c7b97b6a7d 52 /**
MikkoZ 9:51c7b97b6a7d 53 * FIFO Read @buf_len value(s) to @*buf from sensor @reg in address @sad.
MikkoZ 9:51c7b97b6a7d 54 * Difference is the usage of stop-bit between commands.
MikkoZ 9:51c7b97b6a7d 55 * @param sad Slave address of sensor
MikkoZ 9:51c7b97b6a7d 56 * @param reg Register of sensor
MikkoZ 9:51c7b97b6a7d 57 * @param *buf uint8_t[@buf_len] for read data
MikkoZ 9:51c7b97b6a7d 58 * @param buf_len amount of data to read from @reg
MikkoZ 9:51c7b97b6a7d 59 */
MikkoZ 8:dea50f607a45 60 uint8_t read_fifo_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len);
MikkoZ 9:51c7b97b6a7d 61
MikkoZ 9:51c7b97b6a7d 62 /**
MikkoZ 9:51c7b97b6a7d 63 * Write @data_len value(s) from @*data to sensor @reg in address @sad.
MikkoZ 9:51c7b97b6a7d 64 * @param sad Slave address of sensor
MikkoZ 9:51c7b97b6a7d 65 * @param reg Register of sensor
MikkoZ 9:51c7b97b6a7d 66 * @param *data uint8_t[@data_len] for written data
MikkoZ 9:51c7b97b6a7d 67 * @param data_len amount of data to written to @reg
MikkoZ 9:51c7b97b6a7d 68 */
MikkoZ 8:dea50f607a45 69 void write_register(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len);
MikkoZ 9:51c7b97b6a7d 70
MikkoZ 9:51c7b97b6a7d 71 /**
MikkoZ 9:51c7b97b6a7d 72 * Write 1 value from @data to sensor @reg in address @sad.
MikkoZ 9:51c7b97b6a7d 73 * @param sad Slave address of sensor
MikkoZ 9:51c7b97b6a7d 74 * @param reg Register of sensor
MikkoZ 9:51c7b97b6a7d 75 * @param data to be written
MikkoZ 9:51c7b97b6a7d 76 */
MikkoZ 8:dea50f607a45 77 void write_register(uint8_t sad, uint8_t reg, uint8_t data);
MikkoZ 9:51c7b97b6a7d 78
MikkoZ 9:51c7b97b6a7d 79 /**
MikkoZ 9:51c7b97b6a7d 80 * Read-change-write register (@sad/@reg)
MikkoZ 9:51c7b97b6a7d 81 * @param sad Slave address of sensor
MikkoZ 9:51c7b97b6a7d 82 * @param reg Register of sensor
MikkoZ 9:51c7b97b6a7d 83 * @param mask bits to clear before applying new @bits
MikkoZ 9:51c7b97b6a7d 84 * @param bits value to write
MikkoZ 9:51c7b97b6a7d 85 */
MikkoZ 8:dea50f607a45 86 bool change_bits(uint8_t sad, uint8_t reg, uint8_t mask, uint8_t bits);
MikkoZ 8:dea50f607a45 87
MikkoZ 8:dea50f607a45 88 private:
MikkoZ 8:dea50f607a45 89 I2C i2c_bus;
MikkoZ 8:dea50f607a45 90 bool self_created_i2c;
MikkoZ 8:dea50f607a45 91 };
MikkoZ 8:dea50f607a45 92
MikkoZ 8:dea50f607a45 93
MikkoZ 8:dea50f607a45 94
MikkoZ 8:dea50f607a45 95
MikkoZ 8:dea50f607a45 96 #endif
MikkoZ 8:dea50f607a45 97
MikkoZ 8:dea50f607a45 98