|
| 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 | +} |
0 commit comments