Revision 247b3413

View differences:

source/P9221R/v1/alld_P9221R_v1.c
113 113
apalExitStatus_t p9221r_lld_read_x_alignment(const P9221RDriver* const p9221r, int8_t* const x_alignment, const apalTime_t timeout)
114 114
{
115 115
    uint8_t addr[2] = {(P9221R_LLD_REGISTER_ALIGNMENT_X & 0xFF00) >> 8, P9221R_LLD_REGISTER_ALIGNMENT_X & 0x00FF};
116
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, x_alignment, 1, timeout); // TODO check if implicit cast is ok (uint)
116
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, (uint8_t*)x_alignment, 2, timeout); // TODO check if implicit cast is ok (uint)
117 117

  
118 118
    return status;
119 119
}
......
129 129
apalExitStatus_t p9221r_lld_read_y_alignment(const P9221RDriver* const p9221r, int8_t* const y_alignment, const apalTime_t timeout)
130 130
{
131 131
    uint8_t addr[2] = {(P9221R_LLD_REGISTER_ALIGNMENT_Y & 0xFF00) >> 8, P9221R_LLD_REGISTER_ALIGNMENT_Y & 0x00FF};
132
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, y_alignment, 1, timeout); // TODO check if implicit cast is ok (uint)
132
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, (uint8_t*)y_alignment, 2, timeout); // TODO check if implicit cast is ok (uint)
133 133

  
134 134
    return status;
135 135
}
......
149 149
    uint16_t value;
150 150

  
151 151
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, buffer, 2, timeout);
152
    value = ((buffer[1] << 8) & 0x0F) | buffer[0]; // 4MSB are in buffer[1] so we shift and mask, 8LSB are in buffer[0]
153
    *voltage = (((float) value) * 6 * 2.1)/4095.0;
152
    value = ((buffer[1] & 0x0F) << 8) | buffer[0]; // 4MSB are in buffer[1] so we shift and mask, 8LSB are in buffer[0]
153
    *voltage = (((float) value) * 6 * 2.1f)/4095.0f;
154 154

  
155 155
    return status;
156 156
}
......
171 171

  
172 172
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, buffer, 2, timeout);
173 173
    value = (buffer[1] << 8) | buffer[0]; // 8MSB are in buffer[1] so we shift, 8LSB are in buffer[0]
174
    *current = (((float) value) * 2 * 2.1)/4095.0;
174
    *current = (((float) value) * 2 * 2.1f)/4095.0f;
175 175

  
176 176
    return status;
177 177
}

Also available in: Unified diff