Arduino AudioKit HAL
i2c_bus.h
1 /*
2  * ESPRESSIF MIT License
3  *
4  * Copyright (c) 2017 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 #ifndef _IOT_I2C_BUS_H_
25 #define _IOT_I2C_BUS_H_
26 
27 #ifdef ESP32
28 #include "driver/i2c.h"
29 #else
30 #include "audio_error.h"
31 #include "board_pins_config.h"
32 #define GPIO_PULLUP_ENABLE 1
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 typedef void *i2c_bus_handle_t;
39 
40 #ifndef ESP32
41 typedef int portBASE_TYPE;
42 typedef void* i2c_cmd_handle_t;
43 #endif
44 
45 /**
46  * @brief Create and init I2C bus and return a I2C bus handle
47  *
48  * @param port I2C port number
49  * @param conf Pointer to I2C parameters
50  *
51  * @return
52  * - I2C bus handle
53  */
54 i2c_bus_handle_t i2c_bus_create(i2c_port_t port, i2c_config_t *conf);
55 
56 /**
57  * @brief Write bytes to I2C bus
58  *
59  * @param bus I2C bus handle
60  * @param addr The address of the device
61  * @param reg The register of the device
62  * @param regLen The length of register
63  * @param data The data pointer
64  * @param datalen The length of data
65  *
66  * @return
67  * - NULL Fail
68  * - Others Success
69  */
70 esp_err_t i2c_bus_write_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg, int regLen, uint8_t *data, int datalen);
71 
72 /**
73  * @brief Write data to I2C bus
74  *
75  * @param bus I2C bus handle
76  * @param addr The address of the device
77  * @param data The data pointer
78  * @param datalen The length of data
79  *
80  * @return
81  * - NULL Fail
82  * - Others Success
83  */
84 esp_err_t i2c_bus_write_data(i2c_bus_handle_t bus, int addr, uint8_t *data, int datalen);
85 
86 /**
87  * @brief Read bytes to I2C bus
88  *
89  * @param bus I2C bus handle
90  * @param addr The address of the device
91  * @param reg The register of the device
92  * @param regLen The length of register
93  * @param outdata The outdata pointer
94  * @param datalen The length of outdata
95  *
96  * @return
97  * - NULL Fail
98  * - Others Success
99  */
100 esp_err_t i2c_bus_read_bytes(i2c_bus_handle_t bus, int addr, uint8_t *reg, int reglen, uint8_t *outdata, int datalen);
101 
102 /**
103  * @brief Delete and release the I2C bus object
104  *
105  * @param bus I2C bus handle
106  *
107  * @return
108  * - ESP_OK Success
109  * - ESP_FAIL Fail
110  */
111 esp_err_t i2c_bus_delete(i2c_bus_handle_t bus);
112 
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif
I2C pins.
Definition: audio_gpio.h:102