rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_reg.c File Reference

Register image conversions and the field table. More...

#include "kst_reg.h"
#include <string.h>

Macros

#define ONE(name, reg, shift, bits, access, unit, conv)
#define TWO(name, lo, hi, hi_shift, hi_bits, access, unit, conv)
#define UNNAMED(reg, shift, bits)
#define ED   KST_ACCESS_EDITABLE
#define LK   KST_ACCESS_LOCKED
#define NV   KST_ACCESS_NEVER
#define REG_BIT(reg)

Enumerations

enum  {
  CONV_RAW = 0 , CONV_DUTY , CONV_BOOST , CONV_STRETCH ,
  CONV_DEAD_BAND , CONV_PULSE , CONV_NEUTRAL , CONV_PROT1_TIME ,
  CONV_PROT1_PWM , CONV_THERMO
}
 Conversions between a raw value and its displayed value.

Functions

const kst_field_t * kst_field (kst_field_id_t id)
 The table row of id; NULL for an id outside the table.
static unsigned part_mask (unsigned shift, unsigned bits)
 Mask of a run of bits in one register.
static unsigned width (const kst_field_t *f)
 Total width of a field in bits.
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.
static int32_t thermo (unsigned raw)
 1 bits upward from bit 0, up to the first 0.
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.
static void fp_fail (kst_fingerprint_t *fp, kst_fp_rule_t rule, uint32_t regs)
 Record a broken layout rule and the registers it concerns.
bool kst_fingerprint (const kst_image_t *img, kst_fingerprint_t *out)
 True when the image has the measured layout.

Variables

static const kst_field_t k_fields [KST_F_COUNT]
 In the order of kst_field_id_t.

Detailed Description

Register image conversions and the field table.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ ONE

#define ONE ( name,
reg,
shift,
bits,
access,
unit,
conv )
Value:
{ name, reg, shift, bits, 0, 0, 0, access, unit, conv }

◆ REG_BIT

#define REG_BIT ( reg)
Value:
((uint32_t)1 << (reg))

◆ TWO

#define TWO ( name,
lo,
hi,
hi_shift,
hi_bits,
access,
unit,
conv )
Value:
{ name, lo, 0, 8, hi, hi_shift, hi_bits, access, unit, conv }

◆ UNNAMED

#define UNNAMED ( reg,
shift,
bits )
Value:
ONE("", reg, shift, bits, KST_ACCESS_NEVER, KST_UNIT_RAW, CONV_RAW)
@ KST_UNIT_RAW
Definition kst_reg.h:128
@ KST_ACCESS_NEVER
Definition kst_reg.h:123

Function Documentation

◆ kst_field()

const kst_field_t * kst_field ( kst_field_id_t id)

The table row of id; NULL for an id outside the table.

Parameters
idField.
Returns
The table row, or NULL for an id outside the table.

◆ kst_field_display()

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

Parameters
idField.
rawRaw value.
displayReceives the displayed value.
Returns
true when the displayed value is established.

◆ kst_field_edit()

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.

Parameters
imgImage to change.
idField.
rawRaw value.
Returns
true when the value fits and was stored.

◆ kst_field_get()

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.

Parameters
imgImage to read.
idField.
Returns
Raw value of the field; 0 for a NULL image or bad id.

◆ kst_field_raw_from_display()

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.

Parameters
idField.
displayDisplayed value.
rawReceives the raw value.
Returns
true when a raw value gives this display value.

◆ kst_field_raw_max()

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.

Parameters
idField.
Returns
Largest raw value the field holds; 0 for an id outside the table.

◆ kst_field_reg_mask()

uint8_t kst_field_reg_mask ( kst_field_id_t id,
uint8_t reg )

Bits of register reg that belong to id.

Parameters
idField.
regRegister address.
Returns
Bits of reg that belong to id.

◆ kst_field_set()

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.

Parameters
imgImage to change.
idField.
rawRaw value.
Returns
true when the value fits and was stored.

◆ kst_fingerprint()

bool kst_fingerprint ( const kst_image_t * img,
kst_fingerprint_t * out )

True when the image has the measured layout.

out may be NULL.

Parameters
imgImage to check.
outReceives the broken rules and deviating registers; may be NULL.
Returns
true when the image has the measured layout.

◆ kst_type()

kst_type_t kst_type ( const kst_image_t * img)

The type of img; KST_TYPE_NONE for NULL.

Parameters
imgImage to read.
Returns
The servo type; KST_TYPE_NONE for NULL.

◆ kst_type_name()

const char * kst_type_name ( kst_type_t type)

"V8", "V6", and "" for any other value.

Parameters
typeServo type.
Returns
"V8", "V6", or "" for any other value.