dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

PIOS interface to read and write from servo PWM ports. More...

Files

file  pios_servo_priv.h
 Servo private structures.
 
file  pios_servo.h
 RC Servo functions header.
 
file  pios_servo_priv.h
 Servo private structures.
 

Data Structures

struct  pios_pwm_cfg
 
struct  pios_servo_callbacks
 
struct  pios_servo_cfg
 
struct  dshot_info
 
struct  output_channel
 
struct  timer_bank
 

Macros

#define PIOS_SERVO_MAX_BANKS   8
 

Enumerations

enum  pios_servo_shot_type { SHOT_ONESHOT = 0, SHOT_DSHOT300 = 65532, SHOT_DSHOT600 = 65533, SHOT_DSHOT1200 = 65534 }
 
enum  dshot_gpio
 The counter rate for the channel, used to calculate compare values. More...
 
enum  channel_mode
 

Functions

int32_t PIOS_PWM_Init (uintptr_t *pwm_id, const struct pios_pwm_cfg *cfg)
 
int PIOS_Servo_GetPins (dio_tag_t *dios, int max_dio)
 
void PIOS_Servo_SetCallbacks (const struct pios_servo_callbacks *cb)
 
int PIOS_Servo_SetMode (const uint16_t *out_rate, const int banks, const uint16_t *channel_max, const uint16_t *channel_min)
 PIOS_Servo_SetMode Sets the PWM output frequency and resolution. An output rate of 0 indicates Synchronous updates (e.g. SyncPWM/OneShot), otherwise normal PWM at the specified output rate. SyncPWM uses hardware one-pulse mode. Timer prescaler and related parameters are calculated based on the channel with highest max pulse length on each timer. A deadtime is provided to ensure SyncPWM pulses cannot merge. The information required to convert from us to compare value is cached for each channel (not timer) to facilitate PIOS_Servo_Set. More...
 
void PIOS_Servo_SetFraction (uint8_t servo, uint16_t fraction, uint16_t max_val, uint16_t min_val)
 
void PIOS_Servo_DisableChannel (int channel)
 
void PIOS_Servo_PrepareForReset ()
 Determines the APB clock used by a given timer. More...
 
void PIOS_Servo_Set (uint8_t servo, float position)
 
void PIOS_Servo_Update (void)
 
bool PIOS_Servo_IsDshot (uint8_t servo)
 
int32_t PIOS_Servo_Init (const struct pios_servo_cfg *cfg)
 
enum dshot_gpio __attribute__ ((packed))
 
static uint32_t timer_apb_clock (TIM_TypeDef *timer)
 
static uint32_t max_timer_clock (TIM_TypeDef *timer)
 Determines the maximum clock rate for a given timer (i.e. no prescale) More...
 
static void ChannelSetup_DShot (int j, uint16_t rate)
 
static int BankSetup_DShot (struct timer_bank *bank)
 
static int BankSetup_OneShot (struct timer_bank *bank, int32_t max_tim_clock)
 
static int BankSetup_PWM (struct timer_bank *bank, int32_t max_tim_clock, uint16_t rate)
 
static void PIOS_Servo_SetRaw (uint8_t servo, uint32_t raw_position)
 
static int DSHOT_Update ()
 

Variables

const struct pios_rcvr_driver pios_pwm_rcvr_driver
 
static const struct
pios_servo_cfg
servo_cfg
 
static uint32_t channel_mask = 0
 
 DS_GPIOA = 0
 
 DS_GPIOB
 
 DS_GPIOC
 
 DS_GPIO_NUMVALS
 
 UNCONFIGURED = 0
 
 REGULAR_PWM
 
 REGULAR_INVERTED_PWM
 
 SYNC_PWM
 
 SYNC_DSHOT_300
 
 SYNC_DSHOT_600
 
 SYNC_DSHOT_1200
 
 SYNC_DSHOT_DMA
 
uint16_t dshot_info::value
 
uint16_t dshot_info::pin
 
enum dshot_gpio dshot_info::gpio
 
struct dshot_info __attribute__
 
enum channel_mode output_channel::mode
 
uint32_t   output_channel::pwm_res
 
struct dshot_info   output_channel::dshot
 
union {
   uint32_t   output_channel::pwm_res
 
   struct dshot_info   output_channel::dshot
 
output_channel::i
 
enum channel_mode mode
 
uint32_t   pwm_res
 
struct dshot_info   dshot
 
union {
   uint32_t   pwm_res
 
   struct dshot_info   dshot
 
i
 
static struct output_channeloutput_channels
 
static uintptr_t servo_tim_id
 
static bool resetting
 
static bool dshot_in_use
 
TIM_TypeDef * timer_bank::timer
 
uint32_t timer_bank::clk_rate
 
uint16_t timer_bank::max_pulse
 
uint16_t timer_bank::prescaler
 
uint16_t timer_bank::period
 

Detailed Description

PIOS interface to read and write from servo PWM ports.

Code to do set RC servo output.

Macro Definition Documentation

#define PIOS_SERVO_MAX_BANKS   8

Definition at line 35 of file pios_servo.h.

Enumeration Type Documentation

Definition at line 68 of file pios_servo.c.

enum dshot_gpio

The counter rate for the channel, used to calculate compare values.

Definition at line 61 of file pios_servo.c.

Enumerator
SHOT_ONESHOT 
SHOT_DSHOT300 
SHOT_DSHOT600 
SHOT_DSHOT1200 

Definition at line 40 of file pios_servo.h.

Function Documentation

enum dshot_gpio __attribute__ ( (packed)  )

Definition at line 38 of file serial_4way.h.

static int BankSetup_DShot ( struct timer_bank bank)
static

Definition at line 225 of file pios_servo.c.

static int BankSetup_OneShot ( struct timer_bank bank,
int32_t  max_tim_clock 
)
static

Definition at line 235 of file pios_servo.c.

static int BankSetup_PWM ( struct timer_bank bank,
int32_t  max_tim_clock,
uint16_t  rate 
)
static

Definition at line 261 of file pios_servo.c.

static void ChannelSetup_DShot ( int  j,
uint16_t  rate 
)
static

Definition at line 188 of file pios_servo.c.

static int DSHOT_Update ( )
static

Definition at line 674 of file pios_servo.c.

static uint32_t max_timer_clock ( TIM_TypeDef *  timer)
static

Determines the maximum clock rate for a given timer (i.e. no prescale)

Parameters
[in]timerPointer to the base register of the timer to check
Return values
Clockfrequency in Hz

Definition at line 957 of file pios_servo.c.

int32_t PIOS_PWM_Init ( uintptr_t *  pwm_id,
const struct pios_pwm_cfg cfg 
)
void PIOS_Servo_DisableChannel ( int  channel)

Definition at line 158 of file pios_servo.c.

int PIOS_Servo_GetPins ( dio_tag_t dios,
int  max_dio 
)

Definition at line 163 of file pios_servo.c.

int32_t PIOS_Servo_Init ( const struct pios_servo_cfg cfg)

Initialise Servos

Definition at line 109 of file pios_servo.c.

bool PIOS_Servo_IsDshot ( uint8_t  servo)

Definition at line 605 of file pios_servo.c.

void PIOS_Servo_PrepareForReset ( )

Determines the APB clock used by a given timer.

Parameters
[in]timerPointer to the base register of the timer to check
Return values
Clockfrequency in Hz Prepare for IAP reset. Stop PWM, so ESCs disarm.

Definition at line 948 of file pios_servo.c.

void PIOS_Servo_Set ( uint8_t  servo,
float  position 
)

Set servo position

Parameters
[in]ServoServo number (0->num_channels-1)
[in]PositionServo position in microseconds

Definition at line 624 of file pios_servo.c.

void PIOS_Servo_SetCallbacks ( const struct pios_servo_callbacks cb)
void PIOS_Servo_SetFraction ( uint8_t  servo,
uint16_t  fraction,
uint16_t  max_val,
uint16_t  min_val 
)

Definition at line 546 of file pios_servo.c.

int PIOS_Servo_SetMode ( const uint16_t *  out_rate,
const int  banks,
const uint16_t *  channel_max,
const uint16_t *  channel_min 
)

PIOS_Servo_SetMode Sets the PWM output frequency and resolution. An output rate of 0 indicates Synchronous updates (e.g. SyncPWM/OneShot), otherwise normal PWM at the specified output rate. SyncPWM uses hardware one-pulse mode. Timer prescaler and related parameters are calculated based on the channel with highest max pulse length on each timer. A deadtime is provided to ensure SyncPWM pulses cannot merge. The information required to convert from us to compare value is cached for each channel (not timer) to facilitate PIOS_Servo_Set.

Parameters
out_ratearray of output rate in Hz, banks elements
banksmaximum number of banks
channel_maxarray of max pulse lengths, number of channels elements
Todo:
attempts to just fall back to bitbanging, which seems not ideal– no benefit to doing DMA if we are bitbanging at the same time.

Definition at line 304 of file pios_servo.c.

static void PIOS_Servo_SetRaw ( uint8_t  servo,
uint32_t  raw_position 
)
static

Definition at line 519 of file pios_servo.c.

void PIOS_Servo_Update ( void  )

Update the timer for HPWM/OneShot

Definition at line 865 of file pios_servo.c.

static uint32_t timer_apb_clock ( TIM_TypeDef *  timer)
static

Variable Documentation

uint32_t channel_mask = 0
static

Definition at line 57 of file pios_servo.c.

uint32_t timer_bank::clk_rate

Definition at line 182 of file pios_servo.c.

DS_GPIO_NUMVALS

Definition at line 58 of file pios_servo.c.

DS_GPIOA = 0

Definition at line 58 of file pios_servo.c.

DS_GPIOB

Definition at line 58 of file pios_servo.c.

DS_GPIOC

Definition at line 58 of file pios_servo.c.

struct dshot_info dshot

Definition at line 62 of file pios_servo.c.

struct { ... } dshot

Definition at line 62 of file pios_servo.c.

struct dshot_info output_channel::dshot

Definition at line 90 of file pios_servo.c.

struct { ... } ::dshot

Definition at line 90 of file pios_servo.c.

bool dshot_in_use
static

Definition at line 100 of file pios_servo.c.

enum dshot_gpio dshot_info::gpio

Definition at line 82 of file pios_servo.c.

union { ... } i
union { ... } output_channel::i
uint16_t timer_bank::max_pulse

Definition at line 183 of file pios_servo.c.

enum channel_mode output_channel::mode

Definition at line 86 of file pios_servo.c.

enum channel_mode mode

Definition at line 58 of file pios_servo.c.

struct output_channel* output_channels
static

Definition at line 94 of file pios_servo.c.

uint16_t timer_bank::period

Definition at line 185 of file pios_servo.c.

uint16_t dshot_info::pin

Definition at line 81 of file pios_servo.c.

const struct pios_rcvr_driver pios_pwm_rcvr_driver
uint16_t timer_bank::prescaler

Definition at line 184 of file pios_servo.c.

uint32_t pwm_res

Definition at line 61 of file pios_servo.c.

uint32_t { ... } pwm_res

Definition at line 61 of file pios_servo.c.

uint32_t output_channel::pwm_res

Definition at line 89 of file pios_servo.c.

uint32_t { ... } ::pwm_res

Definition at line 89 of file pios_servo.c.

REGULAR_INVERTED_PWM

Definition at line 58 of file pios_servo.c.

REGULAR_PWM

Definition at line 58 of file pios_servo.c.

bool resetting
static

Definition at line 98 of file pios_servo.c.

const struct pios_servo_cfg* servo_cfg
static

Definition at line 55 of file pios_servo.c.

uintptr_t servo_tim_id
static

Definition at line 96 of file pios_servo.c.

SYNC_DSHOT_1200

Definition at line 58 of file pios_servo.c.

SYNC_DSHOT_300

Definition at line 58 of file pios_servo.c.

SYNC_DSHOT_600

Definition at line 58 of file pios_servo.c.

SYNC_DSHOT_DMA

Definition at line 58 of file pios_servo.c.

SYNC_PWM

Definition at line 58 of file pios_servo.c.

TIM_TypeDef* timer_bank::timer

Definition at line 181 of file pios_servo.c.

UNCONFIGURED = 0

Definition at line 58 of file pios_servo.c.

uint16_t dshot_info::value

Definition at line 80 of file pios_servo.c.