|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The AS5600 codec and driver. More...
#include "as5600.h"Functions | |
| uint16_t | as5600_u12 (const uint8_t *b) |
| A 12-bit register pair, most significant byte first: RAW ANGLE, ANGLE or MAGNITUDE. | |
| bool | as5600_status_possible (uint8_t status) |
Whether status is one an AS5600 can give: not ML and MH together. | |
| bool | as5600_md (uint8_t status) |
The magnet bits of status. | |
| bool | as5600_ml (uint8_t status) |
| Read the ML bit of a STATUS value. | |
| bool | as5600_mh (uint8_t status) |
| Read the MH bit of a STATUS value. | |
| int16_t | as5600_delta (uint16_t a, uint16_t b) |
a minus b on the circle, -2048 to 2047 counts: the shortest way from b to a. | |
| int32_t | as5600_cdeg (int32_t counts) |
counts in hundredths of a degree, rounded to the nearest, halves away from zero. | |
| void | as5600_init (as5600_t *d, sense_bus_t *bus) |
A part on bus at AS5600_ADDR, not yet probed. | |
| static sense_state_t | probe (as5600_t *d) |
| Probe the part: read STATUS and classify the answer. | |
| bool | as5600_step (as5600_t *d, uint32_t now_ms) |
| Every tick: probes the part when it is due – at the first call, and SENSE_RETRY_MS after it was found absent, wrong or offline. | |
| sense_state_t | as5600_state (const as5600_t *d) |
| The part's state as of the last probe. | |
| sense_err_t | as5600_read_status (as5600_t *d, uint8_t *status) |
| STATUS: 1 byte from 0x0B. | |
| sense_err_t | as5600_read_raw (as5600_t *d, uint16_t *raw) |
| RAW ANGLE: 2 bytes from 0x0C, 0 to 4095; the same rule. | |
| sense_err_t | as5600_read_agc (as5600_t *d, uint8_t *agc) |
| AGC: 1 byte from 0x1A; the same rule. | |
| sense_err_t | as5600_read_mag (as5600_t *d, uint16_t *magnitude) |
| MAGNITUDE: 2 bytes from 0x1B, 0 to 4095; the same rule. | |
| sense_err_t | as5600_read_angle (as5600_t *d, uint8_t *status, uint16_t *raw) |
| STATUS, then RAW ANGLE: two transactions. | |
| sense_err_t | as5600_read_magnitude (as5600_t *d, uint8_t *agc, uint16_t *magnitude) |
| AGC, then MAGNITUDE: two transactions; the same rule. | |
| int32_t as5600_cdeg | ( | int32_t | counts | ) |
counts in hundredths of a degree, rounded to the nearest, halves away from zero.
Any int32_t is accepted. Above |counts| 244,335,917 the result saturates at +-2,147,483,647.
| counts | Angle in counts; 4096 counts make a turn. |
| int16_t as5600_delta | ( | uint16_t | a, |
| uint16_t | b ) |
a minus b on the circle, -2048 to 2047 counts: the shortest way from b to a.
Both are taken modulo 4096.
| a | An angle, in counts. |
| b | An angle, in counts. |
| void as5600_init | ( | as5600_t * | d, |
| sense_bus_t * | bus ) |
A part on bus at AS5600_ADDR, not yet probed.
| d | The driver. |
| bus | The sensor bus the part sits on. |
| bool as5600_md | ( | uint8_t | status | ) |
The magnet bits of status.
RAW ANGLE is a position only with MD.
| status | The STATUS byte. |
| bool as5600_mh | ( | uint8_t | status | ) |
Read the MH bit of a STATUS value.
| status | The STATUS byte. |
| bool as5600_ml | ( | uint8_t | status | ) |
Read the ML bit of a STATUS value.
| status | The STATUS byte. |
| sense_err_t as5600_read_agc | ( | as5600_t * | d, |
| uint8_t * | agc ) |
AGC: 1 byte from 0x1A; the same rule.
| d | The driver. |
| agc | Receives the AGC byte. |
| sense_err_t as5600_read_angle | ( | as5600_t * | d, |
| uint8_t * | status, | ||
| uint16_t * | raw ) |
STATUS, then RAW ANGLE: two transactions.
On anything but SENSE_OK both are left as they were.
| d | The driver. |
| status | Receives the STATUS byte. |
| raw | Receives the angle, 0 to 4095. |
| sense_err_t as5600_read_mag | ( | as5600_t * | d, |
| uint16_t * | magnitude ) |
MAGNITUDE: 2 bytes from 0x1B, 0 to 4095; the same rule.
| d | The driver. |
| magnitude | Receives the magnitude, 0 to 4095. |
| sense_err_t as5600_read_magnitude | ( | as5600_t * | d, |
| uint8_t * | agc, | ||
| uint16_t * | magnitude ) |
AGC, then MAGNITUDE: two transactions; the same rule.
| d | The driver. |
| agc | Receives the AGC byte. |
| magnitude | Receives the magnitude, 0 to 4095. |
| sense_err_t as5600_read_raw | ( | as5600_t * | d, |
| uint16_t * | raw ) |
RAW ANGLE: 2 bytes from 0x0C, 0 to 4095; the same rule.
| d | The driver. |
| raw | Receives the angle, 0 to 4095. |
| sense_err_t as5600_read_status | ( | as5600_t * | d, |
| uint8_t * | status ) |
STATUS: 1 byte from 0x0B.
On anything but SENSE_OK status is left as it was.
| d | The driver. |
| status | Receives the STATUS byte. |
| sense_state_t as5600_state | ( | const as5600_t * | d | ) |
The part's state as of the last probe.
| d | The driver. |
| bool as5600_status_possible | ( | uint8_t | status | ) |
Whether status is one an AS5600 can give: not ML and MH together.
Bits 7, 6, 2, 1 and 0 are not looked at.
| status | The STATUS byte. |
| bool as5600_step | ( | as5600_t * | d, |
| uint32_t | now_ms ) |
Every tick: probes the part when it is due – at the first call, and SENSE_RETRY_MS after it was found absent, wrong or offline.
Returns whether it is online.
| d | The driver. |
| now_ms | The current time, in ms. |
| uint16_t as5600_u12 | ( | const uint8_t * | b | ) |
A 12-bit register pair, most significant byte first: RAW ANGLE, ANGLE or MAGNITUDE.
0 to 4095.
| b | The two bytes, high byte first. |
|
static |
Probe the part: read STATUS and classify the answer.
| d | The driver. |