nucleo-f334r8: Add OPAMP support
This commit is contained in:
parent
0b6190c1c4
commit
c3109acb29
@ -237,8 +237,14 @@
|
||||
#define GPIO_USART1_RX GPIO_USART1_RX_1 /* PA10 */
|
||||
#define GPIO_USART1_TX GPIO_USART1_TX_1 /* PA9 */
|
||||
|
||||
/* HRTIM */
|
||||
/* COMP */
|
||||
|
||||
/* OPAMP */
|
||||
|
||||
#define OPAMP2_VMSEL OPAMP2_VMSEL_PC5
|
||||
#define OPAMP2_VPSEL OPAMP2_VPSEL_PB14
|
||||
|
||||
/* HRTIM */
|
||||
|
||||
/* DMA channels *************************************************************/
|
||||
/* ADC */
|
||||
|
@ -202,4 +202,16 @@ int stm32_can_setup(void);
|
||||
int stm32_comp_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_opamp_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize OPAMP peripheral for the board.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_OPAMP
|
||||
int stm32_opamp_setup(void);
|
||||
#endif
|
||||
|
||||
#endif /* __CONFIGS_NUCLEO_F334R8_SRC_NUCLEO_F334R8_H */
|
||||
|
@ -137,6 +137,16 @@ int board_app_initialize(uintptr_t arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_OPAMP
|
||||
/* Initialize OPAMP and register the OPAMP driver. */
|
||||
|
||||
ret = stm32_opamp_setup();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: stm32_opamp_setup failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
* configs/nucleo-f334r8/src/stm32_opamp.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Mateusz Szafoni <raiden00@railab.me>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/analog/opamp.h>
|
||||
|
||||
#include "stm32.h"
|
||||
|
||||
#if defined(CONFIG_OPAMP) && defined(CONFIG_STM32_OPAMP2)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_opamp_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize OPAMP
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_opamp_setup(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
struct opamp_dev_s* opamp = NULL;
|
||||
int ret;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
/* Get the OPAMP interface */
|
||||
|
||||
#ifdef CONFIG_STM32_OPAMP2
|
||||
opamp = stm32_opampinitialize(2);
|
||||
if (opamp == NULL)
|
||||
{
|
||||
aerr("ERROR: Failed to get OPAMP%d interface\n", 2);
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Register the OPAMP character driver at /dev/opamp0 */
|
||||
|
||||
ret = opamp_register("/dev/opamp0", opamp);
|
||||
if (ret < 0)
|
||||
{
|
||||
aerr("ERROR: opamp_register failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_OPAMP && CONFIG_STM32_OPAMP2 */
|
Loading…
Reference in New Issue
Block a user