Skip to content

Instantly share code, notes, and snippets.

@ThePerfectComputer
Created March 7, 2023 04:16
Show Gist options
  • Save ThePerfectComputer/7c256ff9e980aae3f7a35f4c63dff998 to your computer and use it in GitHub Desktop.
Save ThePerfectComputer/7c256ff9e980aae3f7a35f4c63dff998 to your computer and use it in GitHub Desktop.
Some notes from Clash Haskell
module Blinky(topEntity, main) where
import qualified Data.List as List
import Clash.Prelude
counter :: HiddenClockResetEnable dom => Signal dom (Signed 8)
counter = c
where c = register 0 (c + 1)
pulseHighEveryNTicks :: forall n dom. HiddenClockResetEnable dom
=> 1 <= n
=> SNat n
-> Signal dom (BitVector 1)
pulseHighEveryNTicks SNat =
let cntr = register (0 :: Index n) $ satSucc SatWrap <$> cntr
in register 0 $ pack <$> (cntr .==. 0)
blinky :: HiddenClockResetEnable dom => Signal dom (BitVector 8)
blinky = snd <$> blinky_state
where
blinky_state = register (0, 0) (update <$> blinky_state)
-- test_newl = register 0 (Internal.head# slow_pulse)
update (slow_counter :: Signed 4,
led :: BitVector 8)
= (slow_counter', led')
where
slow_counter' = slow_counter + 1
led' = case slow_counter of
0 -> toggle led
_ -> led
slow_pulse :: HiddenClockResetEnable dom => Signal dom (BitVector 1)
slow_pulse = pulseHighEveryNTicks (SNat @6_000_000)
toggle led = case led of
0 -> 1
1 -> 0
_ -> led
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment