Skip to content
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

1-wire: add 1-wire bus driver #171

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

suda-morris
Copy link
Collaborator

@suda-morris suda-morris commented Apr 24, 2023

Added onewire_bus library based on RMT peripheral driver. Previously this library was located in the esp-idf's example: https://github.com/espressif/esp-idf/tree/master/examples/peripherals/rmt/onewire_ds18b20/components/onewire_bus

Now I have refactored that, and split it into multiple parts: bus, device and other helper functions (e.g. CRC).

As the one-wire bus implementation can be various, so added an interface to abstract the bus behavior. Easy to extend with other backend peripherals.

Fixed an issue that reported in espressif/esp-idf#10790

examples and doc will be added in the later PR(s).

device driver like "ds18b20" will go into esp-bsp repo, after this PR got merged.

@CLAassistant
Copy link

CLAassistant commented Apr 24, 2023

CLA assistant check
All committers have signed the CLA.

ESP_RETURN_ON_FALSE(onewire_crc8(0, iter->rom_number, 7) == iter->rom_number[7], ESP_ERR_INVALID_CRC, TAG, "bad device crc");

// save the ROM number as the device address
memcpy(&dev->address, iter->rom_number, sizeof(onewire_device_address_t));

Check warning

Code scanning / clang-tidy

Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
onewire_bus/src/onewire_bus_impl_rmt.c Fixed Show resolved Hide resolved
onewire_bus/src/onewire_bus_impl_rmt.c Fixed Show resolved Hide resolved

// transmit one bits to generate read clock
uint8_t tx_buffer[rx_buf_size];
memset(tx_buffer, 0xFF, rx_buf_size);

Check warning

Code scanning / clang-tidy

Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
onewire_bus/src/onewire_bus_impl_rmt.c Fixed Show fixed Hide fixed
Copy link
Collaborator

@tore-espressif tore-espressif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left few question/comments, otherwise LGTM!

You also mentioned setting up a runner in espressif/esp-idf#10790 (comment) , do you plan to connect the runner to esp-idf or in idf-extra-components?

onewire_bus/src/onewire_crc.c Show resolved Hide resolved
onewire_bus/include/onewire_bus_impl_rmt.h Show resolved Hide resolved
onewire_bus/src/onewire_bus_impl_rmt.c Fixed Show resolved Hide resolved
onewire_bus/src/onewire_bus_impl_rmt.c Fixed Show resolved Hide resolved
onewire_bus_rmt_obj_t *bus_rmt = __containerof(bus, onewire_bus_rmt_obj_t, base);
esp_err_t ret = ESP_OK;
ESP_RETURN_ON_FALSE(rx_buf_size <= bus_rmt->max_rx_bytes, ESP_ERR_INVALID_ARG, TAG, "rx_buf_size too large for buffer to hold");
memset(rx_buf, 0, rx_buf_size);

Check warning

Code scanning / clang-tidy

Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
@suda-morris suda-morris merged commit 27ec308 into espressif:master Apr 26, 2023
@suda-morris suda-morris deleted the feature/1-wire-library branch April 26, 2023 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants