mirror of
https://github.com/esphome/esphome.git
synced 2025-03-02 04:01:43 +01:00
[io_bus] Initial implementation (#8227)
This commit is contained in:
parent
74a25a7e76
commit
f11ad9ad5b
@ -226,6 +226,7 @@ esphome/components/inkplate6/* @jesserockz
|
|||||||
esphome/components/integration/* @OttoWinter
|
esphome/components/integration/* @OttoWinter
|
||||||
esphome/components/internal_temperature/* @Mat931
|
esphome/components/internal_temperature/* @Mat931
|
||||||
esphome/components/interval/* @esphome/core
|
esphome/components/interval/* @esphome/core
|
||||||
|
esphome/components/io_bus/* @clydebarrow
|
||||||
esphome/components/jsn_sr04t/* @Mafus1
|
esphome/components/jsn_sr04t/* @Mafus1
|
||||||
esphome/components/json/* @OttoWinter
|
esphome/components/json/* @OttoWinter
|
||||||
esphome/components/kamstrup_kmp/* @cfeenstra1024
|
esphome/components/kamstrup_kmp/* @cfeenstra1024
|
||||||
|
8
esphome/components/io_bus/__init__.py
Normal file
8
esphome/components/io_bus/__init__.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
|
||||||
|
io_bus_ns = cg.esphome_ns.namespace("io_bus")
|
||||||
|
IOBus = io_bus_ns.class_("IOBus")
|
||||||
|
|
||||||
|
CODEOWNERS = ["@clydebarrow"]
|
||||||
|
# Allow configuration in yaml, for testing
|
||||||
|
CONFIG_SCHEMA = {}
|
73
esphome/components/io_bus/io_bus.h
Normal file
73
esphome/components/io_bus/io_bus.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "esphome/core/log.h"
|
||||||
|
#include "esphome/core/gpio.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace io_bus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pin to replace those that don't exist.
|
||||||
|
*/
|
||||||
|
class NullPin : public GPIOPin {
|
||||||
|
public:
|
||||||
|
void setup() override {}
|
||||||
|
|
||||||
|
void pin_mode(gpio::Flags _) override {}
|
||||||
|
|
||||||
|
bool digital_read() override { return false; }
|
||||||
|
|
||||||
|
void digital_write(bool _) override {}
|
||||||
|
|
||||||
|
std::string dump_summary() const override { return {"Not used"}; }
|
||||||
|
|
||||||
|
gpio::Flags get_flags() const override { return gpio::Flags{}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://bugs.llvm.org/show_bug.cgi?id=48040
|
||||||
|
static GPIOPin *const NULL_PIN = new NullPin(); // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that can write a byte-oriented bus interface with CS and DC controls, typically used for
|
||||||
|
* LCD display controller interfacing.
|
||||||
|
*/
|
||||||
|
class IOBus {
|
||||||
|
public:
|
||||||
|
virtual void bus_setup() = 0;
|
||||||
|
|
||||||
|
virtual void bus_teardown() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a data array. Will not control dc or cs pins.
|
||||||
|
* @param data
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
|
virtual void write_array(const uint8_t *data, size_t length) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a command followed by data. CS and DC will be controlled automatically.
|
||||||
|
* On return, the DC pin will be in DATA mode.
|
||||||
|
* @param cmd An 8 bit command. Passing -1 will suppress the command phase
|
||||||
|
* @param data The data to write. May be null if length==0
|
||||||
|
* @param length The number of data bytes to write (excludes the command byte)
|
||||||
|
*/
|
||||||
|
virtual void write_cmd_data(int cmd, const uint8_t *data, size_t length) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience function for parameterless commands.
|
||||||
|
* @param cmd The 8 bit command.
|
||||||
|
*/
|
||||||
|
void write_cmd(uint8_t cmd) { this->write_cmd_data(cmd, nullptr, 0); }
|
||||||
|
|
||||||
|
virtual void dump_config(){};
|
||||||
|
|
||||||
|
virtual void begin_transaction() = 0;
|
||||||
|
virtual void end_transaction() = 0;
|
||||||
|
|
||||||
|
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GPIOPin *dc_pin_{io_bus::NULL_PIN};
|
||||||
|
};
|
||||||
|
} // namespace io_bus
|
||||||
|
} // namespace esphome
|
7
tests/components/io_bus/common.yaml
Normal file
7
tests/components/io_bus/common.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
io_bus:
|
||||||
|
|
||||||
|
esphome:
|
||||||
|
on_boot:
|
||||||
|
lambda: |-
|
||||||
|
#include "esphome/components/io_bus/io_bus.h"
|
||||||
|
|
1
tests/components/io_bus/test.esp32-ard.yaml
Normal file
1
tests/components/io_bus/test.esp32-ard.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.esp32-c3-ard.yaml
Normal file
1
tests/components/io_bus/test.esp32-c3-ard.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.esp32-c3-idf.yaml
Normal file
1
tests/components/io_bus/test.esp32-c3-idf.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.esp32-idf.yaml
Normal file
1
tests/components/io_bus/test.esp32-idf.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.esp8266-ard.yaml
Normal file
1
tests/components/io_bus/test.esp8266-ard.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.host.yaml
Normal file
1
tests/components/io_bus/test.host.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
1
tests/components/io_bus/test.rp2040-ard.yaml
Normal file
1
tests/components/io_bus/test.rp2040-ard.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
!include common.yaml
|
Loading…
Reference in New Issue
Block a user