Skip to content

Commit

Permalink
Disable IDLE interrupt for telemetry,
Browse files Browse the repository at this point in the history
cleanup buzzer init,
  • Loading branch information
ajjjjjjjj committed Dec 10, 2024
1 parent c935e0b commit 7f2a5ca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
32 changes: 8 additions & 24 deletions radio/src/targets/flysky/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ void buzzerInit()
GPIO_PinAFConfig(BUZZER_GPIO_PORT, BUZZER_GPIO_PinSource, GPIO_AF_2);
}

void referenceSystemAudioFiles()
{
}

#define __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH() do {SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_MEM_MODE); \
SYSCFG->CFGR1 |= SYSCFG_CFGR1_MEM_MODE_0; \
}while(0)
Expand Down Expand Up @@ -95,26 +91,14 @@ void watchdogInit(unsigned int duration)

void initBuzzerTimer()
{
PWM_TIMER->PSC = 48 - 1; // 48MHz -> 1MHz
/* set counter mode */
PWM_TIMER->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
PWM_TIMER->CR1 |= TIM_CounterMode_Up;
/* Auto-Reload Register */
PWM_TIMER->ARR = 400; // count up to
/* Set Clock Division */
PWM_TIMER->CR1 &= ~ TIM_CR1_CKD;
PWM_TIMER->CR1 |= TIM_CKD_DIV1;
PWM_TIMER->CCR1 = 200; // ARR/2 = PWM duty 50%
/* Set repetition counter */
PWM_TIMER->RCR = 0;

// Timer output mode PWM
/* Select the Output Compare (OC) Mode 1 */
PWM_TIMER->CCMR1 |= (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1); // = TIM_OCMODE_PWM1
/* Reset and set the Output N Polarity level to LOW */
// TIM1->CCER &= ~TIM_CCER_CC1P;
PWM_TIMER->CCER |= TIM_CCER_CC1P | TIM_CCER_CC1E; // = TIM_OCPOLARITY_LOW + enable Capture compare channel
/* Enable the main output */
PWM_TIMER->PSC = 48 - 1; // 48MHz -> 1MHz
PWM_TIMER->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS | TIM_CR1_CKD);
PWM_TIMER->CR1 |= TIM_CounterMode_Up | TIM_CKD_DIV1;
PWM_TIMER->ARR = 400; // count up to
PWM_TIMER->CCR1 = 200; // ARR/2 = PWM duty 50%
// PWM_TIMER->RCR = 0;
PWM_TIMER->CCMR1 |= TIM_OCMode_PWM1;
PWM_TIMER->CCER |= TIM_OCPolarity_Low | TIM_CCER_CC1E; // TIM_OCPOLARITY_LOW + enable Capture compare channel
PWM_TIMER->BDTR |= TIM_BDTR_MOE;
}

Expand Down
1 change: 1 addition & 0 deletions radio/src/targets/flysky/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ void telemetryPortSetDirectionOutput(void);
//void sportSendBuffer(uint8_t * buffer, uint32_t count);
void sportSendBuffer(const uint8_t* buffer, unsigned long count);
uint8_t telemetryGetByte(uint8_t * byte);
bool telemetryIsEmpty();
// extern uint32_t telemetryErrors;

extern volatile bool pendingTelemetryPollFrame;
Expand Down
22 changes: 13 additions & 9 deletions radio/src/targets/flysky/telemetry_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode) {
USART_DeInit(TELEMETRY_USART);

// OverSampling + IDLE
TELEMETRY_USART->CR1 |= ( USART_CR1_OVER8 | USART_CR1_IDLEIE );
TELEMETRY_USART->CR1 |= ( USART_CR1_OVER8 /*| USART_CR1_IDLEIE*/ );

GPIO_PinAFConfig(TELEMETRY_GPIO, TELEMETRY_GPIO_PinSource_TX, TELEMETRY_TX_GPIO_AF);

Expand Down Expand Up @@ -121,7 +121,7 @@ void telemetryPortSetDirectionOutput() {
// Disable RX
#if !defined(CRSF_FULLDUPLEX)
TELEMETRY_DMA_Channel_RX->CCR &= ~DMA_CCR_EN;
TELEMETRY_USART->CR1 &= ~USART_CR1_RE;
TELEMETRY_USART->CR1 &= ~(USART_CR1_RE /* | USART_CR1_IDLEIE*/);
#endif

// Enable TX
Expand All @@ -136,7 +136,7 @@ void telemetryPortSetDirectionInput() {
#endif

// Enable RX
TELEMETRY_USART->CR1 |= USART_CR1_RE;
TELEMETRY_USART->CR1 |= (USART_CR1_RE/* | USART_CR1_IDLEIE*/);
TELEMETRY_DMA_Channel_RX->CCR |= DMA_CCR_EN;
}

Expand Down Expand Up @@ -192,15 +192,19 @@ extern "C" void TELEMETRY_USART_IRQHandler(void) {

// RX, handled by DMA

// IDLE
if (status & USART_FLAG_IDLE) {
TELEMETRY_USART->ICR = USART_ICR_IDLECF;
pendingTelemetryPollFrame = true;
TELEMETRY_USART->CR1 |= USART_CR1_IDLEIE;
}
// TODO IDLE disabled, it is always triggering, spamming ISR
// if ((TELEMETRY_USART->CR1 & USART_CR1_IDLEIE) && (status & USART_ISR_IDLE)) {
// TRACE_NOCRLF("x");
// pendingTelemetryPollFrame = true;
// TELEMETRY_USART->ICR = USART_ICR_IDLECF;
// }
}

// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
uint8_t telemetryGetByte(uint8_t* byte) {
return telemetryDMAFifo.pop(*byte);
}

bool telemetryIsEmpty() {
return telemetryDMAFifo.isEmpty();
}
33 changes: 24 additions & 9 deletions radio/src/telemetry/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ uint8_t telemetryProtocol = 255;

volatile bool pendingTelemetryPollFrame = false;

extern DMAFifo<TELEMETRY_FIFO_SIZE> telemetryDMAFifo __DMA;


void processTelemetryData(uint8_t data)
{
Expand Down Expand Up @@ -76,6 +78,16 @@ void telemetryWakeup()
telemetryInit(requiredTelemetryProtocol);
}

#if defined(CROSSFIRE)
if (telemetryProtocol == PROTOCOL_TELEMETRY_CROSSFIRE && !telemetryIsEmpty()) {
uint8_t data;
while (telemetryGetByte(&data)) {
processCrossfireTelemetryData(data); // TODO handle full frame as in EdgeTX
LOG_TELEMETRY_WRITE_BYTE(data);
}
}
#endif

// Handle complete telemetry frame
if (pendingTelemetryPollFrame) {
pendingTelemetryPollFrame = false;
Expand All @@ -86,15 +98,18 @@ void telemetryWakeup()
break;
#endif
#if defined(CROSSFIRE)
case PROTOCOL_TELEMETRY_CROSSFIRE:
{
uint8_t data;
while (telemetryGetByte(&data)) {
processCrossfireTelemetryData(data); // TODO handle full frame as in EdgeTX
LOG_TELEMETRY_WRITE_BYTE(data);
}
}
break;
// case PROTOCOL_TELEMETRY_CROSSFIRE:
// {
// uint8_t data;
// uint8_t count = 0;
// while (telemetryGetByte(&data)) {
// processCrossfireTelemetryData(data); // TODO handle full frame as in EdgeTX
// LOG_TELEMETRY_WRITE_BYTE(data);
// count++;
// }
// TRACE("c%d", count);
// }
// break;
#endif
default:
// TRACE("Unhandled telemetry %d", telemetryProtocol);
Expand Down

0 comments on commit 7f2a5ca

Please sign in to comment.