diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/internal/binary/binary.go | 32 | ||||
-rw-r--r-- | src/machine/machine_atsamd21.go | 2 | ||||
-rw-r--r-- | src/machine/machine_atsamd51.go | 2 | ||||
-rw-r--r-- | src/machine/machine_nrf.go | 2 | ||||
-rw-r--r-- | src/machine/machine_stm32f4.go | 2 | ||||
-rw-r--r-- | src/machine/machine_stm32l4.go | 2 | ||||
-rw-r--r-- | src/machine/machine_stm32wlx.go | 2 | ||||
-rw-r--r-- | src/machine/usb/descriptor/configuration.go | 2 | ||||
-rw-r--r-- | src/machine/usb/descriptor/device.go | 2 | ||||
-rw-r--r-- | src/machine/usb/descriptor/endpoint.go | 2 | ||||
-rw-r--r-- | src/machine/usb/descriptor/hid.go | 2 |
11 files changed, 42 insertions, 10 deletions
diff --git a/src/internal/binary/binary.go b/src/internal/binary/binary.go new file mode 100644 index 000000000..f3dbf6e9b --- /dev/null +++ b/src/internal/binary/binary.go @@ -0,0 +1,32 @@ +// Package binary is a lightweight replacement package for encoding/binary. +package binary + +// This file contains small helper functions for working with binary data. + +var LittleEndian = littleEndian{} + +type littleEndian struct{} + +// Encode data like encoding/binary.LittleEndian.Uint16. +func (littleEndian) Uint16(b []byte) uint16 { + return uint16(b[0]) | uint16(b[1])<<8 +} + +// Store data like binary.LittleEndian.PutUint16. +func (littleEndian) PutUint16(b []byte, v uint16) { + b[0] = byte(v) + b[1] = byte(v >> 8) +} + +// Append data like binary.LittleEndian.AppendUint16. +func (littleEndian) AppendUint16(b []byte, v uint16) []byte { + return append(b, + byte(v), + byte(v>>8), + ) +} + +// Encode data like encoding/binary.LittleEndian.Uint32. +func (littleEndian) Uint32(b []byte) uint32 { + return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 +} diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 755bedf9a..fe67f45a3 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -10,8 +10,8 @@ import ( "bytes" "device/arm" "device/sam" - "encoding/binary" "errors" + "internal/binary" "runtime/interrupt" "unsafe" ) diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index fdc368a63..bcaaec721 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -10,8 +10,8 @@ import ( "bytes" "device/arm" "device/sam" - "encoding/binary" "errors" + "internal/binary" "runtime/interrupt" "unsafe" ) diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index 99c49d3ca..945700711 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -5,7 +5,7 @@ package machine import ( "bytes" "device/nrf" - "encoding/binary" + "internal/binary" "runtime/interrupt" "unsafe" ) diff --git a/src/machine/machine_stm32f4.go b/src/machine/machine_stm32f4.go index 42193a739..41e1b2204 100644 --- a/src/machine/machine_stm32f4.go +++ b/src/machine/machine_stm32f4.go @@ -6,8 +6,8 @@ package machine import ( "device/stm32" - "encoding/binary" "errors" + "internal/binary" "math/bits" "runtime/interrupt" "runtime/volatile" diff --git a/src/machine/machine_stm32l4.go b/src/machine/machine_stm32l4.go index 856320911..4eb3588f7 100644 --- a/src/machine/machine_stm32l4.go +++ b/src/machine/machine_stm32l4.go @@ -4,8 +4,8 @@ package machine import ( "device/stm32" - "encoding/binary" "errors" + "internal/binary" "runtime/interrupt" "runtime/volatile" "unsafe" diff --git a/src/machine/machine_stm32wlx.go b/src/machine/machine_stm32wlx.go index b27c779fe..84e302a10 100644 --- a/src/machine/machine_stm32wlx.go +++ b/src/machine/machine_stm32wlx.go @@ -6,8 +6,8 @@ package machine import ( "device/stm32" - "encoding/binary" "errors" + "internal/binary" "math/bits" "runtime/interrupt" "runtime/volatile" diff --git a/src/machine/usb/descriptor/configuration.go b/src/machine/usb/descriptor/configuration.go index d9446e673..efb9ab1d2 100644 --- a/src/machine/usb/descriptor/configuration.go +++ b/src/machine/usb/descriptor/configuration.go @@ -1,7 +1,7 @@ package descriptor import ( - "encoding/binary" + "internal/binary" ) const ( diff --git a/src/machine/usb/descriptor/device.go b/src/machine/usb/descriptor/device.go index 48229fbfd..0c3ee92f9 100644 --- a/src/machine/usb/descriptor/device.go +++ b/src/machine/usb/descriptor/device.go @@ -1,7 +1,7 @@ package descriptor import ( - "encoding/binary" + "internal/binary" ) const ( diff --git a/src/machine/usb/descriptor/endpoint.go b/src/machine/usb/descriptor/endpoint.go index affaffa0a..c7fa011fa 100644 --- a/src/machine/usb/descriptor/endpoint.go +++ b/src/machine/usb/descriptor/endpoint.go @@ -1,7 +1,7 @@ package descriptor import ( - "encoding/binary" + "internal/binary" ) var endpointEP1IN = [endpointTypeLen]byte{ diff --git a/src/machine/usb/descriptor/hid.go b/src/machine/usb/descriptor/hid.go index cdd4fc7e5..d8f86a41e 100644 --- a/src/machine/usb/descriptor/hid.go +++ b/src/machine/usb/descriptor/hid.go @@ -2,8 +2,8 @@ package descriptor import ( "bytes" - "encoding/binary" "errors" + "internal/binary" ) var configurationCDCHID = [configurationTypeLen]byte{ |