-
Notifications
You must be signed in to change notification settings - Fork 2.1k
DRAFT: Add onewire driver #18051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
DRAFT: Add onewire driver #18051
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * Copyright (C) 2017 Frits Kuipers | ||
| * | ||
| * This file is subject to the terms and conditions of the GNU Lesser | ||
| * General Public License v2.1. See the file LICENSE in the top level | ||
| * directory for more details. | ||
| */ | ||
|
|
||
| /** | ||
| * @defgroup drivers_ds18 DS18 temperature sensor driver | ||
| * @ingroup drivers_sensors | ||
| * @ingroup drivers_saul | ||
| * @brief Driver interface for the DS18 temperature sensors | ||
| * | ||
| * This driver provides @ref drivers_saul capabilities. | ||
| * Currently the driver has the following limitations: | ||
| *- Does not allow addressing devices, only supports a single device on the bus. | ||
| *- The 1-Wire bus handling is hardcoded to the driver. | ||
| *- Does not allow configuration of sampling width. | ||
| * | ||
| * @note Due to timing issues present on some boards this drivers features two | ||
| * ways of reading information from the sensor. The optimized uses accurate | ||
| * delays to handle this, while the second way polls the line for changes. If | ||
| * you know that your board can handle ~3us resolution with the xtimer module, | ||
| * then the optimized way is recommended. To used the optimized way add the | ||
| * ds18_optimized module. Also this driver test application has a whitelist of | ||
| * the boards this driver has been tested on and known to work. | ||
| * | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Driver for Maxim Integrated DS1822 and DS18B20 temperature | ||
| * sensors. | ||
| * | ||
| * @author Frits Kuipers <[email protected]> | ||
| */ | ||
|
|
||
| #ifndef ONEWIRE_H | ||
| #define ONEWIRE_H | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| #include "mutex.h" | ||
| #include "periph/gpio.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @name ds18 commands | ||
| * @{ | ||
| */ | ||
| #define DS18_CMD_RSCRATCHPAD (0xbe) | ||
| #define DS18_CMD_WRITESCRATCHPAD (0x4e) | ||
| #define DS18_CMD_COPYSCRATCHPAD (0x48) | ||
| #define DS18_CMD_RECALLE (0xb8) | ||
| #define DS18_CMD_RPWRSPPLY (0xb4) | ||
| #define DS18_CMD_SEARCHROM (0xf0) | ||
|
|
||
| #define ONEWIRE_CMD_READROM (0x33) | ||
| #define ONEWIRE_CMD_MATCHROM (0x55) | ||
| #define ONEWIRE_CMD_SEARCHROM (0xf0) | ||
| #define ONEWIRE_CMD_ALARMSEARCH (0xec) | ||
| #define ONEWIRE_CMD_SKIPROM (0xcc) | ||
| /** @} */ | ||
|
|
||
| /** | ||
| * @brief Device initialization parameters | ||
| */ | ||
| typedef struct { | ||
| gpio_t pin; /**< Pin the sensor is connected to */ | ||
| gpio_mode_t out_mode; /**< Pin output mode */ | ||
| gpio_mode_t in_mode; /**< Pin input mode (usually deduced from output mode) */ | ||
| } onewire_params_t; | ||
|
|
||
| /** | ||
| * @brief Device descriptor for a ds18 device | ||
| */ | ||
| typedef struct { | ||
| onewire_params_t params; /**< Device Parameters */ | ||
| mutex_t lock; | ||
| } onewire_t; | ||
|
|
||
| typedef struct { | ||
| uint8_t type; | ||
| uint8_t serial_number[6]; | ||
| uint8_t crc; | ||
| } onewire_id_rom_t; | ||
|
|
||
| /*static const onewire_params_t onewire_params[] = {*/ | ||
| /* {*/ | ||
| /* .pin = GPIO_PIN(PORT_F, 13),*/ | ||
| /* .out_mode = GPIO_OD_PU,*/ | ||
| /* }*/ | ||
| /*};*/ | ||
|
|
||
| /** | ||
| * @brief Initialize a ds18 device | ||
| * | ||
| * @param[out] dev device descriptor | ||
| * @param[in] params ds18 initialization struct | ||
| * | ||
| * | ||
| * @return 0 on success | ||
| * @return -1 on error | ||
| */ | ||
| int onewire_init(onewire_t *dev, const onewire_params_t *params); | ||
|
|
||
| int onewire_reset(const onewire_t *dev); //TODO: make static? | ||
|
|
||
| void onewire_aquire(onewire_t *dev); | ||
| void onewire_release(onewire_t *dev); | ||
|
|
||
| int onewire_cmd_skiprom(onewire_t *dev); | ||
| int onewire_cmd_readrom(onewire_t *dev, onewire_id_rom_t *rom); | ||
|
|
||
| int onewire_read_bit(const onewire_t *dev, uint8_t *bit); | ||
| int onewire_read_byte(const onewire_t *dev, uint8_t *byte); | ||
| int onewire_read_word(const onewire_t *dev, uint16_t *word); | ||
| int onewire_read(const onewire_t *dev, void *buf, size_t size); | ||
|
|
||
| void onewire_write_bit(const onewire_t *dev, uint8_t bit); | ||
| void onewire_write_byte(const onewire_t *dev, uint8_t byte); | ||
| void onewire_write_word(const onewire_t *dev, uint16_t word); | ||
| void onewire_write(const onewire_t *dev, const void *buf, size_t size); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| /** @} */ | ||
| #endif /* ONEWIRE_H */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright (c) 2020 HAW Hamburg | ||
| # | ||
| # This file is subject to the terms and conditions of the GNU Lesser | ||
| # General Public License v2.1. See the file LICENSE in the top level | ||
| # directory for more details. | ||
| # | ||
|
|
||
| menuconfig MODULE_DS18 | ||
| bool "DS18 temperature sensors" | ||
| depends on HAS_PERIPH_GPIO | ||
| depends on TEST_KCONFIG | ||
| select MODULE_PERIPH_GPIO | ||
| select MODULE_XTIMER | ||
|
|
||
| config MODULE_DS18_OPTIMIZED | ||
| bool "Optimized mode" | ||
| depends on MODULE_DS18 | ||
| help | ||
| Say y to use the optimized mode if the board can handle ~3us resolution | ||
| with the xtimer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include $(RIOTMAKE)/driver_with_saul.mk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| USEMODULE += xtimer | ||
| FEATURES_REQUIRED += periph_gpio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # define optimized read function of DS18 driver as a pseudo module | ||
| PSEUDOMODULES += ds18_optimized | ||
|
|
||
| USEMODULE_INCLUDES_onewire := $(LAST_MAKEFILEDIR)/include | ||
| USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_onewire) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright (C) 2017 Frits Kuipers | ||
| * | ||
| * This file is subject to the terms and conditions of the GNU Lesser | ||
| * General Public License v2.1. See the file LICENSE in the top level | ||
| * directory for more details. | ||
| */ | ||
|
|
||
| /** | ||
| * @ingroup drivers_ds18 | ||
| * | ||
| * @{ | ||
| * @file | ||
| * @brief Default configuration for DS1822 and DS18B20 temperature sensors | ||
| * | ||
| * @author Frits Kuipers <[email protected]> | ||
| */ | ||
|
|
||
| #ifndef ONEWIRE_PARAMS_H | ||
| #define ONEWIRE_PARAMS_H | ||
|
|
||
| #include "board.h" | ||
| #include "onewire.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief Set default configuration parameters for the ds18 | ||
| * @{ | ||
| */ | ||
| #ifndef ONEWIRE_PARAMS_PIN | ||
| #define ONEWIRE_PARAMS_PIN (GPIO_PIN(0, 0)) | ||
| #endif | ||
|
|
||
| #ifndef ONEWIRE_PARAMS_OUT_MODE | ||
| #define ONEWIRE_PARAMS_OUT_MODE (GPIO_OD_PU) | ||
| #endif | ||
|
|
||
| #ifndef ONEWIRE_PARAMS | ||
| #define ONEWIRE_PARAMS \ | ||
| { \ | ||
| .pin = ONEWIRE_PARAMS_PIN, \ | ||
| .out_mode = ONEWIRE_PARAMS_OUT_MODE \ | ||
| } | ||
| #endif | ||
|
|
||
| /**@}*/ | ||
|
|
||
| /** | ||
| * @brief Configure ds18 | ||
| */ | ||
| static const onewire_params_t onewire_params[] = { | ||
| ONEWIRE_PARAMS | ||
| }; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* ONEWIRE_PARAMS_H */ | ||
| /** @} */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?? never set but used ??
i remember to have seen this in #14897 and there i wrote: "if it is deduced from omode there is no need to save it"
#14897 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well shoot. I didn't realize somebody had already attempted this. It looks like #14897 is further along than mine. Would it make more since to re-open the older one and close this PR? I'd be happy to work on resolving the issues in the older PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used a copy of the ds18 as my starting point. I agree this is not as it should be. Up until now, I've mostly concerned myself with the API and not the implementation, since I knew the implementation was at least mature. I'll make sure this gets cleaned up.