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

feature request: update_bit() #120

Open
SebKuzminsky opened this issue Aug 27, 2024 · 1 comment
Open

feature request: update_bit() #120

SebKuzminsky opened this issue Aug 27, 2024 · 1 comment

Comments

@SebKuzminsky
Copy link

I need to checksum data that isn't an integer multiple of 8 bits in length.

I'm working on an interface library for a SPI device that uses CRC to validate frames on the SPI bus. The frames are made up of fields that don't start and end on byte boundaries.

Here's a diagram showing what i mean:
Screenshot from 2024-08-27 13-46-12

The microcontroller performs a SPI transfer of 6+n bytes. The first two bytes sent by the micro contain the command (zero-padded on the left). The next two bytes contain a 15-bit checksum of the command, with a 0 in the LSB.

The device receives the command and validates it with the checksum. If that passes it sends n bytes of data, followed by a two byte trailer consisting of 6 bits of "command count" and 10 bits of checksum covering the n payload bytes and the 6 bits of "command count".

As far as i can tell, there's not a way in crc-rs to compute a checksum that doesn't cover an integer number of bytes.

It's easy enough to implement my own amateurish crc code to do this, but it'd be nice if i could just use your awesome library.

I'd be happy to try to implement this in crc-rs if you think it'd be a useful addition.

@akhilles
Copy link
Collaborator

akhilles commented Sep 9, 2024

I would like to support this use-case, but it really depends on the API. Maybe we can add something like this to Digest?

fn update_bits<const BITS: usize>(&mut self, byte: u8) {}

with compile-time enforcement of BITS < 8.

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

No branches or pull requests

2 participants