Fixed ISerialBus interface and added device and register address fields so that future i2c and SPI devices can be addressed, to. Added i2c HAL. Tested, working.

The update on the interface required FunctionStatus and the logger to be updated, too
This commit is contained in:
Matthias Mitscherlich
2024-03-11 17:00:07 +01:00
parent a0d13f08c1
commit d5e389f1bd
11 changed files with 137 additions and 530 deletions
+4 -2
View File
@@ -45,6 +45,8 @@
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define NO_DEVICE_ADDRESS (255)
#define NO_REGISTER_ADDRESS (255)
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
@@ -70,9 +72,9 @@ class ISerialBus
FunctionStatus close() {status = CLOSED; return FUNCTION_STATUS_OK;}
virtual FunctionStatus read(T* buffer, uint32_t length, uint32_t* actualLength) = 0;
virtual FunctionStatus read(T deviceAddress, T registerAddress, T* buffer, uint32_t length, uint32_t* actualLength) = 0;
virtual FunctionStatus write(T* buffer, uint32_t length) = 0;
virtual FunctionStatus write(T deviceAddress, T registerAddress, T* buffer, uint32_t length) = 0;
+96
View File
@@ -0,0 +1,96 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file i2c.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_HAL_INC_I2C_H_
#define MAIN_HAL_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
// ProjectIncludes
// All include files that are provided by the project
#include "ISerialBus.h"
#include "driver/i2c.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class i2c : public ISerialBus<uint8_t>
{
// -----------------------------------------------------------------------------------------------------------------
// Public Section
// -----------------------------------------------------------------------------------------------------------------
public:
// Class Constructor
i2c(i2c_port_t* port);
~i2c();
FunctionStatus read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, uint32_t length, uint32_t* actualLength);
FunctionStatus write(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, uint32_t length);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section
// -----------------------------------------------------------------------------------------------------------------
protected:
// -----------------------------------------------------------------------------------------------------------------
// Private Section
// -----------------------------------------------------------------------------------------------------------------
private:
void intWrite(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
void intRead(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
i2c_port_t* port;
};
/** @} */
#endif /* MAIN_HAL_INC_I2C_H_ */
+2 -2
View File
@@ -67,9 +67,9 @@ class uart : public ISerialBus<uint8_t>
uart(uart_port_t* uartPort);
~uart();
FunctionStatus read(uint8_t* buffer, uint32_t length, uint32_t* actualLength);
FunctionStatus read(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, uint32_t length, uint32_t* actualLength);
FunctionStatus write(uint8_t* buffer, uint32_t length);
FunctionStatus write(uint8_t deviceAddress, uint8_t registerAddress, uint8_t* buffer, uint32_t length);
// -----------------------------------------------------------------------------------------------------------------
// Protected Section