I'm hoping someone can shed light on what's the best way to solve this problem.
- I have an i2c device that takes a command (via a i2c write call), performs some computation
- We then read from the device after a delay of a few milliseconds.
- The size of the response can vary but the first byte contains the
length in bytes
- I'm looking for a way to use the returned
length-informationcontained in the
first-byteto perform a second read and retrieve the rest of response.
But as I'm not using a heap and array lengths don't support generic parameters, I don't know of a way to achieve this other than - just define a big enough array (i.e. MAX) buffer for the response. I was looking at
generic arrays and wondered whether my problem can be solved by it.
If no, is there some other way to achieve this.
Pseudocode for what I'm trying to achieve
//First read let mut count_byte = [0; 1]; self.i2c.read(self.dev_addr, &mut count_byte); //Second Read let mut remaining_bytes = [0; count_byte]; // This doesn't work in Rust as array lengths can't be generic constants self.i2c.read(self.dev_addr, &mut remaining_bytes);