1
+ /* =========================================================================
2
+ I2Cbus library is placed under the MIT License
3
+ Copyright 2017 Natanael Josue Rabello. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to
7
+ deal in the Software without restriction, including without limitation the
8
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9
+ sell copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
+ IN THE SOFTWARE.
22
+ ========================================================================= */
23
+
1
24
#ifndef _I2CBUS_HPP_
2
25
#define _I2CBUS_HPP_
3
26
27
+ #include < stdint.h>
4
28
#include " driver/i2c.h"
5
29
#include " driver/gpio.h"
6
30
#include " esp_err.h"
@@ -25,7 +49,9 @@ extern I2Cbus_t I2Cbus0; /*!< port: I2C_NUM_0 */
25
49
extern I2Cbus_t I2Cbus1; /* !< port: I2C_NUM_1 */
26
50
27
51
28
-
52
+ /* ^^^^^^
53
+ * I2CBUS
54
+ * ^^^^^^ */
29
55
class I2Cbus_t {
30
56
private:
31
57
i2c_port_t port; /* !< I2C port: I2C_NUM_0 or I2C_NUM_1 */
@@ -47,8 +73,10 @@ class I2Cbus_t {
47
73
* - ESP_ERR_INVALID_ARG Parameter error
48
74
* - ESP_FAIL Driver install error
49
75
*/
50
- esp_err_t begin (gpio_num_t sda_io_num, gpio_num_t scl_io_num, uint32_t clk_speed = I2CBUS_CLOCKSPEED_DEFAULT);
51
- esp_err_t begin (gpio_num_t sda_io_num, gpio_num_t scl_io_num,
76
+ esp_err_t begin (gpio_num_t sda_io_num, gpio_num_t scl_io_num,
77
+ uint32_t clk_speed = I2CBUS_CLOCKSPEED_DEFAULT);
78
+
79
+ esp_err_t begin (gpio_num_t sda_io_num, gpio_num_t scl_io_num,
52
80
gpio_pullup_t sda_pullup_en, gpio_pullup_t scl_pullup_en,
53
81
uint32_t clk_speed = I2CBUS_CLOCKSPEED_DEFAULT);
54
82
@@ -67,12 +95,15 @@ class I2Cbus_t {
67
95
* *** WRITING interface ***
68
96
* @brief I2C commands for writing to a 8-bit slave device register.
69
97
* All of them returns standard esp_err_t codes. So it can be used
70
- * within ESP_ERROR_CHECK();
98
+ * with ESP_ERROR_CHECK();
71
99
* @param devAddr [I2C slave device register]
72
- * @param regAddr [Register address to write to]
73
- * @param bit [Number of the bit position to write (bit 7~0)]
100
+ * @param regAddr [Register address to write to]
101
+ * @param bitNum [Bit position number to write to (bit 7~0)]
102
+ * @param bitStart [Start bit number when writing a bit-sequence (MSB)]
74
103
* @param data [Value(s) to be write to the register]
75
104
* @param length [Number of bytes to write (should be within the data buffer size)]
105
+ * [writeBits() -> Number of bits after bitStart (including)]
106
+ * @param timeout [Custom timeout for the particular call]
76
107
* @return - ESP_OK Success
77
108
* - ESP_ERR_INVALID_ARG Parameter error
78
109
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
@@ -88,12 +119,14 @@ class I2Cbus_t {
88
119
* *** READING interface ***
89
120
* @breif I2C commands for reading a 8-bit slave device register.
90
121
* All of them returns standard esp_err_t codes.So it can be used
91
- * within ESP_ERROR_CHECK();
122
+ * with ESP_ERROR_CHECK();
92
123
* @param devAddr [I2C slave device register]
93
- * @param regAddr [Register address to read from]
94
- * @param bit [Number of the bit position to write (bit 7~0)]
95
- * @param data [Buffer to store the read data(s)]
124
+ * @param regAddr [Register address to read from]
125
+ * @param bitNum [Bit position number to write to (bit 7~0)]
126
+ * @param bitStart [Start bit number when writing a bit-sequence (MSB)]
127
+ * @param data [Buffer to store the read value(s)]
96
128
* @param length [Number of bytes to read (should be within the data buffer size)]
129
+ * @param timeout [Custom timeout for the particular call]
97
130
* @return - ESP_OK Success
98
131
* - ESP_ERR_INVALID_ARG Parameter error
99
132
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
@@ -107,7 +140,8 @@ class I2Cbus_t {
107
140
108
141
/* *
109
142
* @brief Quick check to see if a slave device responds.
110
- * @param devAddr [I2C slave device register]
143
+ * @param devAddr [I2C slave device register]
144
+ * @param timeout [Custom timeout for the particular call]
111
145
* @return - ESP_OK Success
112
146
* - ESP_ERR_INVALID_ARG Parameter error
113
147
* - ESP_FAIL Sending command error, slave doesn't ACK the transfer.
@@ -124,8 +158,4 @@ class I2Cbus_t {
124
158
125
159
126
160
127
-
128
-
129
-
130
-
131
161
#endif /* end of include guard: _I2CBUS_H_ */
0 commit comments