/* Write one 16 bit register to a INA220 device and swap byte order, if necessary.  */
static int ina220_write_reg(ina220_t *dev, uint8_t reg, uint16_t in)
/* Write one 16 bit register to a INA220 device and swap byte order, if necessary.  */
static int ina220_write_reg(ina220_t *dev, uint8_t reg, uint16_t in)
{
    union {
        char c[2];
        uint16_t u16;
    } tmp = { .u16 = 0 };
    int status = 0;
    tmp.u16 = HTONS(in);
    status = i2c_write_regs(dev->i2c, dev->addr, reg, &tmp.c[0], 2);
    if (status != 2) {
        return -1;
    }
    return 0;
}