I received a new RISC-V-based board from Milk-V and started using this library to work with GPIO: https://github.com/warthog618/gpiod. Apparently, the naming scheme in Duo is different from those used in RPi and Banana Pi for which the pin mappings are provided.
I created this tiny module to support Milk-V Duo mappings.
It’s not required to be part of the gpiod
module so it can be imported separately.
See the example below.
In this board there are 5 GPIO chips (gpiochip0
to gpiochip4
).
The pins are named like GPIOA14
, GPIOC9
, or PWR_GPIO21
and they are served by different chips.
In this case the names above would be translated to gpiochip0
+ offset 14, gpiochip2
+ offset 9,
and gpiochip4
+ offset 21 respectively.
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
milkvduo "github.com/pavelanni/gpiod-milkvduo"
"github.com/warthog618/gpiod"
)
func main() {
pin := "PWR_GPIO21" // this could be "GPIOA14" or "GPIOC9"
lineId, err := milkvduo.PinLineID(pin)
if err != nil {
log.Fatal(err)
}
l, err := gpiod.RequestLine(lineId.Chip, lineId.Offset, gpiod.AsOutput())
if err != nil {
log.Fatal(err)
}
// The rest is the same: you set the line's value, etc.
}
Here is the official Milk-V Duo documentation: https://milkv.io/docs/duo/overview
More information and guides are available here: https://spotpear.com/index/product/detail/id/1296.html (check the RESOURCES tab for the guides)
This repo contains datasheets and other info for the CPU/TPU used in Duo: https://github.com/sophgocommunity/Duo_Doc/tree/main