mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 05:53:39 +00:00
17302ca762
* initial implementation for Tillitis TKey device * add UART implementation for TKey * add Pin interface implementation for TKey touch sensor * add RNG interface implementation for TKey * add helpful machine package functions to return identifiers such as name and version for TKey * use built-in timer for sleep timing on TKey * modify UART implementation for TKey to implement Serialer interface * implement BLAKE2s ROM function call for TKey device * handle abort by triggering TKey device fault using illegal instruction to halt CPU * simplify TKey implementation by inheriting from existing riscv32 target * return error for trying to configure invalid baudrates on UART * add tkey to builder test * be very specific for features passed to LLVM for specific config in use for TKey * handle feedback items from TKey device code review Signed-off-by: deadprogram <ron@hybridgroup.com>
39 lines
637 B
Go
39 lines
637 B
Go
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey
|
|
|
|
// If you update the above build constraint, you'll probably also need to update
|
|
// src/runtime/rand_hwrng.go.
|
|
|
|
package rand
|
|
|
|
import (
|
|
"machine"
|
|
)
|
|
|
|
func init() {
|
|
Reader = &reader{}
|
|
}
|
|
|
|
type reader struct {
|
|
}
|
|
|
|
func (r *reader) Read(b []byte) (n int, err error) {
|
|
if len(b) == 0 {
|
|
return
|
|
}
|
|
|
|
var randomByte uint32
|
|
for i := range b {
|
|
if i%4 == 0 {
|
|
randomByte, err = machine.GetRNG()
|
|
if err != nil {
|
|
return n, err
|
|
}
|
|
} else {
|
|
randomByte >>= 8
|
|
}
|
|
b[i] = byte(randomByte)
|
|
}
|
|
|
|
return len(b), nil
|
|
}
|