Grove driver, I2C migrations, bugfixes and docs (#532)
This commit is contained in:
committed by
GitHub
parent
8dabda2b5b
commit
a35c88c8fd
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "./I2cCompat.h"
|
||||
#include "Tactility/Lock.h"
|
||||
|
||||
#include <Tactility/freertoscompat/RTOS.h>
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
namespace tt::hal::i2c {
|
||||
|
||||
constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS;
|
||||
|
||||
enum class Status {
|
||||
Started,
|
||||
Stopped,
|
||||
Unknown
|
||||
};
|
||||
|
||||
/** Start the bus for the specified port. */
|
||||
bool start(i2c_port_t port);
|
||||
|
||||
/** Stop the bus for the specified port. */
|
||||
bool stop(i2c_port_t port);
|
||||
|
||||
/** @return true if the bus is started */
|
||||
bool isStarted(i2c_port_t port);
|
||||
|
||||
/** @return name or nullptr */
|
||||
const char* getName(i2c_port_t port);
|
||||
|
||||
/** Read bytes in master mode. */
|
||||
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/** Read bytes from the specified register in master mode. */
|
||||
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/** Write bytes in master mode. */
|
||||
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/** Write bytes to a register in master mode */
|
||||
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/**
|
||||
* Write multiple values to multiple registers in master mode.
|
||||
* The input is as follows: { register1, value1, register2, value2, ... }
|
||||
* @return false if any of the write operations failed
|
||||
*/
|
||||
bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/** Write bytes and then read the response bytes in master mode*/
|
||||
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/** @return true when a device is detected at the specified address */
|
||||
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout = defaultTimeout);
|
||||
|
||||
/**
|
||||
* The lock for the specified bus.
|
||||
* This can be used when calling native I2C functionality outside of Tactility.
|
||||
*/
|
||||
Lock& getLock(i2c_port_t port);
|
||||
|
||||
} // namespace
|
||||
@@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <hal/i2c_types.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum i2c_port_t {
|
||||
I2C_NUM_0 = 0,
|
||||
I2C_NUM_1,
|
||||
LP_I2C_NUM_0,
|
||||
I2C_NUM_MAX,
|
||||
};
|
||||
|
||||
enum i2c_mode_t {
|
||||
I2C_MODE_MASTER,
|
||||
I2C_MODE_MAX,
|
||||
};
|
||||
|
||||
struct i2c_config_t {
|
||||
i2c_mode_t mode;
|
||||
int sda_io_num;
|
||||
int scl_io_num;
|
||||
bool sda_pullup_en;
|
||||
bool scl_pullup_en;
|
||||
union {
|
||||
struct {
|
||||
uint32_t clk_speed;
|
||||
} master;
|
||||
};
|
||||
uint32_t clk_flags;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <tactility/hal/Device.h>
|
||||
#include "I2c.h"
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
|
||||
namespace tt::hal::i2c {
|
||||
|
||||
@@ -10,12 +10,13 @@ namespace tt::hal::i2c {
|
||||
* It helps to read and write registers.
|
||||
*
|
||||
* All read and write calls are thread-safe.
|
||||
* @deprecated Use the device API from the Kernel project
|
||||
*/
|
||||
class I2cDevice : public Device {
|
||||
|
||||
protected:
|
||||
|
||||
i2c_port_t port;
|
||||
::Device* controller;
|
||||
uint8_t address;
|
||||
|
||||
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
|
||||
@@ -36,11 +37,11 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
|
||||
explicit I2cDevice(::Device* controller, uint32_t address) : controller(controller), address(address) {}
|
||||
|
||||
Type getType() const override { return Type::I2c; }
|
||||
|
||||
i2c_port_t getPort() const { return port; }
|
||||
::Device* getController() const { return controller; }
|
||||
|
||||
uint8_t getAddress() const { return address; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user