1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/ina2xx/include/ina2xx_params.h
Marian Buschsieweke a6476bd813
drivers/ina2xx: Match RIOT's driver design goals
- Use standard RIOT style `ina2xx_params_t` on initialization as explained in
  [1] instead of a custom API
- Provided a default configuration via `ina2xx_params_t` as required by [1] that
  works fine for the INA219 breakout board and with an optimal resolution that
  still covers the whole range of USB high-power devices (500 mA @ 5V) with a
  comfortable safe margin.
- Changed initialization procedure to include a device reset and connectivity
  test, as required by [1]
- The calibration value is now calculated by the driver
    - This simplifies using the driver a lot
    - The user can still choose a trade-off between range and resolution that
      matches the application requirements, but now among predefined values
    - This allows the driver to easily convert the raw data into meaningful
      physical data, as the resolution of the raw data is known
- All measurements are provided as meaningful physical data as required by [1]

[1]: https://github.com/RIOT-OS/RIOT/wiki/Guide:-Writing-a-device-driver-in-RIOT
2019-11-22 20:28:57 +01:00

110 lines
3.2 KiB
C

/*
* Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_ina2xx
*
* @{
* @file
* @brief Default configuration for INA2xx power/current monitors
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*/
#ifndef INA2XX_PARAMS_H
#define INA2XX_PARAMS_H
#include "board.h"
#include "ina2xx.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name Set default configuration parameters for the INA2XX
* @{
*/
#ifndef INA2XX_PARAM_I2C
/**
* @brief Default to first I2C device
*/
#define INA2XX_PARAM_I2C (I2C_DEV(0))
#endif
#ifndef INA2XX_PARAM_ADDR
/**
* @brief Default to address 0x40, which is active if A0 and A1 are connected
* to GND
*
* On the popular INA219 breakout board this is the default address if solder
* jumpers remain open.
*/
#define INA2XX_PARAM_ADDR (0x40)
#endif
#ifndef INA2XX_PARAM_CONFIG
/**
* @brief Default to an optimal configuration for current/power measurements
* of USB high-power devices using the popular INA219 break out board
* with 128 samples averaged
*
* | Setting | Value |
* |:------------------- |:--------------------------------------------- |
* | Mode | Continuous shunt and bus voltage measurements |
* | Shunt ADC Setting | 128 Samples, 68.10 ms per conversion |
* | Bus ADC Setting | 128 Samples, 68.10 ms per conversion |
* | Shunt Voltage Range | ±80mV |
* | Bus Voltage Range | 16V |
*/
#define INA2XX_PARAM_CONFIG (INA2XX_MODE_CONTINUOUS_SHUNT_BUS | \
INA2XX_SADC_AVG_128_SAMPLES | \
INA2XX_BADC_AVG_128_SAMPLES | \
INA2XX_SHUNT_RANGE_80MV | \
INA2XX_BUS_RANGE_16V)
#endif
#ifndef INA2XX_PARAM_RSHUNT_MOHM
/**
* @brief Default to 100 mΩ as shunt resistor
*
* This is the value used in the popular INA219 breakout board.
*/
#define INA2XX_PARAM_RSHUNT_MOHM (100)
#endif
#ifndef INA2XX_PARAM_I_RANGE
/**
* @brief Default to a current range of ±655.36mA
*
* This is the highest resolution suitable to measure USB high-power devices
* (up to 500 mA).
*/
#define INA2XX_PARAM_I_RANGE (INA2XX_CURRENT_RANGE_655_MA)
#endif
#ifndef INA2XX_PARAMS
#define INA2XX_PARAMS { .i2c = INA2XX_PARAM_I2C, \
.addr = INA2XX_PARAM_ADDR, \
.config = INA2XX_PARAM_CONFIG, \
.rshunt_mohm = INA2XX_PARAM_RSHUNT_MOHM, \
.i_range = INA2XX_PARAM_I_RANGE }
#endif
/**@}*/
/**
* @brief Configure INA2XX devices
*/
static const ina2xx_params_t ina2xx_params[] =
{
INA2XX_PARAMS
};
#ifdef __cplusplus
}
#endif
#endif /* INA2XX_PARAMS_H */
/** @} */