mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-03 06:27:47 +00:00
f7ae6fac6d
Signed-off-by: deadprogram <ron@hybridgroup.com>
50 lines
830 B
Go
50 lines
830 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/examples/sdcard/tinyfs/console"
|
|
"tinygo.org/x/drivers/sdcard"
|
|
"tinygo.org/x/tinyfs/fatfs"
|
|
)
|
|
|
|
var (
|
|
spi machine.SPI
|
|
sckPin machine.Pin
|
|
sdoPin machine.Pin
|
|
sdiPin machine.Pin
|
|
csPin machine.Pin
|
|
ledPin machine.Pin
|
|
)
|
|
|
|
func main() {
|
|
waitSerial()
|
|
|
|
sd := sdcard.New(spi, sckPin, sdoPin, sdiPin, csPin)
|
|
err := sd.Configure()
|
|
if err != nil {
|
|
fmt.Printf("%s\r\n", err.Error())
|
|
for {
|
|
time.Sleep(time.Hour)
|
|
}
|
|
}
|
|
|
|
filesystem := fatfs.New(&sd)
|
|
|
|
// Configure FATFS with sector size (must match value in ff.h - use 512)
|
|
filesystem.Configure(&fatfs.Config{
|
|
SectorSize: 512,
|
|
})
|
|
|
|
console.RunFor(&sd, filesystem)
|
|
}
|
|
|
|
// Wait for user to open serial console
|
|
func waitSerial() {
|
|
for !machine.Serial.DTR() {
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
}
|