mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
machine: remove bytes package dependency in flash code
This also moves flash padding code to a single place, since it was copied 5 times. This change is necessary in Go 1.24 to avoid an import cycle.
This commit is contained in:
committed by
Ron Evans
parent
ea53ace270
commit
52b9fcd57f
@@ -5,7 +5,6 @@ package machine
|
||||
import (
|
||||
"device/stm32"
|
||||
|
||||
"bytes"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -41,7 +40,8 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
|
||||
unlockFlash()
|
||||
defer lockFlash()
|
||||
|
||||
return writeFlashData(FlashDataStart()+uintptr(off), f.pad(p))
|
||||
p = flashPad(p, int(f.WriteBlockSize()))
|
||||
return writeFlashData(FlashDataStart()+uintptr(off), p)
|
||||
}
|
||||
|
||||
// Size returns the number of bytes in this block device.
|
||||
@@ -90,17 +90,6 @@ func (f flashBlockDevice) EraseBlocks(start, len int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pad data if needed so it is long enough for correct byte alignment on writes.
|
||||
func (f flashBlockDevice) pad(p []byte) []byte {
|
||||
overflow := int64(len(p)) % f.WriteBlockSize()
|
||||
if overflow == 0 {
|
||||
return p
|
||||
}
|
||||
|
||||
padding := bytes.Repeat([]byte{0xff}, int(f.WriteBlockSize()-overflow))
|
||||
return append(p, padding...)
|
||||
}
|
||||
|
||||
const memoryStart = 0x08000000
|
||||
|
||||
func unlockFlash() {
|
||||
|
||||
Reference in New Issue
Block a user