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

Add safe abstractions to CRC functions in ESP ROM #261

Merged
merged 3 commits into from Jun 12, 2023

Conversation

jordanhalase
Copy link
Contributor

@jordanhalase jordanhalase commented Jun 10, 2023

This is the safe CRC abstraction over the newly merged esp-rs/esp-idf-sys@4ffb883

I created the rom module to put commonly available ROM libraries, such as CRC. MD5 could be next. Since these libraries rely on the bindings provided by esp-idf-sys but are only on ESP32 chips they belong here in esp-idf-hal and not esp-idf-svc.

Test code is below or at my repository

use esp_idf_sys as _; // For binstart

use esp_idf_hal::rom::crc;

fn main() {
    esp_idf_sys::link_patches();

    let data = "123456789";

    loop {
        let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref());
        let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref());
        let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref());
        let crc_cksum = crc::crc32_be(!0, data.as_ref());
        let crc_kermit = !crc::crc16_le(!0, data.as_ref());
        let crc_genibus = crc::crc16_be(!0xffff, data.as_ref());
        let crc_rohc = !crc::crc8_le(!0xff, data.as_ref());
        let crc_smbus = !crc::crc8_be(!0, data.as_ref());

        assert_eq!(crc_hdlc, 0xcbf43926);
        assert_eq!(crc_bzip2, 0xfc891918);
        assert_eq!(crc_mpeg2, 0x0376e6e7);
        assert_eq!(crc_cksum, 0x765e7680);
        assert_eq!(crc_kermit, 0x2189);
        assert_eq!(crc_genibus, 0xd64e);
        assert_eq!(crc_rohc, 0xd0);
        assert_eq!(crc_smbus, 0xf4);

        println!("{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x}",
            crc_hdlc, crc_bzip2, crc_mpeg2, crc_cksum, crc_kermit, crc_genibus, crc_rohc, crc_smbus);

        std::thread::sleep(std::time::Duration::from_millis(5000));
    }
}

Copy link
Collaborator

@Vollbrecht Vollbrecht left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution ❤️

src/lib.rs Show resolved Hide resolved
src/rom/mod.rs Outdated Show resolved Hide resolved
@ivmarkov
Copy link
Collaborator

@jordanhalase Can you run cargo fmt on your PR and update? Also, please run cargo clippy as well, as that's the next step after fmt.

@jordanhalase
Copy link
Contributor Author

Ran cargo fmt and clippy :)

@ivmarkov ivmarkov merged commit bf4a5af into esp-rs:master Jun 12, 2023
4 of 8 checks passed
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.

None yet

3 participants