Skip to content

Commit

Permalink
Merge pull request #6 from esp-cpp/feature/peripheral-api-refactor
Browse files Browse the repository at this point in the history
feat(periphreals): update espp submodule
  • Loading branch information
finger563 authored Nov 6, 2023
2 parents c3f82b2 + a160697 commit 38087b9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 194 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_compile_definitions(BOARD_HAS_PSRAM)

set(
COMPONENTS
"main esptool_py esp_psram esp_littlefs task format monitor wifi bm8563 battery esp32-camera socket math led rtsp mdns"
"main esptool_py esp_psram esp_littlefs task format monitor wifi bm8563 battery esp32-camera socket math led rtsp mdns i2c"
CACHE STRING
"List of components to include"
)
Expand Down
4 changes: 0 additions & 4 deletions components/bm8563/CMakeLists.txt

This file was deleted.

147 changes: 0 additions & 147 deletions components/bm8563/include/bm8563.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion components/espp
Submodule espp updated 214 files
57 changes: 16 additions & 41 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#include <chrono>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

#include "driver/i2c.h"
#include "esp_heap_caps.h"
#include "mdns.h"
#include "nvs_flash.h"
#include <esp_heap_caps.h>
#include <mdns.h>
#include <nvs_flash.h>

#include "format.hpp"
#include "gaussian.hpp"
#include "i2c.hpp"
#include "led.hpp"
#include "oneshot_adc.hpp"
#include "task.hpp"
Expand Down Expand Up @@ -154,44 +154,19 @@ extern "C" void app_main(void) {

// initialize the i2c bus (for RTC)
logger.info("Initializing I2C");
i2c_config_t i2c_cfg;
memset(&i2c_cfg, 0, sizeof(i2c_cfg));
i2c_cfg.sda_io_num = GPIO_NUM_12;
i2c_cfg.scl_io_num = GPIO_NUM_14;
i2c_cfg.mode = I2C_MODE_MASTER;
i2c_cfg.sda_pullup_en = GPIO_PULLUP_ENABLE;
i2c_cfg.scl_pullup_en = GPIO_PULLUP_ENABLE;
i2c_cfg.master.clk_speed = (400*1000);
err = i2c_param_config(I2C_NUM_0, &i2c_cfg);
if (err != ESP_OK)
logger.error("config i2c failed {} '{}'", err, esp_err_to_name(err));
err = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
if (err != ESP_OK)
logger.error("install i2c driver failed {} '{}'", err, esp_err_to_name(err));
static const int I2C_TIMEOUT_MS = 10;
auto bm8563_write = [](uint8_t *write_data, size_t write_len) {
i2c_master_write_to_device(I2C_NUM_0,
Bm8563::ADDRESS,
write_data,
write_len,
I2C_TIMEOUT_MS / portTICK_PERIOD_MS);
};
auto bm8563_read = [](uint8_t reg_addr, uint8_t *read_data, size_t read_len) {
i2c_master_write_read_device(I2C_NUM_0,
Bm8563::ADDRESS,
&reg_addr,
1, // size of addr
read_data,
read_len,
I2C_TIMEOUT_MS / portTICK_PERIOD_MS);

};
espp::I2c i2c({
.port = I2C_NUM_0,
.sda_io_num = GPIO_NUM_12,
.scl_io_num = GPIO_NUM_14,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
});

// initialize RTC
logger.info("Initializing RTC");
Bm8563 bm8563(Bm8563::Config{
.write = bm8563_write,
.read = bm8563_read,
espp::Bm8563 bm8563({
.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3),
.read = std::bind(&espp::I2c::read_at_register, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
.log_level = espp::Logger::Verbosity::WARN
});

Expand Down

0 comments on commit 38087b9

Please sign in to comment.