mirror of
https://github.com/esphome/esphome.git
synced 2024-12-11 07:54:54 +01:00
38 lines
946 B
C
38 lines
946 B
C
|
#pragma once
|
||
|
|
||
|
#ifdef USE_ARDUINO
|
||
|
|
||
|
#include "i2c_bus.h"
|
||
|
#include "esphome/core/component.h"
|
||
|
#include <Wire.h>
|
||
|
|
||
|
namespace esphome {
|
||
|
namespace i2c {
|
||
|
|
||
|
class ArduinoI2CBus : public I2CBus, public Component {
|
||
|
public:
|
||
|
void setup() override;
|
||
|
void dump_config() override;
|
||
|
ErrorCode readv(uint8_t address, ReadBuffer *buffers, size_t cnt) override;
|
||
|
ErrorCode writev(uint8_t address, WriteBuffer *buffers, size_t cnt) override;
|
||
|
float get_setup_priority() const override { return setup_priority::BUS; }
|
||
|
|
||
|
void set_scan(bool scan) { scan_ = scan; }
|
||
|
void set_sda_pin(uint8_t sda_pin) { sda_pin_ = sda_pin; }
|
||
|
void set_scl_pin(uint8_t scl_pin) { scl_pin_ = scl_pin; }
|
||
|
void set_frequency(uint32_t frequency) { frequency_ = frequency; }
|
||
|
|
||
|
protected:
|
||
|
TwoWire *wire_;
|
||
|
bool scan_;
|
||
|
uint8_t sda_pin_;
|
||
|
uint8_t scl_pin_;
|
||
|
uint32_t frequency_;
|
||
|
bool initialized_ = false;
|
||
|
};
|
||
|
|
||
|
} // namespace i2c
|
||
|
} // namespace esphome
|
||
|
|
||
|
#endif // USE_ARDUINO
|