mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
p1am: documentation and example program
This commit is contained in:
@@ -95,6 +95,8 @@ smoke-test:
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
|
||||
|
||||
@@ -93,6 +93,7 @@ The following 58 devices are supported.
|
||||
| [Microphone - PDM](https://cdn-learn.adafruit.com/assets/assets/000/049/977/original/MP34DT01-M.pdf) | I2S/PDM |
|
||||
| [MMA8653 accelerometer](https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf) | I2C |
|
||||
| [MPU6050 accelerometer/gyroscope](https://store.invensense.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf) | I2C |
|
||||
| [P1AM-100 Base Controller](https://facts-engineering.github.io/modules/P1AM-100/P1AM-100.html) | SPI |
|
||||
| [PCD8544 display](http://eia.udg.edu/~forest/PCD8544_1.pdf) | SPI |
|
||||
| [Resistive Touchscreen (4-wire)](http://ww1.microchip.com/downloads/en/Appnotes/doc8091.pdf) | GPIO |
|
||||
| [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/p1am"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for {
|
||||
if err := loop(); err != nil {
|
||||
fmt.Printf("loop failed, retrying: %v\n", err)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
func loop() error {
|
||||
led := machine.LED
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
sw := machine.SWITCH
|
||||
sw.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
|
||||
if err := p1am.Controller.Initialize(); err != nil {
|
||||
return fmt.Errorf("initializing controller: %w", err)
|
||||
}
|
||||
|
||||
version, err := p1am.Controller.Version()
|
||||
if err != nil {
|
||||
return fmt.Errorf("fetching base controller version: %w", err)
|
||||
}
|
||||
fmt.Printf("Base controller version: %d.%d.%d\n", version[0], version[1], version[2])
|
||||
|
||||
for i := 1; i <= p1am.Controller.Slots; i++ {
|
||||
slot := p1am.Controller.Slot(i)
|
||||
fmt.Printf("Slot %d: ID 0x%08x, Props %+v\n", i, slot.ID, slot.Props)
|
||||
}
|
||||
|
||||
slot1 := p1am.Controller.Slot(1)
|
||||
var lastInput uint32
|
||||
state := sw.Get()
|
||||
for {
|
||||
if active, err := p1am.Controller.Active(); err != nil || !active {
|
||||
return fmt.Errorf("controller active %v: %v", active, err)
|
||||
}
|
||||
if state != sw.Get() {
|
||||
state = sw.Get()
|
||||
fmt.Printf("New switch state: %v\n", state)
|
||||
if slot1.Props.DO > 0 {
|
||||
if err := slot1.Channel(1).WriteDiscrete(state); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if slot1.Props.DI > 0 {
|
||||
sstate, err := slot1.ReadDiscrete()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading slot: %w", err)
|
||||
}
|
||||
if sstate != lastInput {
|
||||
lastInput = sstate
|
||||
fmt.Printf("new DI state: %#b\n", sstate)
|
||||
}
|
||||
}
|
||||
if state {
|
||||
led.High()
|
||||
} else {
|
||||
led.Low()
|
||||
}
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user