RTC battery voltage on X12S

This commit is contained in:
Bertrand Songis
2019-04-19 13:44:36 +02:00
parent 05f0057b6b
commit 501238af41
6 changed files with 31 additions and 8 deletions
+22 -3
View File
@@ -113,13 +113,22 @@ void adcInit()
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(ADC_GPIO_MOUSE, &GPIO_InitStructure);
// RTC battery
ADC1->CR1 = ADC_CR1_SCAN;
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
ADC1->SQR1 = (1 - 1) << 20;
ADC1->SQR3 = ADC_CHANNEL_RTC;
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);
// Track pad
ADC3->CR1 = ADC_CR1_SCAN;
ADC3->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
ADC3->SQR1 = (2-1) << 20;
ADC3->SQR1 = (2 - 1) << 20;
ADC3->SQR2 = 0;
ADC3->SQR3 = ADC_IN_MOUSE1 + (ADC_IN_MOUSE2<<5);
ADC3->SQR3 = ADC_CHANNEL_MOUSE1 + (ADC_CHANNEL_MOUSE2<<5);
ADC3->SMPR1 = 0;
ADC3->SMPR2 = (ADC_SAMPTIME<<(3*ADC_IN_MOUSE1)) + (ADC_SAMPTIME<<(3*ADC_IN_MOUSE2));
ADC3->SMPR2 = (ADC_SAMPTIME<<(3*ADC_CHANNEL_MOUSE1)) + (ADC_SAMPTIME<<(3*ADC_CHANNEL_MOUSE2));
ADC->CCR = 0;
// Enable the DMA channel here, DMA2 stream 1, channel 2
@@ -197,12 +206,14 @@ uint32_t adcReadNextSPIChannel(uint8_t index)
void adcOnChipReadStart()
{
ADC_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA
ADC1->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
ADC3->SR &= ~(uint32_t)(ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
ADC_DMA->LIFCR = DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 | DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0; // Write ones to clear bits
ADC_DMA_Stream->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
ADC_DMA_Stream->NDTR = 2;
ADC_DMA_Stream->CR |= DMA_SxCR_EN; // Enable DMA
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART;
}
bool adcOnChipReadFinished()
@@ -247,6 +258,14 @@ void adcRead()
}
}
uint16_t getRTCBattVoltage()
{
ADC->CCR |= ADC_CCR_VBATE;
adcRead();
ADC->CCR &= ADC_CCR_VBATE;
return ADC1->DR * 330 / 2048;
}
#if !defined(SIMU)
const int8_t ana_direction[NUM_ANALOGS] = {1,-1,1,-1, -1,1,-1, -1,-1, -1,1, 0,0,0};
+2
View File
@@ -237,6 +237,8 @@ void boardInit()
#endif
ledBlue();
vbattRTC = getRTCBattVoltage();
#endif
}
+2 -2
View File
@@ -192,8 +192,8 @@
#define ADC_GPIO_PIN_MOUSE1 GPIO_Pin_8 // PF.08 ADC3_IN6 J5 MOUSE_X
#define ADC_GPIO_PIN_MOUSE2 GPIO_Pin_9 // PF.09 ADC3_IN7 J6 MOUSE_Y
#define ADC_GPIO_MOUSE GPIOF
#define ADC_IN_MOUSE1 6
#define ADC_IN_MOUSE2 7
#define ADC_CHANNEL_MOUSE1 6
#define ADC_CHANNEL_MOUSE2 7
#define ADC_DMA DMA2
#define ADC_DMA_Stream DMA2_Stream0
#define ADC_SAMPTIME 3
+3 -1
View File
@@ -18,7 +18,7 @@
* GNU General Public License for more details.
*/
#define SIMPGMSPC_USE_QT 0
#define SIMPGMSPC_USE_QT 0
#include "opentx.h"
#include <errno.h>
@@ -66,6 +66,8 @@ Dacc dacc;
Adc Adc0;
#endif
FATFS g_FATFS_Obj;
void lcdInit()
{
}
+1 -1
View File
@@ -232,7 +232,7 @@ extern char * main_thread_error;
#define OPENTX_START_DEFAULT_ARGS simu_start_mode
static inline void getADC() { }
inline void getADC() { }
uint64_t simuTimerMicros(void);
+1 -1
View File
@@ -103,7 +103,7 @@ extern "C" void INTERRUPT_xMS_IRQHandler()
}
#endif
#if defined(PWR_BUTTON_PRESS) && !defined(SIMU)
#if defined(PWR_BUTTON_PRESS)
#define PWR_PRESS_DURATION_MIN 100 // 1s
#define PWR_PRESS_DURATION_MAX 500 // 5s
#endif