PX4 Firmware
PX4 Autopilot Software http://px4.io
ina226.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file ina226.cpp
36  * @author David Sidrane <david_s5@usa.net>
37  *
38  * Driver for the I2C attached INA226
39  */
40 #define INA226_RAW // remove this
41 
42 #include <string.h>
43 
44 #include <px4_platform_common/px4_config.h>
45 #include <px4_platform_common/getopt.h>
46 #include <drivers/device/i2c.h>
47 #include <lib/parameters/param.h>
48 #include <lib/perf/perf_counter.h>
49 #include <drivers/drv_hrt.h>
50 #include <uORB/uORB.h>
52 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
53 
54 /* Configuration Constants */
55 #define INA226_BUS_DEFAULT PX4_I2C_BUS_EXPANSION
56 #define INA226_BASEADDR 0x41 /* 7-bit address. 8-bit address is 0x41 */
57 
58 /* INA226 Registers addresses */
59 #define INA226_REG_CONFIGURATION (0x00)
60 #define INA226_REG_SHUNTVOLTAGE (0x01)
61 #define INA226_REG_BUSVOLTAGE (0x02)
62 #define INA226_REG_POWER (0x03)
63 #define INA226_REG_CURRENT (0x04)
64 #define INA226_REG_CALIBRATION (0x05)
65 #define INA226_REG_MASKENABLE (0x06)
66 #define INA226_REG_ALERTLIMIT (0x07)
67 #define INA226_MFG_ID (0xfe)
68 #define INA226_MFG_DIEID (0xff)
69 
70 #define INA226_MFG_ID_TI (0x5449) // TI
71 #define INA226_MFG_DIE (0x2260) // INA2260
72 
73 /* INA226 Configuration Register */
74 #define INA226_MODE_SHIFTS (0)
75 #define INA226_MODE_MASK (7 << INA226_MODE_SHIFTS)
76 #define INA226_MODE_SHUTDOWN (0 << INA226_MODE_SHIFTS)
77 #define INA226_MODE_SHUNT_TRIG (1 << INA226_MODE_SHIFTS)
78 #define INA226_MODE_BUS_TRIG (2 << INA226_MODE_SHIFTS)
79 #define INA226_MODE_SHUNT_BUS_TRIG (3 << INA226_MODE_SHIFTS)
80 #define INA226_MODE_ADC_OFF (4 << INA226_MODE_SHIFTS)
81 #define INA226_MODE_SHUNT_CONT (5 << INA226_MODE_SHIFTS)
82 #define INA226_MODE_BUS_CONT (6 << INA226_MODE_SHIFTS)
83 #define INA226_MODE_SHUNT_BUS_CONT (7 << INA226_MODE_SHIFTS)
84 
85 #define INA226_VSHCT_SHIFTS (3)
86 #define INA226_VSHCT_MASK (7 << INA226_VSHCT_SHIFTS)
87 #define INA226_VSHCT_140US (0 << INA226_VSHCT_SHIFTS)
88 #define INA226_VSHCT_204US (1 << INA226_VSHCT_SHIFTS)
89 #define INA226_VSHCT_332US (2 << INA226_VSHCT_SHIFTS)
90 #define INA226_VSHCT_588US (3 << INA226_VSHCT_SHIFTS)
91 #define INA226_VSHCT_1100US (4 << INA226_VSHCT_SHIFTS)
92 #define INA226_VSHCT_2116US (5 << INA226_VSHCT_SHIFTS)
93 #define INA226_VSHCT_4156US (6 << INA226_VSHCT_SHIFTS)
94 #define INA226_VSHCT_8244US (7 << INA226_VSHCT_SHIFTS)
95 
96 #define INA226_VBUSCT_SHIFTS (6)
97 #define INA226_VBUSCT_MASK (7 << INA226_VBUSCT_SHIFTS)
98 #define INA226_VBUSCT_140US (0 << INA226_VBUSCT_SHIFTS)
99 #define INA226_VBUSCT_204US (1 << INA226_VBUSCT_SHIFTS)
100 #define INA226_VBUSCT_332US (2 << INA226_VBUSCT_SHIFTS)
101 #define INA226_VBUSCT_588US (3 << INA226_VBUSCT_SHIFTS)
102 #define INA226_VBUSCT_1100US (4 << INA226_VBUSCT_SHIFTS)
103 #define INA226_VBUSCT_2116US (5 << INA226_VBUSCT_SHIFTS)
104 #define INA226_VBUSCT_4156US (6 << INA226_VBUSCT_SHIFTS)
105 #define INA226_VBUSCT_8244US (7 << INA226_VBUSCT_SHIFTS)
106 
107 #define INA226_AVERAGES_SHIFTS (9)
108 #define INA226_AVERAGES_MASK (7 << INA226_AVERAGES_SHIFTS)
109 #define INA226_AVERAGES_1 (0 << INA226_AVERAGES_SHIFTS)
110 #define INA226_AVERAGES_4 (1 << INA226_AVERAGES_SHIFTS)
111 #define INA226_AVERAGES_16 (2 << INA226_AVERAGES_SHIFTS)
112 #define INA226_AVERAGES_64 (3 << INA226_AVERAGES_SHIFTS)
113 #define INA226_AVERAGES_128 (4 << INA226_AVERAGES_SHIFTS)
114 #define INA226_AVERAGES_256 (5 << INA226_AVERAGES_SHIFTS)
115 #define INA226_AVERAGES_512 (6 << INA226_AVERAGES_SHIFTS)
116 #define INA226_AVERAGES_1024 (7 << INA226_AVERAGES_SHIFTS)
117 
118 #define INA226_CONFIG (INA226_MODE_SHUNT_BUS_CONT | INA226_VSHCT_588US | INA226_VBUSCT_588US | INA226_AVERAGES_64)
119 
120 #define INA226_RST (1 << 15)
121 
122 /* INA226 Enable / Mask Register */
123 
124 #define INA226_LEN (1 << 0)
125 #define INA226_APOL (1 << 1)
126 #define INA226_OVF (1 << 2)
127 #define INA226_CVRF (1 << 3)
128 #define INA226_AFF (1 << 4)
129 
130 #define INA226_CNVR (1 << 10)
131 #define INA226_POL (1 << 11)
132 #define INA226_BUL (1 << 12)
133 #define INA226_BOL (1 << 13)
134 #define INA226_SUL (1 << 14)
135 #define INA226_SOL (1 << 15)
136 
137 #define INA226_CONVERSION_INTERVAL (100000-7) /* 100 ms / 10 Hz */
138 #define MAX_CURRENT 164.0f /* 164 Amps */
139 #define DN_MAX 32768.0f /* 2^15 */
140 #define INA226_CONST 0.00512f /* is an internal fixed value used to ensure scaling is maintained properly */
141 #define INA226_SHUNT 0.0005f /* Shunt is 500 uOhm */
142 #define INA226_VSCALE 0.00125f /* LSB of voltage is 1.25 mV */
143 
144 #define swap16(w) __builtin_bswap16((w))
145 
146 class INA226 : public device::I2C, px4::ScheduledWorkItem
147 {
148 public:
149  INA226(int bus = INA226_BUS_DEFAULT, int address = INA226_BASEADDR);
150  virtual ~INA226();
151 
152  virtual int init();
153 
154  /**
155  * Diagnostics - print some basic information about the driver.
156  */
157  void print_info();
158 
159 protected:
160  virtual int probe();
161 
162 private:
163  bool _sensor_ok{false};
165  bool _collect_phase{false};
166 
168 
171 
172  int16_t _bus_volatage{0};
173  int16_t _power{-1};
174  int16_t _current{-1};
175  int16_t _shunt{0};
176  int16_t _cal{0};
177  bool _mode_trigged{false};
178 
183  float _power_lsb{25.0f * _current_lsb};
184 
185  /**
186  * Test whetpower_monitorhe device supported by the driver is present at a
187  * specific address.
188  *
189  * @param address The I2C bus address to read or write.
190  * @return .
191  */
192  int read(uint8_t address);
193  int write(uint8_t address, uint16_t data);
194 
195  /**
196  * Initialise the automatic measurement state machine and start it.
197  *
198  * @note This function is called at open and error time. It might make sense
199  * to make it more aggressive about resetting the bus in case of errors.
200  */
201  void start();
202 
203  /**
204  * Stop the automatic measurement state machine.
205  */
206  void stop();
207 
208  /**
209  * Perform a poll cycle; collect from the previous measurement
210  * and start a new one.
211  */
212  void Run() override;
213 
214  int measure();
215  int collect();
216 
217 };
218 
219 /*
220  * Driver 'main' command.
221  */
222 extern "C" __EXPORT int ina226_main(int argc, char *argv[]);
223 
224 INA226::INA226(int bus, int address) :
225  I2C("INA226", nullptr, bus, address, 100000),
226  ScheduledWorkItem(MODULE_NAME, px4::device_bus_to_wq(get_device_id())),
227  _sample_perf(perf_alloc(PC_ELAPSED, "ina226_read")),
228  _comms_errors(perf_alloc(PC_COUNT, "ina226_com_err"))
229 {
230  float fvalue = MAX_CURRENT;
231  _max_current = fvalue;
232  param_t ph = param_find("INA226_CURRENT");
233 
234  if (ph != PARAM_INVALID && param_get(ph, &fvalue) == PX4_OK) {
235  _max_current = fvalue;
236  }
237 
238  fvalue = INA226_SHUNT;
239  _rshunt = fvalue;
240  ph = param_find("INA226_SHUNT");
241 
242  if (ph != PARAM_INVALID && param_get(ph, &fvalue) == PX4_OK) {
243  _rshunt = fvalue;
244  }
245 
246  ph = param_find("INA226_CONFIG");
247  int32_t value = INA226_CONFIG;
248  _config = (uint16_t)value;
249 
250  if (ph != PARAM_INVALID && param_get(ph, &value) == PX4_OK) {
251  _config = (uint16_t)value;
252  }
253 
257 
259  _power_lsb = 25 * _current_lsb;
260 }
261 
263 {
264  /* make sure we are truly inactive */
265  stop();
266 
267  /* free perf counters */
270 }
271 
272 int INA226::read(uint8_t address)
273 {
274  union {
275  uint16_t reg;
276  uint8_t b[2] = {};
277  } data;
278 
279  int ret = transfer(&address, 1, &data.b[0], sizeof(data.b));
280 
281  if (OK != ret) {
283  PX4_DEBUG("i2c::transfer returned %d", ret);
284  return -1;
285  }
286 
287  return swap16(data.reg);
288 }
289 
290 int INA226::write(uint8_t address, uint16_t value)
291 {
292  uint8_t data[3] = {address, ((uint8_t)((value & 0xff00) >> 8)), (uint8_t)(value & 0xff)};
293  return transfer(data, sizeof(data), nullptr, 0);
294 }
295 
296 int
298 {
299  int ret = PX4_ERROR;
300 
301  /* do I2C init (and probe) first */
302  if (I2C::init() != OK) {
303  return ret;
304  }
305 
307 
309 
310  if (write(INA226_REG_CALIBRATION, _cal) < 0) {
311  return -3;
312  }
313 
314  // If we run in continuous mode then start it here
315 
316  if (!_mode_trigged) {
318 
319  } else {
320  ret = OK;
321  }
322 
323  set_device_address(INA226_BASEADDR); /* set I2c Address */
324 
325  start();
326  _sensor_ok = true;
327 
328  return ret;
329 }
330 
331 int
333 {
334  int value = read(INA226_MFG_ID);
335 
336  if (value < 0) {
338  }
339 
340  if (value != INA226_MFG_ID_TI) {
341  PX4_DEBUG("probe mfgid %d", value);
342  return -1;
343  }
344 
345  value = read(INA226_MFG_DIEID);
346 
347  if (value < 0) {
349  }
350 
351  if (value != INA226_MFG_DIE) {
352  PX4_DEBUG("probe die id %d", value);
353  return -1;
354  }
355 
356  return OK;
357 }
358 
359 int
361 {
362  int ret = OK;
363 
364  if (_mode_trigged) {
366 
367  if (ret < 0) {
369  PX4_DEBUG("i2c::transfer returned %d", ret);
370  }
371  }
372 
373  return ret;
374 }
375 
376 int
378 {
379  int ret = -EIO;
380 
381  /* read from the sensor */
383 
385 
386  if (_bus_volatage >= 0) {
387  ret = _power = read(INA226_REG_POWER);
388 
389  if (_power >= 0) {
391 
392  if (_current >= 0) {
394 
395  if (_shunt >= 0) {
396 
397  struct power_monitor_s report;
398  report.timestamp = hrt_absolute_time();
399  report.voltage_v = (float) _bus_volatage * INA226_VSCALE;
400  report.current_a = (float) _current * _current_lsb;
401  report.power_w = (float) _power * _power_lsb;
402 #if defined(INA226_RAW)
404  report.rsv = read(INA226_REG_SHUNTVOLTAGE);
405  report.rbv = read(INA226_REG_BUSVOLTAGE);
406  report.rp = read(INA226_REG_POWER);
407  report.rc = read(INA226_REG_CURRENT);
408  report.rcal = read(INA226_REG_CALIBRATION);
409  report.me = read(INA226_REG_MASKENABLE);
410  report.al = read(INA226_REG_ALERTLIMIT);
411 #endif
412 
413  /* publish it */
414  int instance;
415  orb_publish_auto(ORB_ID(power_monitor), &_power_monitor_topic, &report, &instance, ORB_PRIO_DEFAULT);
416 
417  ret = OK;
419  return ret;
420  }
421  }
422  }
423  }
424 
425  PX4_DEBUG("error reading from sensor: %d", ret);
428  return ret;
429 }
430 
431 void
433 {
434  ScheduleClear();
435 
436  /* reset the report ring and state machine */
437  _collect_phase = false;
438 
440 
441  /* schedule a cycle to start things */
442  ScheduleDelayed(5);
443 }
444 
445 void
447 {
448  ScheduleClear();
449 }
450 
451 void
453 {
454  if (_collect_phase) {
455 
456  /* perform collection */
457  if (OK != collect()) {
458  PX4_DEBUG("collection error");
459  /* if error restart the measurement state machine */
460  start();
461  return;
462  }
463 
464  /* next phase is measurement */
466 
468 
469  /* schedule a fresh cycle call when we are ready to measure again */
471  return;
472  }
473  }
474 
475  /* Measurement phase */
476 
477  /* Perform measurement */
478  if (OK != measure()) {
479  PX4_DEBUG("measure error ina226");
480  }
481 
482  /* next phase is collection */
483  _collect_phase = true;
484 
485  /* schedule a fresh cycle call when the measurement is done */
486  ScheduleDelayed(INA226_CONVERSION_INTERVAL);
487 }
488 
489 void
491 {
494 
495  printf("poll interval: %u \n", _measure_interval);
496 }
497 
498 /**
499  * Local functions in support of the shell command.
500  */
501 namespace ina226
502 {
503 
505 
506 int start();
507 int start_bus(int i2c_bus);
508 int stop();
509 int info();
510 
511 /**
512  *
513  * Attempt to start driver on all available I2C busses.
514  *
515  * This function will return as soon as the first sensor
516  * is detected on one of the available busses or if no
517  * sensors are detected.
518  *
519  */
520 int
522 {
523  if (g_dev != nullptr) {
524  PX4_ERR("already started");
525  return PX4_ERROR;
526  }
527 
528  for (unsigned i = 0; i < NUM_I2C_BUS_OPTIONS; i++) {
529  if (start_bus(i2c_bus_options[i]) == PX4_OK) {
530  return PX4_OK;
531  }
532  }
533 
534  return PX4_ERROR;
535 }
536 
537 /**
538  * Start the driver on a specific bus.
539  *
540  * This function only returns if the sensor is up and running
541  * or could not be detected successfully.
542  */
543 int
544 start_bus(int i2c_bus)
545 {
546  if (g_dev != nullptr) {
547  PX4_ERR("already started");
548  return PX4_ERROR;
549  }
550 
551  /* create the driver */
552  g_dev = new INA226(i2c_bus);
553 
554  if (g_dev == nullptr) {
555  goto fail;
556  }
557 
558  if (OK != g_dev->init()) {
559  goto fail;
560  }
561 
562  return PX4_OK;
563 
564 fail:
565 
566  if (g_dev != nullptr) {
567  delete g_dev;
568  g_dev = nullptr;
569  }
570 
571  return PX4_ERROR;
572 }
573 
574 /**
575  * Stop the driver
576  */
577 int
579 {
580  if (g_dev != nullptr) {
581  delete g_dev;
582  g_dev = nullptr;
583 
584  } else {
585  PX4_ERR("driver not running");
586  return PX4_ERROR;
587  }
588 
589  return PX4_OK;
590 }
591 
592 /**
593  * Print a little info about the driver.
594  */
595 int
597 {
598  if (g_dev == nullptr) {
599  PX4_ERR("driver poll restart failed");
600  return PX4_ERROR;
601  }
602 
603  printf("state @ %p\n", g_dev);
604  g_dev->print_info();
605 
606  return PX4_OK;
607 }
608 
609 } /* namespace */
610 
611 
612 static void
614 {
615  PX4_INFO("usage: ina226 command [options]");
616  PX4_INFO("options:");
617  PX4_INFO("\t-b --bus i2cbus (%d)", INA226_BUS_DEFAULT);
618  PX4_INFO("\t-a --all");
619  PX4_INFO("command:");
620  PX4_INFO("\tstart|stop|test|info");
621 }
622 
623 int
624 ina226_main(int argc, char *argv[])
625 {
626  int ch;
627  int myoptind = 1;
628  const char *myoptarg = nullptr;
629  bool start_all = false;
630 
631  int i2c_bus = INA226_BUS_DEFAULT;
632 
633  while ((ch = px4_getopt(argc, argv, "ab:R:", &myoptind, &myoptarg)) != EOF) {
634  switch (ch) {
635 
636  case 'b':
637  i2c_bus = atoi(myoptarg);
638  break;
639 
640  case 'a':
641  start_all = true;
642  break;
643 
644  default:
645  PX4_WARN("Unknown option!");
646  goto out_error;
647  }
648  }
649 
650  if (myoptind >= argc) {
651  goto out_error;
652  }
653 
654  /*
655  * Start/load the driver.
656  */
657  if (!strcmp(argv[myoptind], "start")) {
658  if (start_all) {
659  return ina226::start();
660 
661  } else {
662  return ina226::start_bus(i2c_bus);
663  }
664  }
665 
666  /*
667  * Stop the driver
668  */
669  if (!strcmp(argv[myoptind], "stop")) {
670  return ina226::stop();
671  }
672 
673  /*
674  * Print driver information.
675  */
676  if (!strcmp(argv[myoptind], "info") || !strcmp(argv[myoptind], "status")) {
677  return ina226::info();
678  }
679 
680 out_error:
681  ina2262_usage();
682  return PX4_ERROR;
683 }
#define INA226_REG_BUSVOLTAGE
Definition: ina226.cpp:61
int start()
Attempt to start driver on all available I2C busses.
Definition: ina226.cpp:521
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
Definition: param.h:103
#define INA226_MFG_DIE
Definition: ina226.cpp:71
#define INA226_MFG_DIEID
Definition: ina226.cpp:68
bool _mode_trigged
Definition: ina226.cpp:177
#define INA226_MODE_MASK
Definition: ina226.cpp:75
int measure()
Definition: ina226.cpp:360
int collect()
Definition: ina226.cpp:377
__EXPORT int ina226_main(int argc, char *argv[])
Definition: ina226.cpp:624
uint16_t _config
Definition: ina226.cpp:181
measure the time elapsed performing an event
Definition: perf_counter.h:56
float _max_current
Definition: ina226.cpp:179
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
Definition: parameters.cpp:589
API for the uORB lightweight object broker.
orb_advert_t _power_monitor_topic
Definition: ina226.cpp:167
int _measure_interval
Definition: ina226.cpp:164
#define INA226_MODE_SHIFTS
Definition: ina226.cpp:74
#define INA226_BUS_DEFAULT
Definition: ina226.cpp:55
Definition: I2C.hpp:51
int read(uint8_t address)
Test whetpower_monitorhe device supported by the driver is present at a specific address.
Definition: ina226.cpp:272
bool _collect_phase
Definition: ina226.cpp:165
static void ina2262_usage()
Definition: ina226.cpp:613
uint64_t timestamp
Definition: power_monitor.h:53
#define INA226_REG_ALERTLIMIT
Definition: ina226.cpp:66
virtual int probe()
Definition: ina226.cpp:332
LidarLite * instance
Definition: ll40ls.cpp:65
count the number of times an event occurs
Definition: perf_counter.h:55
#define swap16(w)
Definition: ina226.cpp:144
High-resolution timer with callouts and timekeeping.
Global flash based parameter store.
int16_t _current
Definition: ina226.cpp:174
#define DN_MAX
Definition: ina226.cpp:139
void stop()
Stop the automatic measurement state machine.
Definition: ina226.cpp:446
int16_t _bus_volatage
Definition: ina226.cpp:172
float _rshunt
Definition: ina226.cpp:180
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
int16_t _power
Definition: ina226.cpp:173
void perf_count(perf_counter_t handle)
Count a performance event.
Header common to all counters.
#define INA226_SHUNT
Definition: ina226.cpp:141
float _power_lsb
Definition: ina226.cpp:183
void perf_free(perf_counter_t handle)
Free a counter.
void init()
Activates/configures the hardware registers.
perf_counter_t _sample_perf
Definition: ina226.cpp:169
#define perf_alloc(a, b)
Definition: px4io.h:59
INA226 * g_dev
Definition: ina226.cpp:504
uint8_t * data
Definition: dataman.cpp:149
INA226(int bus=INA226_BUS_DEFAULT, int address=INA226_BASEADDR)
Definition: ina226.cpp:224
#define INA226_MFG_ID_TI
Definition: ina226.cpp:70
#define INA226_RST
Definition: ina226.cpp:120
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
Definition: ina226.cpp:452
int stop()
Stop the driver.
Definition: ina226.cpp:578
void perf_end(perf_counter_t handle)
End a performance event.
#define INA226_REG_CURRENT
Definition: ina226.cpp:63
void print_info()
Diagnostics - print some basic information about the driver.
Definition: ina226.cpp:490
#define INA226_BASEADDR
Definition: ina226.cpp:56
#define MAX_CURRENT
Definition: ina226.cpp:138
void start()
Initialise the automatic measurement state machine and start it.
Definition: ina226.cpp:432
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
bool _sensor_ok
Definition: ina226.cpp:163
static const int i2c_bus_options[]
Definition: i2c.h:46
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
Definition: parameters.cpp:370
#define INA226_VSCALE
Definition: ina226.cpp:142
perf_counter_t _comms_errors
Definition: ina226.cpp:170
#define INA226_MODE_SHUNT_BUS_TRIG
Definition: ina226.cpp:79
virtual ~INA226()
Definition: ina226.cpp:262
Local functions in support of the shell command.
Definition: ina226.cpp:501
int16_t _shunt
Definition: ina226.cpp:175
int write(uint8_t address, uint16_t data)
Definition: ina226.cpp:290
int16_t _cal
Definition: ina226.cpp:176
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
int info()
Print a little info about the driver.
Definition: ina226.cpp:596
Definition: bst.cpp:62
float _current_lsb
Definition: ina226.cpp:182
#define INA226_CONFIG
Definition: ina226.cpp:118
#define INA226_REG_POWER
Definition: ina226.cpp:62
#define OK
Definition: uavcan_main.cpp:71
#define INA226_REG_CALIBRATION
Definition: ina226.cpp:64
virtual int init()
Definition: ina226.cpp:297
#define NUM_I2C_BUS_OPTIONS
Definition: i2c.h:61
#define INA226_MFG_ID
Definition: ina226.cpp:67
#define INA226_REG_SHUNTVOLTAGE
Definition: ina226.cpp:60
void perf_begin(perf_counter_t handle)
Begin a performance event.
#define INA226_REG_MASKENABLE
Definition: ina226.cpp:65
#define INA226_CONVERSION_INTERVAL
Definition: ina226.cpp:137
#define INA226_CONST
Definition: ina226.cpp:140
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
uint32_t param_t
Parameter handle.
Definition: param.h:98
static int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data, int *instance, int priority)
Advertise as the publisher of a topic.
Definition: uORB.h:177
int start_bus(int i2c_bus)
Start the driver on a specific bus.
Definition: ina226.cpp:544
#define INA226_REG_CONFIGURATION
Definition: ina226.cpp:59
Performance measuring tools.
Base class for devices connected via I2C.