Skip to content

Commit

Permalink
Add xiao-rp2040 for sg48key, improve joystick (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 authored Feb 15, 2024
1 parent 732c234 commit 5ebf6db
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ smoketest: FORCE
tinygo build -o ./out/gopher-badge.uf2 --target gopher-badge --size short ./targets/gopher-badge/
tinygo build -o ./out/macropad-rp2040.uf2 --target macropad-rp2040 --size short ./targets/macropad-rp2040/
tinygo build -o ./out/sg48key.uf2 --target xiao --size short ./targets/sg48key/
tinygo build -o ./out/sg48key-rp2040.uf2 --target xiao-rp2040 --size short ./targets/sg48key/
tinygo build -o ./out/sgh60.uf2 --target waveshare-rp2040-zero --size short ./targets/sgh60/
tinygo build -o ./out/sgkb-left.uf2 --target xiao-rp2040 --size short ./targets/sgkb/left/
tinygo build -o ./out/sgkb-left-0.3.0.uf2 --target xiao-rp2040 --size short ./targets/sgkb/left-0.3.0/
Expand Down
2 changes: 1 addition & 1 deletion targets/sg48key/adcdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (a *ADCDevice) Get() int16 {
var mapx = map[int]int16{
0: 0,
1: 0,
2: 10,
2: 0,
3: 10,
4: 20,
5: 30,
Expand Down
17 changes: 4 additions & 13 deletions targets/sg48key/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,30 @@ func run() error {
machine.D4, // not connected
}

led1 := machine.LED
led1.Configure(machine.PinConfig{Mode: machine.PinOutput})
led2 := machine.LED2
led2.Configure(machine.PinConfig{Mode: machine.PinOutput})
led3 := machine.LED3
led3.Configure(machine.PinConfig{Mode: machine.PinOutput})

sm := d.AddSquaredMatrixKeyboard(colPins, [][]keyboard.Keycode{
{
jp.KeyTab, jp.KeyQ, jp.KeyW, jp.KeyE, jp.KeyR, jp.KeyT, jp.KeyY, jp.KeyU, jp.KeyI, jp.KeyO, jp.KeyP, jp.KeyAt,
jp.KeyLeftCtrl, jp.KeyA, jp.KeyS, jp.KeyD, jp.KeyF, jp.KeyG, jp.KeyH, jp.KeyJ, jp.KeyK, jp.KeyL, jp.KeySemicolon, jp.KeyColon,
jp.KeyLeftShift, jp.KeyZ, jp.KeyX, jp.KeyC, jp.KeyV, jp.KeyB, jp.KeyN, jp.KeyM, jp.KeyComma, jp.KeyPeriod, jp.KeySlash, jp.KeyBackslash,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeyTo1, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyLeftAlt, jp.KeyPrintscreen, jp.KeyDelete,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeySpace, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyTo1, jp.KeyPrintscreen, jp.KeyDelete,
},
{
jp.KeyTab, jp.KeyQ, jp.KeyF15, jp.KeyEnd, jp.KeyF17, jp.KeyF18, jp.KeyY, jp.KeyU, jp.KeyTab, jp.KeyO, jp.WheelUp, jp.KeyAt,
jp.KeyLeftCtrl, jp.KeyHome, jp.KeyS, jp.MouseRight, jp.MouseLeft, jp.MouseBack, jp.KeyLeft, jp.KeyDown, jp.KeyUp, jp.KeyRight, jp.KeyEnter, jp.KeyEsc,
jp.KeyLeftShift, jp.KeyF13, jp.KeyF14, jp.MouseMiddle, jp.KeyF16, jp.MouseForward, jp.WheelDown, jp.KeyM, jp.KeyComma, jp.KeyPeriod, jp.KeySlash, jp.KeyBackslash,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeyTo2, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyLeftAlt, jp.KeyPrintscreen, jp.KeyDelete,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeySpace, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyTo2, jp.KeyPrintscreen, jp.KeyDelete,
},
{
jp.KeyTab, jp.Key1, jp.Key2, jp.Key3, jp.Key4, jp.Key5, jp.Key6, jp.Key7, jp.Key8, jp.Key9, jp.Key0, jp.KeyBackspace,
jp.KeyLeftCtrl, jp.KeyMinus, jp.KeyHat, jp.KeyBackslash2, jp.KeyLeftBrace, jp.KeyRightBrace, jp.KeyHome, jp.KeyPageDown, jp.KeyPageUp, jp.KeyEnd, jp.KeyEnter, jp.KeyEsc,
jp.KeyLeftShift, jp.KeyF1, jp.KeyF2, jp.KeyF3, jp.KeyF4, jp.KeyF5, jp.KeyF6, jp.KeyF7, jp.KeyF8, jp.KeyF9, jp.KeyF10, jp.KeyF11,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeyTo0, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyLeftAlt, jp.KeyPrintscreen, jp.KeyF12,
jp.KeyEsc, jp.KeyWindows, jp.KeyLeftAlt, jp.KeyMod1, jp.KeySpace, jp.KeySpace, jp.KeySpace, jp.KeyMod2, jp.KeyHiragana, jp.KeyTo0, jp.KeyPrintscreen, jp.KeyF12,
},
})
sm.SetCallback(func(layer, index int, state keyboard.State) {
layer = d.Layer()
fmt.Printf("sm: %d %d %d\n", layer, index, state)
led1.Set(layer != 0)
led2.Set(layer == 0)
led3.Set(layer == 0)
callback(layer)
})

// override ctrl-h to BackSpace
Expand Down
29 changes: 29 additions & 0 deletions targets/sg48key/xiao-rp2040.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build xiao_rp2040

package main

import (
"machine"
)

var (
led1 = machine.LED_RED
led2 = machine.LED_GREEN
led3 = machine.LED_BLUE
)

func init() {
led1.Configure(machine.PinConfig{Mode: machine.PinOutput})
led2.Configure(machine.PinConfig{Mode: machine.PinOutput})
led3.Configure(machine.PinConfig{Mode: machine.PinOutput})

led1.Low()
led2.Low()
led3.High()
}

func callback(layer int) {
led1.Set(layer != 0)
led2.Set(layer != 0)
led3.Set(layer == 0)
}
25 changes: 25 additions & 0 deletions targets/sg48key/xiao.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build xiao

package main

import (
"machine"
)

var (
led1 = machine.LED
led2 = machine.LED2
led3 = machine.LED3
)

func init() {
led1.Configure(machine.PinConfig{Mode: machine.PinOutput})
led2.Configure(machine.PinConfig{Mode: machine.PinOutput})
led3.Configure(machine.PinConfig{Mode: machine.PinOutput})
}

func callback(layer int) {
led1.Set(layer != 0)
led2.Set(layer == 0)
led3.Set(layer == 0)
}

0 comments on commit 5ebf6db

Please sign in to comment.