-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpio.fs
107 lines (104 loc) · 2.31 KB
/
gpio.fs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
\ #require common.fs
%00 constant INPUT
%01 constant OUTPUT
%10 constant AF
%11 constant ANALOG
#0 constant AF0
#1 constant AF1
#2 constant AF2
#3 constant AF3
#4 constant AF4
#5 constant AF5
#6 constant AF6
#7 constant AF7
#8 constant AF8
#9 constant AF9
#10 constant AF10
#11 constant AF11
#12 constant AF12
#13 constant AF13
#14 constant AF14
#15 constant AF15
%00 constant LOW
%01 constant MED
%10 constant HIGH
%11 constant VERY_HIGH
%0 constant PUSH_PULL
%1 constant OPEN_DRAIN
MODER_MODER0
constant MODER_WIDTH
constant MODER_PIN0_OFFSET
constant MODER_OFFSET
: moder! ( mode port pin -- )
MODER_WIDTH *
MODER_PIN0_OFFSET +
MODER_WIDTH
MODER_OFFSET -rot
bf!
;
OSPEEDR_OSPEEDR0
constant OSPEEDR_WIDTH
constant OSPEEDR_PIN0_OFFSET
constant OSPEEDR_OFFSET
: ospeedr! ( speed port pin -- )
OSPEEDR_WIDTH *
OSPEEDR_PIN0_OFFSET +
OSPEEDR_WIDTH
OSPEEDR_OFFSET -rot
bf!
;
OTYPER_OT0
constant OTYPER_WIDTH
constant OTYPER_PIN0_OFFSET
constant OTYPER_OFFSET
: otyper! ( speed port pin -- )
OTYPER_WIDTH *
OTYPER_PIN0_OFFSET +
OTYPER_WIDTH
OTYPER_OFFSET -rot
bf!
;
AFRL_AFRL0
constant AFRL_WIDTH
constant AFRL_PIN0_OFFSET
constant AFRL_OFFSET
: afrl! ( af port pin -- )
AFRL_WIDTH *
AFRL_PIN0_OFFSET +
AFRL_WIDTH
AFRL_OFFSET -rot
bf!
;
AFRH_AFRH8
constant AFRH_WIDTH
constant AFRH_PIN8_OFFSET
constant AFRH_OFFSET
: afrh! ( af port pin -- )
#8 -
AFRH_WIDTH *
AFRH_PIN8_OFFSET +
AFRH_WIDTH
AFRH_OFFSET -rot
bf!
;
: afr! ( af port pin -- )
dup 8 < if afrl! else afrh! then
;
: bs! ( port pin -- )
>R BSRR_BS0 swap R> + swap bfs!
;
: br! ( port pin -- )
>R BSRR_BR0 swap R> + swap bfs!
;
\ mecrisp-stellaris automatically enables all gpio ports, but swdcom version doesn't
: enable-gpioa-clock ( -- ) RCC AHB1ENR_GPIOAEN bfs! ;
: enable-gpiob-clock ( -- ) RCC AHB1ENR_GPIOBEN bfs! ;
: enable-gpioc-clock ( -- ) RCC AHB1ENR_GPIOCEN bfs! ;
: enable-gpiod-clock ( -- ) RCC AHB1ENR_GPIODEN bfs! ;
: enable-gpioe-clock ( -- ) RCC AHB1ENR_GPIOEEN bfs! ;
: enable-gpiof-clock ( -- ) RCC AHB1ENR_GPIOFEN bfs! ;
: enable-gpiog-clock ( -- ) RCC AHB1ENR_GPIOGEN bfs! ;
: enable-gpioh-clock ( -- ) RCC AHB1ENR_GPIOHEN bfs! ;
: enable-gpioi-clock ( -- ) RCC AHB1ENR_GPIOIEN bfs! ;
: enable-gpioj-clock ( -- ) RCC AHB1ENR_GPIOJEN bfs! ;
: enable-gpiok-clock ( -- ) RCC AHB1ENR_GPIOKEN bfs! ;