-
Notifications
You must be signed in to change notification settings - Fork 449
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
feat: support <driver/i2c_master.h> in i2cdev #655
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,17 @@ | |
#ifndef __I2CDEV_H__ | ||
#define __I2CDEV_H__ | ||
|
||
#include <driver/i2c.h> | ||
#include <freertos/FreeRTOS.h> | ||
#include <freertos/semphr.h> | ||
#include <esp_err.h> | ||
#include <esp_idf_lib_helpers.h> | ||
|
||
#if CONFIG_I2CDEV_USING_LEGACY_I2C | ||
#include <driver/i2c.h> | ||
#else | ||
#include <driver/i2c_master.h> | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
@@ -68,12 +73,23 @@ extern "C" { | |
typedef struct | ||
{ | ||
i2c_port_t port; //!< I2C port number | ||
i2c_config_t cfg; //!< I2C driver configuration | ||
uint8_t addr; //!< Unshifted address | ||
SemaphoreHandle_t mutex; //!< Device mutex | ||
#if defined(CONFIG_I2CDEV_USING_LEGACY_I2C) | ||
i2c_config_t cfg; //!< I2C driver configuration (i2c.h only) | ||
uint32_t timeout_ticks; /*!< HW I2C bus timeout (stretch time), in ticks. 80MHz APB clock | ||
ticks for ESP-IDF, CPU ticks for ESP8266. | ||
When this value is 0, I2CDEV_MAX_STRETCH_TIME will be used */ | ||
When this value is 0, I2CDEV_MAX_STRETCH_TIME will be used | ||
(i2c.h only) */ | ||
#else | ||
Comment on lines
+76
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are so many files using the initializer code, that it might be easier to keep these parts of the structure and ignore them when using the updated driver. |
||
i2c_master_bus_handle_t bus; //!< I2C master bus handle (i2c_master.h only) | ||
i2c_master_dev_handle_t device; //!< I2C master bus device handle | ||
//(i2c_master.h only) | ||
i2c_device_config_t device_config; //!< I2C device configuration (i2c_master.h only) | ||
i2c_master_bus_config_t master_bus_config; /*! < I2C master bus specific | ||
configurations (i2c_master.h | ||
only) */ | ||
#endif | ||
uint8_t addr; //!< Unshifted address | ||
SemaphoreHandle_t mutex; //!< Device mutex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use use the mutex from i2c_port_state_t? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the part is obtained from the old code, I cannot comment on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh alright, it may be that they use the same logic for controlling the mutex. We'll have to ask the author |
||
} i2c_dev_t; | ||
|
||
/** | ||
|
@@ -97,6 +113,7 @@ esp_err_t i2cdev_init(); | |
/** | ||
* @brief Finish work with library | ||
* | ||
* Delete Deinitialize the I2C master bus. When the legacy i2c.h is used, | ||
* Uninstall i2c drivers. | ||
* | ||
* @return ESP_OK on success | ||
|
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.
Thinking about the restructuring as a whole, where you currently split the new and legacy functionality into separate files, it might result in repetitions of code. It depends what the author thinks of this, but using existing function implementations (using preprocessor blocks) will result in the implementations for both the legacy version and updated version in the same place (same functions too).
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.
Completely right.