bolar_2 backup
This commit is contained in:
63
main/platform/borla_s3/i2c_bus.cc
Normal file
63
main/platform/borla_s3/i2c_bus.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "platform/borla_s3/i2c_bus.h"
|
||||
|
||||
#include "platform/borla_s3/board_config.h"
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/rtc_io.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
namespace borla {
|
||||
namespace {
|
||||
|
||||
constexpr const char* kTag = "BorlaI2cBus2";
|
||||
|
||||
} // namespace
|
||||
|
||||
BorlaS3I2cBus::~BorlaS3I2cBus()
|
||||
{
|
||||
if (handle_ != nullptr) {
|
||||
i2c_del_master_bus(handle_);
|
||||
}
|
||||
}
|
||||
|
||||
bool BorlaS3I2cBus::Initialize()
|
||||
{
|
||||
if (handle_ != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
gpio_hold_dis(board_config::kAudioI2cSdaGpio);
|
||||
gpio_hold_dis(board_config::kAudioI2cSclGpio);
|
||||
rtc_gpio_hold_dis(board_config::kAudioI2cSdaGpio);
|
||||
rtc_gpio_hold_dis(board_config::kAudioI2cSclGpio);
|
||||
|
||||
const i2c_master_bus_config_t config = {
|
||||
.i2c_port = I2C_NUM_0,
|
||||
.sda_io_num = board_config::kAudioI2cSdaGpio,
|
||||
.scl_io_num = board_config::kAudioI2cSclGpio,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
//.enable_internal_pullup = true,
|
||||
.enable_internal_pullup = false,
|
||||
.allow_pd = false,
|
||||
},
|
||||
};
|
||||
const esp_err_t result = i2c_new_master_bus(&config, &handle_);
|
||||
if (result != ESP_OK) {
|
||||
ESP_LOGE(kTag, "bus initialization failed: %s",
|
||||
esp_err_to_name(result));
|
||||
handle_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGI(kTag, "I2C0 initialized SDA=%d SCL=%d",
|
||||
static_cast<int>(board_config::kAudioI2cSdaGpio),
|
||||
static_cast<int>(board_config::kAudioI2cSclGpio));
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace borla
|
||||
Reference in New Issue
Block a user