2e8aa31cbf
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
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
// --------------------------------------------------------------------------------------------------------------------
|
|
/// \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_ */
|