mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 07:45:16 +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:
@@ -329,6 +329,33 @@ was successful by running ``cxxtest``::
|
|||||||
Invalid file! /invalid
|
Invalid file! /invalid
|
||||||
File /proc/version exists!
|
File /proc/version exists!
|
||||||
|
|
||||||
|
dac
|
||||||
|
---
|
||||||
|
This configuration enables DAC and registers a `DAC example application <https://github.com/apache/nuttx-apps/tree/master/examples/dac>`_.
|
||||||
|
|
||||||
|
.. note:: The DAC module is hard-wired to pins 25 (channel 0) and 26
|
||||||
|
(channel 1). The default device name is ``/dev/dac0`` and can be changed in
|
||||||
|
the config menu.
|
||||||
|
|
||||||
|
.. note:: The DAC channels in `IDF <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/dac.html>`_ are numbered ``channel 1`` (pin 25) and ``channel 2`` (pin 26).
|
||||||
|
|
||||||
|
.. note:: Max value 255 should be close to VRef (3.3V) but it probably will not.
|
||||||
|
You can more realistically expect to get voltage around 3.09V.
|
||||||
|
|
||||||
|
With this example you can use (not only) the following commands:
|
||||||
|
|
||||||
|
For a multimeter, you can use the command:
|
||||||
|
|
||||||
|
``dac -d 5000 -s 32 test``
|
||||||
|
|
||||||
|
For oscilloscope or anything else with tracing:
|
||||||
|
|
||||||
|
``dac -d 0 -s 4 test``
|
||||||
|
|
||||||
|
For more info about the example capabilities invoke help message by typing
|
||||||
|
|
||||||
|
``dac -h``
|
||||||
|
|
||||||
efuse
|
efuse
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ AES Yes
|
|||||||
Bluetooth Yes
|
Bluetooth Yes
|
||||||
CAN/TWAI Yes
|
CAN/TWAI Yes
|
||||||
DMA Yes
|
DMA Yes
|
||||||
|
DAC Yes One-shot
|
||||||
eFuse Yes
|
eFuse Yes
|
||||||
Ethernet Yes
|
Ethernet Yes
|
||||||
GPIO Yes
|
GPIO Yes
|
||||||
|
|||||||
@@ -2355,6 +2355,35 @@ config ESP32_RTC_CLK_SRC_INT_8MD256
|
|||||||
endchoice
|
endchoice
|
||||||
endmenu # "RTC Configuration"
|
endmenu # "RTC Configuration"
|
||||||
|
|
||||||
|
menu "DAC Configuration"
|
||||||
|
depends on ANALOG && DAC
|
||||||
|
|
||||||
|
config ESP32_DAC_DEVPATH
|
||||||
|
string "DAC device path"
|
||||||
|
default "/dev/dac0"
|
||||||
|
|
||||||
|
choice ESP32_DAC_MODE
|
||||||
|
prompt "DAC mode of operation"
|
||||||
|
default ESP32_DAC_MODE_ONE_SHOT
|
||||||
|
---help---
|
||||||
|
One-shot mode requires to write every single value with a write call while
|
||||||
|
retaining the last value on output.
|
||||||
|
|
||||||
|
Following modes are not implemented yet.
|
||||||
|
Timer mode utilizes timer IRQs to call handler which can manage the write.
|
||||||
|
DMA is using a ring buffer accessed directly by the driver.
|
||||||
|
Cosine Wave Generator can output preset wave without the need to generate
|
||||||
|
the data and write in memory.
|
||||||
|
|
||||||
|
config ESP32_DAC_MODE_ONE_SHOT
|
||||||
|
bool "One-shot mode"
|
||||||
|
---help---
|
||||||
|
One-shot mode requires to write every single value with a write call while
|
||||||
|
retaining the last value on output.
|
||||||
|
|
||||||
|
endchoice # "DAC mode of operation"
|
||||||
|
endmenu # "DAC Configuration"
|
||||||
|
|
||||||
menu "LEDC Configuration"
|
menu "LEDC Configuration"
|
||||||
depends on ESP32_LEDC
|
depends on ESP32_LEDC
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ ifeq ($(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP),y)
|
|||||||
CHIP_CSRCS += esp32_imm.c
|
CHIP_CSRCS += esp32_imm.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_DAC),y)
|
||||||
|
CHIP_CSRCS += esp32_dac.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_ESP32_LEDC),y)
|
ifeq ($(CONFIG_ESP32_LEDC),y)
|
||||||
CHIP_CSRCS += esp32_ledc.c
|
CHIP_CSRCS += esp32_ledc.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -0,0 +1,399 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32/esp32_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 "xtensa.h"
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
#include <nuttx/analog/dac.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include "esp32_dac.h"
|
||||||
|
#include "esp32_rtc_gpio.h"
|
||||||
|
#include "hardware/esp32_rtc_io.h"
|
||||||
|
#include "hardware/esp32_dport.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define ESP32_DAC0_RTC_IO_CHANNEL RTCIO_GPIO25_CHANNEL
|
||||||
|
#define ESP32_DAC1_RTC_IO_CHANNEL RTCIO_GPIO26_CHANNEL
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct esp32_dac_priv_s
|
||||||
|
{
|
||||||
|
spinlock_t slock; /* Device specific lock. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* DAC methods */
|
||||||
|
|
||||||
|
static void dac_reset(struct dac_dev_s *dev);
|
||||||
|
static int dac_setup(struct dac_dev_s *dev);
|
||||||
|
static void dac_shutdown(struct dac_dev_s *dev);
|
||||||
|
static void dac_txint(struct dac_dev_s *dev, bool enable);
|
||||||
|
static int dac_send(struct dac_dev_s *dev, struct dac_msg_s *msg);
|
||||||
|
static int dac_ioctl(struct dac_dev_s *dev, int cmd, unsigned long arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct esp32_dac_priv_s esp32_dac_priv;
|
||||||
|
|
||||||
|
static const struct dac_ops_s g_dacops =
|
||||||
|
{
|
||||||
|
.ao_reset = dac_reset,
|
||||||
|
.ao_setup = dac_setup,
|
||||||
|
.ao_shutdown = dac_shutdown,
|
||||||
|
.ao_txint = dac_txint,
|
||||||
|
.ao_send = dac_send,
|
||||||
|
.ao_ioctl = dac_ioctl,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct dac_dev_s g_dac =
|
||||||
|
{
|
||||||
|
.ad_ops = &g_dacops, /* Arch-specific operations */
|
||||||
|
.ad_nchannel = 2, /* Available number of DAC channels */
|
||||||
|
.ad_priv = (void *) (&esp32_dac_priv), /* Used by the arch-specific logic */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_power
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Power ON or OFF both DAC channels
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* bool on - true : turn DAC ON; false : turn DAC OFF
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void dac_power(bool on)
|
||||||
|
{
|
||||||
|
if (on)
|
||||||
|
{
|
||||||
|
modifyreg32(RTC_IO_PAD_DAC1_REG, 0, RTC_IO_PDAC1_DAC_XPD_FORCE |
|
||||||
|
RTC_IO_PDAC1_XPD_DAC);
|
||||||
|
modifyreg32(RTC_IO_PAD_DAC2_REG, 0, RTC_IO_PDAC2_DAC_XPD_FORCE |
|
||||||
|
RTC_IO_PDAC2_XPD_DAC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modifyreg32(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_DAC_XPD_FORCE |
|
||||||
|
RTC_IO_PDAC1_XPD_DAC, 0);
|
||||||
|
modifyreg32(RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_DAC_XPD_FORCE |
|
||||||
|
RTC_IO_PDAC2_XPD_DAC, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_reset
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Reset the DAC channel. Called early to initialize the hardware. This
|
||||||
|
* is called, before dac_setup() and on error conditions.
|
||||||
|
*
|
||||||
|
* NOTE: DAC reset will reset both DAC channels!
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void dac_reset(struct dac_dev_s *dev)
|
||||||
|
{
|
||||||
|
dac_shutdown(dev);
|
||||||
|
dac_setup(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_setup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Configure the DAC. This method is called the first time that the DAC
|
||||||
|
* device is opened. This will occur when the port is first opened.
|
||||||
|
* This setup includes configuring and attaching DAC interrupts.
|
||||||
|
* Interrupts are all disabled upon return.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int dac_setup(struct dac_dev_s *dev)
|
||||||
|
{
|
||||||
|
irqstate_t flags;
|
||||||
|
struct esp32_dac_priv_s *priv = (struct esp32_dac_priv_s *) dev->ad_priv;
|
||||||
|
ainfo("DAC starting setup (for both channels)");
|
||||||
|
|
||||||
|
flags = spin_lock_irqsave(&priv->slock);
|
||||||
|
|
||||||
|
/* Initialize RTC GPIO set to RTC Disabled and disable both pull resistors
|
||||||
|
* set RTC_IO_PDACn_MUX_SEL to route the pad to RTC block
|
||||||
|
* set RTC_IO_PDACn_DRV to 0x2 (which is default anyway)
|
||||||
|
* Note: Drive strength _DRV (you won't find this in TRM)
|
||||||
|
* 0: ~5 mA; 1: ~10 mA; 2: ~20 mA; 3: ~40 mA; the default value is 2.
|
||||||
|
* Keep other bits 0, especially:
|
||||||
|
* RTC_IO_PDACn_FUN_SEL (2 bits) = mode 0 to choose RTC_GPIO function.
|
||||||
|
* RTC_IO_PDACn_FUN_IE to disable Input
|
||||||
|
* RTC_IO_PDACn_RUE to disable pull up resistor
|
||||||
|
* RTC_IO_PDACn_RDE to disable pull down resistor
|
||||||
|
*
|
||||||
|
* Note: the following 2 bits are setup separately in dac_power as a last
|
||||||
|
* operation.
|
||||||
|
* set RTC_IO_PDACn_DAC_XPD_FORCE to power up DAC
|
||||||
|
* set RTC_IO_PDACn_XPD_DAC to power on DAC
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t reg_val = RTC_IO_PDAC1_MUX_SEL |
|
||||||
|
0x2 << RTC_IO_PDAC1_DRV_S;
|
||||||
|
|
||||||
|
/* Write the same value to both registers for DAC 1 and DAC 2 */
|
||||||
|
|
||||||
|
putreg32(reg_val, RTC_IO_PAD_DAC1_REG);
|
||||||
|
putreg32(reg_val, RTC_IO_PAD_DAC2_REG);
|
||||||
|
|
||||||
|
/* Disable GPIO output by setting bits in "write 1 to clear" reg */
|
||||||
|
|
||||||
|
modifyreg32(RTC_GPIO_ENABLE_W1TC_REG, 0 ,
|
||||||
|
(UINT32_C(1) << (ESP32_DAC0_RTC_IO_CHANNEL +
|
||||||
|
RTC_GPIO_ENABLE_W1TC_S)) |
|
||||||
|
(UINT32_C(1) << (ESP32_DAC1_RTC_IO_CHANNEL +
|
||||||
|
RTC_GPIO_ENABLE_W1TC_S)));
|
||||||
|
|
||||||
|
/* Clear bit of PAD_DRIVER to setup "normal" output mode for the
|
||||||
|
* corresponding pads
|
||||||
|
*/
|
||||||
|
|
||||||
|
modifyreg32(RTC_GPIO_PIN6_REG, RTC_GPIO_PIN6_PAD_DRIVER, 0);
|
||||||
|
modifyreg32(RTC_GPIO_PIN7_REG, RTC_GPIO_PIN7_PAD_DRIVER, 0);
|
||||||
|
|
||||||
|
dac_power(true);
|
||||||
|
|
||||||
|
dev->ad_ocount += 1;
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&priv->slock, flags);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_shutdown
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Disable the DAC. This method is called when the DAC device is closed.
|
||||||
|
* This method reverses the operation the setup method.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void dac_shutdown(struct dac_dev_s *dev)
|
||||||
|
{
|
||||||
|
esp32_configrtcio(ESP32_DAC0_RTC_IO_CHANNEL, RTC_FUNCTION_DIGITAL);
|
||||||
|
esp32_configrtcio(ESP32_DAC1_RTC_IO_CHANNEL, RTC_FUNCTION_DIGITAL);
|
||||||
|
dac_power(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_txint
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Call to enable or disable TX (transmit) interrupts for the DAC device.
|
||||||
|
* This function is intended to control interrupt-driven data transfers.
|
||||||
|
* Enabling TX interrupts allows the DAC device to generate
|
||||||
|
* an interrupt when it is ready to accept new data for transmission.
|
||||||
|
* Disabling TX interrupts would prevent the DAC from generating these
|
||||||
|
* interrupts.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device.
|
||||||
|
* enable - Set true to enable TX interrupts. set false to disable
|
||||||
|
* TX interrupts.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Note:
|
||||||
|
* The actual logic for enabling or disabling TX interrupts is not
|
||||||
|
* implemented in this function!
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void dac_txint(struct dac_dev_s *dev, bool enable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_send
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the DAC (Digital-to-Analog Converter) output.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device.
|
||||||
|
* msg - A pointer to the DAC message structure. This structure includes
|
||||||
|
* the data to be sent to the DAC and the target DAC channel.
|
||||||
|
* The 'am_data' field of this structure is the actual data to be
|
||||||
|
* written to the DAC, and 'am_channel' determines which DAC channel
|
||||||
|
* (0 or 1) to use.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure. -EINVAL is
|
||||||
|
* returned if an invalid channel is specified.
|
||||||
|
*
|
||||||
|
* Note: The dac_msg_s.am_data is treated as 8 bit value i.e. in range
|
||||||
|
* from 0-255 and corresponds to the analog 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).
|
||||||
|
* The output voltage can be calculated as the following:
|
||||||
|
* out_voltage = 3.3 * digi_val / 255
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int dac_send(struct dac_dev_s *dev, struct dac_msg_s *msg)
|
||||||
|
{
|
||||||
|
irqstate_t flags;
|
||||||
|
uint8_t value = (uint8_t)(msg->am_data & 0xff);
|
||||||
|
uint32_t reg_val;
|
||||||
|
struct esp32_dac_priv_s *priv = (struct esp32_dac_priv_s *) dev->ad_priv;
|
||||||
|
|
||||||
|
flags = spin_lock_irqsave(&priv->slock);
|
||||||
|
|
||||||
|
switch (msg->am_channel)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
modifyreg32(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_CW_EN1, 0);
|
||||||
|
reg_val = getreg32(RTC_IO_PAD_DAC1_REG);
|
||||||
|
reg_val &= ~RTC_IO_PDAC1_DAC_M;
|
||||||
|
reg_val |= value << RTC_IO_PDAC1_DAC_S;
|
||||||
|
putreg32(reg_val, RTC_IO_PAD_DAC1_REG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
modifyreg32(SENS_SAR_DAC_CTRL2_REG, SENS_DAC_CW_EN2, 0);
|
||||||
|
reg_val = getreg32(RTC_IO_PAD_DAC2_REG);
|
||||||
|
reg_val &= ~RTC_IO_PDAC2_DAC_M;
|
||||||
|
reg_val |= value << RTC_IO_PDAC2_DAC_S;
|
||||||
|
putreg32(reg_val, RTC_IO_PAD_DAC2_REG);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
spin_unlock_irqrestore(&priv->slock, flags);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&priv->slock, flags);
|
||||||
|
|
||||||
|
/* One shot mode does not support interrupts for DAC. The TX Done is
|
||||||
|
* signaled to upper half driver directly from this function because the
|
||||||
|
* value is used right away.
|
||||||
|
*/
|
||||||
|
|
||||||
|
dac_txdone(dev);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dac_ioctl
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* All ioctl (input/output control) calls for the DAC device are routed
|
||||||
|
* through this method. This function handles various control commands
|
||||||
|
* for the DAC device. Currently, it returns -ENOTTY for all commands,
|
||||||
|
* indicating that no command is implemented.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* dev - A pointer to the DAC device structure. This structure contains
|
||||||
|
* information about the DAC device, required for handling the ioctl
|
||||||
|
* commands.
|
||||||
|
* cmd - An integer value representing the ioctl command. These commands
|
||||||
|
* are used to perform various control operations on the DAC device.
|
||||||
|
* arg - An unsigned long value representing additional information or
|
||||||
|
* arguments that are relevant to the ioctl command.
|
||||||
|
* The interpretation of this parameter
|
||||||
|
* depends on the specific command.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure. Currently, it
|
||||||
|
* always returns -ENOTTY, indicating that no ioctl commands are supported.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int dac_ioctl(struct dac_dev_s *dev, int cmd, unsigned long arg)
|
||||||
|
{
|
||||||
|
return -ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_dac_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the DAC.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Valid dac device structure reference on success; a NULL on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct dac_dev_s *esp32_dac_initialize(void)
|
||||||
|
{
|
||||||
|
return &g_dac;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32/esp32_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 __ARCH_XTENSA_SRC_ESP32_ESP32_DAC_H
|
||||||
|
#define __ARCH_XTENSA_SRC_ESP32_ESP32_DAC_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/analog/dac.h>
|
||||||
|
#include "hardware/esp32_sens.h"
|
||||||
|
#include "hardware/esp32_rtc_io.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_dac_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the DAC.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Valid dac device structure reference on success; a NULL on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct dac_dev_s *esp32_dac_initialize(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_DAC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
CSRCS += esp32_rmt.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
#ifeq ($(CONFIG_DAC),y)
|
||||||
|
CSRCS += esp32_board_dac.c
|
||||||
|
#endif
|
||||||
|
|
||||||
DEPPATH += --dep-path src
|
DEPPATH += --dep-path src
|
||||||
VPATH += :src
|
VPATH += :src
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)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"
|
# include "esp32_rmt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DAC
|
||||||
|
# include "esp32_board_dac.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "esp32-devkitc.h"
|
#include "esp32-devkitc.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -645,6 +649,14 @@ int esp32_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef CONFIG_RTC_DRIVER
|
||||||
/* Instantiate the ESP32 RTC driver */
|
/* Instantiate the ESP32 RTC driver */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user