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
RegisterWriter/RegisterWriter.h@8:dea50f607a45, 2016-09-29 (annotated)
- Committer:
- MikkoZ
- Date:
- Thu Sep 29 15:10:08 2016 +0000
- Revision:
- 8:dea50f607a45
- Child:
- 9:51c7b97b6a7d
Initial version of C++ RegisterWriter. Code ported from 'C'-library rohm-sensor-hal.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 8:dea50f607a45 | 20 | class RegisterWriter |
| MikkoZ | 8:dea50f607a45 | 21 | { |
| MikkoZ | 8:dea50f607a45 | 22 | public: |
| MikkoZ | 8:dea50f607a45 | 23 | /** |
| MikkoZ | 8:dea50f607a45 | 24 | * Use pre-instantiated I2C instance for hal. |
| MikkoZ | 8:dea50f607a45 | 25 | * |
| MikkoZ | 8:dea50f607a45 | 26 | * @param i2c_obj pre-instantiated i2c object. |
| MikkoZ | 8:dea50f607a45 | 27 | */ |
| MikkoZ | 8:dea50f607a45 | 28 | RegisterWriter(I2C &i2c_obj); |
| MikkoZ | 8:dea50f607a45 | 29 | |
| MikkoZ | 8:dea50f607a45 | 30 | /** |
| MikkoZ | 8:dea50f607a45 | 31 | * Create a i2c instance which is connected to specified I2C pins. |
| MikkoZ | 8:dea50f607a45 | 32 | * |
| MikkoZ | 8:dea50f607a45 | 33 | * @param sda SDA pin |
| MikkoZ | 8:dea50f607a45 | 34 | * @param sdl SCL pin |
| MikkoZ | 8:dea50f607a45 | 35 | */ |
| MikkoZ | 8:dea50f607a45 | 36 | RegisterWriter(PinName sda = I2C_SDA, PinName scl = I2C_SCL); |
| MikkoZ | 8:dea50f607a45 | 37 | |
| MikkoZ | 8:dea50f607a45 | 38 | /** |
| MikkoZ | 8:dea50f607a45 | 39 | * RegisterWriter destructor |
| MikkoZ | 8:dea50f607a45 | 40 | */ |
| MikkoZ | 8:dea50f607a45 | 41 | ~RegisterWriter(); |
| MikkoZ | 8:dea50f607a45 | 42 | |
| MikkoZ | 8:dea50f607a45 | 43 | /** |
| MikkoZ | 8:dea50f607a45 | 44 | * read/write commands for sensor registers |
| MikkoZ | 8:dea50f607a45 | 45 | */ |
| MikkoZ | 8:dea50f607a45 | 46 | uint8_t read_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len); |
| MikkoZ | 8:dea50f607a45 | 47 | uint8_t read_fifo_register(uint8_t sad, uint8_t reg, uint8_t* buf, uint8_t buf_len); |
| MikkoZ | 8:dea50f607a45 | 48 | void write_register(uint8_t sad, uint8_t reg, uint8_t* data, uint8_t data_len); |
| MikkoZ | 8:dea50f607a45 | 49 | void write_register(uint8_t sad, uint8_t reg, uint8_t data); |
| MikkoZ | 8:dea50f607a45 | 50 | bool change_bits(uint8_t sad, uint8_t reg, uint8_t mask, uint8_t bits); |
| MikkoZ | 8:dea50f607a45 | 51 | |
| MikkoZ | 8:dea50f607a45 | 52 | private: |
| MikkoZ | 8:dea50f607a45 | 53 | I2C i2c_bus; |
| MikkoZ | 8:dea50f607a45 | 54 | bool self_created_i2c; |
| MikkoZ | 8:dea50f607a45 | 55 | }; |
| MikkoZ | 8:dea50f607a45 | 56 | |
| MikkoZ | 8:dea50f607a45 | 57 | |
| MikkoZ | 8:dea50f607a45 | 58 | |
| MikkoZ | 8:dea50f607a45 | 59 | |
| MikkoZ | 8:dea50f607a45 | 60 | #endif |
| MikkoZ | 8:dea50f607a45 | 61 | |
| MikkoZ | 8:dea50f607a45 | 62 |
