@@ -12,6 +12,7 @@ if(PCB STREQUAL X9E)
|
||||
set(FLAVOUR x9e)
|
||||
add_definitions(-DSTM32F40_41xxx -DPCBX9E)
|
||||
add_definitions(-DEEPROM_VARIANT=0x8000)
|
||||
add_definitions(-DBLUETOOTH)
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
${FIRMWARE_TARGET_SRC}
|
||||
top_lcd_driver.cpp
|
||||
@@ -111,6 +112,8 @@ set(TARGET_SRC
|
||||
${LED_DRIVER}
|
||||
backlight_driver.cpp
|
||||
extmodule_driver.cpp
|
||||
../common/arm/stm32/audio_dac_driver.cpp
|
||||
../common/arm/stm32/adc_driver.cpp
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
// Sample time should exceed 1uS
|
||||
#define SAMPTIME 2 // sample time = 28 cycles
|
||||
#define SAMPTIME_LONG 3 // sample time = 56 cycles
|
||||
|
||||
#if !defined(SIMU)
|
||||
#if defined(PCBX9E) && defined(HORUS_STICKS)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,-1,-1,1, -1,1,1,1, -1};
|
||||
#elif defined(PCBX9E)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,1,-1,-1, -1,-1,-1,1, -1,1,1,1, -1};
|
||||
#elif defined(PCBX9DP)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,-1, -1,1, 1};
|
||||
#elif defined(PCBX7)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {-1,1,-1,1, 1,1, 1};
|
||||
#elif defined(REV4a)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,-1,0, -1,1, 1};
|
||||
#else
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,0, -1,1, 1};
|
||||
#endif
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
#if defined(PCBX9E)
|
||||
#define NUMBER_ANALOG_ADC1 10
|
||||
#define NUMBER_ANALOG_ADC3 (NUMBER_ANALOG - 10)
|
||||
#if !defined(SIMU)
|
||||
// mapping from adcValues order to enum Analogs
|
||||
const uint8_t ana_mapping[NUMBER_ANALOG] = { 0 /*STICK1*/, 1 /*STICK2*/, 2 /*STICK3*/, 3 /*STICK4*/,
|
||||
10 /*POT1*/, 4 /*POT2*/, 5 /*POT3*/, 6 /*POT4*/,
|
||||
11 /*SLIDER1*/, 12 /*SLIDER2*/, 7 /*SLIDER3*/, 8 /*SLIDER4*/,
|
||||
9 /*TX_VOLTAGE*/ };
|
||||
#endif // !defined(SIMU)
|
||||
#else
|
||||
#define NUMBER_ANALOG_ADC1 NUMBER_ANALOG
|
||||
#endif
|
||||
|
||||
uint16_t adcValues[NUMBER_ANALOG] __DMA;
|
||||
|
||||
void adcInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOA_PINS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOB_PINS;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOC_PINS;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
#if defined(PCBX9E)
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIOF_PINS;
|
||||
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
ADC1->CR1 = ADC_CR1_SCAN;
|
||||
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC1->SQR1 = (NUMBER_ANALOG_ADC1-1) << 20; // bits 23:20 = number of conversions
|
||||
#if defined(PCBX9E)
|
||||
ADC1->SQR2 = (ADC_CHANNEL_POT4<<0) + (ADC_CHANNEL_SLIDER3<<5) + (ADC_CHANNEL_SLIDER4<<10) + (ADC_CHANNEL_BATT<<15); // conversions 7 and more
|
||||
ADC1->SQR3 = (ADC_CHANNEL_STICK_LH<<0) + (ADC_CHANNEL_STICK_LV<<5) + (ADC_CHANNEL_STICK_RV<<10) + (ADC_CHANNEL_STICK_RH<<15) + (ADC_CHANNEL_POT2<<20) + (ADC_CHANNEL_POT3<<25); // conversions 1 to 6
|
||||
#elif defined(PCBX7)
|
||||
ADC1->SQR2 = (ADC_CHANNEL_BATT<<0); // conversions 7 and more
|
||||
ADC1->SQR3 = (ADC_CHANNEL_STICK_LH<<0) + (ADC_CHANNEL_STICK_LV<<5) + (ADC_CHANNEL_STICK_RV<<10) + (ADC_CHANNEL_STICK_RH<<15) + (ADC_CHANNEL_POT1<<25) + (ADC_CHANNEL_POT2<<20); // conversions 1 to 6
|
||||
#else
|
||||
ADC1->SQR2 = (ADC_CHANNEL_POT3<<0) + (ADC_CHANNEL_SLIDER1<<5) + (ADC_CHANNEL_SLIDER2<<10) + (ADC_CHANNEL_BATT<<15); // conversions 7 and more
|
||||
ADC1->SQR3 = (ADC_CHANNEL_STICK_LH<<0) + (ADC_CHANNEL_STICK_LV<<5) + (ADC_CHANNEL_STICK_RV<<10) + (ADC_CHANNEL_STICK_RH<<15) + (ADC_CHANNEL_POT1<<20) + (ADC_CHANNEL_POT2<<25); // conversions 1 to 6
|
||||
#endif
|
||||
ADC1->SMPR1 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12) + (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24);
|
||||
ADC1->SMPR2 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12) + (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24) + (SAMPTIME<<27);
|
||||
|
||||
ADC->CCR = 0;
|
||||
|
||||
ADC1_DMA_Stream->CR = DMA_SxCR_PL | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
ADC1_DMA_Stream->PAR = CONVERT_PTR_UINT(&ADC1->DR);
|
||||
ADC1_DMA_Stream->M0AR = CONVERT_PTR_UINT(adcValues);
|
||||
ADC1_DMA_Stream->NDTR = NUMBER_ANALOG_ADC1;
|
||||
ADC1_DMA_Stream->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
|
||||
#if defined(PCBX9E)
|
||||
ADC3->CR1 = ADC_CR1_SCAN;
|
||||
ADC3->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC3->SQR1 = (NUMBER_ANALOG_ADC3-1) << 20; // NUMBER_ANALOG Channels
|
||||
ADC3->SQR2 = 0;
|
||||
ADC3->SQR3 = (ADC_CHANNEL_POT1<<0) + (ADC_CHANNEL_SLIDER1<<5) + (ADC_CHANNEL_SLIDER2<<10); // conversions 1 to 3
|
||||
ADC3->SMPR1 = 0;
|
||||
ADC3->SMPR2 = (SAMPTIME_LONG<<(3*ADC_CHANNEL_POT1)) + (SAMPTIME_LONG<<(3*ADC_CHANNEL_SLIDER1)) + (SAMPTIME_LONG<<(3*ADC_CHANNEL_SLIDER2));
|
||||
|
||||
ADC3_DMA_Stream->CR = DMA_SxCR_PL | DMA_SxCR_CHSEL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
ADC3_DMA_Stream->PAR = CONVERT_PTR_UINT(&ADC3->DR);
|
||||
ADC3_DMA_Stream->M0AR = CONVERT_PTR_UINT(adcValues + NUMBER_ANALOG_ADC1);
|
||||
ADC3_DMA_Stream->NDTR = NUMBER_ANALOG_ADC3;
|
||||
ADC3_DMA_Stream->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcSingleRead()
|
||||
{
|
||||
ADC1_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
ADC1->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
ADC1_DMA->HIFCR = ADC1_DMA_FLAGS; // Write ones to clear bits
|
||||
ADC1_DMA_Stream->CR |= DMA_SxCR_EN; // Enable DMA
|
||||
ADC1->CR2 |= (uint32_t) ADC_CR2_SWSTART;
|
||||
|
||||
#if defined(PCBX9E)
|
||||
ADC3_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
ADC3->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR );
|
||||
ADC3_DMA->LIFCR = ADC3_DMA_FLAGS; // Write ones to clear bits
|
||||
ADC3_DMA_Stream->CR |= DMA_SxCR_EN; // Enable DMA
|
||||
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
#endif
|
||||
|
||||
#if defined(PCBX9E)
|
||||
for (unsigned int i=0; i<10000; i++) {
|
||||
if ((ADC1_DMA->HISR & ADC1_DMA_FLAG_TC) && (ADC3_DMA->LISR & ADC3_DMA_FLAG_TC)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ADC1_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
ADC3_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
#else
|
||||
for (unsigned int i = 0; i < 10000; i++) {
|
||||
if (ADC1_DMA->HISR & ADC1_DMA_FLAG_TC) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ADC1_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
{
|
||||
uint16_t temp[NUMBER_ANALOG] = { 0 };
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
adcSingleRead();
|
||||
for (uint8_t x=0; x<NUMBER_ANALOG; x++) {
|
||||
uint16_t val = adcValues[x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
if (JITTER_MEASURE_ACTIVE()) {
|
||||
rawJitter[x].measure(val);
|
||||
}
|
||||
#endif
|
||||
temp[x] += val;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x=0; x<NUMBER_ANALOG; x++) {
|
||||
adcValues[x] = temp[x] >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
void adcStop()
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
uint16_t getAnalogValue(uint8_t index)
|
||||
{
|
||||
if (IS_POT(index) && !IS_POT_SLIDER_AVAILABLE(index)) {
|
||||
// Use fixed analog value for non-existing and/or non-connected pots.
|
||||
// Non-connected analog inputs will slightly follow the adjacent connected analog inputs,
|
||||
// which produces ghost readings on these inputs.
|
||||
return 0;
|
||||
}
|
||||
#if defined(PCBX9E)
|
||||
index = ana_mapping[index];
|
||||
#endif
|
||||
if (ana_direction[index] < 0)
|
||||
return 4095 - adcValues[index];
|
||||
else
|
||||
return adcValues[index];
|
||||
}
|
||||
#endif // #if !defined(SIMU)
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
const AudioBuffer * nextBuffer = 0;
|
||||
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
uint32_t timer = (PERI1_FREQUENCY * TIMER_MULT_APB1) / frequency - 1 ; // MCK/8 and 100 000 Hz
|
||||
|
||||
AUDIO_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
AUDIO_TIMER->CNT = 0 ;
|
||||
AUDIO_TIMER->ARR = limit<uint32_t>(2, timer, 65535) ;
|
||||
AUDIO_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
// Start TIMER6 at 100000Hz, used for DAC trigger
|
||||
void dacTimerInit()
|
||||
{
|
||||
AUDIO_TIMER->PSC = 0 ; // Max speed
|
||||
AUDIO_TIMER->ARR = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 100000 - 1 ; // 10 uS, 100 kHz
|
||||
AUDIO_TIMER->CR2 = 0 ;
|
||||
AUDIO_TIMER->CR2 = 0x20 ;
|
||||
AUDIO_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
// Configure DAC0 (or DAC1 for REVA)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerInit();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_OUTPUT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(AUDIO_OUTPUT_GPIO, &GPIO_InitStructure);
|
||||
|
||||
// Chan 7, 16-bit wide, Medium priority, memory increments
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
|
||||
AUDIO_DMA_Stream->CR = DMA_SxCR_CHSEL_0 | DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_2 | DMA_SxCR_PL_0 |
|
||||
DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC | DMA_SxCR_DIR_0 | DMA_SxCR_CIRC ;
|
||||
AUDIO_DMA_Stream->PAR = CONVERT_PTR_UINT(&DAC->DHR12R1);
|
||||
// AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(Sine_values);
|
||||
AUDIO_DMA_Stream->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
// AUDIO_DMA_Stream->NDTR = 100 ;
|
||||
|
||||
DAC->DHR12R1 = 2010 ;
|
||||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
DAC->CR = DAC_CR_TEN1 | DAC_CR_EN1 ; // Enable DAC
|
||||
NVIC_EnableIRQ(AUDIO_TIM_IRQn); // TODO needed?
|
||||
NVIC_SetPriority(AUDIO_TIM_IRQn, 7);
|
||||
NVIC_EnableIRQ(AUDIO_DMA_Stream_IRQn);
|
||||
NVIC_SetPriority(AUDIO_DMA_Stream_IRQn, 7);
|
||||
}
|
||||
|
||||
void audioConsumeCurrentBuffer()
|
||||
{
|
||||
if (nextBuffer == 0) {
|
||||
|
||||
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA channel
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
|
||||
AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
AUDIO_DMA_Stream->NDTR = nextBuffer->size;
|
||||
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel and interrupt
|
||||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void dacStart()
|
||||
{
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
|
||||
AUDIO_DMA_Stream->CR |= DMA_SxCR_CIRC | DMA_SxCR_EN ; // Enable DMA channel
|
||||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC
|
||||
}
|
||||
|
||||
void dacStop()
|
||||
{
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_CIRC ;
|
||||
}
|
||||
|
||||
|
||||
// Sound routines
|
||||
void audioInit()
|
||||
{
|
||||
dacInit();
|
||||
}
|
||||
|
||||
void audioEnd()
|
||||
{
|
||||
DAC->CR = 0 ;
|
||||
AUDIO_TIMER->CR1 = 0 ;
|
||||
// Also need to turn off any possible interrupts
|
||||
NVIC_DisableIRQ(AUDIO_TIM_IRQn) ;
|
||||
NVIC_DisableIRQ(AUDIO_DMA_Stream_IRQn) ;
|
||||
}
|
||||
|
||||
extern "C" void AUDIO_TIM_IRQHandler()
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_AUDIO);
|
||||
DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests
|
||||
#if !defined(PCBX9E)
|
||||
DAC->CR &= ~DAC_CR_DMAUDRIE1 ; // Stop underrun interrupt
|
||||
#endif
|
||||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
}
|
||||
|
||||
extern "C" void AUDIO_DMA_Stream_IRQHandler()
|
||||
{
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_TCIE ; // Stop interrupt
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear flags
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA channel
|
||||
|
||||
if (nextBuffer) audioQueue.buffersFifo.freeNextFilledBuffer();
|
||||
|
||||
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(nextBuffer->data);
|
||||
AUDIO_DMA_Stream->NDTR = nextBuffer->size;
|
||||
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
|
||||
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel
|
||||
DAC->SR = DAC_SR_DMAUDR1; // Write 1 to clear flag
|
||||
}
|
||||
}
|
||||
#endif // #if !defined(SIMU)
|
||||
@@ -373,11 +373,25 @@ enum Analogs {
|
||||
SLIDER2,
|
||||
#endif
|
||||
TX_VOLTAGE,
|
||||
NUMBER_ANALOG
|
||||
NUM_ANALOGS
|
||||
};
|
||||
|
||||
#define NUM_POTS (POT_LAST-POT_FIRST+1)
|
||||
#define NUM_SLIDERS (TX_VOLTAGE-POT_LAST-1)
|
||||
#define NUM_XPOTS NUM_POTS
|
||||
#define NUM_SLIDERS (TX_VOLTAGE-POT_LAST-1)
|
||||
|
||||
enum CalibratedAnalogs {
|
||||
CALIBRATED_STICK1,
|
||||
CALIBRATED_STICK2,
|
||||
CALIBRATED_STICK3,
|
||||
CALIBRATED_STICK4,
|
||||
CALIBRATED_POT_FIRST,
|
||||
CALIBRATED_POT_LAST = CALIBRATED_POT_FIRST + NUM_POTS - 1,
|
||||
CALIBRATED_SLIDER_FIRST,
|
||||
CALIBRATED_SLIDER_LAST = CALIBRATED_SLIDER_FIRST + NUM_SLIDERS - 1,
|
||||
NUM_CALIBRATED_ANALOGS
|
||||
};
|
||||
|
||||
#if defined(PCBX9D)
|
||||
#define IS_POT(x) ((x)>=POT_FIRST && (x)<=POT2) // POT3 is only defined in software
|
||||
#else
|
||||
@@ -386,7 +400,7 @@ enum Analogs {
|
||||
#define IS_SLIDER(x) ((x)>POT_LAST && (x)<TX_VOLTAGE)
|
||||
void adcInit(void);
|
||||
void adcRead(void);
|
||||
extern uint16_t adcValues[NUMBER_ANALOG];
|
||||
extern uint16_t adcValues[NUM_ANALOGS];
|
||||
uint16_t getAnalogValue(uint8_t index);
|
||||
uint16_t getBatteryVoltage(); // returns current battery voltage in 10mV steps
|
||||
|
||||
@@ -412,7 +426,12 @@ uint32_t pwrPressedDuration(void);
|
||||
#else
|
||||
uint32_t pwroffPressed(void);
|
||||
#endif
|
||||
|
||||
#if defined(SIMU)
|
||||
#define UNEXPECTED_SHUTDOWN() false
|
||||
#else
|
||||
#define UNEXPECTED_SHUTDOWN() (WAS_RESET_BY_WATCHDOG() || g_eeGeneral.unexpectedShutdown)
|
||||
#endif
|
||||
|
||||
// Backlight driver
|
||||
void backlightInit(void);
|
||||
|
||||
@@ -348,10 +348,14 @@
|
||||
#endif
|
||||
#define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
|
||||
#define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
|
||||
#define ADC1_DMA DMA2
|
||||
#define ADC1_DMA_Stream DMA2_Stream4
|
||||
#define ADC1_DMA_FLAGS (DMA_HIFCR_CTCIF4 | DMA_HIFCR_CHTIF4 | DMA_HIFCR_CTEIF4 | DMA_HIFCR_CDMEIF4 | DMA_HIFCR_CFEIF4)
|
||||
#define ADC1_DMA_FLAG_TC DMA_HISR_TCIF4
|
||||
#define ADC_MAIN ADC1
|
||||
#define ADC_DMA DMA2
|
||||
#define ADC_DMA_SxCR_CHSEL 0
|
||||
#define ADC_DMA_Stream DMA2_Stream4
|
||||
#define ADC_SET_DMA_FLAGS() ADC_DMA->HIFCR = (DMA_HIFCR_CTCIF4 | DMA_HIFCR_CHTIF4 | DMA_HIFCR_CTEIF4 | DMA_HIFCR_CDMEIF4 | DMA_HIFCR_CFEIF4)
|
||||
#define ADC_TRANSFER_COMPLETE() (ADC_DMA->HISR & DMA_HISR_TCIF4)
|
||||
#define ADC_SAMPTIME 2 // sample time = 28 cycles
|
||||
|
||||
#if defined(PCBX9E)
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_8 // PF.08
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
|
||||
@@ -375,10 +379,12 @@
|
||||
#define ADC_CHANNEL_SLIDER3 ADC_Channel_6 // ADC1_IN6
|
||||
#define ADC_CHANNEL_SLIDER4 ADC_Channel_9 // ADC1_IN9
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_10 // ADC1_IN10
|
||||
#define ADC3_DMA DMA2
|
||||
#define ADC3_DMA_Stream DMA2_Stream0
|
||||
#define ADC3_DMA_FLAGS (DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0)
|
||||
#define ADC3_DMA_FLAG_TC DMA_LISR_TCIF0
|
||||
#define ADC_EXT ADC3
|
||||
#define ADC_EXT_DMA DMA2
|
||||
#define ADC_EXT_DMA_Stream DMA2_Stream0
|
||||
#define ADC_EXT_SET_DMA_FLAGS() ADC_DMA->LIFCR = (DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0)
|
||||
#define ADC_EXT_TRANSFER_COMPLETE() (ADC_DMA->LISR & DMA_LISR_TCIF0)
|
||||
#define ADC_EXT_SAMPTIME 3 // sample time = 56 cycles
|
||||
#elif defined(PCBX9DP)
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
|
||||
|
||||
Reference in New Issue
Block a user