Skip to content

Commit 5234b47

Browse files
authored
RSDK-5412: add an esp32 board for the config schema (#4165)
1 parent 0c24ea7 commit 5234b47

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

components/board/esp32/board.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Package esp32 exists for the sole purpose of exposing the esp32 as a micro-rdk configuration in app.viam.com
2+
// The ESP32 is supported by the micro-rdk only (https://github.com/viamrobotics/micro-rdk)
3+
package esp32
4+
5+
import (
6+
"context"
7+
8+
"github.com/pkg/errors"
9+
10+
"go.viam.com/rdk/components/board"
11+
"go.viam.com/rdk/logging"
12+
"go.viam.com/rdk/resource"
13+
)
14+
15+
var (
16+
espModel = resource.DefaultModelFamily.WithModel("esp32")
17+
errUnsupported = errors.New("The ESP32 board is not supported in the RDK. " +
18+
"Please use with the micro-rdk (https://github.com/viamrobotics/micro-rdk).")
19+
)
20+
21+
type digitalInterruptConfig struct {
22+
Pin int `json:"pin"`
23+
}
24+
25+
type analogConfig struct {
26+
Name string `json:"name"`
27+
Pin int `json:"pin"`
28+
}
29+
30+
type i2CConfig struct {
31+
Name string `json:"name"`
32+
Bus string `json:"bus"`
33+
DataPin int `json:"data_pin,omitempty"`
34+
ClockPin int `json:"clock_pin,omitempty"`
35+
BaudRate int `json:"baudrate_hz,omitempty"`
36+
Timeout int `json:"timeout_ns,omitempty"`
37+
}
38+
39+
// Config mirrors the config structure in (https://github.com/viamrobotics/micro-rdk/blob/main/micro-rdk/src/esp32/board.rs).
40+
type Config struct {
41+
Pins []int `json:"pins,omitempty"`
42+
DigitalInterrupts []digitalInterruptConfig `json:"digital_interrupts,omitempty"`
43+
Analogs []analogConfig `json:"analogs,omitempty"`
44+
I2Cs []i2CConfig `json:"i2cs,omitempty"`
45+
}
46+
47+
func init() {
48+
resource.RegisterComponent(
49+
board.API,
50+
espModel,
51+
resource.Registration[board.Board, *Config]{
52+
Constructor: newEsp32Board,
53+
})
54+
}
55+
56+
// Validate for esp32 will always return an unsupported error.
57+
func (conf *Config) Validate(path string) ([]string, error) {
58+
return []string{}, errUnsupported
59+
}
60+
61+
func newEsp32Board(
62+
ctx context.Context,
63+
deps resource.Dependencies,
64+
conf resource.Config,
65+
logger logging.Logger,
66+
) (board.Board, error) {
67+
return nil, errUnsupported
68+
}

components/board/register/register.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
// for boards.
66
_ "go.viam.com/rdk/components/board/beaglebone"
77
_ "go.viam.com/rdk/components/board/customlinux"
8+
_ "go.viam.com/rdk/components/board/esp32"
89
_ "go.viam.com/rdk/components/board/fake"
910
_ "go.viam.com/rdk/components/board/hat/pca9685"
1011
_ "go.viam.com/rdk/components/board/jetson"

0 commit comments

Comments
 (0)