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:
Ayke van Laethem
2025-02-16 15:11:39 +01:00
committed by Ron Evans
parent ea53ace270
commit 52b9fcd57f
7 changed files with 17 additions and 65 deletions
+1 -13
View File
@@ -3,7 +3,6 @@
package machine
import (
"bytes"
"device/nrf"
"internal/binary"
"runtime/interrupt"
@@ -386,7 +385,7 @@ func (f flashBlockDevice) WriteAt(p []byte, off int64) (n int, err error) {
}
address := FlashDataStart() + uintptr(off)
padded := f.pad(p)
padded := flashPad(p, int(f.WriteBlockSize()))
waitWhileFlashBusy()
@@ -444,17 +443,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...)
}
func waitWhileFlashBusy() {
for nrf.NVMC.GetREADY() != nrf.NVMC_READY_READY_Ready {
}