mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 23:13:40 +00:00
functioning USB-CDC class initialization
This commit is contained in:
+27
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user