mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 12:53:23 +00:00
drivers/flash: restore previous calls directly to machine package until we implement SetClockSpeed()
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+6
-6
@@ -135,12 +135,12 @@ func (dev *Device) Configure(config *DeviceConfig) (err error) {
|
|||||||
// Speed up to max device frequency
|
// Speed up to max device frequency
|
||||||
// I propose a check here for max frequency, but not put that functionality directly into the driver.
|
// I propose a check here for max frequency, but not put that functionality directly into the driver.
|
||||||
// Either that or we have to change the signature of the SPI interface in the machine package itself.
|
// Either that or we have to change the signature of the SPI interface in the machine package itself.
|
||||||
// if dev.attrs.MaxClockSpeedMHz > 0 {
|
if dev.attrs.MaxClockSpeedMHz > 0 {
|
||||||
// err := dev.trans.setClockSpeed(uint32(dev.attrs.MaxClockSpeedMHz) * 1e6)
|
err := dev.trans.setClockSpeed(uint32(dev.attrs.MaxClockSpeedMHz) * 1e6)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Enable Quad Mode if available
|
// Enable Quad Mode if available
|
||||||
if dev.trans.supportQuadMode() && dev.attrs.QuadEnableBitMask > 0 {
|
if dev.trans.supportQuadMode() && dev.attrs.QuadEnableBitMask > 0 {
|
||||||
|
|||||||
+23
-4
@@ -2,13 +2,12 @@ package flash
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
"machine"
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type transport interface {
|
type transport interface {
|
||||||
configure(config *DeviceConfig)
|
configure(config *DeviceConfig)
|
||||||
supportQuadMode() bool
|
supportQuadMode() bool
|
||||||
|
setClockSpeed(hz uint32) (err error)
|
||||||
runCommand(cmd byte) (err error)
|
runCommand(cmd byte) (err error)
|
||||||
readCommand(cmd byte, rsp []byte) (err error)
|
readCommand(cmd byte, rsp []byte) (err error)
|
||||||
writeCommand(cmd byte, data []byte) (err error)
|
writeCommand(cmd byte, data []byte) (err error)
|
||||||
@@ -19,7 +18,7 @@ type transport interface {
|
|||||||
|
|
||||||
// NewSPI returns a pointer to a flash device that uses a SPI peripheral to
|
// NewSPI returns a pointer to a flash device that uses a SPI peripheral to
|
||||||
// communicate with a serial memory chip.
|
// communicate with a serial memory chip.
|
||||||
func NewSPI(spi drivers.SPI, sdo, sdi, sck, cs machine.Pin) *Device {
|
func NewSPI(spi *machine.SPI, sdo, sdi, sck, cs machine.Pin) *Device {
|
||||||
return &Device{
|
return &Device{
|
||||||
trans: &spiTransport{
|
trans: &spiTransport{
|
||||||
spi: spi,
|
spi: spi,
|
||||||
@@ -32,7 +31,7 @@ func NewSPI(spi drivers.SPI, sdo, sdi, sck, cs machine.Pin) *Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type spiTransport struct {
|
type spiTransport struct {
|
||||||
spi drivers.SPI
|
spi *machine.SPI
|
||||||
sdo machine.Pin
|
sdo machine.Pin
|
||||||
sdi machine.Pin
|
sdi machine.Pin
|
||||||
sck machine.Pin
|
sck machine.Pin
|
||||||
@@ -40,11 +39,31 @@ type spiTransport struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tr *spiTransport) configure(config *DeviceConfig) {
|
func (tr *spiTransport) configure(config *DeviceConfig) {
|
||||||
|
// Configure spi bus
|
||||||
|
tr.setClockSpeed(5000000)
|
||||||
|
|
||||||
// Configure chip select pin
|
// Configure chip select pin
|
||||||
tr.ss.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
tr.ss.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
tr.ss.High()
|
tr.ss.High()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tr *spiTransport) setClockSpeed(hz uint32) error {
|
||||||
|
// TODO: un-hardcode this max speed; it is probably a sensible
|
||||||
|
// default maximum for atsamd and nrf at least
|
||||||
|
if hz > 24*1e6 {
|
||||||
|
hz = 24 * 1e6
|
||||||
|
}
|
||||||
|
tr.spi.Configure(machine.SPIConfig{
|
||||||
|
Frequency: hz,
|
||||||
|
SDI: tr.sdi,
|
||||||
|
SDO: tr.sdo,
|
||||||
|
SCK: tr.sck,
|
||||||
|
LSBFirst: false,
|
||||||
|
Mode: 0,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (tr *spiTransport) supportQuadMode() bool {
|
func (tr *spiTransport) supportQuadMode() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user