M5Unified
INA3221_Class.hpp
Go to the documentation of this file.
1 // Copyright (c) M5Stack. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
4 #ifndef __M5_INA3221_CLASS_H__
5 #define __M5_INA3221_CLASS_H__
6 
7 #include "I2C_Class.hpp"
8 
9 namespace m5
10 {
11  class INA3221_Class : public I2C_Device
12  {
13  public:
14  static constexpr uint8_t INA3221_CH1_SHUNT_V = 0x01;
15  static constexpr uint8_t INA3221_CH1_BUS_V = 0x02;
16  static constexpr uint8_t INA3221_CH2_SHUNT_V = 0x03;
17  static constexpr uint8_t INA3221_CH2_BUS_V = 0x04;
18  static constexpr uint8_t INA3221_CH3_SHUNT_V = 0x05;
19  static constexpr uint8_t INA3221_CH3_BUS_V = 0x06;
20  static constexpr std::uint8_t INA3221_CH_NUM_MAX = 3;
21 
22  static constexpr std::uint8_t DEFAULT_ADDRESS = 0x40;
23 
24  INA3221_Class(std::uint8_t i2c_addr = DEFAULT_ADDRESS, std::uint32_t freq = 400000, I2C_Class* i2c = &In_I2C)
25  : I2C_Device ( i2c_addr, freq, i2c )
26  {
27  _shunt_res[0] = 10;
28  _shunt_res[1] = 10;
29  _shunt_res[2] = 10;
30  }
31 
32  bool begin(void);
33 
37  float getBusVoltage(uint8_t channel);
38  float getShuntVoltage(uint8_t channel);
39  float getCurrent(uint8_t channel);
40 
41  int_fast16_t getBusMilliVoltage(uint8_t channel);
42  int32_t getShuntMilliVoltage(uint8_t channel);
43 
44  void setShuntRes(uint8_t channel, uint32_t res);
45 
46  private:
47  std::size_t readRegister16(std::uint8_t addr);
48 
49  uint32_t _shunt_res[INA3221_CH_NUM_MAX];
50  };
51 }
52 
53 #endif
INA3221_Class(std::uint8_t i2c_addr=DEFAULT_ADDRESS, std::uint32_t freq=400000, I2C_Class *i2c=&In_I2C)
static constexpr uint8_t INA3221_CH3_BUS_V
float getBusVoltage(uint8_t channel)
void setShuntRes(uint8_t channel, uint32_t res)
static constexpr std::uint8_t INA3221_CH_NUM_MAX
static constexpr uint8_t INA3221_CH1_BUS_V
static constexpr uint8_t INA3221_CH3_SHUNT_V
static constexpr uint8_t INA3221_CH2_SHUNT_V
static constexpr uint8_t INA3221_CH2_BUS_V
static constexpr uint8_t INA3221_CH1_SHUNT_V
int_fast16_t getBusMilliVoltage(uint8_t channel)
static constexpr std::uint8_t DEFAULT_ADDRESS
float getShuntVoltage(uint8_t channel)
float getCurrent(uint8_t channel)
int32_t getShuntMilliVoltage(uint8_t channel)
Definition: M5Unified.cpp:48
I2C_Class In_I2C
for internal I2C device
Definition: I2C_Class.cpp:10