ina226.h
104 lines
| 3.6 KiB
| text/x-c
|
CLexer
r47 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the libuc, microcontroler library | ||||
-- Copyright (C) 2011, Alexis Jeandet | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------- | ||||
-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@gmail.com | ||||
-------------------------------------------------------------------------------*/ | ||||
#ifndef INA226_H | ||||
#define INA226_H | ||||
#include <i2c.h> | ||||
#include <uhandle.h> | ||||
typedef struct INA226_t | ||||
{ | ||||
i2c_t i2cdev; | ||||
uint8_t devAddress; | ||||
uint32_t shuntmOhm; | ||||
uint32_t CurrentRangeuAmp; | ||||
}INA226_t; | ||||
extern int ina226open(INA226_t* dev,i2c_t i2cdev,uint16_t config,uint8_t A0,uint8_t A1,uint32_t shuntmOhm, uint32_t CurrentRangeuAmp); | ||||
extern uint16_t ina226getID(INA226_t* dev); | ||||
extern int ina226calibrate(INA226_t* dev,uint32_t shuntmOhm, uint32_t CurrentRangeuAmp); | ||||
extern uint32_t ina226getBusVoltage(INA226_t* dev); | ||||
extern uint32_t ina226getPower(INA226_t* dev); | ||||
extern int32_t ina226getCurrent(INA226_t* dev); | ||||
extern uint16_t ina226getReg(INA226_t* dev,char reg); | ||||
extern int ina226setReg(INA226_t* dev,char reg,int16_t value); | ||||
#define INA226_I2C_ADDRESS 0x40 | ||||
#define INA226_Die_ID_Reg 0xFF | ||||
#define INA226_Configuration_Reg 0 | ||||
#define INA226_Shunt_Voltage_Reg 1 | ||||
#define INA226_Bus_Voltage_Reg 2 | ||||
#define INA226_Power_Reg 3 | ||||
#define INA226_Current_Reg 4 | ||||
#define INA226_Calibration_Reg 5 | ||||
#define INA226_Mask_Enable_Reg 6 | ||||
#define INA226_Alert_Limit_Reg 7 | ||||
#define INA226_AVERAGES_1 0 | ||||
#define INA226_AVERAGES_4 (1<<9) | ||||
#define INA226_AVERAGES_16 (2<<9) | ||||
#define INA226_AVERAGES_64 (3<<9) | ||||
#define INA226_AVERAGES_128 (4<<9) | ||||
#define INA226_AVERAGES_256 (5<<9) | ||||
#define INA226_AVERAGES_512 (6<<9) | ||||
#define INA226_AVERAGES_1024 (7<<9) | ||||
#define INA226_BUS_CONV_140us 0 | ||||
#define INA226_BUS_CONV_204us (1<<6) | ||||
#define INA226_BUS_CONV_332us (2<<6) | ||||
#define INA226_BUS_CONV_588us (3<<6) | ||||
#define INA226_BUS_CONV_1100us (4<<6) | ||||
#define INA226_BUS_CONV_2116us (5<<6) | ||||
#define INA226_BUS_CONV_4156us (6<<6) | ||||
#define INA226_BUS_CONV_8244us (7<<6) | ||||
#define INA226_SHUNT_CONV_140us 0 | ||||
#define INA226_SHUNT_CONV_204us (1<<3) | ||||
#define INA226_SHUNT_CONV_332us (2<<3) | ||||
#define INA226_SHUNT_CONV_588us (3<<3) | ||||
#define INA226_SHUNT_CONV_1100us (4<<3) | ||||
#define INA226_SHUNT_CONV_2116us (5<<3) | ||||
#define INA226_SHUNT_CONV_4156us (6<<3) | ||||
#define INA226_SHUNT_CONV_8244us (7<<3) | ||||
#define INA226_MODE_POWER_DOWN 0 | ||||
#define INA226_MODE_SHUNT_VOLTAGE_TRIGGERRED 1 | ||||
#define INA226_MODE_BUS_VOLTAGE_TRIGGERRED 2 | ||||
#define INA226_MODE_SHUNT_AND_BUS_TRIGGERRED 3 | ||||
#define INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS 5 | ||||
#define INA226_MODE_BUS_VOLTAGE_CONTINUOUS 6 | ||||
#define INA226_MODE_SHUNT_AND_BUS_CONTINUOUS 7 | ||||
#endif | ||||