removed the old i2c files

This commit is contained in:
Matthias Mitscherlich
2024-03-11 17:03:12 +01:00
parent d5e389f1bd
commit 58353a439c
2 changed files with 0 additions and 208 deletions
-86
View File
@@ -1,86 +0,0 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file i2c.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_I2C_H_
#define MAIN_INC_I2C_H_
/**
* i2c implementation
* \defgroup i2c
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include "stdint.h"
// ProjectIncludes
// All include files that are provided by the project
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class I2C
{
public:
I2C(unsigned int SCL, unsigned int SDA);
bool write_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length);
bool read_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
private:
static unsigned int number;
unsigned int thisNumber;
unsigned int SCL;
unsigned int SDA;
unsigned int frequency;
unsigned int timeout_ms;
void write(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length);
void read(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
};
/** @} */
#endif /* MAIN_INC_I2C_H_ */
-122
View File
@@ -1,122 +0,0 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file i2c.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "i2c.h"
#include "driver/i2c.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
// Reset the class variable
unsigned int I2C::number = 0;
I2C::I2C(unsigned int SCL, unsigned int SDA)
{
I2C::thisNumber = number++;
I2C::SCL = SCL;
I2C::SDA = SDA;
I2C::frequency = I2C_MASTER_FREQ_HZ;
I2C::timeout_ms = I2C_MASTER_TIMEOUT_MS;
//
i2c_port_t i2c_master_port = (i2c_port_t)I2C::thisNumber;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = (int)I2C::SDA,
.scl_io_num = (int)I2C::SCL,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {I2C::frequency},
.clk_flags = 0
};
ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &conf));
ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0));
}
bool I2C::write_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length)
{
bool returnValue = true;
write(slaveAddress, registerAddress, data, length);
return returnValue;
}
bool I2C::read_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length)
{
bool returnValue = true;
read(slaveAddress, registerAddress, data, length);
return returnValue;
}
void I2C::write(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length)
{
uint8_t buffer[length + 1];
buffer[0] = registerAddress;
for (int i = 0; i < length; i++)
{
buffer[i+1] = data[i];
}
ESP_ERROR_CHECK(i2c_master_write_to_device((i2c_port_t)thisNumber, slaveAddress, buffer, sizeof(buffer), timeout_ms / portTICK_PERIOD_MS));
}
void I2C::read(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length)
{
ESP_ERROR_CHECK(i2c_master_write_read_device((i2c_port_t)thisNumber, slaveAddress, &registerAddress, 1, data, length, timeout_ms / portTICK_PERIOD_MS));
}