blmorris wrote:Thanks for the reply. If I understand you correctly, the reason that I can't currently do it in the Pythonic way is that the current I2C and other serial device classes don't present a file-like interface.
Correct.
That works well enough for me. As much as I would like to develop good Python programming habits, for now it is easy enough to work around as you pointed out. I'll keep an eye on this issue as my project develops.
One question- when you said that it is still possible to trivially do the transfer that I need, did you mean loading the data into a buffer in RAM, or did you mean that it can be streamed in a more RAM-eficient but not-very-pythonic way. I'm happy to do it the simple way for now, but if there is a more efficient way to do it as a single transfer then I'm still not seeing it.
Well, you surely would need to load data into buffer in RAM. Depending on how disk controller is implemented, it might be formally possible to do DMA directly from disk controller into device. But mixing both filesystem support, and disk-device DMA support would be something non-orthodox (if any OS or RTOS supports that, let me know, that could set an objective to strive for).
And bothering with DMA for your case would probably be much more trouble than real need. So, buffer in RAM, but how big, depends actually on bus semantic (or how well it's implemented in "pyb" module). I didn't really have much practical experience with I2C, but with SPI, single transfer is when you keep SlaveSelect signal asserted during the entire transfer. But in
http://micropython.org/doc/module/pyb/SPI , I don't see any way to control SS explicitly, which means you won't be able to read file by chunks into small buffer, than spool it to SPI, and repeat until end of file - you'll have to read entire, file, then send content at once to SPI. It might be the same for I2C (again, depending on its bus semantics, IIRC, there's kind of STOP condition, and again, I don't see any way to control that explicitly at
http://micropython.org/doc/module/pyb/I2C).
Bottom line, so far there's just rough interface, and ideas how it might be improved, but what we need is that people who know hardware and Python well enough to actually start using it, to come up with actually better way to do it.