-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Adds read-only property for the I2C EEPROM Target #75777
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
Manu3l0us
wants to merge
2
commits into
zephyrproject-rtos:main
from
Manu3l0us:read_only_eeprom_target
Closed
Changes from all commits
Commits
Show all changes
2 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ struct i2c_eeprom_target_data { | |||||
| uint32_t buffer_idx; | ||||||
| uint32_t idx_write_cnt; | ||||||
| uint8_t address_width; | ||||||
| bool read_only; | ||||||
| }; | ||||||
|
|
||||||
| struct i2c_eeprom_target_config { | ||||||
|
|
@@ -115,22 +116,26 @@ static int eeprom_target_write_received(struct i2c_target_config *config, | |||||
| struct i2c_eeprom_target_data, | ||||||
| config); | ||||||
|
|
||||||
| LOG_DBG("eeprom: write done, val=0x%x", val); | ||||||
|
|
||||||
| /* In case EEPROM wants to be R/O, return !0 here could trigger | ||||||
| * a NACK to the I2C controller, support depends on the | ||||||
| * I2C controller support | ||||||
| */ | ||||||
|
|
||||||
| if (data->idx_write_cnt < (data->address_width >> 3)) { | ||||||
| LOG_DBG("eeprom: write addr, val=0x%x", val); | ||||||
|
|
||||||
| if (data->idx_write_cnt == 0) { | ||||||
| data->buffer_idx = 0; | ||||||
| } | ||||||
|
|
||||||
| data->buffer_idx = val | (data->buffer_idx << 8); | ||||||
| data->idx_write_cnt++; | ||||||
| } else { | ||||||
| } else if (!data->read_only) { | ||||||
| LOG_DBG("eeprom: write data, val=0x%x", val); | ||||||
|
|
||||||
| data->buffer[data->buffer_idx++] = val; | ||||||
| } else { | ||||||
| LOG_DBG("eeprom: write attempt to read-only EEPROM"); | ||||||
|
|
||||||
| /* In case the EEPROM is read-only, an error code is returned | ||||||
| * to trigger a NACK on I2C controllers that support it. | ||||||
| */ | ||||||
| return -EIO; | ||||||
| } | ||||||
|
|
||||||
| data->buffer_idx = data->buffer_idx % data->buffer_size; | ||||||
|
|
@@ -249,34 +254,25 @@ static int i2c_eeprom_target_init(const struct device *dev) | |||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| #define I2C_EEPROM_INIT(inst) \ | ||||||
| static struct i2c_eeprom_target_data \ | ||||||
| i2c_eeprom_target_##inst##_dev_data = { \ | ||||||
| .address_width = DT_INST_PROP_OR(inst, \ | ||||||
| address_width, 8), \ | ||||||
| }; \ | ||||||
| \ | ||||||
| static uint8_t \ | ||||||
| i2c_eeprom_target_##inst##_buffer[(DT_INST_PROP(inst, size))]; \ | ||||||
| \ | ||||||
| BUILD_ASSERT(DT_INST_PROP(inst, size) <= \ | ||||||
| (1 << DT_INST_PROP_OR(inst, address_width, 8)), \ | ||||||
| "size must be <= than 2^address_width"); \ | ||||||
| \ | ||||||
| static const struct i2c_eeprom_target_config \ | ||||||
| i2c_eeprom_target_##inst##_cfg = { \ | ||||||
| .bus = I2C_DT_SPEC_INST_GET(inst), \ | ||||||
| .buffer_size = DT_INST_PROP(inst, size), \ | ||||||
| .buffer = i2c_eeprom_target_##inst##_buffer \ | ||||||
| }; \ | ||||||
| \ | ||||||
| DEVICE_DT_INST_DEFINE(inst, \ | ||||||
| &i2c_eeprom_target_init, \ | ||||||
| NULL, \ | ||||||
| &i2c_eeprom_target_##inst##_dev_data, \ | ||||||
| &i2c_eeprom_target_##inst##_cfg, \ | ||||||
| POST_KERNEL, \ | ||||||
| CONFIG_I2C_TARGET_INIT_PRIORITY, \ | ||||||
| &api_funcs); | ||||||
| #define I2C_EEPROM_INIT(inst) \ | ||||||
| static struct i2c_eeprom_target_data i2c_eeprom_target_##inst##_dev_data = { \ | ||||||
| .address_width = DT_INST_PROP_OR(inst, address_width, 8), \ | ||||||
| .read_only = DT_INST_PROP_OR(inst, read_only, 8), \ | ||||||
|
Contributor
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. Looks like a copy-paste error. The
Suggested change
|
||||||
| }; \ | ||||||
| \ | ||||||
| static uint8_t i2c_eeprom_target_##inst##_buffer[(DT_INST_PROP(inst, size))]; \ | ||||||
| \ | ||||||
| BUILD_ASSERT(DT_INST_PROP(inst, size) <= (1 << DT_INST_PROP_OR(inst, address_width, 8)), \ | ||||||
| "size must be <= than 2^address_width"); \ | ||||||
| \ | ||||||
| static const struct i2c_eeprom_target_config i2c_eeprom_target_##inst##_cfg = { \ | ||||||
| .bus = I2C_DT_SPEC_INST_GET(inst), \ | ||||||
| .buffer_size = DT_INST_PROP(inst, size), \ | ||||||
| .buffer = i2c_eeprom_target_##inst##_buffer}; \ | ||||||
| \ | ||||||
| DEVICE_DT_INST_DEFINE(inst, &i2c_eeprom_target_init, NULL, \ | ||||||
| &i2c_eeprom_target_##inst##_dev_data, \ | ||||||
| &i2c_eeprom_target_##inst##_cfg, POST_KERNEL, \ | ||||||
| CONFIG_I2C_TARGET_INIT_PRIORITY, &api_funcs); | ||||||
|
|
||||||
| DT_INST_FOREACH_STATUS_OKAY(I2C_EEPROM_INIT) | ||||||
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
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
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.