I2C PWM expander added from different Project
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file i2cPort.hpp
|
||||
* @author Gustice
|
||||
* @brief C++ Wrapper for I2C-interface
|
||||
*
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "portBase.hpp"
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief I2C-Master Class
|
||||
* @details More recent implementation of IDF-based I2C master
|
||||
*/
|
||||
class I2cMaster : public PortBase {
|
||||
public:
|
||||
class Slave {
|
||||
public:
|
||||
enum ClockRate {
|
||||
_100k = 100000,
|
||||
_400k = 400000,
|
||||
};
|
||||
|
||||
Slave(I2cMaster &interface, uint8_t addr, ClockRate rate = _100k);
|
||||
~Slave();
|
||||
bool writeTo(const std::vector<uint8_t> &data);
|
||||
std::vector<uint8_t> readFrom(const std::vector<uint8_t> &address, unsigned size);
|
||||
|
||||
protected:
|
||||
const uint8_t Addr;
|
||||
I2cMaster &Interface;
|
||||
i2c_master_dev_handle_t _devHandle;
|
||||
};
|
||||
|
||||
I2cMaster(i2c_port_t port, gpio_num_t sda, gpio_num_t scl);
|
||||
~I2cMaster() = default;
|
||||
|
||||
bool probe(uint8_t addr);
|
||||
|
||||
const i2c_port_t Port;
|
||||
|
||||
private:
|
||||
friend class Slave;
|
||||
i2c_master_bus_handle_t _busHandle;
|
||||
};
|
||||
Reference in New Issue
Block a user