esp32: Add MAX6675 temperature sensor support

This commit is contained in:
Alan Carvalho de Assis 2022-10-29 17:48:07 -03:00 committed by Xiang Xiao
parent a2ff09642c
commit 99cfffc96a
5 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/****************************************************************************
* boards/xtensa/esp32/common/include/esp32_max6675.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.
*
****************************************************************************/
/****************************************************************************
* Name: board_max6675_initialize
*
* Description:
* Initialize and register the MAX6675 Temperature Sensor driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as /dev/tempN
* busno - The SPI bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_max6675_initialize(int devno, int busno);

View File

@ -40,6 +40,10 @@ ifeq ($(CONFIG_ESP32_PCNT_AS_QE),y)
CSRCS += esp32_qencoder.c
endif
ifeq ($(CONFIG_SENSORS_MAX6675),y)
CSRCS += esp32_max6675.c
endif
ifeq ($(CONFIG_AUDIO_CS4344),y)
CSRCS += esp32_cs4344.c
endif

View File

@ -0,0 +1,103 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_max6675.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/arch.h>
#include <nuttx/sensors/max6675.h>
#include <nuttx/spi/spi.h>
#include <stdio.h>
#include <debug.h>
#include "esp32_spi.h"
#ifdef CONFIG_SENSORS_MAX6675
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_max6675_initialize
*
* Description:
* Initialize and register the MAX6675 Temperature Sensor driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as /dev/tempN
* busno - The SPI bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_max6675_initialize(int devno, int busno)
{
struct spi_dev_s *spi;
char devpath[12];
int ret;
spi = esp32_spibus_initialize(busno);
if (!spi)
{
return -ENODEV;
}
/* Then register the barometer sensor */
snprintf(devpath, sizeof(devpath), "/dev/temp%d", devno);
ret = max6675_register(devpath, spi);
if (ret < 0)
{
snerr("ERROR: Error registering MAX6675\n");
}
return ret;
}
#endif

View File

@ -0,0 +1,50 @@
#
# 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_NSH_CMDPARMS is not set
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_ESP32_SPI2=y
CONFIG_ESP32_UART0=y
CONFIG_EXAMPLES_MAX31855=y
CONFIG_EXAMPLES_MAX31855_PROGNAME="max6675"
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_SENSORS=y
CONFIG_SENSORS_MAX6675=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y

View File

@ -143,6 +143,10 @@
# include "esp32_lcd_backpack.h"
#endif
#ifdef CONFIG_SENSORS_MAX6675
# include "esp32_max6675.h"
#endif
#include "esp32-devkitc.h"
/****************************************************************************
@ -257,6 +261,14 @@ int esp32_bringup(void)
}
#endif /* CONFIG_ESP32_LEDC */
#ifdef CONFIG_SENSORS_MAX6675
ret = board_max6675_initialize(0, 2);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: MAX6675 initialization failed: %d\n", ret);
}
#endif
#ifdef CONFIG_ESP32_TWAI
/* Initialize TWAI and register the TWAI driver. */