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

PPM frame layout. More...

#include "ppm.h"

Functions

static ppm_cfg_t resolve (const ppm_cfg_t *cfg)
 A zero field means "the default for it", so a caller can set one thing.
uint32_t ppm_min_frame_us (uint8_t channels, const ppm_cfg_t *cfg)
 The shortest frame that can carry channels channels whatever they are commanded to, in microseconds: every channel at PPM_CHANNEL_MAX_US, plus the terminating mark, plus the smallest gap that is still a gap.
size_t ppm_frame (const uint16_t *channel_us, uint8_t channels, const ppm_cfg_t *cfg, uint16_t *runs, size_t max_runs)
 Lay a frame out as alternating run lengths in microseconds.

Variables

static const ppm_cfg_t k_default

Detailed Description

PPM frame layout.

See ppm.h for the model.

SPDX-License-Identifier: MIT

Function Documentation

◆ ppm_frame()

size_t ppm_frame ( const uint16_t * channel_us,
uint8_t channels,
const ppm_cfg_t * cfg,
uint16_t * runs,
size_t max_runs )

Lay a frame out as alternating run lengths in microseconds.

runs receives mark, space, mark, space, ... and ends with the terminating mark and the sync gap, so it always holds an even number of entries and always begins with a mark. A driver toggles the pin at each one and does not need to know which is which.

Returns the number of runs written, or 0 when the frame cannot be built: no channels or too many, a channel shorter than the mark it has to contain, a channel outside PPM_CHANNEL_MIN_US..PPM_CHANNEL_MAX_US, or a sync gap below cfg->sync_min_us once the channels have been paid for.

Parameters
channel_usPulse width of each channel, in us.
channelsNumber of channels in channel_us.
cfgFrame timing; NULL takes the defaults.
runsReceives the runs.
max_runsCapacity of runs, in entries.
Returns
Number of runs written, or 0 when the frame cannot be built.

◆ ppm_min_frame_us()

uint32_t ppm_min_frame_us ( uint8_t channels,
const ppm_cfg_t * cfg )

The shortest frame that can carry channels channels whatever they are commanded to, in microseconds: every channel at PPM_CHANNEL_MAX_US, plus the terminating mark, plus the smallest gap that is still a gap.

A configuration screen wants this before it offers a frame rate, so the refusal above becomes a range the operator never leaves rather than an error they hit. Returns 0 for a channel count this module cannot carry.

Parameters
channelsNumber of channels to carry.
cfgFrame timing; NULL takes the defaults.
Returns
Frame length in us, or 0 when channels is 0 or above PPM_MAX_CHANNELS.

Variable Documentation

◆ k_default

const ppm_cfg_t k_default
static
Initial value:
= {
.mark_us = PPM_DEFAULT_MARK_US,
.frame_us = PPM_DEFAULT_FRAME_US,
.sync_min_us = PPM_SYNC_MIN_US,
}
#define PPM_SYNC_MIN_US
The shortest gap that is unambiguously a gap.
Definition ppm.h:70