@@ -27,22 +27,31 @@ const (
2727
2828 TKEY_TOUCH = Pin (3 ) // 3 is unused, but we need a value here to match the Pin interface.
2929 BUTTON = TKEY_TOUCH
30+
31+ GPIO1 = Pin (tkey .TK1_MMIO_TK1_GPIO1_BIT + 8 )
32+ GPIO2 = Pin (tkey .TK1_MMIO_TK1_GPIO2_BIT + 8 )
33+ GPIO3 = Pin (tkey .TK1_MMIO_TK1_GPIO3_BIT + 8 )
34+ GPIO4 = Pin (tkey .TK1_MMIO_TK1_GPIO4_BIT + 8 )
3035)
3136
32- var buttonConfig PinConfig
37+ var touchConfig , gpio1Config , gpio2Config PinConfig
3338
3439// No config needed for TKey, just to match the Pin interface.
3540func (p Pin ) Configure (config PinConfig ) {
3641 switch p {
3742 case BUTTON :
38- buttonConfig = config
43+ touchConfig = config
3944
4045 // Clear any pending touch events.
4146 tkey .TOUCH .STATUS .Set (0 )
47+ case GPIO1 :
48+ gpio1Config = config
49+ case GPIO2 :
50+ gpio2Config = config
4251 }
4352}
4453
45- // Set GPIO pin to high or low.
54+ // Set pin to high or low.
4655func (p Pin ) Set (high bool ) {
4756 switch p {
4857 case LED_BLUE , LED_GREEN , LED_RED :
@@ -51,26 +60,46 @@ func (p Pin) Set(high bool) {
5160 } else {
5261 tkey .TK1 .LED .ClearBits (1 << uint (p ))
5362 }
63+ case GPIO3 , GPIO4 :
64+ if high {
65+ tkey .TK1 .GPIO .SetBits (1 << uint (p - 8 ))
66+ } else {
67+ tkey .TK1 .GPIO .ClearBits (1 << uint (p - 8 ))
68+ }
5469 }
5570}
5671
72+ // Get returns the current value of a pin.
5773func (p Pin ) Get () bool {
74+ pushed := false
75+ mode := PinInput
76+
5877 switch p {
5978 case BUTTON :
60- pushed := false
79+ mode = touchConfig . Mode
6180 if tkey .TOUCH .STATUS .HasBits (1 ) {
6281 tkey .TOUCH .STATUS .Set (0 )
6382 pushed = true
6483 }
65-
66- switch buttonConfig .Mode {
67- case PinInputPullup :
68- return ! pushed
69- case PinInput , PinInputPulldown :
70- return pushed
84+ case GPIO1 :
85+ mode = gpio1Config .Mode
86+ if tkey .TK1 .GPIO .HasBits (1 << uint (p - 8 )) {
87+ pushed = true
88+ }
89+ case GPIO2 :
90+ mode = gpio2Config .Mode
91+ if tkey .TK1 .GPIO .HasBits (1 << uint (p - 8 )) {
92+ pushed = true
7193 }
7294 }
7395
96+ switch mode {
97+ case PinInputPullup :
98+ return ! pushed
99+ case PinInput , PinInputPulldown :
100+ return pushed
101+ }
102+
74103 return false
75104}
76105
0 commit comments