mirror of https://github.com/ARMmbed/mbed-os.git
* added base code for ADC. Not tested.
parent
8658c77d26
commit
06b1fdfb2b
|
@ -40,7 +40,7 @@ typedef enum {
|
||||||
UART_4 = (int)0x42001800UL, // Base address of SERCOM4
|
UART_4 = (int)0x42001800UL, // Base address of SERCOM4
|
||||||
UART_5 = (int)0x42001C00UL // Base address of SERCOM5
|
UART_5 = (int)0x42001C00UL // Base address of SERCOM5
|
||||||
} UARTName;
|
} UARTName;
|
||||||
/*
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC0_0 = 0,
|
ADC0_0 = 0,
|
||||||
ADC0_1,
|
ADC0_1,
|
||||||
|
@ -49,9 +49,22 @@ typedef enum {
|
||||||
ADC0_4,
|
ADC0_4,
|
||||||
ADC0_5,
|
ADC0_5,
|
||||||
ADC0_6,
|
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;
|
} ADCName;
|
||||||
|
|
||||||
|
/*
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DAC_0 = 0
|
DAC_0 = 0
|
||||||
} DACName;*/
|
} DACName;*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ uint32_t find_mux_setting (PinName output, PinName input, PinName clock, PinName
|
||||||
//extern const PinMap PinMap_RTC[];
|
//extern const PinMap PinMap_RTC[];
|
||||||
|
|
||||||
/************ADC***************/
|
/************ADC***************/
|
||||||
//extern const PinMap PinMap_ADC[];
|
extern const PinMap PinMap_ADC[];
|
||||||
|
|
||||||
/************DAC***************/
|
/************DAC***************/
|
||||||
//extern const PinMap PinMap_DAC[];
|
//extern const PinMap PinMap_DAC[];
|
||||||
|
|
|
@ -34,6 +34,14 @@ const PinMap PinMap_RTC[] = {
|
||||||
|
|
||||||
/************ADC***************/
|
/************ADC***************/
|
||||||
const PinMap PinMap_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***************/
|
/************DAC***************/
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#define DEVICE_INTERRUPTIN 0
|
#define DEVICE_INTERRUPTIN 0
|
||||||
|
|
||||||
#define DEVICE_ANALOGIN 0
|
#define DEVICE_ANALOGIN 1
|
||||||
#define DEVICE_ANALOGOUT 0
|
#define DEVICE_ANALOGOUT 0
|
||||||
|
|
||||||
#define DEVICE_SERIAL 1
|
#define DEVICE_SERIAL 1
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "PortNames.h"
|
#include "PortNames.h"
|
||||||
#include "PeripheralNames.h"
|
#include "PeripheralNames.h"
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -58,6 +59,11 @@ struct serial_s {
|
||||||
uint32_t events;
|
uint32_t events;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct analogin_s {
|
||||||
|
ADCName adc;
|
||||||
|
struct adc_module adc_instance;
|
||||||
|
};
|
||||||
/*
|
/*
|
||||||
struct pwmout_s {
|
struct pwmout_s {
|
||||||
__IO uint32_t *MR;
|
__IO uint32_t *MR;
|
||||||
|
@ -69,10 +75,6 @@ struct serial_s {
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct analogin_s {
|
|
||||||
ADCName adc;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dac_s {
|
struct dac_s {
|
||||||
DACName dac;
|
DACName dac;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue