From b2305a992ba673843accebd525452a69ef14b13a Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sat, 27 Jul 2024 09:53:26 -0400 Subject: [PATCH] vendorer periiph host --- go.mod | 2 +- go.sum | 4 +- vendor/modules.txt | 2 +- vendor/periph.io/x/host/v3/bcm283x/gpio.go | 67 +++++++++++++++++++- vendor/periph.io/x/host/v3/bcm283x/timer.go | 6 +- vendor/periph.io/x/host/v3/distro/devtree.go | 2 + 6 files changed, 76 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index a251d8c..f64da0b 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module go-orange go 1.22 -replace periph.io/x/host/v3 v3.8.2 => github.com/didiercrunch/host/v3 v3.8.2 +replace periph.io/x/host/v3 v3.8.2 => github.com/didiercrunch/host/v3 v3.8.3-0.20240727134510-3ddf0ec6acb8 require ( periph.io/x/conn/v3 v3.7.0 diff --git a/go.sum b/go.sum index b4be859..86f4dd1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/didiercrunch/host/v3 v3.8.2 h1:3FCnaC7Dyf6RKBTwUbS5pDA4k3/XttijMmi4PBQgNh8= -github.com/didiercrunch/host/v3 v3.8.2/go.mod h1:yFL76AesNHR68PboofSWYaQTKmvPXsQH2Apvp/ls/K4= +github.com/didiercrunch/host/v3 v3.8.3-0.20240727134510-3ddf0ec6acb8 h1:Fe73Ns7pPH6rqbDhiKUHEkCwTaasuv8JQAQwEqlq+Es= +github.com/didiercrunch/host/v3 v3.8.3-0.20240727134510-3ddf0ec6acb8/go.mod h1:yFL76AesNHR68PboofSWYaQTKmvPXsQH2Apvp/ls/K4= github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= periph.io/x/conn/v3 v3.7.0 h1:f1EXLn4pkf7AEWwkol2gilCNZ0ElY+bxS4WE2PQXfrA= diff --git a/vendor/modules.txt b/vendor/modules.txt index e94ee20..d99c90f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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.2 +# periph.io/x/host/v3 v3.8.2 => github.com/didiercrunch/host/v3 v3.8.3-0.20240727134510-3ddf0ec6acb8 ## explicit; go 1.20 periph.io/x/host/v3 periph.io/x/host/v3/allwinner diff --git a/vendor/periph.io/x/host/v3/bcm283x/gpio.go b/vendor/periph.io/x/host/v3/bcm283x/gpio.go index dc51c20..b49a3d3 100644 --- a/vendor/periph.io/x/host/v3/bcm283x/gpio.go +++ b/vendor/periph.io/x/host/v3/bcm283x/gpio.go @@ -969,8 +969,12 @@ var cpuPins = []Pin{ {number: 46, name: "GPIO46", defaultPull: gpio.PullUp}, } -// This excludes the functions in and out. -var mapping = [][6]pin.Func{ +// The alternate function mapping tables exclude the functions in and out. +// Mapping may be overridden during driverGPIO.Init(). +var mapping = mapping283x + +// BCM238x specific alternate function mapping (the default). +var mapping283x = [][6]pin.Func{ {"I2C0_SDA"}, // 0 {"I2C0_SCL"}, {"I2C1_SDA"}, @@ -1020,6 +1024,64 @@ var mapping = [][6]pin.Func{ {""}, } +// BCM2711 specific alternate function mapping; mostly compatible to +// mapping283x, with the exception that there is no user-accessible SPI2 +// (the original SPI2-related positions have been assigned +// corresponding SPI0 functions). Also, since there is an additional +// PWM1 device, the original PWM0/PWM1 entries had to be +// renamed into PWM0_0, PWM0_1. +// The table has been generated from BCM2711's specification, +// slightly adjusted to match the original mapping's naming. +var mapping2711 = [][6]pin.Func{ + {"I2C0_SDA", "", "", "SPI3_CS0", "UART2_TX", "I2C6_SDA"}, // 0 + {"I2C0_SCL", "", "", "SPI3_MISO", "UART2_RX", "I2C6_SCL"}, + {"I2C1_SDA", "", "", "SPI3_MOSI", "UART2_CTS", "I2C3_SDA"}, + {"I2C1_SCL", "", "", "SPI3_CLK", "UART2_RTS", "I2C3_SCL"}, + {"CLK0", "", "", "SPI4_CS0", "UART3_TX", "I2C3_SDA"}, + {"CLK1", "", "", "SPI4_MISO", "UART3_RX", "I2C3_SCL"}, // 5 + {"CLK2", "", "", "SPI4_MOSI", "UART3_CTS", "I2C4_SDA"}, + {"SPI0_CS1", "", "", "SPI4_CLK", "UART3_RTS", "I2C4_SCL"}, + {"SPI0_CS0", "", "", "", "UART4_TX", "I2C4_SDA"}, + {"SPI0_MISO", "", "", "", "UART4_RX", "I2C4_SCL"}, + {"SPI0_MOSI", "", "", "", "UART4_CTS", "I2C5_SDA"}, // 10 + {"SPI0_CLK", "", "", "", "UART4_RTS", "I2C5_SCL"}, + {"PWM0_0", "", "", "SPI5_CS0", "UART5_TX", "I2C5_SDA"}, + {"PWM0_1", "", "", "SPI5_MISO", "UART5_RX", "I2C5_SCL"}, + {"UART0_TX", "", "", "SPI5_MOSI", "UART5_CTS", "UART1_TX"}, + {"UART0_RX", "", "", "SPI5_CLK", "UART5_RTS", "UART1_RX"}, // 15 + {"", "", "", "UART0_CTS", "SPI1_CS2", "UART1_CTS"}, + {"", "", "", "UART0_RTS", "SPI1_CS1", "UART1_RTS"}, + {"I2S_SCK", "", "", "SPI6_CS0", "SPI1_CS0", "PWM0_0"}, + {"I2S_WS", "", "", "SPI6_MISO", "SPI1_MISO", "PWM0_1"}, + {"I2S_DIN", "", "", "SPI6_MOSI", "SPI1_MOSI", "CLK0"}, // 20 + {"I2S_DOUT", "", "", "SPI6_CLK", "SPI1_CLK", "CLK1"}, + {"", "", "", "", "", "I2C6_SDA"}, + {"", "", "", "", "", "I2C6_SCL"}, + {"", "", "", "", "", "SPI3_CS1"}, + {"", "", "", "", "", "SPI4_CS1"}, // 25 + {"", "", "", "", "", "SPI5_CS1"}, + {"", "", "", "", "", "SPI6_CS1"}, + {"I2C0_SDA", "", "I2S_SCK", "", "", ""}, + {"I2C0_SCL", "", "I2S_WS", "", "", ""}, + {"", "", "I2S_DIN", "UART0_CTS", "", "UART1_CTS"}, // 30 + {"", "", "I2S_DOUT", "UART0_RTS", "", "UART1_RTS"}, + {"CLK0", "", "", "UART0_TX", "", "UART1_TX"}, + {"", "", "", "UART0_RX", "", "UART1_RX"}, + {"CLK0"}, + {"SPI0_CS1"}, // 35 + {"SPI0_CS0", "", "UART0_TX", "", "", ""}, + {"SPI0_MISO", "", "UART0_RX", "", "", ""}, + {"SPI0_MOSI", "", "UART0_RTS", "", "", ""}, + {"SPI0_CLK", "", "UART0_CTS", "", "", ""}, + {"PWM1_0", "", "", "", "SPI0_MISO", "UART1_TX"}, // 40 + {"PWM1_1", "", "", "", "SPI0_MOSI", "UART1_RX"}, + {"CLK1", "", "", "", "SPI0_CLK", "UART1_RTS"}, + {"CLK2", "", "", "", "SPI0_CS0", "UART1_CTS"}, + {"CLK1", "I2C0_SDA", "I2C1_SDA", "", "SPI0_CS1", ""}, + {"PWM0_1", "I2C0_SCL", "I2C1_SCL", "", "SPI0_CS2", ""}, // 45 + {""}, +} + // function specifies the active functionality of a pin. The alternative // function is GPIO pin dependent. type function uint8 @@ -1305,6 +1367,7 @@ func (d *driverGPIO) Init() (bool, error) { // BCM2711 (and perhaps future versions?) uses a simpler way to // setup internal pull resistors. d.useLegacyPull = false + mapping = mapping2711 } // Page 6. // Virtual addresses in kernel mode will range between 0xC0000000 and diff --git a/vendor/periph.io/x/host/v3/bcm283x/timer.go b/vendor/periph.io/x/host/v3/bcm283x/timer.go index 13a4022..a22cc87 100644 --- a/vendor/periph.io/x/host/v3/bcm283x/timer.go +++ b/vendor/periph.io/x/host/v3/bcm283x/timer.go @@ -5,6 +5,7 @@ package bcm283x import ( + "sync/atomic" "time" "periph.io/x/host/v3/cpu" @@ -17,7 +18,10 @@ func ReadTime() time.Duration { if drvDMA.timerMemory == nil { return 0 } - return (time.Duration(drvDMA.timerMemory.high)<<32 | time.Duration(drvDMA.timerMemory.low)) * time.Microsecond + // Use atomic package to safely access memory + high := atomic.LoadUint32(&drvDMA.timerMemory.high) + low := atomic.LoadUint32(&drvDMA.timerMemory.low) + return (time.Duration(high)<<32 | time.Duration(low)) * time.Microsecond } // Nanospin spins the CPU without calling into the kernel code if possible. diff --git a/vendor/periph.io/x/host/v3/distro/devtree.go b/vendor/periph.io/x/host/v3/distro/devtree.go index 970b4f9..0091714 100644 --- a/vendor/periph.io/x/host/v3/distro/devtree.go +++ b/vendor/periph.io/x/host/v3/distro/devtree.go @@ -6,6 +6,7 @@ package distro import ( "encoding/binary" + "fmt" "os" ) @@ -30,6 +31,7 @@ func DTModel() string { func DTCompatible() []string { mu.Lock() defer mu.Unlock() + fmt.Println("\n\n\n\n\tdidier: Deep in the dependencies...\n\n\n\n\n") if dtCompatible == nil { dtCompatible = []string{}