spi: SPIParamsBase param needs to be public
[sifive-blocks.git] / src / main / scala / devices / pinctrl / PinCtrl.scala
1 //See LICENSE for license details
2
3 package sifive.blocks.devices.pinctrl
4
5 import Chisel._
6
7 // This is the base class of things you "always"
8 // want to control from a HW block.
9 class PinCtrl extends Bundle {
10 val oval = Bool()
11 val oe = Bool()
12 val ie = Bool()
13 }
14
15 // Package up the inputs and outputs
16 // for the Pin
17 abstract class Pin extends Bundle {
18 val i = new Bundle {
19 val ival = Bool(INPUT)
20 }
21 val o: PinCtrl
22
23 // Must be defined by the subclasses
24 def default(): Unit
25 def inputPin(pue: Bool = Bool(false)): Bool
26 def outputPin(signal: Bool,
27 pue: Bool = Bool(false),
28 ds: Bool = Bool(false),
29 ie: Bool = Bool(false)
30 ): Unit
31
32 }
33
34
35 ////////////////////////////////////////////////////////////////////////////////////
36
37 class BasePin extends Pin() {
38 val o = new PinCtrl().asOutput
39
40 def default(): Unit = {
41 this.o.oval := Bool(false)
42 this.o.oe := Bool(false)
43 this.o.ie := Bool(false)
44 }
45
46 def inputPin(pue: Bool = Bool(false) /*ignored*/): Bool = {
47 this.o.oval := Bool(false)
48 this.o.oe := Bool(false)
49 this.o.ie := Bool(true)
50 this.i.ival
51 }
52
53 def outputPin(signal: Bool,
54 pue: Bool = Bool(false), /*ignored*/
55 ds: Bool = Bool(false), /*ignored*/
56 ie: Bool = Bool(false)
57 ): Unit = {
58 this.o.oval := signal
59 this.o.oe := Bool(true)
60 this.o.ie := ie
61 }
62 }
63
64 /////////////////////////////////////////////////////////////////////////
65 class EnhancedPinCtrl extends PinCtrl {
66 val pue = Bool()
67 val ds = Bool()
68 }
69
70 class EnhancedPin extends Pin() {
71
72 val o = new EnhancedPinCtrl().asOutput
73
74 def default(): Unit = {
75 this.o.oval := Bool(false)
76 this.o.oe := Bool(false)
77 this.o.ie := Bool(false)
78 this.o.ds := Bool(false)
79 this.o.pue := Bool(false)
80 }
81
82 def inputPin(pue: Bool = Bool(false)): Bool = {
83 this.o.oval := Bool(false)
84 this.o.oe := Bool(false)
85 this.o.pue := pue
86 this.o.ds := Bool(false)
87 this.o.ie := Bool(true)
88
89 this.i.ival
90 }
91
92 def outputPin(signal: Bool,
93 pue: Bool = Bool(false),
94 ds: Bool = Bool(false),
95 ie: Bool = Bool(false)
96 ): Unit = {
97 this.o.oval := signal
98 this.o.oe := Bool(true)
99 this.o.pue := pue
100 this.o.ds := ds
101 this.o.ie := ie
102 }
103
104 def toBasePin(): BasePin = {
105
106 val base_pin = Wire(new BasePin())
107 base_pin <> this
108 base_pin
109 }
110 }