Added I2C and BMP280
i2c already running and functional, bmp280 code is still in the main and needs re-organisation Temperature readout works, pressure is not required at this stage
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file bme280.cpp
|
||||
/// \brief Description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <bmp280.h>
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <gpio.h>
|
||||
#include "driver/gpio.h"
|
||||
|
||||
@@ -52,11 +49,7 @@
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
GPIO::GPIO(int number, GPIO_Direction_t direction)
|
||||
|
||||
{
|
||||
this->number = number;
|
||||
this->direction = direction;
|
||||
@@ -111,6 +104,3 @@ GPIO_Value_t GPIO::GetInput(void)
|
||||
return this->value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \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, ®isterAddress, 1, data, length, timeout_ms / portTICK_PERIOD_MS));
|
||||
}
|
||||
@@ -48,10 +48,10 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//static const char* ssid = "Kowalski";
|
||||
//static const char* pass = "madagascar";
|
||||
static const char* ssid = "vbchaos";
|
||||
static const char* pass = "mijninternet";
|
||||
static const char* ssid = "Kowalski";
|
||||
static const char* pass = "madagascar";
|
||||
//static const char* ssid = "vbchaos";
|
||||
//static const char* pass = "mijninternet";
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
|
||||
Reference in New Issue
Block a user