lpc8xx-hal icon indicating copy to clipboard operation
lpc8xx-hal copied to clipboard

DynamicPin IO is very slow

Open snakehand opened this issue 4 years ago • 1 comments

I am trying to do some I2C bitbanging ( not really for 824 since it has enough ports ), I then need dynamic pins so that I can both read and write to the pins. The problem is that every set_high() & set_low() ends up calling into Register::new() which is a rather expensive function to call as it is 30+ instructions long with many writes to memory, This severely hampers the speed at which I can switch the gpio pins. I am thinking that the Register block will be the same every time it is newed() and can be cached somehow ?

snakehand avatar Sep 13 '21 16:09 snakehand

Hi @snakehand, thank your for opening this issue.

Are you compiling with --release? I always assumed that the compiler would optimize this out, but looking at the code again, I'm not sure that's right. Maybe adding an #[inline(always)] to Registers::new will help though.

hannobraun avatar Sep 13 '21 19:09 hannobraun