Fix style and license for AVR ADC driver
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5897 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
48dfd4e898
commit
cf4c8b5281
|
@ -1,26 +1,22 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
||||||
2011,2012 Giovanni Di Sirio.
|
|
||||||
|
|
||||||
This file is part of ChibiOS/RT.
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
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.
|
|
||||||
|
|
||||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
Unless required by applicable law or agreed to in writing, software
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
GNU General Public License for more details.
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file templates/adc_lld.c
|
* @file AVR/adc_lld.c
|
||||||
* @brief ADC Driver subsystem low level driver source template.
|
* @brief ADC Driver subsystem low level driver source.
|
||||||
*
|
*
|
||||||
* @addtogroup ADC
|
* @addtogroup ADC
|
||||||
* @{
|
* @{
|
||||||
|
@ -50,26 +46,26 @@ ADCDriver ADCD1;
|
||||||
/* Driver local functions. */
|
/* Driver local functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel)
|
static size_t getAdcChannelNumberFromMask(uint8_t mask, uint8_t currentChannel) {
|
||||||
{
|
|
||||||
for(uint8_t i = 0; mask>0; i++)
|
for (uint8_t i = 0; mask > 0; i++) {
|
||||||
{
|
if (mask & 0x01) {
|
||||||
if(mask & 0x01)
|
if (!currentChannel)
|
||||||
{
|
return i;
|
||||||
if(!currentChannel)
|
currentChannel--;
|
||||||
return i;
|
|
||||||
currentChannel--;
|
|
||||||
}
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
}
|
||||||
|
mask >>= 1;
|
||||||
/* error, should never reach this line */
|
}
|
||||||
|
|
||||||
|
/* error, should never reach this line */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setAdcChannel(uint8_t channelNum)
|
static void setAdcChannel(uint8_t channelNum) {
|
||||||
{
|
|
||||||
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
|
ADMUX = (ADMUX & 0xf8) | (channelNum & 0x07);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver interrupt handlers. */
|
/* Driver interrupt handlers. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -77,35 +73,29 @@ static void setAdcChannel(uint8_t channelNum)
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
CH_IRQ_HANDLER(ADC_vect) {
|
CH_IRQ_HANDLER(ADC_vect) {
|
||||||
|
|
||||||
CH_IRQ_PROLOGUE();
|
CH_IRQ_PROLOGUE();
|
||||||
uint8_t low = ADCL;
|
uint8_t low = ADCL;
|
||||||
uint8_t high = ADCH;
|
uint8_t high = ADCH;
|
||||||
uint16_t result = (high << 8) | low;
|
uint16_t result = (high << 8) | low;
|
||||||
|
|
||||||
ADCD1.samples[ADCD1.currentBufferPosition] = result;
|
ADCD1.samples[ADCD1.currentBufferPosition] = result;
|
||||||
ADCD1.currentBufferPosition++;
|
ADCD1.currentBufferPosition++;
|
||||||
|
|
||||||
size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels;
|
size_t bufferSize = ADCD1.depth * ADCD1.grpp->num_channels;
|
||||||
size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels;
|
size_t currentChannel = ADCD1.currentBufferPosition % ADCD1.grpp->num_channels;
|
||||||
size_t currentIteration = ADCD1.currentBufferPosition / ADCD1.grpp->num_channels;
|
size_t currentIteration = ADCD1.currentBufferPosition / ADCD1.grpp->num_channels;
|
||||||
if(ADCD1.grpp-> circular && currentChannel == 0 && currentIteration == ADCD1.depth/2)
|
if (ADCD1.grpp->circular && currentChannel == 0 && currentIteration == ADCD1.depth/2) {
|
||||||
{
|
_adc_isr_half_code(&ADCD1);
|
||||||
_adc_isr_half_code(&ADCD1);
|
}
|
||||||
|
|
||||||
}
|
if (ADCD1.currentBufferPosition == bufferSize) {
|
||||||
|
_adc_isr_full_code(&ADCD1);
|
||||||
if(ADCD1.currentBufferPosition == bufferSize)
|
} else {
|
||||||
{
|
setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel));
|
||||||
_adc_isr_full_code(&ADCD1);
|
ADCSRA |= 1 << ADSC;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
setAdcChannel(getAdcChannelNumberFromMask(ADCD1.grpp->channelsMask,currentChannel));
|
|
||||||
ADCSRA |= 1<<ADSC;
|
|
||||||
}
|
|
||||||
|
|
||||||
CH_IRQ_EPILOGUE();
|
CH_IRQ_EPILOGUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,12 +109,17 @@ CH_IRQ_HANDLER(ADC_vect) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void adc_lld_init(void) {
|
void adc_lld_init(void) {
|
||||||
adcObjectInit(&ADCD1);
|
|
||||||
ADCSRA =(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) | //prescaler 128, unico valore possibile a 20Mhz
|
|
||||||
(1<<ADIE) ; //interrupt
|
|
||||||
|
|
||||||
ADCSRB=0; //single shot
|
adcObjectInit(&ADCD1);
|
||||||
ADMUX=(0<<REFS1)| (0<<REFS0); //uso aref, vale solo per arduino. arduino ha aref collegato
|
|
||||||
|
//prescaler 128, only value possible at 20Mhz, interrupt
|
||||||
|
ADCSRA = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADIE);
|
||||||
|
|
||||||
|
ADCSRB = 0; //single shot
|
||||||
|
|
||||||
|
//uso aref, only valid for arduino. arduino ha aref collegato
|
||||||
|
ADMUX = (0 << REFS1) | (0 << REFS0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,12 +133,11 @@ void adc_lld_start(ADCDriver *adcp) {
|
||||||
|
|
||||||
if (adcp->state == ADC_STOP) {
|
if (adcp->state == ADC_STOP) {
|
||||||
/* Clock activation.*/
|
/* Clock activation.*/
|
||||||
ADCSRA |= (1<<ADEN);
|
ADCSRA |= (1 << ADEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adcp->config != NULL)
|
if (adcp->config != NULL) {
|
||||||
{
|
ADMUX = (adcp->config->analog_reference << REFS0);
|
||||||
ADMUX = (adcp->config->analog_reference << REFS0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,8 +152,9 @@ void adc_lld_stop(ADCDriver *adcp) {
|
||||||
|
|
||||||
if (adcp->state == ADC_READY) {
|
if (adcp->state == ADC_READY) {
|
||||||
/* Clock de-activation.*/
|
/* Clock de-activation.*/
|
||||||
ADCSRA &= ~(1<<ADEN);
|
ADCSRA &= ~(1 << ADEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,10 +165,12 @@ void adc_lld_stop(ADCDriver *adcp) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void adc_lld_start_conversion(ADCDriver *adcp) {
|
void adc_lld_start_conversion(ADCDriver *adcp) {
|
||||||
adcp->currentBufferPosition=0;
|
|
||||||
|
adcp->currentBufferPosition=0;
|
||||||
setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0));
|
|
||||||
ADCSRA |= 1<<ADSC;
|
setAdcChannel(getAdcChannelNumberFromMask(adcp->grpp->channelsMask,0));
|
||||||
|
ADCSRA |= 1 << ADSC;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,7 +181,9 @@ void adc_lld_start_conversion(ADCDriver *adcp) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void adc_lld_stop_conversion(ADCDriver *adcp) {
|
void adc_lld_stop_conversion(ADCDriver *adcp) {
|
||||||
ADCSRA &= ~(1<<ADSC);
|
|
||||||
|
ADCSRA &= ~(1 << ADSC);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAL_USE_ADC */
|
#endif /* HAL_USE_ADC */
|
||||||
|
|
|
@ -1,26 +1,22 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
||||||
2011,2012 Giovanni Di Sirio.
|
|
||||||
|
|
||||||
This file is part of ChibiOS/RT.
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
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.
|
|
||||||
|
|
||||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
Unless required by applicable law or agreed to in writing, software
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
GNU General Public License for more details.
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file templates/adc_lld.h
|
* @file AVR/adc_lld.h
|
||||||
* @brief ADC Driver subsystem low level driver header template.
|
* @brief ADC Driver subsystem low level driver source.
|
||||||
*
|
*
|
||||||
* @addtogroup ADC
|
* @addtogroup ADC
|
||||||
* @{
|
* @{
|
||||||
|
@ -35,12 +31,10 @@
|
||||||
/* Driver constants. */
|
/* Driver constants. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#define ANALOG_REFERENCE_AREF 0
|
#define ANALOG_REFERENCE_AREF 0
|
||||||
#define ANALOG_REFERENCE_AVCC 1
|
#define ANALOG_REFERENCE_AVCC 1
|
||||||
#define ANALOG_REFERENCE_1V1 2
|
#define ANALOG_REFERENCE_1V1 2
|
||||||
#define ANALOG_REFERENCE_2V56 3
|
#define ANALOG_REFERENCE_2V56 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver pre-compile time settings. */
|
/* Driver pre-compile time settings. */
|
||||||
|
@ -104,9 +98,9 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
adccallback_t end_cb;
|
adccallback_t end_cb;
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
|
|
||||||
uint8_t channelsMask;
|
uint8_t channelsMask;
|
||||||
|
|
||||||
} ADCConversionGroup;
|
} ADCConversionGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +110,9 @@ typedef struct {
|
||||||
* @note It could be empty on some architectures.
|
* @note It could be empty on some architectures.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t analog_reference;
|
|
||||||
|
uint8_t analog_reference;
|
||||||
|
|
||||||
} ADCConfig;
|
} ADCConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,7 +179,6 @@ struct ADCDriver {
|
||||||
extern ADCDriver ADCD1;
|
extern ADCDriver ADCD1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -196,8 +191,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* HAL_USE_ADC */
|
#endif /* HAL_USE_ADC */
|
||||||
|
|
||||||
#endif /* _ADC_LLD_H_ */
|
#endif /* _ADC_LLD_H_ */
|
||||||
|
|
Loading…
Reference in New Issue