|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
KST servo programming protocol: the register image and its fields. More...
Go to the source code of this file.
Data Structures | |
| struct | kst_image_t |
| The 32 registers, by address. More... | |
| struct | kst_field_t |
| One row of the field table. More... | |
| struct | kst_fingerprint_t |
| Broken rules and deviating registers of an image. More... | |
Macros | |
| #define | KST_REG_DUTY_COPY 0x01u |
| Register addresses that code outside the field table names. | |
| #define | KST_REG_DUTY 0x02u |
| #define | KST_REG_NODE_ADDR 0x1Du |
| #define | KST_FIELD_BIT(id) |
The bit of field id in a kst_field_set_t. | |
Typedefs | |
| typedef uint64_t | kst_field_set_t |
| A set of fields, bit n for field n. | |
Functions | |
| const kst_field_t * | kst_field (kst_field_id_t id) |
The table row of id; NULL for an id outside the table. | |
| uint16_t | kst_field_raw_max (kst_field_id_t id) |
| Largest raw value the field's bits hold; 0 for an id outside the table. | |
| uint8_t | kst_field_reg_mask (kst_field_id_t id, uint8_t reg) |
Bits of register reg that belong to id. | |
| uint16_t | kst_field_get (const kst_image_t *img, kst_field_id_t id) |
| Raw value of a field; 0 for a bad argument. | |
| bool | kst_field_set (kst_image_t *img, kst_field_id_t id, uint16_t raw) |
| Set a field's bits. | |
| bool | kst_field_edit (kst_image_t *img, kst_field_id_t id, uint16_t raw) |
| Set a field as an edit does: kst_field_set(), and for KST_F_DUTY the copy in register 0x01 as well. | |
| bool | kst_field_display (kst_field_id_t id, uint16_t raw, int32_t *display) |
| Raw value to displayed value. | |
| bool | kst_field_raw_from_display (kst_field_id_t id, int32_t display, uint16_t *raw) |
| Displayed value to the nearest raw value. | |
| kst_type_t | kst_type (const kst_image_t *img) |
The type of img; KST_TYPE_NONE for NULL. | |
| const char * | kst_type_name (kst_type_t type) |
| "V8", "V6", and "" for any other value. | |
| bool | kst_fingerprint (const kst_image_t *img, kst_fingerprint_t *out) |
| True when the image has the measured layout. | |
KST servo programming protocol: the register image and its fields.
Implements the programming protocol of KST and Chaservo servos. KST and Chaservo are names or trademarks of their respective owners; they are used here only to say which servos this module works with (README.md, "Legal notice and disclaimer").
A servo holds 32 registers of 8 bits. This file names every bit of them as a field, converts a field's raw value to the value the vendor tool shows and back, and checks an image against the layout the wire readings come from.
The image stores raw values. A displayed value is derived from the raw value and never written back on its own, so a field that is not edited keeps its bits. kst_field_set() changes the bits of one field and no other.
Displayed values are integers in the unit the field's kst_unit_t names. No floating point is used. Rounding, where a conversion rounds, is to the nearest value with a tie going up, except Max. Duty, whose tie goes down as the vendor tool's does (50% is raw 127).
The conversions are what the vendor tool displays and writes. The effect of a register on servo motion is not measured for any register. The scaling the vendor tool applies in Gyro Servo mode (register 0x1F bit 0: half the microsecond values, 0.05s time unit) is not applied here.
SPDX-License-Identifier: MIT
| #define KST_FIELD_BIT | ( | id | ) |
The bit of field id in a kst_field_set_t.
| enum kst_access_t |
Who may change a field.
A decision about a field changes this column of the table and no code.
| enum kst_field_id_t |
Every bit of the 32 registers belongs to exactly one field.
Fields named KST_F_Rxx are bits the vendor tool gives no name.
| enum kst_fp_rule_t |
What both known images have in common and the vendor tool forces on every write.
An image that breaks one of these does not have the measured layout, and nothing is written to that servo.
| enum kst_type_t |
The servo type of an image.
A servo answers no model number. The type is one bit: 20k_sel, register 04 bit 6. The manufacturer states the factory default of that bit as set for the V6.0 series (20kHz drive) and clear for the V8.0 series (333Hz drive). The mapping rests on that statement. It is read on 1 servo, whose bit is set; no V8.0 servo is measured. A servo whose 20k_sel was changed by another tool reads as the other type.
| Enumerator | |
|---|---|
| KST_TYPE_V8 | 20k_sel clear |
| KST_TYPE_V6 | 20k_sel set |
| KST_TYPE_NONE | no image, or a file that states no type |
| enum kst_unit_t |
Unit of a displayed value.
| const kst_field_t * kst_field | ( | kst_field_id_t | id | ) |
The table row of id; NULL for an id outside the table.
| id | Field. |
| bool kst_field_display | ( | kst_field_id_t | id, |
| uint16_t | raw, | ||
| int32_t * | display ) |
Raw value to displayed value.
False where the displayed value of that raw value is not established: Stretch index 6 and 7.
Max. Duty round(raw x 100 / 255) % Boost 50us + 12.5us x raw Stretch 1 << index Dead Band 0.2us x (65 - raw) Pulse Lower, Pulse Upper, Uncontrolled Pos 0.8us x raw Neutral 810us + raw x 409 / 2048us, to 0.1us; the constants are a fit through 3 values and uncertain by about 1us Uncontrolled Time, prot1_time 0.1s x raw; prot1_time shown capped at 100.0s prot1_pwm round(raw x 97 / 255) % prot_pot_err, prot_pwm_err count of 1 bits upward from bit 0. The vendor tool shows 0 for registers 17 = FF, 18 = FF; here that image gives 12 SPD 0.1% x raw all others raw
| id | Field. |
| raw | Raw value. |
| display | Receives the displayed value. |
| bool kst_field_edit | ( | kst_image_t * | img, |
| kst_field_id_t | id, | ||
| uint16_t | raw ) |
Set a field as an edit does: kst_field_set(), and for KST_F_DUTY the copy in register 0x01 as well.
Both known images hold 0x01 equal to 0x02.
| img | Image to change. |
| id | Field. |
| raw | Raw value. |
| uint16_t kst_field_get | ( | const kst_image_t * | img, |
| kst_field_id_t | id ) |
Raw value of a field; 0 for a bad argument.
| img | Image to read. |
| id | Field. |
| bool kst_field_raw_from_display | ( | kst_field_id_t | id, |
| int32_t | display, | ||
| uint16_t * | raw ) |
Displayed value to the nearest raw value.
False when the value lies outside what the field encodes, when Stretch is not a power of two from 1 to 32, and for prot1_time and prot1_pwm, whose encoding on write is not observed.
| id | Field. |
| display | Displayed value. |
| raw | Receives the raw value. |
| uint16_t kst_field_raw_max | ( | kst_field_id_t | id | ) |
Largest raw value the field's bits hold; 0 for an id outside the table.
| id | Field. |
| uint8_t kst_field_reg_mask | ( | kst_field_id_t | id, |
| uint8_t | reg ) |
Bits of register reg that belong to id.
| id | Field. |
| reg | Register address. |
| bool kst_field_set | ( | kst_image_t * | img, |
| kst_field_id_t | id, | ||
| uint16_t | raw ) |
Set a field's bits.
No other bit of the image changes. False, and no change, when raw does not fit the field.
| img | Image to change. |
| id | Field. |
| raw | Raw value. |
| bool kst_fingerprint | ( | const kst_image_t * | img, |
| kst_fingerprint_t * | out ) |
True when the image has the measured layout.
out may be NULL.
| img | Image to check. |
| out | Receives the broken rules and deviating registers; may be NULL. |
| kst_type_t kst_type | ( | const kst_image_t * | img | ) |
The type of img; KST_TYPE_NONE for NULL.
| img | Image to read. |
| const char * kst_type_name | ( | kst_type_t | type | ) |
"V8", "V6", and "" for any other value.
| type | Servo type. |