Revision 9be47646 drivers/P9221R/v1/alld_P9221R.c
drivers/P9221R/v1/alld_P9221R.c | ||
---|---|---|
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
/** |
103 |
* @brief Read the x_alignment. |
|
104 |
* @param[in] i2cd i2c driver |
|
103 |
* @brief Read the alignment. |
|
105 | 104 |
* @param[in] PRd p9221r driver |
106 |
* @param[out] x_alignment alignment register content
|
|
105 |
* @param[out] alignment alignment register content
|
|
107 | 106 |
* @param[in] timeout timeout |
108 | 107 |
* @return An indicator whether the call was successfull |
109 | 108 |
*/ |
110 |
apalExitStatus_t p9221r_lld_read_x_alignment(const P9221RDriver* const p9221r, int8_t* const x_alignment, const apalTime_t timeout)
|
|
109 |
apalExitStatus_t p9221r_lld_read_alignment(const P9221RDriver* const p9221r, int8_t* const alignment, const apalTime_t timeout)
|
|
111 | 110 |
{ |
112 |
uint8_t addr[2] = {(P9221R_LLD_REGISTER_ALIGNMENT_X & 0xFF00) >> 8, P9221R_LLD_REGISTER_ALIGNMENT_X & 0x00FF}; |
|
113 |
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) |
|
114 |
|
|
115 |
return status; |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* @brief Read the y_alignment. |
|
120 |
* @param[in] i2cd i2c driver |
|
121 |
* @param[in] PRd p9221r driver |
|
122 |
* @param[out] y_alignment alignment register content |
|
123 |
* @param[in] timeout timeout |
|
124 |
* @return An indicator whether the call was successfull |
|
125 |
*/ |
|
126 |
apalExitStatus_t p9221r_lld_read_y_alignment(const P9221RDriver* const p9221r, int8_t* const y_alignment, const apalTime_t timeout) |
|
127 |
{ |
|
128 |
uint8_t addr[2] = {(P9221R_LLD_REGISTER_ALIGNMENT_Y & 0xFF00) >> 8, P9221R_LLD_REGISTER_ALIGNMENT_Y & 0x00FF}; |
|
129 |
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) |
|
111 |
apalExitStatus_t status = p9221r_lld_read_register(p9221r, P9221R_LLD_REGISTER_ALIGNMENT_X, (uint8_t*) alignment, 2, timeout); |
|
130 | 112 |
|
131 | 113 |
return status; |
132 | 114 |
} |
... | ... | |
141 | 123 |
*/ |
142 | 124 |
apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, float* const voltage, const apalTime_t timeout) |
143 | 125 |
{ |
144 |
uint8_t addr[2] = {(P9221R_LLD_REGISTER_OUTPUT_VOLTAGE_LSB & 0xFF00) >> 8, P9221R_LLD_REGISTER_OUTPUT_VOLTAGE_LSB & 0x00FF}; |
|
145 | 126 |
uint8_t buffer[2]; |
146 | 127 |
uint16_t value; |
147 | 128 |
|
148 |
apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, buffer, 2, timeout); |
|
129 |
apalExitStatus_t status = p9221r_lld_read_register(p9221r, P9221R_LLD_I2C_ADDR_FIXED, buffer, 2, timeout); |
|
130 |
|
|
149 | 131 |
value = ((buffer[1] & 0x0F) << 8) | buffer[0]; // 4MSB are in buffer[1] so we shift and mask, 8LSB are in buffer[0] |
150 | 132 |
*voltage = (((float) value) * 6 * 2.1f)/4095.0f; |
151 | 133 |
|
... | ... | |
162 | 144 |
*/ |
163 | 145 |
apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, float* const current, const apalTime_t timeout) |
164 | 146 |
{ |
165 |
uint8_t addr[2] = {(P9221R_LLD_REGISTER_IOUT_CURRENT_LSB & 0xFF00) >> 8, P9221R_LLD_REGISTER_IOUT_CURRENT_LSB & 0x00FF}; |
|
166 | 147 |
uint8_t buffer[2]; |
167 | 148 |
uint16_t value; |
168 | 149 |
|
169 |
apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), addr, 2, buffer, 2, timeout);
|
|
150 |
apalExitStatus_t status = p9221r_lld_read_register(p9221r, P9221R_LLD_REGISTER_IOUT_CURRENT_LSB, buffer, 2, timeout);
|
|
170 | 151 |
value = (buffer[1] << 8) | buffer[0]; // 8MSB are in buffer[1] so we shift, 8LSB are in buffer[0] |
171 | 152 |
*current = (((float) value) * 2 * 2.1f)/4095.0f; |
172 | 153 |
|
Also available in: Unified diff