Drivers: ADC: removed old "ADC1_MDx" driver
This commit is contained in:
parent
6ff868c7a4
commit
07c4ea6753
|
|
@ -1,111 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2020 - 2023 by Silvano Seva IU2KWO *
|
|
||||||
* and Niccolò Izzo IU2KIN *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* 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. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#include <peripherals/gpio.h>
|
|
||||||
#include <hwconfig.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "ADC1_MDx.h"
|
|
||||||
|
|
||||||
static pthread_mutex_t adcMutex;
|
|
||||||
|
|
||||||
void adc1_init()
|
|
||||||
{
|
|
||||||
pthread_mutex_init(&adcMutex, NULL);
|
|
||||||
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
|
||||||
__DSB();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Configure GPIOs to analog input mode:
|
|
||||||
*/
|
|
||||||
gpio_setMode(AIN_VBAT, ANALOG);
|
|
||||||
gpio_setMode(AIN_VOLUME, ANALOG);
|
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MD9600)
|
|
||||||
gpio_setMode(AIN_MIC, ANALOG);
|
|
||||||
gpio_setMode(AIN_RSSI, ANALOG);
|
|
||||||
#if defined(PLATFORM_MD9600)
|
|
||||||
gpio_setMode(AIN_SW2, ANALOG);
|
|
||||||
gpio_setMode(AIN_SW1, ANALOG);
|
|
||||||
gpio_setMode(AIN_RSSI2, ANALOG);
|
|
||||||
gpio_setMode(AIN_HTEMP, ANALOG);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ADC clock is APB2 frequency divided by 8, giving 10.5MHz.
|
|
||||||
* We set the sample time of each channel to 84 ADC cycles and we have that
|
|
||||||
* a conversion takes 12 cycles: total conversion time is then of ~9us.
|
|
||||||
*/
|
|
||||||
ADC->CCR |= ADC_CCR_ADCPRE;
|
|
||||||
ADC1->SMPR2 = ADC_SMPR2_SMP0_2
|
|
||||||
| ADC_SMPR2_SMP1_2
|
|
||||||
| ADC_SMPR2_SMP3_2
|
|
||||||
| ADC_SMPR2_SMP6_2
|
|
||||||
| ADC_SMPR2_SMP7_2
|
|
||||||
| ADC_SMPR2_SMP8_2
|
|
||||||
| ADC_SMPR2_SMP9_2;
|
|
||||||
ADC1->SMPR1 = ADC_SMPR1_SMP15_2;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Convert one channel, no overrun interrupt, 12-bit resolution,
|
|
||||||
* no analog watchdog, discontinuous mode, no end of conversion interrupts,
|
|
||||||
* turn on ADC.
|
|
||||||
*/
|
|
||||||
ADC1->SQR1 = 0;
|
|
||||||
ADC1->CR2 = ADC_CR2_ADON;
|
|
||||||
}
|
|
||||||
|
|
||||||
void adc1_terminate()
|
|
||||||
{
|
|
||||||
pthread_mutex_destroy(&adcMutex);
|
|
||||||
|
|
||||||
ADC1->CR2 &= ~ADC_CR2_ADON;
|
|
||||||
RCC->APB2ENR &= ~RCC_APB2ENR_ADC1EN;
|
|
||||||
__DSB();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t adc1_getRawSample(uint8_t ch)
|
|
||||||
{
|
|
||||||
if(ch > 15) return 0;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&adcMutex);
|
|
||||||
|
|
||||||
ADC1->SQR3 = ch;
|
|
||||||
ADC1->CR2 |= ADC_CR2_SWSTART;
|
|
||||||
while((ADC1->SR & ADC_SR_EOC) == 0) ;
|
|
||||||
uint16_t value = ADC1->DR;
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&adcMutex);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t adc1_getMeasurement(uint8_t ch)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* To avoid using floats, we convert the raw ADC sample to mV using 16.16
|
|
||||||
* fixed point math. The equation for conversion is (sample * 3300)/4096 but,
|
|
||||||
* since converting the raw ADC sample to 16.16 notation requires a left
|
|
||||||
* shift by 16 and dividing by 4096 is equivalent to shifting right by 12,
|
|
||||||
* we just shift left by four and then multiply by 3300.
|
|
||||||
* With respect to using floats, maximum error is -1mV.
|
|
||||||
*/
|
|
||||||
uint32_t sample = (adc1_getRawSample(ch) << 4) * 3300;
|
|
||||||
return ((uint16_t) (sample >> 16));
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2020 - 2023 by Silvano Seva IU2KWO *
|
|
||||||
* and Niccolò Izzo IU2KIN *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* 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. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef ADC1_H
|
|
||||||
#define ADC1_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Driver for ADC1, used on all the MDx devices to continuously sample battery
|
|
||||||
* voltage and other values.
|
|
||||||
*
|
|
||||||
* Channel mapping for MDx platforms:
|
|
||||||
*
|
|
||||||
* +--------+----------+---------+
|
|
||||||
* | MD-3x0 | MD-UV3x0 | MD-9600 |
|
|
||||||
* +-----+------+-----------------+--------+----------+---------+
|
|
||||||
* | PA0 | IN0 | volume level | x | x | |
|
|
||||||
* | PA1 | IN1 | supply voltage | x | x | x |
|
|
||||||
* | PA3 | IN3 | mic level (VOX) | x | x | x |
|
|
||||||
* | PA6 | IN6 | mic SW2 line | | | x |
|
|
||||||
* | PA7 | IN7 | mic SW1 line | | | x |
|
|
||||||
* | PB0 | IN8 | RSSI | x | | x |
|
|
||||||
* | PB1 | IN9 | | | | x |
|
|
||||||
* | PC5 | IN15 | heatsink temp. | | | x |
|
|
||||||
* +-----+------+-----------------+--------+----------+---------+
|
|
||||||
*
|
|
||||||
* NOTE: values inside the enum are the channel numbers of STM32 ADC1 peripheral.
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum adcCh
|
|
||||||
{
|
|
||||||
ADC_VOL_CH = 0,
|
|
||||||
ADC_VBAT_CH = 1,
|
|
||||||
ADC_VOX_CH = 3,
|
|
||||||
ADC_RSSI_CH = 8,
|
|
||||||
ADC_SW1_CH = 7,
|
|
||||||
ADC_SW2_CH = 6,
|
|
||||||
ADC_RSSI2_CH = 9,
|
|
||||||
ADC_HTEMP_CH = 15
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise ADC1.
|
|
||||||
*/
|
|
||||||
void adc1_init();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Turn off ADC1.
|
|
||||||
*/
|
|
||||||
void adc1_terminate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current measurement of a given channel returning the raw ADC value.
|
|
||||||
*
|
|
||||||
* NOTE: the mapping provided in enum adcCh DOES NOT correspond to the physical
|
|
||||||
* ADC channel mapping!
|
|
||||||
*
|
|
||||||
* @param ch: channel number.
|
|
||||||
* @return current value of the specified channel, in ADC counts.
|
|
||||||
*/
|
|
||||||
uint16_t adc1_getRawSample(uint8_t ch);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current measurement of a given channel.
|
|
||||||
*
|
|
||||||
* NOTE: the mapping provided in enum adcCh DOES NOT correspond to the physical
|
|
||||||
* ADC channel mapping!
|
|
||||||
*
|
|
||||||
* @param ch: channel number.
|
|
||||||
* @return current value of the specified channel in mV.
|
|
||||||
*/
|
|
||||||
uint16_t adc1_getMeasurement(uint8_t ch);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* ADC1_H */
|
|
||||||
Loading…
Reference in New Issue