Skip to content

Added programmer.default directive to set a default programmer for a board. #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 boardPlatformRelease.Programmers {
details.Programmers = append(details.GetProgrammers(), &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 @@ -197,11 +197,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 @@ -216,9 +216,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.Id, programmer.Name)
if programmer.Id == details.DefaultProgrammerID {
tab.AddRow("", table.NewCell(programmer.Id, green), table.NewCell(programmer.Name, green), table.NewCell("✔ (default)", green))
} else {
tab.AddRow("", programmer.Id, programmer.Name)
}
}

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 @@ -276,7 +276,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: 2 additions & 0 deletions internal/cli/feedback/result/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ type BoardDetailsResponse struct {
DebuggingSupported bool `json:"debugging_supported,omitempty"`
IdentificationProperties []*BoardIdentificationProperties `json:"identification_properties,omitempty"`
BuildProperties []string `json:"build_properties,omitempty"`
DefaultProgrammerID string `json:"default_programmer_id,omitempty"`
}

func NewBoardDetailsResponse(b *rpc.BoardDetailsResponse) *BoardDetailsResponse {
Expand All @@ -440,6 +441,7 @@ func NewBoardDetailsResponse(b *rpc.BoardDetailsResponse) *BoardDetailsResponse
DebuggingSupported: b.GetDebuggingSupported(),
IdentificationProperties: NewBoardIdentificationProperties(b.GetIdentificationProperties()),
BuildProperties: b.GetBuildProperties(),
DefaultProgrammerID: b.GetDefaultProgrammerId(),
}
}

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