Revision c89b966e

View differences:

include/P9221R/v1/alld_P9221R_v1.h
103 103
  apalExitStatus_t p9221r_lld_write_register(const P9221RDriver* const p9221r, const p9221r_lld_register_t addr, const uint16_t* const data, const uint8_t num, const apalTime_t timeout);
104 104
  apalExitStatus_t p9221r_lld_read_x_alignment(const P9221RDriver* const p9221r, int8_t* const x_alignment, const apalTime_t timeout);
105 105
  apalExitStatus_t p9221r_lld_read_y_alignment(const P9221RDriver* const p9221r, int8_t* const y_alignment, const apalTime_t timeout);
106
  apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, uint16_t* const voltage, const apalTime_t timeout);
107
  apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, uint16_t* const current, const apalTime_t timeout);
106
  apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, float* const voltage, const apalTime_t timeout);
107
  apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, float* const current, const apalTime_t timeout);
108 108

  
109 109
#ifdef __cplusplus
110 110
}
source/P9221R/v1/alld_P9221R_v1.c
114 114
 */
115 115
apalExitStatus_t p9221r_lld_read_x_alignment(const P9221RDriver* const p9221r, int8_t* const x_alignment, const apalTime_t timeout)
116 116
{
117
    uint8_t address = P9221R_LLD_REGISTER_ALIGNMENT_X;
118
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), &address, 2, x_alignment, 1, timeout);
117
    uint8_t addr = P9221R_LLD_REGISTER_ALIGNMENT_X;
118
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), &addr, 2, x_alignment, 1, timeout);
119 119

  
120 120
    return status;
121 121
}
......
130 130
 */
131 131
apalExitStatus_t p9221r_lld_read_y_alignment(const P9221RDriver* const p9221r, int8_t* const y_alignment, const apalTime_t timeout)
132 132
{
133
    uint8_t address = P9221R_LLD_REGISTER_ALIGNMENT_Y;
134
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), &address, 2, y_alignment, 1, timeout);
133
    uint8_t addr = P9221R_LLD_REGISTER_ALIGNMENT_Y;
134
    apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), &addr, 2, y_alignment, 1, timeout);
135 135

  
136 136
    return status;
137 137
}
......
144 144
 * @param[in]   timeout     timeout
145 145
 * @return                  An indicator whether the call was successfull
146 146
 */
147
apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, uint16_t* const voltage, const apalTime_t timeout)
147
apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, float* const voltage, const apalTime_t timeout)
148 148
{
149
    apalExitStatus_t status = NULL;
149
    uint8_t addr = P9221R_LLD_REGISTER_OUTPUT_VOLTAGE_LSB;
150
    uint8_t buffer[2];
151
    uint16_t value;
152

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

  
151 157
    return status;
152 158
}
......
159 165
 * @param[in]   timeout     timeout
160 166
 * @return                  An indicator whether the call was successfull
161 167
 */
162
apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, uint16_t* const current, const apalTime_t timeout)
168
apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, float* const current, const apalTime_t timeout)
163 169
{
164
    apalExitStatus_t status = NULL;
170
    uint8_t addr = P9221R_LLD_REGISTER_IOUT_CURRENT_LSB;
171
    uint8_t buffer[2];
172
    uint16_t value;
173

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

  
166 178
    return status;
167 179
}

Also available in: Unified diff