Skip to content

Commit

Permalink
targets: handle feedback items from TKey device code review
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 14, 2024
1 parent b06c097 commit 20213d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
18 changes: 10 additions & 8 deletions src/machine/machine_tkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,22 @@ func (p Pin) Get() bool {
}
case GPIO1:
mode = gpio1Config.Mode
if tkey.TK1.GPIO.HasBits(1 << uint(p-8)) {
pushed = true
}
pushed = tkey.TK1.GPIO.HasBits(1 << uint(p-8))
case GPIO2:
mode = gpio2Config.Mode
if tkey.TK1.GPIO.HasBits(1 << uint(p-8)) {
pushed = true
}
pushed = tkey.TK1.GPIO.HasBits(1 << uint(p-8))
case GPIO3, GPIO4:
mode = PinOutput
pushed = tkey.TK1.GPIO.HasBits(1 << uint(p-8))
case LED_BLUE, LED_GREEN, LED_RED:
mode = PinOutput
pushed = tkey.TK1.LED.HasBits(1 << uint(p))
}

switch mode {
case PinInputPullup:
return !pushed
case PinInput, PinInputPulldown:
case PinInput, PinInputPulldown, PinOutput:
return pushed
}

Expand All @@ -116,7 +118,7 @@ var (

// The TKey UART is fixed at 62500 baud, 8N1.
func (uart *UART) Configure(config UARTConfig) error {
if config.BaudRate != 62500 {
if !(config.BaudRate == 62500 || config.BaudRate == 0) {
return errors.New("uart: only 62500 baud rate is supported")
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/runtime_tkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
func initPeripherals() {
// prescaler value that results in 0.00001-second timer-ticks.
// given an 18 MHz processor, a millisecond is about 18,000 cycles.
tkey.TIMER.PRESCALER.Set(18_000_000 / 100000)
tkey.TIMER.PRESCALER.Set(18 * machine.MHz / 100000)

machine.InitSerial()
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/runtime_tkey_baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package runtime

import "device/riscv"

// ticksToNanoseconds converts ticks (at 18MHz) to nanoseconds.
// ticksToNanoseconds converts ticks (at 18MHz) to 10 µs.
func ticksToNanoseconds(ticks timeUnit) int64 {
return int64(ticks) * 10000
}

// nanosecondsToTicks converts nanoseconds to ticks (at 18MHz).
// nanosecondsToTicks converts 10 µs to ticks (at 18MHz).
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns / 10000)
}
Expand Down
5 changes: 0 additions & 5 deletions targets/tkey.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
"build-tags": ["tkey"],
"features": "+32bit,+c,+zmmul,-a,-d,-e,-experimental-zacas,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-f,-h,-m,-relax,-smaia,-smepmp,-ssaia,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
"cflags": [
"-mcmodel=medany",
"-march=rv32iczmmul"
],
"linkerscript": "targets/tkey.ld",
"scheduler": "none",
"default-stack-size": 2048,
"gc": "leaking",
"linker": "ld.lld",
"rtlib": "compiler-rt",
"libc": "picolibc",
"flash-command": "tkey-runapp {bin}",
"serial": "uart"
}

0 comments on commit 20213d8

Please sign in to comment.