Skip to content

Commit

Permalink
Added programmer.default directive to set a default programmer for …
Browse files Browse the repository at this point in the history
…a board. (#2416)

* Updated gRPC API

* Implemented default programmer for boards

* Added default programmer in board details CLI command

* Implemented default programmer functionality in CLI

* Added docs
  • Loading branch information
cmaglie committed Nov 13, 2023
1 parent 54caaf1 commit 1c80c05
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 170 deletions.
7 changes: 7 additions & 0 deletions arduino/cores/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,10 @@ func (b *Board) IdentifyBoardConfiguration(query *properties.Map) *properties.Ma
}
return res
}

// GetDefaultProgrammerID returns the board's default programmer as
// defined in 'programmer.default' property of the board. If the board
// has no default programmer the empty string is returned.
func (b *Board) GetDefaultProgrammerID() string {
return b.Properties.Get("programmer.default")
}
1 change: 1 addition & 0 deletions commands/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
})
}

details.DefaultProgrammerId = board.GetDefaultProgrammerID()
details.Programmers = []*rpc.Programmer{}
for id, p := range boardPlatform.Programmers {
details.Programmers = append(details.Programmers, &rpc.Programmer{
Expand Down
18 changes: 18 additions & 0 deletions docs/platform-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,24 @@ the [board and core platform](#platform-terminology) of the currently selected b
platforms may now need to define copies of the programmers that were previously assumed to be provided by another
platform.

### Set a default programmer for a board (since Arduino CLI >=0.35.0, Arduino IDE >=2.3.0)

A default programmer for each board may be specified through the `programmer.default` directive in the board definition:

```
BOARD_ID.programmer.default=PROGRAMMER_ID
```

The default programmer will be selected automatically if the user do not specifiy or select another programmer. This may
be useful for boards with an on-board programmer/debugger.

For example if we want to set Atmel ICE as the default programmer for the Arduino UNO we would add the following line to
the `boards.txt` file:

```
uno.programmer.default=atmel-ice
```

## Tools

The Arduino development software uses external command line tools to upload the compiled sketch to the board or to burn
Expand Down
28 changes: 24 additions & 4 deletions internal/cli/arguments/programmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

package arguments

import "github.com/spf13/cobra"
import (
"context"

"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
)

// Programmer contains the programmer flag data.
// This is useful so all flags used by commands that need
Expand All @@ -32,7 +38,21 @@ func (p *Programmer) AddToCommand(cmd *cobra.Command) {
})
}

// String returns the programmer
func (p *Programmer) String() string {
return p.programmer
// String returns the programmer specified by the user, or the default programmer
// for the given board if defined.
func (p *Programmer) String(inst *commands.Instance, fqbn string) string {
if p.programmer != "" {
return p.programmer
}
if inst == nil || fqbn == "" {
return ""
}
details, err := board.Details(context.Background(), &commands.BoardDetailsRequest{
Instance: inst,
Fqbn: fqbn,
})
if err != nil {
return ""
}
return details.GetDefaultProgrammerId()
}
10 changes: 7 additions & 3 deletions internal/cli/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func (dr detailsResult) String() string {
}
}

green := color.New(color.FgGreen)
tab.AddRow() // get some space from above
for _, option := range details.ConfigOptions {
tab.AddRow(tr("Option:"), option.OptionLabel, "", option.Option)
for _, value := range option.Values {
green := color.New(color.FgGreen)
if value.Selected {
tab.AddRow("",
table.NewCell(value.ValueLabel, green),
Expand All @@ -211,9 +211,13 @@ func (dr detailsResult) String() string {
}
}

tab.AddRow(tr("Programmers:"), tr("ID"), tr("Name"))
tab.AddRow(tr("Programmers:"), tr("ID"), tr("Name"), "")
for _, programmer := range details.Programmers {
tab.AddRow("", programmer.GetId(), programmer.GetName())
if programmer.Id == details.GetDefaultProgrammerId() {
tab.AddRow("", table.NewCell(programmer.GetId(), green), table.NewCell(programmer.GetName(), green), table.NewCell("✔ (default)", green))
} else {
tab.AddRow("", programmer.GetId(), programmer.GetName())
}
}

return t.Render() + tab.Render()
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
Port: discoveryPort,
Verbose: verbose,
Verify: verify,
Programmer: programmer.String(),
Programmer: programmer.String(instance, fqbn.String()),
DryRun: dryRun,
}, stdOut, stdErr); err != nil {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
Verbose: verbose,
Verify: verify,
ImportDir: buildPath,
Programmer: programmer.String(),
Programmer: programmer.String(inst, fqbn),
UserFields: fields,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
Port: port,
Interpreter: interpreter,
ImportDir: importDir,
Programmer: programmer.String(),
Programmer: programmer.String(instance, fqbn),
}

if printInfo {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
Verify: verify,
ImportFile: importFile,
ImportDir: importDir,
Programmer: programmer.String(),
Programmer: programmer.String(inst, fqbn),
DryRun: dryRun,
UserFields: fields,
}
Expand Down
Loading

0 comments on commit 1c80c05

Please sign in to comment.