BH1790GLC

Committer:
ThunderSoft
Date:
Thu Mar 21 08:52:45 2019 +0000
Revision:
1:e9033991d204
Add BH1790GLC code for TT_Mxx.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 1:e9033991d204 1 /*
ThunderSoft 1:e9033991d204 2 The MIT License (MIT)
ThunderSoft 1:e9033991d204 3 Copyright (c) 2017 Rohm Semiconductor
ThunderSoft 1:e9033991d204 4
ThunderSoft 1:e9033991d204 5 Permission is hereby granted, free of charge, to any person obtaining a
ThunderSoft 1:e9033991d204 6 copy of this software and associated documentation files (the
ThunderSoft 1:e9033991d204 7 "Software"), to deal in the Software without restriction, including
ThunderSoft 1:e9033991d204 8 without limitation the rights to use, copy, modify, merge, publish,
ThunderSoft 1:e9033991d204 9 distribute, sublicense, and/or sell copies of the Software, and to
ThunderSoft 1:e9033991d204 10 permit persons to whom the Software is furnished to do so, subject to
ThunderSoft 1:e9033991d204 11 the following conditions:
ThunderSoft 1:e9033991d204 12
ThunderSoft 1:e9033991d204 13 The above copyright notice and this permission notice shall be included
ThunderSoft 1:e9033991d204 14 in all copies or substantial portions of the Software.
ThunderSoft 1:e9033991d204 15
ThunderSoft 1:e9033991d204 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
ThunderSoft 1:e9033991d204 17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
ThunderSoft 1:e9033991d204 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
ThunderSoft 1:e9033991d204 19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
ThunderSoft 1:e9033991d204 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
ThunderSoft 1:e9033991d204 21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
ThunderSoft 1:e9033991d204 22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ThunderSoft 1:e9033991d204 23 */
ThunderSoft 1:e9033991d204 24
ThunderSoft 1:e9033991d204 25 #ifndef i2c_common_pp_h
ThunderSoft 1:e9033991d204 26 #define i2c_common_pp_h
ThunderSoft 1:e9033991d204 27
ThunderSoft 1:e9033991d204 28 #include "rohm_hal2.h" //types, DEBUG_print*, USE_*_HARDWARE_I2C
ThunderSoft 1:e9033991d204 29
ThunderSoft 1:e9033991d204 30 /**
ThunderSoft 1:e9033991d204 31 * RegisterWriter class for writing sensor registers via I2C object
ThunderSoft 1:e9033991d204 32 */
ThunderSoft 1:e9033991d204 33 class RegisterWriter
ThunderSoft 1:e9033991d204 34 {
ThunderSoft 1:e9033991d204 35 public:
ThunderSoft 1:e9033991d204 36 /**
ThunderSoft 1:e9033991d204 37 * Use pre-instantiated I2C instance for HAL.
ThunderSoft 1:e9033991d204 38 *
ThunderSoft 1:e9033991d204 39 * @param i2c_obj pre-instantiated i2c object.
ThunderSoft 1:e9033991d204 40 */
ThunderSoft 1:e9033991d204 41 RegisterWriter(I2C &i2c_obj);
ThunderSoft 1:e9033991d204 42
ThunderSoft 1:e9033991d204 43 /**
ThunderSoft 1:e9033991d204 44 * Create a i2c instance which is connected to specified I2C pins.
ThunderSoft 1:e9033991d204 45 *
ThunderSoft 1:e9033991d204 46 * @param sda SDA pin
ThunderSoft 1:e9033991d204 47 * @param sdl SCL pin
ThunderSoft 1:e9033991d204 48 */
ThunderSoft 1:e9033991d204 49 // RegisterWriter(PinName sda = I2C_SDA, PinName scl = I2C_SCL);
ThunderSoft 1:e9033991d204 50
ThunderSoft 1:e9033991d204 51 ~RegisterWriter();
ThunderSoft 1:e9033991d204 52
ThunderSoft 1:e9033991d204 53 /**
ThunderSoft 1:e9033991d204 54 * General read @buf_len value(s) to @*buf from sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 55 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 56 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 57 * @param *buf uint8_t[@buf_len] for read data
ThunderSoft 1:e9033991d204 58 * @param buf_len amount of data to read from @reg
ThunderSoft 1:e9033991d204 59 */
ThunderSoft 1:e9033991d204 60 uint8_t read_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len = 1);
ThunderSoft 1:e9033991d204 61
ThunderSoft 1:e9033991d204 62 /**
ThunderSoft 1:e9033991d204 63 * FIFO Read @buf_len value(s) to @*buf from sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 64 * Difference is the usage of stop-bit between commands.
ThunderSoft 1:e9033991d204 65 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 66 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 67 * @param *buf uint8_t[@buf_len] for read data
ThunderSoft 1:e9033991d204 68 * @param buf_len amount of data to read from @reg
ThunderSoft 1:e9033991d204 69 */
ThunderSoft 1:e9033991d204 70 uint8_t read_fifo_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len);
ThunderSoft 1:e9033991d204 71
ThunderSoft 1:e9033991d204 72 /**
ThunderSoft 1:e9033991d204 73 * Read @buf_len value(s) in high speed to @*buf from sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 74 * Reference to kx123 specification page 24, hs 3.4mhZ mode.
ThunderSoft 1:e9033991d204 75 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 76 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 77 * @param *buf uint8_t[@buf_len] for read data
ThunderSoft 1:e9033991d204 78 * @param buf_len amount of data to read from @reg
ThunderSoft 1:e9033991d204 79 */
ThunderSoft 1:e9033991d204 80 uint8_t hs_read_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len);
ThunderSoft 1:e9033991d204 81
ThunderSoft 1:e9033991d204 82 /**
ThunderSoft 1:e9033991d204 83 * Write @data_len value(s) from @*data to sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 84 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 85 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 86 * @param *data uint8_t[@data_len] for written data
ThunderSoft 1:e9033991d204 87 * @param data_len amount of data to written to @reg
ThunderSoft 1:e9033991d204 88 */
ThunderSoft 1:e9033991d204 89 bool write_register(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len);
ThunderSoft 1:e9033991d204 90 bool write_register_single(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len);
ThunderSoft 1:e9033991d204 91 bool write_register_separate(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len);
ThunderSoft 1:e9033991d204 92
ThunderSoft 1:e9033991d204 93 /**
ThunderSoft 1:e9033991d204 94 * Write 1 value from @data to sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 95 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 96 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 97 * @param data to be written
ThunderSoft 1:e9033991d204 98 */
ThunderSoft 1:e9033991d204 99 bool write_register(uint8_t sad, uint8_t reg, uint8_t data);
ThunderSoft 1:e9033991d204 100
ThunderSoft 1:e9033991d204 101 /**
ThunderSoft 1:e9033991d204 102 * Write @data_len value(s) in high speed from @*data to sensor @reg in address @sad.
ThunderSoft 1:e9033991d204 103 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 104 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 105 * @param *data uint8_t[@data_len] for written data
ThunderSoft 1:e9033991d204 106 * @param data_len amount of data to written to @reg
ThunderSoft 1:e9033991d204 107 */
ThunderSoft 1:e9033991d204 108 bool hs_write_register(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len);
ThunderSoft 1:e9033991d204 109
ThunderSoft 1:e9033991d204 110 /**
ThunderSoft 1:e9033991d204 111 * Read-change-write register (@sad/@reg)
ThunderSoft 1:e9033991d204 112 * @param sad Slave address of sensor
ThunderSoft 1:e9033991d204 113 * @param reg Register of sensor
ThunderSoft 1:e9033991d204 114 * @param mask bits to clear before applying new @bits
ThunderSoft 1:e9033991d204 115 * @param bits value to write
ThunderSoft 1:e9033991d204 116 * @return true on error, false on ok
ThunderSoft 1:e9033991d204 117 */
ThunderSoft 1:e9033991d204 118 bool change_bits(uint8_t sad, uint8_t reg, uint8_t mask, uint8_t bits);
ThunderSoft 1:e9033991d204 119
ThunderSoft 1:e9033991d204 120 private:
ThunderSoft 1:e9033991d204 121 I2C &i2c_bus;
ThunderSoft 1:e9033991d204 122 bool self_created_i2c;
ThunderSoft 1:e9033991d204 123 bool write_single; //Single command write or two command write
ThunderSoft 1:e9033991d204 124
ThunderSoft 1:e9033991d204 125 void set_hs_mode_for_one_command();
ThunderSoft 1:e9033991d204 126
ThunderSoft 1:e9033991d204 127 };
ThunderSoft 1:e9033991d204 128
ThunderSoft 1:e9033991d204 129
ThunderSoft 1:e9033991d204 130
ThunderSoft 1:e9033991d204 131
ThunderSoft 1:e9033991d204 132 #endif
ThunderSoft 1:e9033991d204 133
ThunderSoft 1:e9033991d204 134
ThunderSoft 1:e9033991d204 135