Adding SPI support to LIS3MDL #1019
Replies: 11 comments
-
Posted at 2019-03-07 by @gfwilliams I'd suggest doing what's done here: https://github.com/espruino/EspruinoDocs/blob/master/devices/LIS2DH12.js#L135 I've started using that pattern on new modules - basically having two In that case I'd keep the I2C function called just |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-07 by TomWS Hmmmm, how very javascript-ish! Thanks for the feedback. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-07 by TomWS Interesting approach on the LIS2DH12. I like the fact that you can pass configuration settings in the options 'option'. It can eliminate a lot of superfluous setup functions. Given this, if using SPI then cs could be a required option and the same connect function used - it's easy enough to distinguish whether the interface is SPI or I2C within the connect function. And, as you say, addr could be an option as you have it in LIS2DH12. I'll mess around with it and see what I can come up with... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-08 by TomWS I think I've got everything modified in LIS3MDL (except updating the documentation) but it is unclear to me how LIS2DH12.readXYZ is used. Can you give me an example? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-08 by @gfwilliams
Yes - it's also a bit more verbose - nothing worse than Personally I'd stick with two connect functions for SPI and I2C. It could be merged into one as you say (and maybe should have originally) but it's nice to try and keep modules all working the same way so it's more familiar to move between them.
Should just be:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-11 by TomWS Just to close this out, I'm moving on to something else and won't be working on this for the foreseeable future. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-11 by @gfwilliams Something else Espruino related, or something else completely? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-11 by TomWS Something else completely. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-12 by @gfwilliams Shame - thanks for letting us know though! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-12 by TomWS I realized last night that I might have left the wrong impression with my previous comment. I'm merely shelving the Espruino work for the time being so I can do some other stuff. I'll be baaack! :-) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-12 by @allObjects @tomws, glad to get that confirmed... After reading between the lines of your conversations and comparing the last two with each other, I interpreted it your way... and I did not get disappointed. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-03-06 by TomWS
My board has an LIS3MDL magnetometer on it, but uses SPI, rather than the I2C interface used in the existing LIS3MDL device code.
Looking at the code, the IO interface is pretty well isolated from the LIS3MDL specific methods so I'm inclined to simply update that module so that, rather than requiring an I2C interface, the connect code accepts either an I2C or SPI instance and the read and write code simply tests for which interface is being used and calls the appropriate lower level IO function.
The alternative is to create a redundant device called something like LIS3MDL-S or something, but I think that's unnecessary since the first approach is not unwieldy.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions