-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
rp2040load.go
52 lines (43 loc) · 1.16 KB
/
rp2040load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package rp2040load
import (
"log"
"os"
"time"
"github.com/arduino/FirmwareUploader/utils/context"
"github.com/arduino/arduino-cli/arduino/serialutils"
"github.com/arduino/arduino-cli/executils"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
)
type RP2040Load struct {
rp2040LoadPath *paths.Path
portName string
}
func NewRP2040Load(ctx *context.Context) *RP2040Load {
return &RP2040Load{
rp2040LoadPath: paths.New(ctx.ProgrammerPath),
portName: ctx.PortName,
}
}
func (b *RP2040Load) Flash(filename string, cb *serialutils.ResetProgressCallbacks) error {
log.Println("Entering board into bootloader mode")
_, err := serialutils.Reset(b.portName, true, cb)
if err != nil {
return err
}
log.Println("Flashing " + filename)
if err := b.invoke("-v", "-D", filename); err != nil {
return errors.Errorf("Error flashing %s: %s", filename, err)
}
time.Sleep(5 * time.Second)
return err
}
func (b *RP2040Load) invoke(args ...string) error {
cmd, err := executils.NewProcessFromPath(b.rp2040LoadPath, args...)
if err != nil {
return err
}
cmd.RedirectStdoutTo(os.Stdout)
cmd.RedirectStderrTo(os.Stderr)
return cmd.Run()
}