Skip to content

Commit 38087b9

Browse files
authored
Merge pull request #6 from esp-cpp/feature/peripheral-api-refactor
feat(periphreals): update espp submodule
2 parents c3f82b2 + a160697 commit 38087b9

File tree

5 files changed

+18
-194
lines changed

5 files changed

+18
-194
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_compile_definitions(BOARD_HAS_PSRAM)
1414

1515
set(
1616
COMPONENTS
17-
"main esptool_py esp_psram esp_littlefs task format monitor wifi bm8563 battery esp32-camera socket math led rtsp mdns"
17+
"main esptool_py esp_psram esp_littlefs task format monitor wifi bm8563 battery esp32-camera socket math led rtsp mdns i2c"
1818
CACHE STRING
1919
"List of components to include"
2020
)

components/bm8563/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

components/bm8563/include/bm8563.hpp

Lines changed: 0 additions & 147 deletions
This file was deleted.

components/espp

Submodule espp updated 214 files

main/main.cpp

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
#include <chrono>
44

5-
#include "freertos/FreeRTOS.h"
6-
#include "freertos/task.h"
5+
#include <freertos/FreeRTOS.h>
6+
#include <freertos/task.h>
77

8-
#include "driver/i2c.h"
9-
#include "esp_heap_caps.h"
10-
#include "mdns.h"
11-
#include "nvs_flash.h"
8+
#include <esp_heap_caps.h>
9+
#include <mdns.h>
10+
#include <nvs_flash.h>
1211

1312
#include "format.hpp"
1413
#include "gaussian.hpp"
14+
#include "i2c.hpp"
1515
#include "led.hpp"
1616
#include "oneshot_adc.hpp"
1717
#include "task.hpp"
@@ -154,44 +154,19 @@ extern "C" void app_main(void) {
154154

155155
// initialize the i2c bus (for RTC)
156156
logger.info("Initializing I2C");
157-
i2c_config_t i2c_cfg;
158-
memset(&i2c_cfg, 0, sizeof(i2c_cfg));
159-
i2c_cfg.sda_io_num = GPIO_NUM_12;
160-
i2c_cfg.scl_io_num = GPIO_NUM_14;
161-
i2c_cfg.mode = I2C_MODE_MASTER;
162-
i2c_cfg.sda_pullup_en = GPIO_PULLUP_ENABLE;
163-
i2c_cfg.scl_pullup_en = GPIO_PULLUP_ENABLE;
164-
i2c_cfg.master.clk_speed = (400*1000);
165-
err = i2c_param_config(I2C_NUM_0, &i2c_cfg);
166-
if (err != ESP_OK)
167-
logger.error("config i2c failed {} '{}'", err, esp_err_to_name(err));
168-
err = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
169-
if (err != ESP_OK)
170-
logger.error("install i2c driver failed {} '{}'", err, esp_err_to_name(err));
171-
static const int I2C_TIMEOUT_MS = 10;
172-
auto bm8563_write = [](uint8_t *write_data, size_t write_len) {
173-
i2c_master_write_to_device(I2C_NUM_0,
174-
Bm8563::ADDRESS,
175-
write_data,
176-
write_len,
177-
I2C_TIMEOUT_MS / portTICK_PERIOD_MS);
178-
};
179-
auto bm8563_read = [](uint8_t reg_addr, uint8_t *read_data, size_t read_len) {
180-
i2c_master_write_read_device(I2C_NUM_0,
181-
Bm8563::ADDRESS,
182-
&reg_addr,
183-
1, // size of addr
184-
read_data,
185-
read_len,
186-
I2C_TIMEOUT_MS / portTICK_PERIOD_MS);
187-
188-
};
157+
espp::I2c i2c({
158+
.port = I2C_NUM_0,
159+
.sda_io_num = GPIO_NUM_12,
160+
.scl_io_num = GPIO_NUM_14,
161+
.sda_pullup_en = GPIO_PULLUP_ENABLE,
162+
.scl_pullup_en = GPIO_PULLUP_ENABLE,
163+
});
189164

190165
// initialize RTC
191166
logger.info("Initializing RTC");
192-
Bm8563 bm8563(Bm8563::Config{
193-
.write = bm8563_write,
194-
.read = bm8563_read,
167+
espp::Bm8563 bm8563({
168+
.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
169+
.read = std::bind(&espp::I2c::read_at_register, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
195170
.log_level = espp::Logger::Verbosity::WARN
196171
});
197172

0 commit comments

Comments
 (0)