stm32-rs / bxcan

bxCAN peripheral driver for STM32 chips
Apache License 2.0
32 stars 22 forks source link

Add unchecked unsafe function to create data for frame #54

Open Fomys opened 2 years ago

Fomys commented 2 years ago

This addition allows the creation of Data without using slices. It's useful when you already have the len and the [u8; 8].

jonas-schievink commented 2 years ago

Can you talk more about what this is useful for? Why do you want to avoid making a slice? I'm somewhat wary of adding unsafe APIs like this unless they pull their weight.

Fomys commented 1 year ago

My specific case is to create a common interface for a protocol over can bus between a raspberry-pi and multiple stm32 (which use canfd and bxcan). I don't want to create multiple function to parse and create specific packet for each interface, it will be redundant and error prone if I have to do that three times, especially because my protocol may change with time.

So I created a function which transform my protocol into a tuple (size: u8, data: [u8;8]). Actually, in the bxcan implementation I have to transform my tuple to a slice before creating the Data struct. As the Data struct contains already only those informations. I think the overhead brought by the slice and the copy is not necessary and can be avoided. I'm open to other solution, but I think it's a good way to do that.