mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
esp32/dac-one-shot: lower-half driver for ESP32 internal DAC
Enable with ./tools/configure.sh -l esp32-devkitc:dac DAC channel 0 = GPIO 25 DAC channel 1 = GPIO 26 default path: /dev/dac0 Resolution 8 bits = values 0~255 Voltage: 0~Vref The reference voltage 'Vref' here is input from the pin VDD3P3_RTC which ideally equals to the power supply VDD (3.3V).
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
* boards/xtensa/esp32/common/include/esp32_board_dac.h
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_DAC_H
|
||||
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_DAC_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_dac_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the Digital to Analog Convertor (DAC) driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The device number, used to build the device path as
|
||||
* /dev/dacN
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_dac_initialize(const char *path);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_DAC_H */
|
||||
@@ -144,6 +144,10 @@ ifeq ($(CONFIG_ESP32_RMT),y)
|
||||
CSRCS += esp32_rmt.c
|
||||
endif
|
||||
|
||||
#ifeq ($(CONFIG_DAC),y)
|
||||
CSRCS += esp32_board_dac.c
|
||||
#endif
|
||||
|
||||
DEPPATH += --dep-path src
|
||||
VPATH += :src
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* boards/xtensa/esp32/common/src/esp32_board_dac.c
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/analog/dac.h>
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <esp32_dac.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_dac_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the Digital to Analog Convertor (DAC) driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path - The device number, used to build the device path as
|
||||
* /dev/dacN
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_dac_initialize(const char *path)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Initialize DAC */
|
||||
|
||||
struct dac_dev_s *dev = esp32_dac_initialize();
|
||||
if (dev != NULL)
|
||||
{
|
||||
/* Try to register the DAC */
|
||||
|
||||
ret = dac_register(path, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering DAC\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -ENODEV;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_ARCH_LEDS is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ANALOG=y
|
||||
CONFIG_ARCH="xtensa"
|
||||
CONFIG_ARCH_BOARD="esp32-devkitc"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
|
||||
CONFIG_ARCH_CHIP="esp32"
|
||||
CONFIG_ARCH_CHIP_ESP32=y
|
||||
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_XTENSA=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DAC=y
|
||||
CONFIG_ESP32_UART0=y
|
||||
CONFIG_EXAMPLES_DAC=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=114688
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_START_DAY=6
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_START_YEAR=2011
|
||||
CONFIG_SYSLOG_BUFFER=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
@@ -165,6 +165,10 @@
|
||||
# include "esp32_rmt.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DAC
|
||||
# include "esp32_board_dac.h"
|
||||
#endif
|
||||
|
||||
#include "esp32-devkitc.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -645,6 +649,14 @@ int esp32_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DAC
|
||||
ret = board_dac_initialize(CONFIG_ESP32_DAC_DEVPATH);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: board_dac_initialize(0) failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTC_DRIVER
|
||||
/* Instantiate the ESP32 RTC driver */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user