ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
waveshare_io_ch32v003.h
Go to the documentation of this file.
1#pragma once
2
6#include "esphome/core/hal.h"
7
9
11 public i2c::I2CDevice,
12 public gpio_expander::CachedGpioExpander<uint8_t, 8> {
13 public:
15
16 void setup() override;
17 void pin_mode(uint8_t pin, gpio::Flags flags);
18
19 float get_setup_priority() const override;
20
21 void dump_config() override;
22
23 void loop() override;
24
25 uint16_t get_adc_value();
27 void set_pwm_value(uint8_t value); // 0 - 255
28
29 protected:
31
32 bool digital_read_hw(uint8_t pin) override;
33 bool digital_read_cache(uint8_t pin) override;
34 void digital_write_hw(uint8_t pin, bool value) override;
35
36 uint8_t mode_mask_{0x00}; // Mask for the pin mode - 1 means output, 0 means input
37 uint8_t output_mask_{0x00}; // The mask to write as output state - 1 means HIGH, 0 means LOW
38 uint8_t input_mask_{0x00}; // The state read in digital_read_hw - 1 means HIGH, 0 means LOW
39
40 bool write_gpio_modes_();
42};
43
45class WaveshareIOCH32V003GPIOPin : public GPIOPin, public Parented<WaveshareIOCH32V003Component> {
46 public:
47 void setup() override;
48 void pin_mode(gpio::Flags flags) override;
49 bool digital_read() override;
50 void digital_write(bool value) override;
51 size_t dump_summary(char *buffer, size_t len) const override;
52
53 void set_pin(uint8_t pin) { this->pin_ = pin; }
54 void set_inverted(bool inverted) { this->inverted_ = inverted; }
56
57 gpio::Flags get_flags() const override { return this->flags_; }
58
59 protected:
60 uint8_t pin_{};
61 bool inverted_{};
63};
64
65} // namespace esphome::waveshare_io_ch32v003
Helper class to easily give an object a parent of type T.
Definition helpers.h:1875
A class to cache the read state of a GPIO expander.
Definition cached_gpio.h:29
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
Helper class to expose a WaveshareIO pin as a GPIO pin.
size_t dump_summary(char *buffer, size_t len) const override
uint16_t flags
const void size_t len
Definition hal.h:64