* added base code for ADC. Not tested.

pull/1243/head
akhilpanayam 2015-06-30 17:42:14 +05:30 committed by Karthik Purushothaman
parent 8658c77d26
commit 06b1fdfb2b
6 changed files with 108 additions and 8 deletions

View File

@ -40,7 +40,7 @@ typedef enum {
UART_4 = (int)0x42001800UL, // Base address of SERCOM4
UART_5 = (int)0x42001C00UL // Base address of SERCOM5
} UARTName;
/*
typedef enum {
ADC0_0 = 0,
ADC0_1,
@ -49,9 +49,22 @@ typedef enum {
ADC0_4,
ADC0_5,
ADC0_6,
ADC0_7
ADC0_7/*,
ADC0_8,
ADC0_9,
ADC0_10,
ADC0_11,
ADC0_12,
ADC0_13,
ADC0_14,
ADC0_15,
ADC0_16,
ADC0_17,
ADC0_18,
ADC0_19*/
} ADCName;
/*
typedef enum {
DAC_0 = 0
} DACName;*/

View File

@ -26,7 +26,7 @@ uint32_t find_mux_setting (PinName output, PinName input, PinName clock, PinName
//extern const PinMap PinMap_RTC[];
/************ADC***************/
//extern const PinMap PinMap_ADC[];
extern const PinMap PinMap_ADC[];
/************DAC***************/
//extern const PinMap PinMap_DAC[];

View File

@ -34,6 +34,14 @@ const PinMap PinMap_RTC[] = {
/************ADC***************/
const PinMap PinMap_ADC[] = {
{PA04, ADC0_0, 1},
{PA05, ADC0_1, 1},
{PA06, ADC0_2, 1},
{PA07, ADC0_3, 1},
{PA08, ADC0_4, 1},
{PA09, ADC0_5, 1},
{PB02, ADC0_6, 1},
{PB03, ADC0_7, 1}
};
/************DAC***************/

View File

@ -22,7 +22,7 @@
#define DEVICE_INTERRUPTIN 0
#define DEVICE_ANALOGIN 0
#define DEVICE_ANALOGIN 1
#define DEVICE_ANALOGOUT 0
#define DEVICE_SERIAL 1

View File

@ -0,0 +1,77 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_assert.h"
#include "analogin_api.h"
#include "cmsis.h"
#include "pinmap.h"
#include "PeripheralPins.h"
#include "adc.h"
void analogin_init(analogin_t *obj, PinName pin)
{
struct adc_config config_adc;
uint32_t pos_input;
switch(pin) {
case PA04:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN4;
break;
case PA05:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN5;
break;
case PA06:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN6;
break;
case PA07:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN7;
break;
case PA08:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN16;
break;
case PA09:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN17;
break;
case PB02:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN10;
break;
case PB03:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN11;
break;
default:
pos_input = ADC_INPUTCTRL_MUXPOS_PIN4; // MBED_ASSERT
break;
}
adc_get_config_defaults(&(obj->adc_instance));
config_adc.positive_input = pos_input;
adc_init(&(obj->adc_instance), ADC, &config_adc);
adc_enable(&(obj->adc_instance));
}
uint16_t analogin_read_u16(analogin_t *obj)
{
uint16_t result;
adc_start_conversion(&(obj->adc_instance));
adc_read(&(obj->adc_instance), &result);
}
float analogin_read(analogin_t *obj)
{
uint16_t value = analogin_read_u16(obj);
return (float)value * (1.0f / (float)0xFFFF);
}

View File

@ -20,6 +20,7 @@
#include "PortNames.h"
#include "PeripheralNames.h"
#include "gpio_object.h"
#include "adc.h"
#ifdef __cplusplus
extern "C" {
@ -58,6 +59,11 @@ struct serial_s {
uint32_t events;
#endif
};
struct analogin_s {
ADCName adc;
struct adc_module adc_instance;
};
/*
struct pwmout_s {
__IO uint32_t *MR;
@ -69,10 +75,6 @@ struct serial_s {
int index;
};
struct analogin_s {
ADCName adc;
};
struct dac_s {
DACName dac;
};