-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spi/pin: how should we handle calls to Configure() inside drivers? #206
Comments
To clarify, this would mean changing the function signature from: Configure(cfg SPIConfig) to Configure(cfg *SPIConfig) |
Is there any other driver that configures the spi? I think the drivers should not configure the transports, since it means they know more than they should. In the example it's setting a freq that might not be supported. Another option might be to extended the SPI interface to add a "SetClockSpeed" method, but I'm not convinced (better to keep the interfaces as simple as possible). I'm trying to understand the use case and why this needs to be done in the driver and not in main() |
The only other places where there is use of SPI that goes beyond the interface are https://github.com/tinygo-org/drivers/blob/release/ili9341/spi_atsamd21.go I'm not sure why that functionality is in the driver? Anyhow, the |
Strongly in favor of this one, for the same reasons as @conejoninja. |
I agree that we need to require all setup take place outside the driver. We will have to make a number of changes to remove those calls. So this change this should allow us to define an interface for In a future iteration I think we should define another function on the SPI interface |
PR #215 mostly solves this issue. |
I have an idea which would still make it possible to call
I'm not sure about the names but you can see the idea here. These methods will simply call the appropriate Alternatively, we could make the But this is only when it is needed within the driver, in my opinion in many cases the peripheral configuration should still happen outside the driver. |
I was going to propose something like |
I am trying to use the driver mcp2515 and getting the following error:
Is this related? It seems to be failing on my Begin function:
I'm using a arduino uno with a mcp2515 shield from Sparkfun. |
In the case of the I2C interface, since no driver calls the I2C
Configure()
method, we did not have any troubles refactoring all the I2C drivers to use the interface.However in the case of both the SPI and the Pin objects passed to the
New()
function , some of the drivers then go on to call the Configure() method.For example: https://github.com/tinygo-org/drivers/blob/release/flash/transport_spi.go#L54
Since
Confgure()
expects a concrete type as param here, it becomes difficult to then replace the call with an interface that does not depend on themachine
package.What should we do about this?
One option would be to expect any configuration to already be done and hence to not allow any drivers to call
Configure()
.Another would be to refactor the machine package itself to expect a pointer so that we can define
Configure(interface{})
in thedrivers.SPI
interface.Any other ideas on how to handle this?
The text was updated successfully, but these errors were encountered: