aboutsummaryrefslogtreecommitdiff
path: root/fpga/src/Numini.bs
blob: 39990fcbceda596b63fb35fe69bcbde5dc7a1c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- | The main board, set up to be wired to either the Inkplate's top-level or
-- the simulator's. This insulates us from Bluesim's lack of Inout support.
package Numini where

import Clocks
import Connectable
import HyperBus
import Uart

-- | The output pins.
interface NuminiOut =
  ch559_uart_tx :: Bit 1
  inkplate_uart_tx :: Bit 1
  usb_uart_tx :: Bit 1

  led_r_n :: Bit 1
  led_g_n :: Bit 1

  rgb_r_n :: Bit 1
  rgb_g_n :: Bit 1
  rgb_b_n :: Bit 1

  hyperbus_ck       :: Bit 1
  hyperbus_ck_n     :: Bit 1
  hyperbus_cs0_n    :: Bit 1
  hyperbus_cs1_n    :: Bit 1
  hyperbus_cs2_n    :: Bit 1
  hyperbus_cs3_n    :: Bit 1
  hyperbus_reset_n  :: Bit 1
  hyperbus_rwds_out :: Maybe (Bit 1)
  hyperbus_dq_out   :: Maybe (Bit 8)

  i2c_scl :: Bit 1
  i2c_sda_out :: Maybe (Bit 1)

clockFreqHz :: Integer
clockFreqHz = 12_000_000

mkNumini :: Wire (Bit 1) -> Wire (Bit 1) -> Wire (Bit 1) -> Wire (Bit 1) ->
  Wire (Bit 8) -> Wire (Bit 1) -> Module NuminiOut
mkNumini ch559_uart_rx inkplate_uart_rx usb_uart_rx hyperbus_rwds_in
         hyperbus_dq_in i2c_sda_in = module
  {-
  -- Make derived clocks and resets.
  clk9600 <- mkClockDivider (clockFreqHz / 9600)
  clk2M <- mkClockDivider (clockFreqHz / 2_000_000)
  clk3M <- mkClockDivider (clockFreqHz / 3_000_000)
  reset9600 <- mkReset (clockFreqHz / 9600) True clk9600.slowClock
  reset2M <- mkReset (clockFreqHz / 2_000_000) True clk2M.slowClock
  reset3M <- mkReset (clockFreqHz / 3_000_000) True clk3M.slowClock

  -- Make the peripherals.
  ch559_uart <- changeSpecialWires (Just clk9600.slowClock)
    (Just reset9600.new_rst) Nothing (mkUart ch559_uart_rx)
  inkplate_uart <- changeSpecialWires (Just clk2M.slowClock)
    (Just reset2M.new_rst) Nothing (mkUart inkplate_uart_rx)
  usb_uart <- changeSpecialWires (Just clk9600.slowClock)
    (Just reset9600.new_rst) Nothing (mkUart usb_uart_rx)
  hyperbus <- changeSpecialWires (Just clk3M.slowClock)
    (Just reset3M.new_rst) Nothing (mkHyperBus hyperbus_rwds_in hyperbus_dq_in)
  -}
  ch559_uart <- (mkUart ch559_uart_rx)
  inkplate_uart <- (mkUart inkplate_uart_rx)
  usb_uart <- (mkUart usb_uart_rx)
  hyperbus <- (mkHyperBus hyperbus_rwds_in hyperbus_dq_in)

  mkConnection usb_uart.send usb_uart.recv

  interface NuminiOut
    ch559_uart_tx = ch559_uart.tx
    inkplate_uart_tx = inkplate_uart.tx
    usb_uart_tx = usb_uart.tx

    led_r_n = 1
    led_g_n = 1

    rgb_r_n = 1
    rgb_g_n = 1
    rgb_b_n = 1

    hyperbus_ck = hyperbus.ck
    hyperbus_ck_n = hyperbus.ck_n
    hyperbus_cs0_n = hyperbus.cs0_n
    hyperbus_cs1_n = hyperbus.cs1_n
    hyperbus_cs2_n = hyperbus.cs2_n
    hyperbus_cs3_n = hyperbus.cs3_n
    hyperbus_reset_n = hyperbus.reset_n
    hyperbus_rwds_out = hyperbus.rwds_out
    hyperbus_dq_out = hyperbus.dq_out

    i2c_scl = 1
    i2c_sda_out = Nothing

-- vim: set ft=haskell :