drivers/sensors: Adds new driver for ds18b20 sensore module

Signed-off-by: Marco Krahl <ocram.lhark@gmail.com>
This commit is contained in:
Marco Krahl
2021-04-10 14:01:10 +02:00
committed by Xiang Xiao
parent 624a60f456
commit 9f9d266f68
5 changed files with 1133 additions and 5 deletions
+29
View File
@@ -171,6 +171,35 @@ config SENSORS_DHTXX
---help---
Enable driver support for the DHTxx humidity/temperature sensor.
config SENSORS_DS18B20
bool "Maxim Integrated DS18B20 Temperature Sensor support"
default n
select 1WIRE
---help---
Enable driver support for the DS18B20 temperature sensor.
config SENSORS_DS18B20_POLL
bool "Enables polling sensor data"
depends on SENSORS_DS18B20
default n
---help---
Enables polling of sensor.
config SENSORS_DS18B20_POLL_INTERVAL
int "Polling interval in microseconds, default 1 sec"
depends on SENSORS_DS18B20 && SENSORS_DS18B20_POLL
default 1000000
range 0 4294967295
---help---
The interval until a new sensor measurement will be triggered.
config SENSORS_DS18B20_THREAD_STACKSIZE
int "Worker thread stack size"
depends on SENSORS_DS18B20 && SENSORS_DS18B20_POLL
default 1024
---help---
The stack size for the worker thread.
config SENSORS_FXOS8700CQ
bool "NXP FXOS8700CQ Motion Sensor support"
default n
+10
View File
@@ -260,6 +260,16 @@ endif
endif # CONFIG_SPI
# These drivers depend on 1WIRE support
ifeq ($(CONFIG_1WIRE),y)
ifeq ($(CONFIG_SENSORS_DS18B20),y)
CSRCS += ds18b20.c
endif
endif # CONFIG_1WIRE
ifeq ($(CONFIG_SENSORS_MPU60X0),y)
CSRCS += mpu60x0.c
endif
File diff suppressed because it is too large Load Diff
+95
View File
@@ -0,0 +1,95 @@
/****************************************************************************
* include/nuttx/sensors/ds18b20.h
* Character driver for DS18B20 Digital Temperature Module.
*
* 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 __INCLUDE_NUTTX_SENSORS_DS18B20_H
#define __INCLUDE_NUTTX_SENSORS_DS18B20_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_1WIRE) && defined(CONFIG_SENSORS_DS18B20)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DS18B20_DEVICE_FAMILY (0x28)
#define DS18B20_CMD_CONVERTT (0x44)
#define DS18B20_CMD_COPYSPAD (0x48)
#define DS18B20_CMD_RECALL (0xb8)
#define DS18B20_CMD_READPOWS (0xb4)
/****************************************************************************
* Public Types
****************************************************************************/
struct onewire_master_s;
struct ds18b20_alarm_s
{
int8_t thigh; /* Upper alarm temperature */
int8_t tlow; /* Lower alarm temperature */
# ifdef CONFIG_SENSORS_DS18B20_POLL
bool wakeup; /* Wakeup poll requests only when alarm detected */
# endif
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: ds18b20_register
*
* Description:
* Register the DS18B20 character device.
*
* Input Parameters:
* devno - The user specifies device number, from 0.
* onewire - An instance of the 1wire interface to communicate with DS18B20
* sensor.
* romcode - The ROM code of the DS18B20.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
****************************************************************************/
int ds18b20_register(int devno, FAR struct onewire_master_s *dev,
uint64_t romcode);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_1WIRE && CONFIG_SENSORS_DS18B20 */
#endif /* __INCLUDE_NUTTX_SENSORS_DS18B20_H */
+12 -5
View File
@@ -229,26 +229,33 @@
#define SNIOC_READADDR SNIOC_READID /* Arg: uint8_t* pointer */
/* IOCTL commands unique to the DS18B20 */
/* SNIOC_SETRESOLUTION */ /* Arg: uint8_t value */
#define SNIOC_READROMCODE _SNIOC(0x0067) /* Arg: uint64_t* pointer */
#define SNIOC_SETALARM _SNIOC(0x0068) /* Arg: struct ds18b20_alarm_s* */
/* Command: SNIOC_ACTIVATE
* Description: Enable or disable sensor
* Argument: true or false.
*/
#define SNIOC_ACTIVATE _SNIOC(0x0067)
#define SNIOC_ACTIVATE _SNIOC(0x0080)
/* Command: SNIOC_SET_INTERVAL
* Description: Set interval between samples
* Argument: This is the interval pointer, in microseconds
*/
#define SNIOC_SET_INTERVAL _SNIOC(0x0068)
#define SNIOC_SET_INTERVAL _SNIOC(0x0081)
/* Command: SNIOC_BATCH
* Description: Set batch latency between batch data.
* Argument: This is the latency pointer, in microseconds
*/
#define SNIOC_BATCH _SNIOC(0x0069)
#define SNIOC_BATCH _SNIOC(0x0082)
/* Command: SNIOC_GET_NEVENTBUF
* Description: the number of sensor events that sensor buffer of upper half
@@ -265,7 +272,7 @@
* See sensor.h(struct sensor_lower_half_s buffer_bytes).
*/
#define SNIOC_GET_NEVENTBUF _SNIOC(0x0070)
#define SNIOC_GET_NEVENTBUF _SNIOC(0x0083)
/* Command: SNIOC_SET_BUFFER_NUMBER
* Description: Set the number of events intermediate circualr buffer can
@@ -275,6 +282,6 @@
* circualr buffer can hold by this ioctl command.
*/
#define SNIOC_SET_BUFFER_NUMBER _SNIOC(0x0071)
#define SNIOC_SET_BUFFER_NUMBER _SNIOC(0x0084)
#endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */