Closed bgould closed 5 months ago
Agreed, they should be the same.
Probably we should now define an interface like SPIer
. Just kidding about this name. Perhaps better to name it it SPIPort
. I do not want ot name it SPIReaderWriter
because it is does not fit into the normal Go Reade
or Writer
interfaces, which would probably make it confusing for people who are used to the standard Go interfaces of those same names.
In any case, whatever we end up calling it, we can then implement this interface to ensure that the code fulfills the expectations and matches the code signatures.
What do you think?
I agree we should use a consistent interface.
Regarding interfaces: I think all drivers should eventually be switched to accept a SPI interface instead of a fixed machine.SPI
. That would make it possible to write software implementations of those drivers and would perhaps also make it possible to use these drivers for different purposes outside of TinyGo.
HI ! I was trying to use the SPI on AVR but found no SPI / SPI0 on [ boards_[with_atmega], machine_atmega, machine_avr, machine_atmega328p ]
But found SPI on machine_nrf.go and spi.go which rised me the following questions:
1) Which function or declaration have precedence ?
spi.go-> func (spi SPI) Tx(w, r []byte) error
machine_nrf.go -> func (spi SPI) Tx(w, r []byte) error {
2) Both have differenes and the SPI struct is also different.
I was thinking of dirty implementing the ISP for myself but wish to know the ISP consistency status.
Thank you so much
If you are interested in implementing SPI for AVR, that sounds great. Please take a look at https://gist.github.com/deadprogram/1e914f0c40e80ff9b10588bfe61379d7 it will probably help get you started.
There has been API changes to how register values are set since when that gist was created. You will need to use the functions exported by the volatile
package see https://github.com/tinygo-org/tinygo/blob/master/src/machine/machine_atmega.go for examples.
It seems interesting, SPI ports range from 0 to 3 in AVR-8bit family. https://www.microchip.com/ParamChartSearch/chart.aspx?branchID=30047&popular=1
I will try for fun to implement it inside machine_atmega. I discover Go just few days ago.
spi.go->
func (spi SPI) Tx(w, r []byte) error
machine_nrf.go ->func (spi SPI) Tx(w, r []byte) error {
These are the same?
If you're wondering whether it should return an error or not, for new code it is better to let Tx
return an error (this can be nil
if no error handling is implemented).
Both have differenes and the SPI struct is also different.
The struct may be different, yes. That is not a problem. The important thing is that the public interface (such as the Tx
function) has the same signature everywhere. This is not yet the case, that should indeed be fixed (patches welcome!).
It seems interesting, SPI ports range from 0 to 3 in AVR-8bit family.
Yes, there are many different AVR chips. That's why an SPI implementation is usually made for a (group of) chips, not for all chips from a given vendor.
Ok, I think I have made something flexible, however I need to figure out how to check if a register exists or not in avr device/avr and make sure this update is safe with the GC, if I should use pointers somewhere, etc..
This was addressed some time ago in TinyGo, so now closing. Thanks everyone!
In machine_atsamd21.go and machine_atsamd51.go, SPI.Configure() signature declares that it returns an error. This does not appear to be consistent with other platforms, such as machine_nrf.go, machine_generic.go, etc which do not declare the error. It might make sense to align these signatures so that code is more portable across platforms.