functioning USB-CDC class initialization

This commit is contained in:
sago35
2022-05-12 20:34:37 +09:00
parent 6e29c17a8b
commit 2f50d24fec
14 changed files with 1499 additions and 509 deletions
+27 -3
View File
@@ -216,12 +216,33 @@ func cycles(microsec, cpuFreqHz uint32) uint32 {
return uint32((uint64(microsec) * uint64(cpuFreqHz)) / 1000000)
}
//go:inline
func endpointValid(address uint8) bool {
return address&descEndpointInvalid == 0
}
//go:inline
func unpackEndpoint(address uint8) (number, direction uint8) {
return (address & descEndptAddrNumberMsk) >> descEndptAddrNumberPos,
(address & descEndptAddrDirectionMsk) >> descEndptAddrDirectionPos
}
//go:inline
func packEndpoint(number, direction uint8) (address uint8) {
return ((number << descEndptAddrNumberPos) & descEndptAddrNumberMsk) |
((direction << descEndptAddrDirectionPos) & descEndptAddrDirectionMsk)
}
//go:inline
func endpointNumber(address uint8) (number uint8) {
return (address & descEndptAddrNumberMsk) >> descEndptAddrNumberPos
}
//go:inline
func endpointDirection(address uint8) (direction uint8) {
return (address & descEndptAddrDirectionMsk) >> descEndptAddrDirectionPos
}
//go:inline
func rxEndpoint(number uint8) uint8 {
return (number & descEndptAddrNumberMsk) | descEndptAddrDirectionOut
@@ -245,20 +266,23 @@ func indexEndpoint(index uint8) uint8 {
}
// wrap computes the index into a circular buffer of length mod by walking
// forward n elements if n is positive, or reverse n elements if n is negative.
// For example, both wrap(42, 10) and wrap(-308, 10) return 2.
// forward n elements if n is positive, or reverse -n elements if n is negative.
// For example, both wrap(12, 10) and wrap(-18, 10) return 2.
//go:inline
func wrap(n, mod int) int {
if mod <= 0 || n == mod {
if mod <= 0 {
// Buffer length (mod) must be positive.
return 0
}
if n < 0 {
if -n < mod {
// Do not wrap around (no underflow).
return mod + n
}
return mod - (-n % mod)
}
if n < mod {
// Do not wrap around (no overflow).
return n
}
return n % mod