tinygo/src/machine/machine_nrf52840_usb_reset_bossa.go
Ayke van Laethem 77ec9b6369 all: update build constraints to Go 1.17
Do it all at once in preparation for Go 1.18 support.

To make this commit, I've simply modified the `fmt-check` Makefile
target to rewrite files instead of listing the differences. So this is a
fully mechanical change, it should not have introduced any errors.
2022-02-04 07:49:46 +01:00

27 строки
740 Б
Go

//go:build nrf52840 && nrf52840_reset_bossa
// +build nrf52840,nrf52840_reset_bossa
package machine
import (
"device/arm"
"device/nrf"
)
const DFU_MAGIC_SERIAL_ONLY_RESET = 0xb0
// checkShouldReset is called by the USB-CDC implementation to check whether to
// reset into the bootloader/OTA and if so, resets the chip appropriately.
func checkShouldReset() {
if usbLineInfo.dwDTERate == 1200 && usbLineInfo.lineState&usb_CDC_LINESTATE_DTR == 0 {
EnterSerialBootloader()
}
}
// EnterSerialBootloader resets the chip into the serial bootloader. After
// reset, it can be flashed using serial/nrfutil.
func EnterSerialBootloader() {
arm.DisableInterrupts()
nrf.POWER.GPREGRET.Set(DFU_MAGIC_SERIAL_ONLY_RESET)
arm.SystemReset()
}