- Notifications
You must be signed in to change notification settings - Fork 7.8k
added support for enabling I2C HAL locks even when system wide HAL locks are disabled #11941
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
Draft
AlmirKadric wants to merge 3 commits into espressif:master Choose a base branch from AlmirKadric:v3.3.2-patches
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+81 −61
Draft
Changes from 1 commit
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
Next Next commit
added support for enabling I2C HAL locks even when system wide HAL lo…
…cks are disabled
- Loading branch information
commit efdf2bf611907ed2acf79e4334602ab549b78fb5
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
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 |
|---|---|---|
| | @@ -14,11 +14,13 @@ | |
| | ||
| #include "esp32-hal-i2c.h" | ||
| | ||
| #define I2C_HAL_LOCKS_ENABLED (!CONFIG_DISABLE_HAL_LOCKS || CONFIG_FORCE_I2C_HAL_LOCKS) | ||
| Member 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. This should be defined in | ||
| | ||
| #if SOC_I2C_SUPPORTED | ||
| #include "esp_idf_version.h" | ||
| #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) | ||
| #include "esp32-hal.h" | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| #include "freertos/FreeRTOS.h" | ||
| #include "freertos/task.h" | ||
| #include "freertos/semphr.h" | ||
| | @@ -32,7 +34,7 @@ | |
| typedef volatile struct { | ||
| bool initialized; | ||
| uint32_t frequency; | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| SemaphoreHandle_t lock; | ||
| #endif | ||
| int8_t scl; | ||
| | @@ -75,7 +77,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency) { | |
| if (i2c_num >= SOC_I2C_NUM) { | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| if (bus[i2c_num].lock == NULL) { | ||
| bus[i2c_num].lock = xSemaphoreCreateMutex(); | ||
| if (bus[i2c_num].lock == NULL) { | ||
| | @@ -147,7 +149,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency) { | |
| } | ||
| if (!perimanSetPinBus(sda, ESP32_BUS_TYPE_I2C_MASTER_SDA, (void *)(i2c_num + 1), i2c_num, -1) | ||
| || !perimanSetPinBus(scl, ESP32_BUS_TYPE_I2C_MASTER_SCL, (void *)(i2c_num + 1), i2c_num, -1)) { | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock so that i2cDetachBus can execute i2cDeinit | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -157,7 +159,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency) { | |
| } | ||
| | ||
| init_fail: | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -169,7 +171,7 @@ esp_err_t i2cDeinit(uint8_t i2c_num) { | |
| if (i2c_num >= SOC_I2C_NUM) { | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //acquire lock | ||
| if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { | ||
| log_e("could not acquire lock"); | ||
| | @@ -201,7 +203,7 @@ esp_err_t i2cDeinit(uint8_t i2c_num) { | |
| bus[i2c_num].bus_handle = NULL; | ||
| } | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -241,7 +243,7 @@ esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t *buff, size_ | |
| log_e("Only 7bit I2C addresses are supported"); | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //acquire lock | ||
| if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { | ||
| log_e("could not acquire lock"); | ||
| | @@ -282,7 +284,7 @@ esp_err_t i2cWrite(uint8_t i2c_num, uint16_t address, const uint8_t *buff, size_ | |
| } | ||
| | ||
| end: | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -295,7 +297,7 @@ esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t *buff, size_t size, | |
| if (i2c_num >= SOC_I2C_NUM) { | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //acquire lock | ||
| if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { | ||
| log_e("could not acquire lock"); | ||
| | @@ -328,7 +330,7 @@ esp_err_t i2cRead(uint8_t i2c_num, uint16_t address, uint8_t *buff, size_t size, | |
| *readCount = size; | ||
| | ||
| end: | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -343,7 +345,7 @@ esp_err_t i2cWriteReadNonStop( | |
| if (i2c_num >= SOC_I2C_NUM) { | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //acquire lock | ||
| if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { | ||
| log_e("could not acquire lock"); | ||
| | @@ -376,7 +378,7 @@ esp_err_t i2cWriteReadNonStop( | |
| *readCount = rsize; | ||
| | ||
| end: | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | @@ -388,7 +390,7 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency) { | |
| if (i2c_num >= SOC_I2C_NUM) { | ||
| return ESP_ERR_INVALID_ARG; | ||
| } | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //acquire lock | ||
| if (bus[i2c_num].lock == NULL || xSemaphoreTake(bus[i2c_num].lock, portMAX_DELAY) != pdTRUE) { | ||
| log_e("could not acquire lock"); | ||
| | @@ -429,7 +431,7 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency) { | |
| } | ||
| | ||
| end: | ||
| #if !CONFIG_DISABLE_HAL_LOCKS | ||
| #if I2C_HAL_LOCKS_ENABLED | ||
| //release lock | ||
| xSemaphoreGive(bus[i2c_num].lock); | ||
| #endif | ||
| | ||
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
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
Oops, something went wrong.
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.
This needs to depend on hal locks being off