mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
esp32s2-saola-1: Add support for BMP180 pressure sensor
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
committed by
Petro Karashchenko
parent
01b3ddd22f
commit
43685aefc8
@@ -45,6 +45,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
|
|||||||
CSRCS += esp32s2_board_i2c.c
|
CSRCS += esp32s2_board_i2c.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SENSORS_BMP180),y)
|
||||||
|
CSRCS += esp32s2_bmp180.c
|
||||||
|
endif
|
||||||
|
|
||||||
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s2.template.ld
|
SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s2.template.ld
|
||||||
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s2_out.ld
|
SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s2_out.ld
|
||||||
|
|
||||||
|
|||||||
@@ -133,5 +133,24 @@ int board_oneshot_init(int timer, uint16_t resolution);
|
|||||||
int board_i2c_init(void);
|
int board_i2c_init(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_bmp180_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize and register the BMP180 Pressure Sensor driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* devno - The device number, used to build the device path as /dev/pressN
|
||||||
|
* busno - The I2C bus number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SENSORS_BMP180
|
||||||
|
int board_bmp180_initialize(int devno, int busno);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_SRC_ESP32S2_SAOLA_1_H */
|
#endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_SRC_ESP32S2_SAOLA_1_H */
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.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 <debug.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/i2c/i2c_master.h>
|
||||||
|
#include <nuttx/sensors/bmp180.h>
|
||||||
|
|
||||||
|
#include "esp32s2_i2c.h"
|
||||||
|
#include "esp32s2-saola-1.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_bmp180_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize and register the BMP180 Pressure Sensor driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* devno - The device number, used to build the device path as /dev/pressN
|
||||||
|
* busno - The I2C bus number
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_bmp180_initialize(int devno, int busno)
|
||||||
|
{
|
||||||
|
struct i2c_master_s *i2c;
|
||||||
|
char devpath[12];
|
||||||
|
|
||||||
|
/* Initialize BMP180 */
|
||||||
|
|
||||||
|
i2c = esp32s2_i2cbus_initialize(busno);
|
||||||
|
if (i2c == NULL)
|
||||||
|
{
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register the barometer sensor */
|
||||||
|
|
||||||
|
(void)snprintf(devpath, sizeof(devpath), "/dev/press%d", devno);
|
||||||
|
|
||||||
|
return bmp180_register(devpath, i2c);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -50,6 +50,10 @@
|
|||||||
# include "esp32s2_tim_lowerhalf.h"
|
# include "esp32s2_tim_lowerhalf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32S2_I2C
|
||||||
|
# include "esp32s2_i2c.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32S2_RT_TIMER
|
#ifdef CONFIG_ESP32S2_RT_TIMER
|
||||||
# include "esp32s2_rt_timer.h"
|
# include "esp32s2_rt_timer.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -202,6 +206,17 @@ int esp32s2_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SENSORS_BMP180
|
||||||
|
/* Try to register BMP180 device in I2C0 */
|
||||||
|
|
||||||
|
ret = board_bmp180_initialize(0, ESP32S2_I2C0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"Failed to initialize BMP180 driver for I2C0: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* If we got here then perhaps not all initialization was successful, but
|
/* If we got here then perhaps not all initialization was successful, but
|
||||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||||
* capabilities.
|
* capabilities.
|
||||||
|
|||||||
Reference in New Issue
Block a user