1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

Master/SBUS Module now working

This commit is contained in:
bsongis 2014-09-28 09:50:03 +02:00
parent 440cd6a162
commit f57444f1cb
9 changed files with 50 additions and 38 deletions

View file

@ -136,11 +136,11 @@ void lcdPutPattern(coord_t x, coord_t y, const uint8_t * pattern, uint8_t width,
void lcd_putcAtt(coord_t x, coord_t y, const unsigned char c, LcdFlags flags)
{
const pm_uchar * q;
uint32_t fontsize = FONTSIZE(flags);
lcdNextPos = x-1;
#if !defined(BOOT)
uint32_t fontsize = FONTSIZE(flags);
unsigned char c_remapped = 0;
if (fontsize == DBLSIZE || (flags&BOLD)) {

View file

@ -2289,20 +2289,7 @@ void perMain()
#endif
#if defined(PCBTARANIS)
uint8_t requiredTrainerMode = g_model.trainerMode;
if (requiredTrainerMode != currentTrainerMode) {
currentTrainerMode = requiredTrainerMode;
if (requiredTrainerMode) {
// slave
stop_trainer_capture();
init_trainer_ppm();
}
else {
// master
stop_trainer_ppm();
init_trainer_capture();
}
}
checkTrainerSettings();
#endif
#if defined(PCBTARANIS) && !defined(SIMU)
@ -2609,7 +2596,7 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS
else {
if (ppmInState>0 && ppmInState<=8) {
if (val>800 && val<2200) { // if valid pulse-width range
ppmInValid = 100;
ppmInValid = PPM_IN_VALID_TIMEOUT;
g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500) * (uint8_t)(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough.
}
else {

View file

@ -1123,6 +1123,7 @@ extern uint8_t g_beepVal[5];
extern uint8_t ppmInState; //0=unsync 1..8= wait for value i-1
extern uint8_t ppmInValid;
#define PPM_IN_VALID_TIMEOUT 100
extern int16_t g_ppmIns[NUM_TRAINER];
extern int32_t chans[NUM_CHNOUT];
extern int16_t ex_chans[NUM_CHNOUT]; // Outputs (before LIMITS) of the last perMain

View file

@ -36,7 +36,7 @@
#include "opentx.h"
Fifo<28> sbusFifo;
Fifo<32> sbusFifo;
uint8_t SbusFrame[28] ;
uint16_t SbusTimer ;
uint8_t SbusIndex = 0 ;
@ -59,6 +59,8 @@ void processSbusFrame(uint8_t *sbus, int16_t *pulses)
inputbitsavailable -= 11;
inputbits >>= 11;
}
ppmInValid = PPM_IN_VALID_TIMEOUT;
}
#define SBUS_DELAY 1000 // 500uS

View file

@ -406,6 +406,7 @@ inline void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) {
#define GPIO_ResetBits(GPIOx, pin) GPIOx->BSRRL &= ~pin
#define GPIO_ReadInputDataBit(GPIOx, pin) (GPIOx->BSRRL & pin)
#define RCC_AHB1PeriphClockCmd(...)
#define RCC_APB2PeriphClockCmd(...)
#endif
#define configure_pins(...)

View file

@ -257,7 +257,7 @@ extern "C" void TC3_IRQHandler() //capture ppm in at 2MHz
else {
if (ppmInState>0 && ppmInState<=16) {
if (val>800 && val<2200) { // if valid pulse-width range
ppmInValid = 100;
ppmInValid = PPM_IN_VALID_TIMEOUT;
g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough.
}
else {

View file

@ -263,7 +263,10 @@ void hapticOff(void);
void uart3Init(unsigned int mode, unsigned int protocol);
void uart3Putc(const char c);
#define telemetrySecondPortInit(protocol) uart3Init(UART_MODE_TELEMETRY, protocol)
void uart3SbusInit();
void uart3Stop();
void uart3SbusInit(void);
void uart3Stop(void);
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
#endif

View file

@ -38,7 +38,7 @@
uint16_t * TrainerPulsePtr;
extern uint16_t ppmStream[NUM_MODULES+1][20];
extern Fifo<28> sbusFifo;
extern Fifo<32> sbusFifo;
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
@ -141,7 +141,7 @@ extern "C" void TIM3_IRQHandler()
else {
if (ppmInState>0 && ppmInState<=16) {
if (val>800 && val<2200) {
ppmInValid = 100;
ppmInValid = PPM_IN_VALID_TIMEOUT;
g_ppmIns[ppmInState++ - 1] = (int16_t)(val - 1500)*(g_eeGeneral.PPM_Multiplier+10)/10; //+-500 != 512, but close enough.
}
else {
@ -208,21 +208,41 @@ void stop_cppm_on_heartbeat_capture(void)
}
}
void init_sbus_on_heartbeat_capture(void)
void init_sbus_on_heartbeat_capture()
{
EXTERNAL_MODULE_ON();
RCC->APB2ENR |= RCC_APB2ENR_USART6EN ; // Enable clock
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN ; // Enable portC clock
// GPIOC->MODER = (GPIOC->MODER & 0xFFFFBFFF ) | 0x00008000 ; // Alternate func.
// GPIOC->AFR[0] = (GPIOC->AFR[0] & 0x0FFFFFFF ) | 0x80000000 ; // Alternate func.
configure_pins( 0x0080, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_8 ) ;
USART6->BRR = PERI2_FREQUENCY / 100000 ;
USART6->CR1 = USART_CR1_UE | USART_CR1_RXNEIE | USART_CR1_RE | USART_CR1_M | USART_CR1_PCE ;
USART6->CR2 = 0 ;
USART6->CR3 = 0 ;
(void) USART6->DR ;
NVIC_EnableIRQ(USART6_IRQn) ;
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
USART_InitStructure.USART_BaudRate = 100000;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx;
USART_Init(USART6, &USART_InitStructure);
USART_Cmd(USART6, ENABLE);
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
NVIC_SetPriority(USART6_IRQn, 7);
NVIC_EnableIRQ(USART6_IRQn);
}
void stop_sbus_on_heartbeat_capture(void)

View file

@ -39,7 +39,7 @@
uint8_t uart3Mode = UART_MODE_NONE;
Fifo<512> uart3TxFifo;
extern Fifo<512> telemetryFifo;
extern Fifo<28> sbusFifo;
extern Fifo<32> sbusFifo;
void uart3Setup(unsigned int baudrate)
{
@ -73,8 +73,8 @@ void uart3Setup(unsigned int baudrate)
USART_ITConfig(UART3, USART_IT_RXNE, DISABLE);
USART_ITConfig(UART3, USART_IT_TXE, DISABLE);
NVIC_EnableIRQ(USART3_IRQn);
NVIC_SetPriority(USART3_IRQn, 7);
NVIC_EnableIRQ(USART3_IRQn);
}
void uart3Init(unsigned int mode, unsigned int protocol)
@ -128,8 +128,6 @@ void uart3Stop()
USART_DeInit(USART3);
}
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
extern "C" void USART3_IRQHandler(void)
{
// Send