-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
avrdude.go
55 lines (47 loc) · 1.13 KB
/
avrdude.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
53
54
55
package avrdude
import (
"fmt"
"log"
"os"
"time"
"github.com/arduino/FirmwareUpdater/utils/context"
"github.com/arduino/arduino-cli/arduino/serialutils"
"github.com/arduino/arduino-cli/executils"
"github.com/arduino/go-paths-helper"
)
type Avrdude struct {
avrdudePath *paths.Path
configPath *paths.Path
}
func NewAvrdude(ctx *context.Context) *Avrdude {
avrdudePath := paths.New(ctx.ProgrammerPath)
return &Avrdude{
avrdudePath: avrdudePath,
configPath: avrdudePath.Parent().Join("..", "etc", "avrdude.conf"),
}
}
func (b *Avrdude) Flash(filename string, cb *serialutils.ResetProgressCallbacks) error {
log.Println("Flashing " + filename)
err := b.invoke(
fmt.Sprintf("-C%s", b.configPath),
"-v",
"-patmega4809",
"-cxplainedmini_updi",
"-Pusb",
"-b115200",
"-e",
"-D",
fmt.Sprintf("-Uflash:w:%s:i", filename),
"-Ufuse8:w:0x00:m")
time.Sleep(5 * time.Second)
return err
}
func (b *Avrdude) invoke(args ...string) error {
cmd, err := executils.NewProcessFromPath(b.avrdudePath, args...)
if err != nil {
return err
}
cmd.RedirectStdoutTo(os.Stdout)
cmd.RedirectStderrTo(os.Stderr)
return cmd.Run()
}