mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 02:32:20 +01:00
BME280 SPI (#5538)
* bme spi finally * linter * CO * tidy * lint * tidy [2] * tidy[-1] * final solution * Update test1.yaml remove failed test * Update test1.1.yaml add test to another file with free GPIO5 pin * fix spi read bytes * fix tests * rename bme280 to bme280_i2c
This commit is contained in:
0
esphome/components/bme280_i2c/__init__.py
Normal file
0
esphome/components/bme280_i2c/__init__.py
Normal file
30
esphome/components/bme280_i2c/bme280_i2c.cpp
Normal file
30
esphome/components/bme280_i2c/bme280_i2c.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "bme280_i2c.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "../bme280_base/bme280_base.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace bme280_i2c {
|
||||
|
||||
bool BME280I2CComponent::read_byte(uint8_t a_register, uint8_t *data) {
|
||||
return I2CDevice::read_byte(a_register, data);
|
||||
};
|
||||
bool BME280I2CComponent::write_byte(uint8_t a_register, uint8_t data) {
|
||||
return I2CDevice::write_byte(a_register, data);
|
||||
};
|
||||
bool BME280I2CComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
|
||||
return I2CDevice::read_bytes(a_register, data, len);
|
||||
};
|
||||
bool BME280I2CComponent::read_byte_16(uint8_t a_register, uint16_t *data) {
|
||||
return I2CDevice::read_byte_16(a_register, data);
|
||||
};
|
||||
|
||||
void BME280I2CComponent::dump_config() {
|
||||
LOG_I2C_DEVICE(this);
|
||||
BME280Component::dump_config();
|
||||
}
|
||||
|
||||
} // namespace bme280_i2c
|
||||
} // namespace esphome
|
20
esphome/components/bme280_i2c/bme280_i2c.h
Normal file
20
esphome/components/bme280_i2c/bme280_i2c.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/bme280_base/bme280_base.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace bme280_i2c {
|
||||
|
||||
static const char *const TAG = "bme280_i2c.sensor";
|
||||
|
||||
class BME280I2CComponent : public esphome::bme280_base::BME280Component, public i2c::I2CDevice {
|
||||
bool read_byte(uint8_t a_register, uint8_t *data) override;
|
||||
bool write_byte(uint8_t a_register, uint8_t data) override;
|
||||
bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) override;
|
||||
bool read_byte_16(uint8_t a_register, uint16_t *data) override;
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
} // namespace bme280_i2c
|
||||
} // namespace esphome
|
19
esphome/components/bme280_i2c/sensor.py
Normal file
19
esphome/components/bme280_i2c/sensor.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import i2c
|
||||
from ..bme280_base.sensor import to_code as to_code_base, cv, CONFIG_SCHEMA_BASE
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
AUTO_LOAD = ["bme280_base"]
|
||||
|
||||
bme280_ns = cg.esphome_ns.namespace("bme280_i2c")
|
||||
BME280I2CComponent = bme280_ns.class_(
|
||||
"BME280I2CComponent", cg.PollingComponent, i2c.I2CDevice
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend(
|
||||
i2c.i2c_device_schema(default_address=0x77)
|
||||
).extend({cv.GenerateID(): cv.declare_id(BME280I2CComponent)})
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
await to_code_base(config, func=i2c.register_i2c_device)
|
Reference in New Issue
Block a user