esphome/esphome/components/mcp23017/mcp23017.h
Otto Winter 6682c43dfa
🏗 Merge C++ into python codebase (#504)
## Description:

Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97

Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍

Progress:
- Core support (file copy etc): 80%
- Base Abstractions (light, switch): ~50%
- Integrations: ~10%
- Working? Yes, (but only with ported components).

Other refactors:
- Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`)
- Rework coroutine syntax
- Move from `component/platform.py` to `domain/component.py` structure as with HA
- Move all defaults out of C++ and into config validation.
- Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration.
- Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit.

Future work:
- Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block
- Enable loading from `custom_components` folder.

**Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97

**Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here>

## Checklist:
  - [ ] The code change is tested and works locally.
  - [ ] Tests have been added to verify that the new code works (under `tests/` folder).

If user exposed functionality or configuration variables are added/changed:
  - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00

82 lines
2 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/esphal.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace mcp23017 {
/// Modes for MCP23017 pins
enum MCP23017GPIOMode : uint8_t {
MCP23017_INPUT = INPUT, // 0x00
MCP23017_INPUT_PULLUP = INPUT_PULLUP, // 0x02
MCP23017_OUTPUT = OUTPUT // 0x01
};
enum MCP23017GPIORegisters {
// A side
MCP23017_IODIRA = 0x00,
MCP23017_IPOLA = 0x02,
MCP23017_GPINTENA = 0x04,
MCP23017_DEFVALA = 0x06,
MCP23017_INTCONA = 0x08,
MCP23017_IOCONA = 0x0A,
MCP23017_GPPUA = 0x0C,
MCP23017_INTFA = 0x0E,
MCP23017_INTCAPA = 0x10,
MCP23017_GPIOA = 0x12,
MCP23017_OLATA = 0x14,
// B side
MCP23017_IODIRB = 0x01,
MCP23017_IPOLB = 0x03,
MCP23017_GPINTENB = 0x05,
MCP23017_DEFVALB = 0x07,
MCP23017_INTCONB = 0x09,
MCP23017_IOCONB = 0x0B,
MCP23017_GPPUB = 0x0D,
MCP23017_INTFB = 0x0F,
MCP23017_INTCAPB = 0x11,
MCP23017_GPIOB = 0x13,
MCP23017_OLATB = 0x15,
};
class MCP23017 : public Component, public i2c::I2CDevice {
public:
MCP23017() = default;
void setup() override;
bool digital_read(uint8_t pin);
void digital_write(uint8_t pin, bool value);
void pin_mode(uint8_t pin, uint8_t mode);
float get_setup_priority() const override;
protected:
// read a given register
bool read_reg_(uint8_t reg, uint8_t *value);
// write a value to a given register
bool write_reg_(uint8_t reg, uint8_t value);
// update registers with given pin value.
void update_reg_(uint8_t pin, bool pin_value, uint8_t reg_a);
uint8_t olat_a_{0x00};
uint8_t olat_b_{0x00};
};
class MCP23017GPIOPin : public GPIOPin {
public:
MCP23017GPIOPin(MCP23017 *parent, uint8_t pin, uint8_t mode, bool inverted = false);
void setup() override;
void pin_mode(uint8_t mode) override;
bool digital_read() override;
void digital_write(bool value) override;
protected:
MCP23017 *parent_;
};
} // namespace mcp23017
} // namespace esphome