2021-03-18 09:57:48 +01:00
|
|
|
/****************************************************************************
|
2019-12-16 00:36:59 +01:00
|
|
|
* boards/arm/samd2l2/arduino-m0/src/sam_adc.c
|
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you 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
|
2019-12-16 00:36:59 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-12-16 00:36:59 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* 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.
|
2019-12-16 00:36:59 +01:00
|
|
|
*
|
2021-03-18 09:57:48 +01:00
|
|
|
****************************************************************************/
|
2019-12-16 00:36:59 +01:00
|
|
|
|
2021-03-18 09:57:48 +01:00
|
|
|
/****************************************************************************
|
2019-12-16 00:36:59 +01:00
|
|
|
* Included Files
|
2021-03-18 09:57:48 +01:00
|
|
|
****************************************************************************/
|
2019-12-16 00:36:59 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/board.h>
|
|
|
|
#include <nuttx/analog/adc.h>
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
#include "chip.h"
|
|
|
|
#include "sam_adc.h"
|
|
|
|
|
|
|
|
#include "arduino_m0.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADC
|
|
|
|
|
2021-03-18 09:57:48 +01:00
|
|
|
/****************************************************************************
|
2019-12-16 00:36:59 +01:00
|
|
|
* Public Functions
|
2021-03-18 09:57:48 +01:00
|
|
|
****************************************************************************/
|
2019-12-16 00:36:59 +01:00
|
|
|
|
2021-03-18 09:57:48 +01:00
|
|
|
/****************************************************************************
|
2019-12-16 00:36:59 +01:00
|
|
|
* Name: sam_adc_setup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize ADC and register the ADC driver.
|
|
|
|
*
|
2021-03-18 09:57:48 +01:00
|
|
|
****************************************************************************/
|
2019-12-16 00:36:59 +01:00
|
|
|
|
|
|
|
int sam_adc_setup(void)
|
|
|
|
{
|
|
|
|
static bool initialized = false;
|
|
|
|
struct adc_dev_s *adc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check if we have already initialized */
|
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
/* Call sam_adcinitialize() to get an instance of the ADC interface */
|
|
|
|
|
|
|
|
adc = sam_adcinitialize(0);
|
|
|
|
if (adc == NULL)
|
|
|
|
{
|
|
|
|
aerr("ERROR: Failed to get ADC interface\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the ADC driver at "/dev/adc0" */
|
|
|
|
|
|
|
|
ret = adc_register("/dev/adc0", adc);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
aerr("ERROR: adc_register failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we are initialized */
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_ADC */
|