updated dependencies

This commit is contained in:
didier committed 2024-08-03 21:12:40 -04:00
1 parent 2729a727dc
commit fb5f6a0d85
9 files changed
+52 -95

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ periph.io/x/conn/v3/pin
periph.io/x/conn/v3/pin/pinreg
periph.io/x/conn/v3/spi
periph.io/x/conn/v3/spi/spireg
# periph.io/x/host/v3 v3.8.2 => github.com/didiercrunch/host/v3 v3.8.3-0.20240731020403-7fe82b3432d5
# periph.io/x/host/v3 v3.8.2 => github.com/didiercrunch/host/v3 v3.8.3-0.20240804011140-a6ce90fa3ccf
## explicit; go 1.20
periph.io/x/host/v3
periph.io/x/host/v3/allwinner
-4
View File
@@ -5,7 +5,6 @@
package allwinner
import (
"fmt"
"strings"
"sync"
@@ -42,7 +41,6 @@ func IsA20() bool {
// It looks for the string "sun50iw1p1" in /proc/device-tree/compatible.
func IsA64() bool {
detection.do()
fmt.Printf("IsA64? %t\n", detection.isA64)
return detection.isA64
}
@@ -98,7 +96,6 @@ func (d *detectionS) do() {
d.done = true
if isArm {
for _, c := range distro.DTCompatible() {
fmt.Println("distro >>> " + c)
if strings.Contains(c, "sun50iw1p1") {
d.isA64 = true
}
@@ -117,7 +114,6 @@ func (d *detectionS) do() {
d.isH5 = true
}
if strings.Contains(c, "sun50i-h6") {
fmt.Println("isH6 detected")
d.isH6 = true
}
}
+7 -46
View File
@@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"os"
"path"
"strconv"
"strings"
"time"
@@ -309,10 +308,8 @@ func (p *Pin) Read() gpio.Level {
//
// This function is very fast.
func (p *Pin) FastRead() gpio.Level {
foo := drvGPIO.gpioMemory.groups[p.group].data
fmt.Printf("Group value is: %d", foo)
return gpio.Level(foo&(1<<p.offset) != 0)
status := drvGPIO.gpioMemory.groups[p.group].data
return status&(1<<p.offset) != 0
}
// WaitForEdge implements gpio.PinIn.
@@ -483,17 +480,9 @@ func (p *Pin) setFunction(f function) {
mask := uint32(disabled) << shift
v := (uint32(f) << shift) ^ mask
// First disable, then setup. This is concurrent safe.
original := drvGPIO.gpioMemory.groups[p.group].cfg[off]
drvGPIO.gpioMemory.groups[p.group].cfg[off] |= mask
drvGPIO.gpioMemory.groups[p.group].cfg[off] &^= v
modified := original | mask
modified &^= v
fmt.Printf("Original: %d\n", original)
fmt.Printf("Modified: %d\n", modified)
fmt.Printf("Memory mapped value: %d\n", drvGPIO.gpioMemory.groups[p.group].cfg[off])
if p.function() != f {
fmt.Printf("Pin number %d. Pin name %s.\n Expected %d to equals %d \n", p.Number(), p.Name(), p.function(), f)
panic(f)
}
}
@@ -1018,7 +1007,6 @@ func (d *driverGPIO) Init() (bool, error) {
// Mark the right pins as available even if the memory map fails so they can
// callback to sysfs.Pins.
fmt.Println("Didier initiating allwinner gpio")
switch {
case IsA64():
if err := mapA64Pins(); err != nil {
@@ -1041,18 +1029,19 @@ func (d *driverGPIO) Init() (bool, error) {
return true, err
}
case IsH6():
fmt.Println("Is H6 CPU!!!")
if err := mapH6Pins(); err != nil {
return true, err
}
default:
fmt.Println("error: unknown Allwinner CPU model")
return false, errors.New("unknown Allwinner CPU model")
}
// gpioBaseAddr is the physical base address of the GPIO registers.
gpioBaseAddr := uint32(getBaseAddressDidier())
if err := pmem.MapAsPOD(uint64(gpioBaseAddr), &d.gpioMemory); err != nil {
gpioBaseAddr, err := getBaseAddress()
if err != nil {
return true, err
}
if err := pmem.MapAsPOD(gpioBaseAddr, &d.gpioMemory); err != nil {
if os.IsPermission(err) {
return true, fmt.Errorf("need more access, try as root: %v", err)
}
@@ -1064,38 +1053,10 @@ func (d *driverGPIO) Init() (bool, error) {
func init() {
if isArm {
fmt.Println("Stating to initiate allwinner")
driverreg.MustRegister(&drvGPIO)
}
}
// getBaseAddress queries the virtual file system to retrieve the base address
// of the GPIO registers for GPIO pins in groups PA to PI.
//
// Defaults to 0x01C20800 as per datasheet if it could not query the file
// system.
func getBaseAddress() uint64 {
base := uint64(0x01C20800)
link, err := os.Readlink("/sys/bus/platform/drivers/sun50i-pinctrl/driver")
if err != nil {
return base
}
parts := strings.SplitN(path.Base(link), ".", 2)
if len(parts) != 2 {
return base
}
base2, err := strconv.ParseUint(parts[0], 16, 64)
if err != nil {
return base
}
return base2
}
func getBaseAddressDidier() uint64 {
fmt.Println("OK did is insane shit.")
return uint64(0x300b000)
}
var drvGPIO driverGPIO
// Ensure that the various structs implement the interfaces they're supposed to.
+41 -28
View File
@@ -8,14 +8,14 @@
package allwinner
import (
"fmt"
"strings"
_ "embed"
"encoding/json"
"periph.io/x/conn/v3/pin"
"periph.io/x/host/v3/sysfs"
"strings"
)
// mappingH6 describes the mapping of the H5 processor gpios to their
// mappingH6 describes the mapping of the H6 processor gpios to their
// alternate functions.
// According to https://linux-sunxi.org/H616 H616 and H618 are the same.
// allwinner marketing team seems to disagree.
@@ -31,25 +31,36 @@ import (
// - SDC means SDCard?
// - NAND connects to a NAND flash controller.
// - CSI and CCI are for video capture.
var mappingH6 = map[string][5]pin.Func{
"PC0": {"NAND_WE", "SDC2_DS", "SPI0_CLK", "", "PA_EINT0"},
"PC1": {"NAND_ALE", "SDC2_RST", "", "", "PA_EINT1"},
"PC2": {"NAND_CLE", "", "SPI0_MOSI", "", "PA_EINT2"},
"PC3": {"NAND_CE1", "", "SPI0_CS0", "BOOT_SEL1", "PA_EINT3"},
"PC4": {"NAND_CE0", "", "SPI0_MIS0", "BOOT_SEL2", "PA_EINT4"},
"PC5": {"NAND_RE", "SDC2_CLK", "", "BOOT_SEL3", "PA_EINT5"},
"PC6": {"NAND_RB0", "SDC2_CMD", "", "BOOT_SEL4", "PA_EINT6"},
"PC7": {"NAND_RB1", "", "SPI0_CS1", "", "PA_EINT7"},
"PC8": {"NAND_DQ7", "SDC2_D3", "", "", "PA_EINT8"},
//
// The data itself has been extracted from the pdf using
// https://ronnywang.github.io/pdf-table-extractor/ and some
// scripting. The data has been validated manually.
//
//go:embed H6_pins.json
var h6PinsSpec []byte
"PC9": {"NAND_DQ6", "SDC2_D4", "", "", "PA_EINT9"},
"PC10": {"NAND_DQ5", "SDC2_D0", "", "", "PA_EINT10"},
"PC11": {"NAND_DQ4", "SDC2_D5", "", "", "PA_EINT11"},
"PC12": {"NAND_DQS", "", "", "", "PA_EINT12"},
"PC13": {"NAND_DQ3", "SDC2_D1", "", "", "PA_EINT13"},
"PC14": {"NAND_DQ2", "SDC2_D6", "", "", "PA_EINT14"},
"PC15": {"NAND_DQ1", "SDC2_D1", "SPI0_WP", "", "PA_EINT15"},
"PC16": {"NAND_DQ0", "SDC2_D7", "SPI0_HOLD", "", "PA_EINT16"},
type serializedPinSpec struct {
Name string
Function2 pin.Func
Function3 pin.Func
Function4 pin.Func
Function5 pin.Func
Function6 pin.Func
}
func getH6SerializedPinSpecs() ([]serializedPinSpec, error) {
var serializedPins []serializedPinSpec
err := json.Unmarshal(h6PinsSpec, &serializedPins)
return serializedPins, err
}
func getAltFunc(pinSpec serializedPinSpec) [5]pin.Func {
return [5]pin.Func{
pinSpec.Function2,
pinSpec.Function3,
pinSpec.Function4,
pinSpec.Function5,
pinSpec.Function6}
}
// mapH6Pins uses mappingH6 to actually set the altFunc fields of all gpio
@@ -57,15 +68,17 @@ var mappingH6 = map[string][5]pin.Func{
//
// It is called by the generic allwinner processor code if an H6 is detected.
func mapH6Pins() error {
fmt.Println("Initializing H6 pins.")
for name, altFuncs := range mappingH6 {
pin := cpupins[name]
pin.altFunc = altFuncs
serializedPinSpecs, err := getH6SerializedPinSpecs()
if err != nil {
return err
}
for _, pinSpec := range serializedPinSpecs {
pin := cpupins[pinSpec.Name]
pin.altFunc = getAltFunc(pinSpec)
pin.available = true
if strings.Contains(string(altFuncs[4]), "_EINT") {
if strings.Contains(string(pinSpec.Function6), "_EINT") {
pin.supportEdge = true
}
// Initializes the sysfs corresponding pin right away.
pin.sysfsPin = sysfs.Pins[pin.Number()]
}
-2
View File
@@ -6,7 +6,6 @@ package distro
import (
"encoding/binary"
"fmt"
"os"
)
@@ -31,7 +30,6 @@ func DTModel() string {
func DTCompatible() []string {
mu.Lock()
defer mu.Unlock()
fmt.Println("\n\n\n\n\tdidier: Deep in the dependencies...")
if dtCompatible == nil {
dtCompatible = []string{}
-7
View File
@@ -60,13 +60,6 @@ func IsRaspbian() bool {
return false
}
// IsNixos returns true if running on a NixOs distribution.
//
// https://nixos.org/
func IsNixos() bool {
return isLinux && OSRelease()["ID"] == "nixos"
}
// IsUbuntu returns true if running on an Ubuntu derived distribution.
//
// https://ubuntu.com/