mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-04-09 01:53:48 +02:00
OP-932 Adds PWM outputs to OPLinkMini. Both gpio pins on the main and/or flexi port can be configured to output PWM for a total of up to 4 PWM outputs.
This commit is contained in:
parent
c76ee7de9d
commit
d0d8a0aadd
@ -77,7 +77,7 @@
|
|||||||
#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600
|
#define RFM22B_PPM_ONLY_DATARATE RFM22_datarate_9600
|
||||||
|
|
||||||
// The maximum amount of time without activity before initiating a reset.
|
// The maximum amount of time without activity before initiating a reset.
|
||||||
#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 100 // ms
|
#define PIOS_RFM22B_SUPERVISOR_TIMEOUT 150 // ms
|
||||||
|
|
||||||
// this is too adjust the RF module so that it is on frequency
|
// this is too adjust the RF module so that it is on frequency
|
||||||
#define OSC_LOAD_CAP 0x7F // cap = 12.5pf .. default
|
#define OSC_LOAD_CAP 0x7F // cap = 12.5pf .. default
|
||||||
@ -1905,13 +1905,11 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (good_packet || corrected_packet) {
|
if (good_packet || corrected_packet) {
|
||||||
bool valid_input_detected = false;
|
|
||||||
for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) {
|
for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) {
|
||||||
// Is this a valid channel?
|
// Is this a valid channel?
|
||||||
if (p[0] & (1 << i)) {
|
if (p[0] & (1 << i)) {
|
||||||
uint32_t val = p[i + 1];
|
uint32_t val = p[i + 1];
|
||||||
radio_dev->ppm[i] = (uint16_t)(1000 + val * 900 / 256);
|
radio_dev->ppm[i] = (uint16_t)(1000 + val * 900 / 256);
|
||||||
valid_input_detected = true;
|
|
||||||
} else {
|
} else {
|
||||||
radio_dev->ppm[i] = PIOS_RCVR_INVALID;
|
radio_dev->ppm[i] = PIOS_RCVR_INVALID;
|
||||||
}
|
}
|
||||||
@ -1921,7 +1919,7 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d
|
|||||||
data_len -= RFM22B_PPM_NUM_CHANNELS + 1;
|
data_len -= RFM22B_PPM_NUM_CHANNELS + 1;
|
||||||
|
|
||||||
// Call the PPM received callback if it's available.
|
// Call the PPM received callback if it's available.
|
||||||
if (valid_input_detected && radio_dev->ppm_callback) {
|
if (radio_dev->ppm_callback) {
|
||||||
radio_dev->ppm_callback(radio_dev->ppm);
|
radio_dev->ppm_callback(radio_dev->ppm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2214,7 +2212,6 @@ static uint8_t rfm22_calcChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t ind
|
|||||||
|
|
||||||
// Are we switching to a new channel?
|
// Are we switching to a new channel?
|
||||||
if (idx != rfm22b_dev->channel_index) {
|
if (idx != rfm22b_dev->channel_index) {
|
||||||
|
|
||||||
// If the on_sync_channel flag is set, it means that we were on the sync channel, but no packet was received, so transition to a non-connected state.
|
// If the on_sync_channel flag is set, it means that we were on the sync channel, but no packet was received, so transition to a non-connected state.
|
||||||
if (!rfm22_isCoordinator(rfm22b_dev) && (rfm22b_dev->channel_index == 0) && rfm22b_dev->on_sync_channel) {
|
if (!rfm22_isCoordinator(rfm22b_dev) && (rfm22b_dev->channel_index == 0) && rfm22b_dev->on_sync_channel) {
|
||||||
rfm22b_dev->on_sync_channel = false;
|
rfm22b_dev->on_sync_channel = false;
|
||||||
@ -2230,7 +2227,6 @@ static uint8_t rfm22_calcChannel(struct pios_rfm22b_dev *rfm22b_dev, uint8_t ind
|
|||||||
|
|
||||||
// Stay on the sync channel.
|
// Stay on the sync channel.
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
|
||||||
} else if (idx == 0) {
|
} else if (idx == 0) {
|
||||||
// If we're switching to the sync channel, set a flag that can be used to detect if a packet was received.
|
// If we're switching to the sync channel, set a flag that can be used to detect if a packet was received.
|
||||||
rfm22b_dev->on_sync_channel = true;
|
rfm22b_dev->on_sync_channel = true;
|
||||||
|
@ -432,9 +432,79 @@ static const struct pios_tim_clock_cfg tim_4_cfg = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct pios_tim_channel pios_tim_ppm_flexi_port = {
|
static const struct pios_tim_channel pios_tim_all_port_pins[] = {
|
||||||
|
/* Main Tx */
|
||||||
|
{
|
||||||
|
.timer = TIM1,
|
||||||
|
.timer_chan = TIM_Channel_2,
|
||||||
|
.pin = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_9,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
/* Main Rx */
|
||||||
|
{
|
||||||
|
.timer = TIM1,
|
||||||
|
.timer_chan = TIM_Channel_3,
|
||||||
|
.pin = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
/* Flexi Tx */
|
||||||
|
{
|
||||||
|
.timer = TIM2,
|
||||||
|
.timer_chan = TIM_Channel_3,
|
||||||
|
.pin = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.remap = GPIO_PartialRemap2_TIM2,
|
||||||
|
},
|
||||||
|
/* Flexi Rx */
|
||||||
|
{
|
||||||
|
.timer = TIM2,
|
||||||
|
.timer_chan = TIM_Channel_4,
|
||||||
|
.pin = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_11,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.remap = GPIO_PartialRemap2_TIM2,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct pios_tim_channel pios_tim_main_port_ppm = {
|
||||||
|
.timer = TIM1,
|
||||||
|
.timer_chan = TIM_Channel_3,
|
||||||
|
.pin = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Mode = GPIO_Mode_IPD,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct pios_tim_channel pios_tim_flexi_port_ppm = {
|
||||||
.timer = TIM2,
|
.timer = TIM2,
|
||||||
.timer_chan = TIM_Channel_4,
|
.timer_chan = TIM_Channel_4,
|
||||||
.pin = {
|
.pin = {
|
||||||
.gpio = GPIOB,
|
.gpio = GPIOB,
|
||||||
.init = {
|
.init = {
|
||||||
@ -443,24 +513,130 @@ static const struct pios_tim_channel pios_tim_ppm_flexi_port = {
|
|||||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.remap = GPIO_PartialRemap2_TIM2,
|
.remap = GPIO_PartialRemap2_TIM2,
|
||||||
};
|
|
||||||
|
|
||||||
static const struct pios_tim_channel pios_tim_ppm_main_port = {
|
|
||||||
.timer = TIM1,
|
|
||||||
.timer_chan = TIM_Channel_2,
|
|
||||||
.pin = {
|
|
||||||
.gpio = GPIOA,
|
|
||||||
.init = {
|
|
||||||
.GPIO_Pin = GPIO_Pin_9,
|
|
||||||
.GPIO_Mode = GPIO_Mode_IPD,
|
|
||||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_TIM */
|
#endif /* PIOS_INCLUDE_TIM */
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
|
||||||
|
/*
|
||||||
|
* Servo outputs
|
||||||
|
*/
|
||||||
|
#include <pios_servo_priv.h>
|
||||||
|
|
||||||
|
const struct pios_servo_cfg pios_servo_main_cfg = {
|
||||||
|
.tim_oc_init = {
|
||||||
|
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||||
|
.TIM_OutputState = TIM_OutputState_Enable,
|
||||||
|
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||||
|
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
||||||
|
.TIM_OCPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCNPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||||
|
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
||||||
|
},
|
||||||
|
.channels = pios_tim_all_port_pins,
|
||||||
|
.num_channels = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct pios_servo_cfg pios_servo_flexi_cfg = {
|
||||||
|
.tim_oc_init = {
|
||||||
|
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||||
|
.TIM_OutputState = TIM_OutputState_Enable,
|
||||||
|
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||||
|
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
||||||
|
.TIM_OCPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCNPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||||
|
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
||||||
|
},
|
||||||
|
.channels = &(pios_tim_all_port_pins[2]),
|
||||||
|
.num_channels = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct pios_servo_cfg pios_servo_main_flexi_cfg = {
|
||||||
|
.tim_oc_init = {
|
||||||
|
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||||
|
.TIM_OutputState = TIM_OutputState_Enable,
|
||||||
|
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||||
|
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
||||||
|
.TIM_OCPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCNPolarity = TIM_OCPolarity_High,
|
||||||
|
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||||
|
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
||||||
|
},
|
||||||
|
.channels = pios_tim_all_port_pins,
|
||||||
|
.num_channels = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PPM Inputs
|
||||||
|
*/
|
||||||
|
#if defined(PIOS_INCLUDE_PPM)
|
||||||
|
#include <pios_ppm_priv.h>
|
||||||
|
|
||||||
|
const struct pios_ppm_cfg pios_ppm_main_cfg = {
|
||||||
|
.tim_ic_init = {
|
||||||
|
.TIM_ICPolarity = TIM_ICPolarity_Rising,
|
||||||
|
.TIM_ICSelection = TIM_ICSelection_DirectTI,
|
||||||
|
.TIM_ICPrescaler = TIM_ICPSC_DIV1,
|
||||||
|
.TIM_ICFilter = 0x0,
|
||||||
|
},
|
||||||
|
.channels = &pios_tim_main_port_ppm,
|
||||||
|
.num_channels = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct pios_ppm_cfg pios_ppm_flexi_cfg = {
|
||||||
|
.tim_ic_init = {
|
||||||
|
.TIM_ICPolarity = TIM_ICPolarity_Rising,
|
||||||
|
.TIM_ICSelection = TIM_ICSelection_DirectTI,
|
||||||
|
.TIM_ICPrescaler = TIM_ICPSC_DIV1,
|
||||||
|
.TIM_ICFilter = 0x0,
|
||||||
|
},
|
||||||
|
.channels = &pios_tim_flexi_port_ppm,
|
||||||
|
.num_channels = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PIOS_INCLUDE_PPM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PPM Output
|
||||||
|
*/
|
||||||
|
#if defined(PIOS_INCLUDE_PPM_OUT)
|
||||||
|
#include <pios_ppm_out_priv.h>
|
||||||
|
|
||||||
|
const struct pios_ppm_out_cfg pios_main_ppm_out_cfg = {
|
||||||
|
.tim_oc_init = {
|
||||||
|
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||||
|
.TIM_OutputState = TIM_OutputState_Enable,
|
||||||
|
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||||
|
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
||||||
|
.TIM_OCPolarity = TIM_OCPolarity_Low,
|
||||||
|
.TIM_OCNPolarity = TIM_OCPolarity_Low,
|
||||||
|
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||||
|
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
||||||
|
},
|
||||||
|
.channel = &(pios_tim_all_port_pins[0]),
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct pios_ppm_out_cfg pios_flexi_ppm_out_cfg = {
|
||||||
|
.tim_oc_init = {
|
||||||
|
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||||
|
.TIM_OutputState = TIM_OutputState_Enable,
|
||||||
|
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||||
|
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
||||||
|
.TIM_OCPolarity = TIM_OCPolarity_Low,
|
||||||
|
.TIM_OCNPolarity = TIM_OCPolarity_Low,
|
||||||
|
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||||
|
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
||||||
|
},
|
||||||
|
.channel = &(pios_tim_all_port_pins[2]),
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PIOS_INCLUDE_PPM_OUT */
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
#if defined(PIOS_INCLUDE_USART)
|
||||||
|
|
||||||
#include <pios_usart_priv.h>
|
#include <pios_usart_priv.h>
|
||||||
@ -576,74 +752,6 @@ void PIOS_RTC_IRQ_Handler(void)
|
|||||||
|
|
||||||
#endif /* if defined(PIOS_INCLUDE_RTC) */
|
#endif /* if defined(PIOS_INCLUDE_RTC) */
|
||||||
|
|
||||||
/*
|
|
||||||
* PPM Inputs
|
|
||||||
*/
|
|
||||||
#if defined(PIOS_INCLUDE_PPM)
|
|
||||||
#include <pios_ppm_priv.h>
|
|
||||||
|
|
||||||
const struct pios_ppm_cfg pios_ppm_flexi_cfg = {
|
|
||||||
.tim_ic_init = {
|
|
||||||
.TIM_ICPolarity = TIM_ICPolarity_Rising,
|
|
||||||
.TIM_ICSelection = TIM_ICSelection_DirectTI,
|
|
||||||
.TIM_ICPrescaler = TIM_ICPSC_DIV1,
|
|
||||||
.TIM_ICFilter = 0x0,
|
|
||||||
},
|
|
||||||
.channels = &pios_tim_ppm_flexi_port,
|
|
||||||
.num_channels = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct pios_ppm_cfg pios_ppm_main_cfg = {
|
|
||||||
.tim_ic_init = {
|
|
||||||
.TIM_ICPolarity = TIM_ICPolarity_Rising,
|
|
||||||
.TIM_ICSelection = TIM_ICSelection_DirectTI,
|
|
||||||
.TIM_ICPrescaler = TIM_ICPSC_DIV1,
|
|
||||||
.TIM_ICFilter = 0x0,
|
|
||||||
},
|
|
||||||
.channels = &pios_tim_ppm_main_port,
|
|
||||||
.num_channels = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_PPM */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PPM Output
|
|
||||||
*/
|
|
||||||
#if defined(PIOS_INCLUDE_PPM_OUT)
|
|
||||||
#include <pios_ppm_out_priv.h>
|
|
||||||
|
|
||||||
static const struct pios_tim_channel pios_tim_ppmout[] = {
|
|
||||||
{
|
|
||||||
.timer = TIM2,
|
|
||||||
.timer_chan = TIM_Channel_3,
|
|
||||||
.pin = {
|
|
||||||
.gpio = GPIOB,
|
|
||||||
.init = {
|
|
||||||
.GPIO_Pin = GPIO_Pin_10,
|
|
||||||
.GPIO_Mode = GPIO_Mode_AF_PP,
|
|
||||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
.remap = GPIO_FullRemap_TIM2,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const struct pios_ppm_out_cfg pios_ppm_out_cfg = {
|
|
||||||
.tim_oc_init = {
|
|
||||||
.TIM_OCMode = TIM_OCMode_PWM1,
|
|
||||||
.TIM_OutputState = TIM_OutputState_Enable,
|
|
||||||
.TIM_OutputNState = TIM_OutputNState_Disable,
|
|
||||||
.TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
|
|
||||||
.TIM_OCPolarity = TIM_OCPolarity_Low,
|
|
||||||
.TIM_OCNPolarity = TIM_OCPolarity_Low,
|
|
||||||
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
|
||||||
.TIM_OCNIdleState = TIM_OCNIdleState_Reset,
|
|
||||||
},
|
|
||||||
.channel = pios_tim_ppmout,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_PPM_OUT */
|
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_RCVR)
|
#if defined(PIOS_INCLUDE_RCVR)
|
||||||
#include "pios_rcvr_priv.h"
|
#include "pios_rcvr_priv.h"
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
/* #define PIOS_INCLUDE_HCSR04 */
|
/* #define PIOS_INCLUDE_HCSR04 */
|
||||||
|
|
||||||
/* PIOS receiver drivers */
|
/* PIOS receiver drivers */
|
||||||
/* #define PIOS_INCLUDE_PWM */
|
#define PIOS_INCLUDE_PWM
|
||||||
#define PIOS_INCLUDE_PPM
|
#define PIOS_INCLUDE_PPM
|
||||||
/* #define PIOS_INCLUDE_PPM_FLEXI */
|
/* #define PIOS_INCLUDE_PPM_FLEXI */
|
||||||
/* #define PIOS_INCLUDE_DSM */
|
/* #define PIOS_INCLUDE_DSM */
|
||||||
@ -101,7 +101,7 @@
|
|||||||
/* PIOS common peripherals */
|
/* PIOS common peripherals */
|
||||||
#define PIOS_INCLUDE_LED
|
#define PIOS_INCLUDE_LED
|
||||||
#define PIOS_INCLUDE_IAP
|
#define PIOS_INCLUDE_IAP
|
||||||
/* #define PIOS_INCLUDE_SERVO */
|
#define PIOS_INCLUDE_SERVO
|
||||||
/* #define PIOS_INCLUDE_I2C_ESC */
|
/* #define PIOS_INCLUDE_I2C_ESC */
|
||||||
/* #define PIOS_INCLUDE_OVERO */
|
/* #define PIOS_INCLUDE_OVERO */
|
||||||
/* #define PIOS_OVERO_SPI */
|
/* #define PIOS_OVERO_SPI */
|
||||||
|
@ -32,6 +32,9 @@
|
|||||||
#include <pios_ppm_out.h>
|
#include <pios_ppm_out.h>
|
||||||
#include <oplinksettings.h>
|
#include <oplinksettings.h>
|
||||||
#include <taskinfo.h>
|
#include <taskinfo.h>
|
||||||
|
#ifdef PIOS_INCLUDE_SERVO
|
||||||
|
#include <pios_servo.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pull in the board-specific static HW definitions.
|
* Pull in the board-specific static HW definitions.
|
||||||
@ -76,11 +79,9 @@ uint8_t *pios_uart_tx_buffer;
|
|||||||
|
|
||||||
uintptr_t pios_uavo_settings_fs_id;
|
uintptr_t pios_uavo_settings_fs_id;
|
||||||
|
|
||||||
|
uint8_t servo_count = 0;
|
||||||
|
|
||||||
// Forward definitions
|
// Forward definitions
|
||||||
static void PIOS_InitUartMainPort();
|
|
||||||
static void PIOS_InitUartFlexiPort();
|
|
||||||
static void PIOS_InitPPMMainPort(bool input);
|
|
||||||
static void PIOS_InitPPMFlexiPort(bool input);
|
|
||||||
static void PIOS_Board_PPM_callback(const int16_t *channels);
|
static void PIOS_Board_PPM_callback(const int16_t *channels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,16 +233,53 @@ void PIOS_Board_Init(void)
|
|||||||
bool is_oneway = (oplinkSettings.OneWay == OPLINKSETTINGS_ONEWAY_TRUE);
|
bool is_oneway = (oplinkSettings.OneWay == OPLINKSETTINGS_ONEWAY_TRUE);
|
||||||
bool ppm_only = (oplinkSettings.PPMOnly == OPLINKSETTINGS_PPMONLY_TRUE);
|
bool ppm_only = (oplinkSettings.PPMOnly == OPLINKSETTINGS_PPMONLY_TRUE);
|
||||||
bool ppm_mode = false;
|
bool ppm_mode = false;
|
||||||
|
bool servo_main = false;
|
||||||
|
bool servo_flexi = false;
|
||||||
switch (oplinkSettings.MainPort) {
|
switch (oplinkSettings.MainPort) {
|
||||||
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
|
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
|
||||||
case OPLINKSETTINGS_MAINPORT_SERIAL:
|
case OPLINKSETTINGS_MAINPORT_SERIAL:
|
||||||
|
{
|
||||||
/* Configure the main port for uart serial */
|
/* Configure the main port for uart serial */
|
||||||
PIOS_InitUartMainPort();
|
#ifndef PIOS_RFM22B_DEBUG_ON_TELEM
|
||||||
|
uint32_t pios_usart1_id;
|
||||||
|
if (PIOS_USART_Init(&pios_usart1_id, &pios_usart_serial_cfg)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
|
PIOS_Assert(pios_uart_rx_buffer);
|
||||||
|
PIOS_Assert(pios_uart_tx_buffer);
|
||||||
|
if (PIOS_COM_Init(&pios_com_telem_uart_main_id, &pios_usart_com_driver, pios_usart1_id,
|
||||||
|
pios_uart_rx_buffer, PIOS_COM_TELEM_RX_BUF_LEN,
|
||||||
|
pios_uart_tx_buffer, PIOS_COM_TELEM_TX_BUF_LEN)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_UART_MAIN;
|
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_UART_MAIN;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case OPLINKSETTINGS_MAINPORT_PPM:
|
case OPLINKSETTINGS_MAINPORT_PPM:
|
||||||
PIOS_InitPPMMainPort(is_coordinator);
|
{
|
||||||
|
#if defined(PIOS_INCLUDE_PPM)
|
||||||
|
/* PPM input is configured on the coordinator modem and output on the remote modem. */
|
||||||
|
if (is_coordinator) {
|
||||||
|
uint32_t pios_ppm_id;
|
||||||
|
PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_main_cfg);
|
||||||
|
|
||||||
|
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, pios_ppm_id)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// For some reason, PPM output on the main port doesn't work.
|
||||||
|
#if defined(PIOS_INCLUDE_PPM_OUT)
|
||||||
|
else {
|
||||||
|
PIOS_PPM_Out_Init(&pios_ppm_out_id, &pios_main_ppm_out_cfg);
|
||||||
|
}
|
||||||
|
#endif /* PIOS_INCLUDE_PPM_OUT */
|
||||||
ppm_mode = true;
|
ppm_mode = true;
|
||||||
|
#endif /* PIOS_INCLUDE_PPM */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OPLINKSETTINGS_MAINPORT_PWM:
|
||||||
|
servo_main = true;
|
||||||
break;
|
break;
|
||||||
case OPLINKSETTINGS_MAINPORT_DISABLED:
|
case OPLINKSETTINGS_MAINPORT_DISABLED:
|
||||||
break;
|
break;
|
||||||
@ -251,14 +289,45 @@ void PIOS_Board_Init(void)
|
|||||||
switch (oplinkSettings.FlexiPort) {
|
switch (oplinkSettings.FlexiPort) {
|
||||||
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
|
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
|
||||||
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
|
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
|
||||||
|
{
|
||||||
/* Configure the flexi port as uart serial */
|
/* Configure the flexi port as uart serial */
|
||||||
PIOS_InitUartFlexiPort();
|
uint32_t pios_usart3_id;
|
||||||
|
|
||||||
|
if (PIOS_USART_Init(&pios_usart3_id, &pios_usart_telem_flexi_cfg)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
|
PIOS_Assert(pios_uart_rx_buffer);
|
||||||
|
PIOS_Assert(pios_uart_tx_buffer);
|
||||||
|
if (PIOS_COM_Init(&pios_com_telem_uart_flexi_id, &pios_usart_com_driver, pios_usart3_id,
|
||||||
|
pios_uart_rx_buffer, PIOS_COM_TELEM_RX_BUF_LEN,
|
||||||
|
pios_uart_tx_buffer, PIOS_COM_TELEM_TX_BUF_LEN)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_UART_FLEXI;
|
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_UART_FLEXI;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case OPLINKSETTINGS_FLEXIPORT_PPM:
|
case OPLINKSETTINGS_FLEXIPORT_PPM:
|
||||||
PIOS_InitPPMFlexiPort(is_coordinator);
|
{
|
||||||
|
#if defined(PIOS_INCLUDE_PPM)
|
||||||
|
/* PPM input is configured on the coordinator modem and output on the remote modem. */
|
||||||
|
if (is_coordinator) {
|
||||||
|
uint32_t pios_ppm_id;
|
||||||
|
PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_flexi_cfg);
|
||||||
|
|
||||||
|
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, pios_ppm_id)) {
|
||||||
|
PIOS_Assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PIOS_PPM_Out_Init(&pios_ppm_out_id, &pios_flexi_ppm_out_cfg);
|
||||||
|
}
|
||||||
|
#endif /* PIOS_INCLUDE_PPM */
|
||||||
ppm_mode = true;
|
ppm_mode = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case OPLINKSETTINGS_FLEXIPORT_PWM:
|
||||||
|
servo_flexi = true;
|
||||||
|
break;
|
||||||
case OPLINKSETTINGS_FLEXIPORT_DISABLED:
|
case OPLINKSETTINGS_FLEXIPORT_DISABLED:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -272,6 +341,22 @@ void PIOS_Board_Init(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_SERVO)
|
||||||
|
if (servo_main) {
|
||||||
|
if (servo_flexi) {
|
||||||
|
servo_count = 4;
|
||||||
|
PIOS_Servo_Init(&pios_servo_main_flexi_cfg);
|
||||||
|
} else {
|
||||||
|
servo_count = 2;
|
||||||
|
PIOS_Servo_Init(&pios_servo_main_cfg);
|
||||||
|
}
|
||||||
|
} else if (servo_flexi) {
|
||||||
|
servo_count = 2;
|
||||||
|
PIOS_Servo_Init(&pios_servo_flexi_cfg);
|
||||||
|
}
|
||||||
|
ppm_mode = ppm_mode || (servo_count > 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize out status object.
|
// Initialize out status object.
|
||||||
OPLinkStatusData oplinkStatus;
|
OPLinkStatusData oplinkStatus;
|
||||||
OPLinkStatusGet(&oplinkStatus);
|
OPLinkStatusGet(&oplinkStatus);
|
||||||
@ -412,83 +497,22 @@ void PIOS_Board_Init(void)
|
|||||||
PIOS_GPIO_Init();
|
PIOS_GPIO_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PIOS_InitUartMainPort()
|
|
||||||
{
|
|
||||||
#ifndef PIOS_RFM22B_DEBUG_ON_TELEM
|
|
||||||
uint32_t pios_usart1_id;
|
|
||||||
if (PIOS_USART_Init(&pios_usart1_id, &pios_usart_serial_cfg)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
PIOS_Assert(pios_uart_rx_buffer);
|
|
||||||
PIOS_Assert(pios_uart_tx_buffer);
|
|
||||||
if (PIOS_COM_Init(&pios_com_telem_uart_main_id, &pios_usart_com_driver, pios_usart1_id,
|
|
||||||
pios_uart_rx_buffer, PIOS_COM_TELEM_RX_BUF_LEN,
|
|
||||||
pios_uart_tx_buffer, PIOS_COM_TELEM_TX_BUF_LEN)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PIOS_InitUartFlexiPort()
|
|
||||||
{
|
|
||||||
uint32_t pios_usart3_id;
|
|
||||||
|
|
||||||
if (PIOS_USART_Init(&pios_usart3_id, &pios_usart_telem_flexi_cfg)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
PIOS_Assert(pios_uart_rx_buffer);
|
|
||||||
PIOS_Assert(pios_uart_tx_buffer);
|
|
||||||
if (PIOS_COM_Init(&pios_com_telem_uart_flexi_id, &pios_usart_com_driver, pios_usart3_id,
|
|
||||||
pios_uart_rx_buffer, PIOS_COM_TELEM_RX_BUF_LEN,
|
|
||||||
pios_uart_tx_buffer, PIOS_COM_TELEM_TX_BUF_LEN)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PIOS_InitPPMMainPort(bool input)
|
|
||||||
{
|
|
||||||
#if defined(PIOS_INCLUDE_PPM)
|
|
||||||
/* PPM input is configured on the coordinator modem and output on the remote modem. */
|
|
||||||
if (input) {
|
|
||||||
uint32_t pios_ppm_id;
|
|
||||||
PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_main_cfg);
|
|
||||||
|
|
||||||
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, pios_ppm_id)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// For some reason, PPM output on the main port doesn't work.
|
|
||||||
#endif /* PIOS_INCLUDE_PPM */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PIOS_InitPPMFlexiPort(bool input)
|
|
||||||
{
|
|
||||||
#if defined(PIOS_INCLUDE_PPM)
|
|
||||||
/* PPM input is configured on the coordinator modem and output on the remote modem. */
|
|
||||||
if (input) {
|
|
||||||
uint32_t pios_ppm_id;
|
|
||||||
PIOS_PPM_Init(&pios_ppm_id, &pios_ppm_flexi_cfg);
|
|
||||||
|
|
||||||
if (PIOS_RCVR_Init(&pios_ppm_rcvr_id, &pios_ppm_rcvr_driver, pios_ppm_id)) {
|
|
||||||
PIOS_Assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if defined(PIOS_INCLUDE_PPM_OUT)
|
|
||||||
else {
|
|
||||||
PIOS_PPM_Out_Init(&pios_ppm_out_id, &pios_ppm_out_cfg);
|
|
||||||
}
|
|
||||||
#endif /* PIOS_INCLUDE_PPM_OUT */
|
|
||||||
#endif /* PIOS_INCLUDE_PPM */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PIOS_Board_PPM_callback(const int16_t *channels)
|
static void PIOS_Board_PPM_callback(const int16_t *channels)
|
||||||
{
|
{
|
||||||
#if defined(PIOS_INCLUDE_PPM) && defined(PIOS_INCLUDE_PPM_OUT)
|
#if defined(PIOS_INCLUDE_PPM) && defined(PIOS_INCLUDE_PPM_OUT)
|
||||||
if (pios_ppm_out_id) {
|
if (pios_ppm_out_id) {
|
||||||
for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) {
|
for (uint8_t i = 0; i < RFM22B_PPM_NUM_CHANNELS; ++i) {
|
||||||
PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]);
|
if (channels[i] != PIOS_RCVR_INVALID) {
|
||||||
|
PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, channels[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(PIOS_INCLUDE_SERVO)
|
||||||
|
for (uint8_t i = 0; i < servo_count; ++i) {
|
||||||
|
uint16_t val = (channels[i] == PIOS_RCVR_INVALID) ? 0 : channels[i];
|
||||||
|
PIOS_Servo_Set(i, val);
|
||||||
|
}
|
||||||
|
#endif /* PIOS_INCLUDE_SERVO */
|
||||||
#endif /* PIOS_INCLUDE_PPM && PIOS_INCLUDE_PPM_OUT */
|
#endif /* PIOS_INCLUDE_PPM && PIOS_INCLUDE_PPM_OUT */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,11 @@ extern uint32_t pios_ppm_out_id;
|
|||||||
#define PIOS_PPM_MAX_DEVS 1
|
#define PIOS_PPM_MAX_DEVS 1
|
||||||
#define PIOS_PPM_NUM_INPUTS 8
|
#define PIOS_PPM_NUM_INPUTS 8
|
||||||
|
|
||||||
|
// -------------------------
|
||||||
|
// Receiver PWM inputs
|
||||||
|
// -------------------------
|
||||||
|
#define PIOS_PWM_NUM_INPUTS 4
|
||||||
|
|
||||||
// -------------------------
|
// -------------------------
|
||||||
// Servo outputs
|
// Servo outputs
|
||||||
// -------------------------
|
// -------------------------
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<field name="PPM" units="" type="enum" elements="1" options="FALSE,TRUE" defaultvalue="FALSE"/>
|
<field name="PPM" units="" type="enum" elements="1" options="FALSE,TRUE" defaultvalue="FALSE"/>
|
||||||
<field name="PPMOnly" units="" type="enum" elements="1" options="FALSE,TRUE" defaultvalue="FALSE"/>
|
<field name="PPMOnly" units="" type="enum" elements="1" options="FALSE,TRUE" defaultvalue="FALSE"/>
|
||||||
<field name="CoordID" units="hex" type="uint32" elements="1" defaultvalue="0"/>
|
<field name="CoordID" units="hex" type="uint32" elements="1" defaultvalue="0"/>
|
||||||
<field name="MainPort" units="" type="enum" elements="1" options="Disabled,Telemetry,Serial,PPM" defaultvalue="Telemetry"/>
|
<field name="MainPort" units="" type="enum" elements="1" options="Disabled,Telemetry,Serial,PPM,PWM" defaultvalue="Disabled"/>
|
||||||
<field name="FlexiPort" units="" type="enum" elements="1" options="Disabled,Telemetry,Serial,PPM" defaultvalue="Disabled"/>
|
<field name="FlexiPort" units="" type="enum" elements="1" options="Disabled,Telemetry,Serial,PPM,PWM" defaultvalue="Disabled"/>
|
||||||
<field name="VCPPort" units="" type="enum" elements="1" options="Disabled,Serial" defaultvalue="Disabled"/>
|
<field name="VCPPort" units="" type="enum" elements="1" options="Disabled,Serial" defaultvalue="Disabled"/>
|
||||||
<field name="ComSpeed" units="bps" type="enum" elements="1" options="4800,9600,19200,38400,57600,115200" defaultvalue="38400"/>
|
<field name="ComSpeed" units="bps" type="enum" elements="1" options="4800,9600,19200,38400,57600,115200" defaultvalue="38400"/>
|
||||||
<field name="MaxRFPower" units="mW" type="enum" elements="1" options="0,1.25,1.6,3.16,6.3,12.6,25,50,100" defaultvalue="0"/>
|
<field name="MaxRFPower" units="mW" type="enum" elements="1" options="0,1.25,1.6,3.16,6.3,12.6,25,50,100" defaultvalue="0"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user