i2c_device (#7641)

This commit is contained in:
Gábor Poczkodi 2024-10-23 05:23:10 +02:00 committed by GitHub
parent 68844c4869
commit dd8d25e43f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 110 additions and 0 deletions

View File

@ -198,6 +198,7 @@ esphome/components/htu31d/* @betterengineering
esphome/components/hydreon_rgxx/* @functionpointer
esphome/components/hyt271/* @Philippe12
esphome/components/i2c/* @esphome/core
esphome/components/i2c_device/* @gabest11
esphome/components/i2s_audio/* @jesserockz
esphome/components/i2s_audio/media_player/* @jesserockz
esphome/components/i2s_audio/microphone/* @jesserockz

View File

@ -0,0 +1,26 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_ID
DEPENDENCIES = ["i2c"]
CODEOWNERS = ["@gabest11"]
MULTI_CONF = True
i2c_device_ns = cg.esphome_ns.namespace("i2c_device")
I2CDeviceComponent = i2c_device_ns.class_(
"I2CDeviceComponent", cg.Component, i2c.I2CDevice
)
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_ID): cv.declare_id(I2CDeviceComponent),
}
).extend(i2c.i2c_device_schema(None))
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)

View File

@ -0,0 +1,17 @@
#include "i2c_device.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
#include <cinttypes>
namespace esphome {
namespace i2c_device {
static const char *const TAG = "i2c_device";
void I2CDeviceComponent::dump_config() {
ESP_LOGCONFIG(TAG, "I2CDevice");
LOG_I2C_DEVICE(this);
}
} // namespace i2c_device
} // namespace esphome

View File

@ -0,0 +1,18 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace i2c_device {
class I2CDeviceComponent : public Component, public i2c::I2CDevice {
public:
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
};
} // namespace i2c_device
} // namespace esphome

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 16
sda: 17
i2c_device:
id: i2cdev
address: 0x2C

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 5
sda: 4
i2c_device:
id: i2cdev
address: 0x2C

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 5
sda: 4
i2c_device:
id: i2cdev
address: 0x2C

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 16
sda: 17
i2c_device:
id: i2cdev
address: 0x2C

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 5
sda: 4
i2c_device:
id: i2cdev
address: 0x2C

View File

@ -0,0 +1,8 @@
i2c:
- id: i2c_i2c
scl: 5
sda: 4
i2c_device:
id: i2cdev
address: 0x2C