diff --git a/boards/xtensa/esp32/common/include/esp32_max6675.h b/boards/xtensa/esp32/common/include/esp32_max6675.h new file mode 100644 index 0000000000..cba1e86825 --- /dev/null +++ b/boards/xtensa/esp32/common/include/esp32_max6675.h @@ -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); diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs index b62c3ac229..ed531347a3 100644 --- a/boards/xtensa/esp32/common/src/Make.defs +++ b/boards/xtensa/esp32/common/src/Make.defs @@ -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 diff --git a/boards/xtensa/esp32/common/src/esp32_max6675.c b/boards/xtensa/esp32/common/src/esp32_max6675.c new file mode 100644 index 0000000000..174c36f02c --- /dev/null +++ b/boards/xtensa/esp32/common/src/esp32_max6675.c @@ -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 +#include +#include +#include +#include +#include +#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 diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/max6675/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/max6675/defconfig new file mode 100644 index 0000000000..843d27d439 --- /dev/null +++ b/boards/xtensa/esp32/esp32-devkitc/configs/max6675/defconfig @@ -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 diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c index 2335a31a1b..cc3eca312c 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c @@ -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. */