Constants renamed (so that Taranis hal is now nice)
This commit is contained in:
@@ -41,35 +41,34 @@ extern Fifo<512> telemetryFifo;
|
||||
void telemetryPortInit(uint32_t baudrate)
|
||||
{
|
||||
if (baudrate == 0) {
|
||||
USART_DeInit(SPORT_USART);
|
||||
USART_DeInit(TELEMETRY_USART);
|
||||
return;
|
||||
}
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_SPORT, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(TELEMETRY_RCC_AHB1Periph_GPIO, ENABLE);
|
||||
|
||||
GPIO_PinAFConfig(GPIO_PIN_SPORT_TXRX, GPIO_PinSource_SPORT_RX, GPIO_AF_SPORT);
|
||||
GPIO_PinAFConfig(GPIO_PIN_SPORT_TXRX, GPIO_PinSource_SPORT_TX, GPIO_AF_SPORT);
|
||||
GPIO_PinAFConfig(TELEMETRY_GPIO, TELEMETRY_GPIO_PinSource_RX, TELEMETRY_GPIO_AF);
|
||||
GPIO_PinAFConfig(TELEMETRY_GPIO, TELEMETRY_GPIO_PinSource_TX, TELEMETRY_GPIO_AF);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PIN_SPORT_TX | PIN_SPORT_RX;
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_GPIO_PIN_TX | TELEMETRY_GPIO_PIN_RX;
|
||||
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(GPIO_PIN_SPORT_TXRX, &GPIO_InitStructure);
|
||||
GPIO_Init(TELEMETRY_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PIN_SPORT_ON;
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_GPIO_PIN_DIR;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIO_PIN_SPORT_ON, &GPIO_InitStructure);
|
||||
GPIO_Init(TELEMETRY_GPIO_DIR, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(TELEMETRY_GPIO_DIR, TELEMETRY_GPIO_PIN_DIR);
|
||||
|
||||
GPIO_ResetBits(GPIO_PIN_SPORT_ON, PIN_SPORT_ON);
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPORT, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(TELEMETRY_RCC_APB1Periph_USART, ENABLE);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
@@ -78,12 +77,12 @@ void telemetryPortInit(uint32_t baudrate)
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
|
||||
USART_Init(SPORT_USART, &USART_InitStructure);
|
||||
USART_Cmd(SPORT_USART, ENABLE);
|
||||
USART_ITConfig(SPORT_USART, USART_IT_RXNE, ENABLE);
|
||||
USART_Init(TELEMETRY_USART, &USART_InitStructure);
|
||||
USART_Cmd(TELEMETRY_USART, ENABLE);
|
||||
USART_ITConfig(TELEMETRY_USART, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_SetPriority(SPORT_IRQn, 6);
|
||||
NVIC_EnableIRQ(SPORT_IRQn);
|
||||
NVIC_SetPriority(TELEMETRY_USART_IRQn, 6);
|
||||
NVIC_EnableIRQ(TELEMETRY_USART_IRQn);
|
||||
}
|
||||
|
||||
struct SportTxBuffer
|
||||
@@ -96,47 +95,47 @@ void sportSendBuffer(uint8_t *buffer, uint32_t count)
|
||||
{
|
||||
sportTxBuffer.ptr = buffer ;
|
||||
sportTxBuffer.count = count ;
|
||||
GPIO_PIN_SPORT_ON->BSRRL = PIN_SPORT_ON ; // output enable
|
||||
SPORT_USART->CR1 &= ~USART_CR1_RE ; // turn off receiver
|
||||
SPORT_USART->CR1 |= USART_CR1_TXEIE ;
|
||||
TELEMETRY_GPIO_DIR->BSRRL = TELEMETRY_GPIO_PIN_DIR ; // output enable
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_RE ; // turn off receiver
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_TXEIE ;
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
extern "C" void SPORT_IRQHandler()
|
||||
extern "C" void TELEMETRY_USART_IRQHandler()
|
||||
{
|
||||
uint32_t status;
|
||||
uint8_t data;
|
||||
|
||||
status = SPORT_USART->SR;
|
||||
status = TELEMETRY_USART->SR;
|
||||
|
||||
if (status & USART_SR_TXE) {
|
||||
if (sportTxBuffer.count) {
|
||||
SPORT_USART->DR = *sportTxBuffer.ptr++;
|
||||
TELEMETRY_USART->DR = *sportTxBuffer.ptr++;
|
||||
if (--sportTxBuffer.count == 0) {
|
||||
SPORT_USART->CR1 &= ~USART_CR1_TXEIE; // stop Tx interrupt
|
||||
SPORT_USART->CR1 |= USART_CR1_TCIE; // enable complete interrupt
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_TXEIE; // stop Tx interrupt
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_TCIE; // enable complete interrupt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((status & USART_SR_TC) && (SPORT_USART->CR1 & USART_CR1_TCIE)) {
|
||||
SPORT_USART->CR1 &= ~USART_CR1_TCIE ; // stop Complete interrupt
|
||||
GPIO_PIN_SPORT_ON->BSRRH = PIN_SPORT_ON ; // output disable
|
||||
SPORT_USART->CR1 |= USART_CR1_RE ;
|
||||
if ((status & USART_SR_TC) && (TELEMETRY_USART->CR1 & USART_CR1_TCIE)) {
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_TCIE ; // stop Complete interrupt
|
||||
TELEMETRY_GPIO_DIR->BSRRH = TELEMETRY_GPIO_PIN_DIR ; // output disable
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_RE ;
|
||||
while (status & (USART_FLAG_RXNE)) {
|
||||
status = SPORT_USART->DR;
|
||||
status = SPORT_USART->SR ;
|
||||
status = TELEMETRY_USART->DR;
|
||||
status = TELEMETRY_USART->SR ;
|
||||
}
|
||||
}
|
||||
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
data = SPORT_USART->DR;
|
||||
data = TELEMETRY_USART->DR;
|
||||
if (!(status & USART_FLAG_ERRORS)) {
|
||||
telemetryFifo.push(data);
|
||||
}
|
||||
status = SPORT_USART->SR;
|
||||
status = TELEMETRY_USART->SR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user