Writing a big endian word to spi in viper #15137
-
I have the following function which writes a word-sized register and a word-sized data value to spi, which works perfectly on a Raspberry Pi Pico: To try to gain as much performance boost as possible I‘m trying to translate this into a viper function, but I can’t get it to work. The code hangs on the first spi.write line. I guess that the combination of to_bites and ptr8 must be the problem (I’ve also tried ptr and ptr16, but that doesn’t make any difference). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
This short function will hardly get any faster when using viper. Viper is fast at straight python code and pure computations. At calls to functions and methods it is not faster than byte code or native code, since most of the time is needed for setting up the arguments, performing the call and eventually returning values. |
Beta Was this translation helpful? Give feedback.
Thanks @robert-hh for your quick suggestion!
I was trying exactly that while you came up with the suggestion :) and this actually works:
@micropython.viper
def _write_register(self, reg: int, data: int):
dc(0)
spi.write(bytearray((reg >> 8, reg & 0xFF)))
dc(1)
spi.write(bytearray((data >> 8, data & 0xFF)))