Skip to content
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

Macropad pio #51

Merged
merged 2 commits into from
Nov 19, 2024
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
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ require (
tinygo.org/x/tinyfont v0.3.0
)

require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/tinygo-org/pio v0.0.0-20240901140349-27cbe9d986eb // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/itchio/lzma v0.0.0-20190703113020-d3e24e3e3d49/go.mod h1:avNrevQMli1p
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/tinygo-org/pio v0.0.0-20240901140349-27cbe9d986eb h1:LRIJwOxeTwo8ELCXWzRe6jaO82Hl386Cd9KhOonoCHw=
github.com/tinygo-org/pio v0.0.0-20240901140349-27cbe9d986eb/go.mod h1:LU7Dw00NJ+N86QkeTGjMLNkYcEYMor6wTDpTCu0EaH8=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
Expand Down
38 changes: 28 additions & 10 deletions targets/macropad-rp2040/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

keyboard "github.com/sago35/tinygo-keyboard"
"github.com/sago35/tinygo-keyboard/keycodes/jp"
pio "github.com/tinygo-org/pio/rp2-pio"
"github.com/tinygo-org/pio/rp2-pio/piolib"
"tinygo.org/x/drivers/sh1106"
"tinygo.org/x/drivers/ws2812"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freemono"
)
Expand All @@ -31,6 +32,18 @@ var (
black = color.RGBA{0x00, 0x00, 0x00, 0xFF}
)

const (
rawWhite = 0x3F3F3FFF
rawRed = 0x00FF00FF
rawGreen = 0xFF0000FF
rawBlue = 0x0000FFFF
rawBlack = 0x000000FF
)

func writeColors(s pio.StateMachine, ws *piolib.WS2812B, colors []uint32) {
ws.WriteRaw(colors)
}

func run() error {
machine.SPI1.Configure(machine.SPIConfig{
Frequency: 48000000,
Expand All @@ -42,13 +55,18 @@ func run() error {
})
display.ClearDisplay()

neo := machine.WS2812
neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
ws := ws2812.New(neo)
wsLeds := [12]color.RGBA{}
wsPin := machine.WS2812
s, _ := pio.PIO0.ClaimStateMachine()
ws, _ := piolib.NewWS2812B(s, wsPin)
err := ws.EnableDMA(true)
if err != nil {
return err
}
wsLeds := [12]uint32{}
for i := range wsLeds {
wsLeds[i] = black
wsLeds[i] = rawBlack
}
writeColors(s, ws, wsLeds[:])

d := keyboard.New()

Expand Down Expand Up @@ -92,9 +110,9 @@ func run() error {
col := index % 3
fmt.Printf("gk: %d %d %d %d %d\n", layer, index, row, col, state)
c := white
wsLeds[index] = white
wsLeds[index] = rawWhite
if state == keyboard.PressToRelease {
wsLeds[index] = black
wsLeds[index] = rawBlack
c = black
}
display.ClearBuffer()
Expand All @@ -114,7 +132,7 @@ func run() error {
// for Vial
loadKeyboardDef()

err := d.Init()
err = d.Init()
if err != nil {
return err
}
Expand All @@ -139,7 +157,7 @@ func run() error {
if err != nil {
return err
}
ws.WriteColors(wsLeds[:])
writeColors(s, ws, wsLeds[:])
time.Sleep(1 * time.Millisecond)
}

Expand Down