forked from espressif/esp-iot-solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(cpp): add cpp code for I2C devices
- Loading branch information
Showing
35 changed files
with
1,468 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* ESPRESSIF MIT License | ||
* | ||
* Copyright (c) 2017 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD> | ||
* | ||
* Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, | ||
* it is free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished | ||
* to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "esp_log.h" | ||
#include "driver/i2c.h" | ||
#include "i2c_bus.h" | ||
|
||
CI2CBus::CI2CBus(i2c_port_t i2c_port, gpio_num_t scl_io, gpio_num_t sda_io, i2c_mode_t i2c_mode, int clk_hz) | ||
{ | ||
i2c_config_t conf; | ||
conf.mode = i2c_mode; | ||
conf.scl_io_num = scl_io; | ||
conf.sda_io_num = sda_io; | ||
conf.scl_pullup_en = GPIO_PULLUP_ENABLE; | ||
conf.sda_pullup_en = GPIO_PULLUP_ENABLE; | ||
conf.master.clk_speed = clk_hz; | ||
m_i2c_bus_handle = i2c_bus_create(i2c_port, &conf); | ||
} | ||
|
||
CI2CBus::~CI2CBus() | ||
{ | ||
i2c_bus_delete(m_i2c_bus_handle); | ||
m_i2c_bus_handle = NULL; | ||
} | ||
|
||
esp_err_t CI2CBus::send(i2c_cmd_handle_t cmd, portBASE_TYPE ticks_to_wait) | ||
{ | ||
return i2c_bus_cmd_begin(m_i2c_bus_handle, cmd, ticks_to_wait); | ||
} | ||
|
||
i2c_bus_handle_t CI2CBus::get_bus_handle() | ||
{ | ||
return m_i2c_bus_handle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.