-
Notifications
You must be signed in to change notification settings - Fork 7
/
boards.js
252 lines (220 loc) · 5.1 KB
/
boards.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
export { boards };
const exampleHelloGo = `package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, Go")
}`;
const exampleHelloTinyGo = `package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, TinyGo")
}`;
const exampleBlinky1 = `package main
import (
"machine"
"time"
)
const led = machine.LED
func main() {
println("Hello, TinyGo")
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
led.Low()
time.Sleep(time.Second)
led.High()
time.Sleep(time.Second)
}
}`;
const exampleMicrobitBlink = `package main
import (
"machine"
"time"
)
func main() {
ledcol := machine.LED_COL_1
ledcol.Configure(machine.PinConfig{Mode: machine.PinOutput})
ledcol.Low()
ledrow := machine.LED_ROW_1
ledrow.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
ledrow.Low()
time.Sleep(time.Millisecond * 500)
ledrow.High()
time.Sleep(time.Millisecond * 500)
}
}`;
const exampleGopherBadge = `// See: https://gopherbadge.com/
package main
import (
"image/color"
"machine"
"strings"
"time"
"tinygo.org/x/drivers/pixel"
"tinygo.org/x/drivers/st7789"
"tinygo.org/x/drivers/ws2812"
"tinygo.org/x/tinygl-font"
"tinygo.org/x/tinygl-font/roboto"
)
var colors = make([]color.RGBA, 2)
func main() {
go blinkEyes()
// configure the display
machine.SPI0.Configure(machine.SPIConfig{
Mode: 3,
SCK: machine.SPI0_SCK_PIN,
SDO: machine.SPI0_SDO_PIN,
SDI: machine.SPI0_SDI_PIN,
Frequency: 62_500_000, // 62.5MHz
})
display := st7789.New(machine.SPI0,
machine.TFT_RST, // TFT_RESET
machine.TFT_WRX, // TFT_DC
machine.TFT_CS, // TFT_CS
machine.TFT_BACKLIGHT) // TFT_LITE
display.Configure(st7789.Config{
Rotation: st7789.ROTATION_270,
Height: 320,
})
// define some constants
type T = pixel.RGB565BE
black := pixel.NewColor[T](0, 0, 0)
white := pixel.NewColor[T](255, 255, 255)
// show pressed buttons
buf := pixel.NewImage[T](320, 28)
labels := []string{"A", "B", "up", "down", "left", "right"}
buttons := []machine.Pin{machine.BUTTON_A, machine.BUTTON_B, machine.BUTTON_UP, machine.BUTTON_DOWN, machine.BUTTON_LEFT, machine.BUTTON_RIGHT}
for _, button := range buttons {
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
}
for {
var pressed []string
for i, button := range buttons {
if !button.Get() {
pressed = append(pressed, labels[i])
}
}
buf.FillSolidColor(black)
text := "button pressed: " + strings.Join(pressed, " ")
if len(pressed) == 0 {
text += "(none)"
}
font.Draw(roboto.Regular24, text, 4, 20, white, buf)
display.DrawBitmap(0, 0, buf)
display.Display()
time.Sleep(time.Second / 8)
}
}
func blinkEyes() {
machine.NEOPIXELS.Configure(machine.PinConfig{Mode: machine.PinOutput})
ws := ws2812.New(machine.NEOPIXELS)
for {
colors[0] = color.RGBA{R: 255}
colors[1] = color.RGBA{B: 255}
ws.WriteColors(colors)
time.Sleep(time.Second / 2)
colors[0] = color.RGBA{B: 255}
colors[1] = color.RGBA{R: 255}
ws.WriteColors(colors)
time.Sleep(time.Second / 2)
}
}`;
const exampleRGBLED = `package main
import (
"machine"
"time"
)
var leds = []machine.Pin{machine.LED_RED, machine.LED_GREEN, machine.LED_BLUE}
func main() {
println("Hello, TinyGo")
for _, led := range leds {
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
led.High()
}
for {
for _, led := range leds {
led.Low()
time.Sleep(time.Second)
led.High()
}
}
}`;
// List of boards to show in the menu. See parts/*.json.
const boards = {
'console-go': {
humanName: 'Console (Go)',
location: 'parts/console.json',
compiler: 'go',
code: exampleHelloGo,
},
'console': {
humanName: 'Console (TinyGo)',
location: 'parts/console.json',
compiler: 'tinygo',
code: exampleHelloTinyGo,
},
'arduino': {
humanName: 'Arduino Uno',
location: 'parts/arduino.json',
compiler: 'tinygo',
code: exampleBlinky1,
},
'arduino-nano33': {
humanName: 'Arduino Nano 33 IoT',
location: 'parts/arduino-nano33.json',
compiler: 'tinygo',
code: exampleBlinky1,
},
'circuitplay-bluefruit': {
humanName: 'Circuit Playground Bluefruit',
location: 'parts/circuitplay-bluefruit.json',
compiler: 'tinygo',
code: exampleBlinky1,
},
'circuitplay-express': {
humanName: 'Circuit Playground Express',
location: 'parts/circuitplay-express.json',
compiler: 'tinygo',
code: exampleBlinky1,
},
'gopher-badge': {
humanName: 'Gopher Badge',
location: 'parts/gopher-badge.json',
compiler: 'tinygo',
code: exampleGopherBadge,
},
'hifive1b': {
humanName: 'HiFive1 rev B',
location: 'parts/hifive1b.json',
compiler: 'tinygo',
code: exampleRGBLED,
},
'microbit': {
humanName: 'BBC micro:bit v1',
location: 'parts/microbit.json',
compiler: 'tinygo',
code: exampleMicrobitBlink,
},
'reelboard': {
humanName: 'Phytec reel board',
location: 'parts/reelboard.json',
compiler: 'tinygo',
code: exampleRGBLED,
},
'pinetime': {
humanName: 'PineTime',
location: 'parts/pinetime.json',
compiler: 'tinygo',
code: exampleBlinky1,
},
'pico': {
humanName: 'Raspberry Pi Pico',
location: 'parts/pico.json',
compiler: 'tinygo',
code: exampleBlinky1,
}
};