esp32-sparrow-kit: add support for the LTR308 light sensor

Add support to esp32-sparrow-kit for the LTR308 sensor. This patch also
enables the sensor in the default nsh config file.

Signed-off-by: Robert-Ionut Alexa <robertalexa2000@gmail.com>
This commit is contained in:
Robert-Ionut Alexa
2022-11-21 18:52:12 +02:00
committed by Xiang Xiao
parent 3351146c0b
commit e0374c30e4
5 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
/****************************************************************************
* boards/xtensa/esp32/common/include/esp32_ltr308.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_LTR308_H
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_LTR308_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_ltr308_initialize
*
* Description:
* Initialize and register the LTR308 Lite-On ambient light sensors driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as
* /dev/uorb/sensor_lightN
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_ltr308_initialize(int devno, int busno);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_LTR308_H */

View File

@@ -88,6 +88,10 @@ ifeq ($(CONFIG_SENSORS_MS5611),y)
CSRCS += esp32_ms5611.c
endif
ifeq ($(CONFIG_SENSORS_LTR308),y)
CSRCS += esp32_ltr308.c
endif
ifeq ($(CONFIG_LCD_HT16K33),y)
CSRCS += esp32_ht16k33.c
endif

View File

@@ -0,0 +1,86 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_ltr308.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 <stdio.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/sensors/ltr308.h>
#include <nuttx/i2c/i2c_master.h>
#include "esp32_board_i2c.h"
#include "esp32_i2c.h"
#include "esp32_ltr308.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_ltr308_initialize
*
* Description:
* Initialize and register the LTR308 Lite-On ambient light sensor driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as
* /dev/uorb/sensor_lightN
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_ltr308_initialize(int devno, int busno)
{
struct i2c_master_s *i2c;
int ret;
sninfo("Initializing LTR308!\n");
/* Initialize LTR308 */
i2c = esp32_i2cbus_initialize(busno);
if (i2c != NULL)
{
/* Then try to register the light sensor in one of the two I2C
* available controllers.
*/
ret = ltr308_register(devno, i2c);
if (ret < 0)
{
snerr("ERROR: Error registering LTR308 in I2C%d\n", busno);
}
}
else
{
ret = -ENODEV;
}
return ret;
}

View File

@@ -20,6 +20,8 @@ CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_ESP32_I2C0=y
CONFIG_ESP32_I2C0_SDAPIN=21
CONFIG_ESP32_UART0=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
@@ -38,6 +40,8 @@ CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_SENSORS=y
CONFIG_SENSORS_LTR308=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011

View File

@@ -80,6 +80,10 @@
# include "esp32_bmp180.h"
#endif
#ifdef CONFIG_SENSORS_LTR308
# include "esp32_ltr308.h"
#endif
#ifdef CONFIG_INPUT_BUTTONS
# include <nuttx/input/buttons.h>
#endif
@@ -342,6 +346,17 @@ int esp32_bringup(void)
}
#endif
#ifdef CONFIG_SENSORS_LTR308
/* Try to register LTR308 device in I2C0 */
ret = board_ltr308_initialize(0, 0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize LTR308 driver: %d\n", ret);
}
#endif
#ifdef CONFIG_INPUT_BUTTONS
/* Register the BUTTON driver */