1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Services to control the bcm2835 chipset as used in the Raspberry Pi
18 # model B revision 1 Uses the C library by Mike McCauley from
19 # http://www.airspayce.com/mikem/bcm2835/
29 protected fun bcm2835_init
: Bool `{ return bcm2835_init(); `}
30 protected fun bcm2835_close `{ bcm2835_close(); `}
31 protected fun bcm2835_debug
=(v
: Bool) `{ bcm2835_set_debug(v); `}
34 extern class RPiPin `{ RPiGPIOPin `}
37 new p1_03
`{ return RPI_GPIO_P1_03; `}
39 new p1_05 `{ return RPI_GPIO_P1_05; `}
40 new p1_07
`{ return RPI_GPIO_P1_07; `}
42 new p1_11 `{ return RPI_GPIO_P1_11; `}
43 new p1_12
`{ return RPI_GPIO_P1_12; `}
44 new p1_13 `{ return RPI_GPIO_P1_13; `}
46 new p1_15
`{ return RPI_GPIO_P1_15; `}
47 new p1_16 `{ return RPI_GPIO_P1_16; `}
49 new p1_18
`{ return RPI_GPIO_P1_18; `}
50 new p1_19 `{ return RPI_GPIO_P1_19; `}
52 new p1_21
`{ return RPI_GPIO_P1_21; `}
53 new p1_22 `{ return RPI_GPIO_P1_22; `}
54 new p1_23
`{ return RPI_GPIO_P1_23; `}
55 new p1_24 `{ return RPI_GPIO_P1_24; `}
57 new p1_26
`{ return RPI_GPIO_P1_26; `}
59 # Select mode: input, output or alts
60 fun fsel=(mode: FunctionSelect) `{ bcm2835_gpio_fsel(recv, mode); `}
63 redef fun write
(high
) `{ bcm2835_gpio_write(recv, high? HIGH: LOW); `}
66 fun pud=(pud: PUDControl) `{ bcm2835_gpio_set_pud(recv, pud); `}
69 # Do not use on raspbian, it is bugged!
70 fun fen
`{ bcm2835_gpio_fen(recv); `}
71 fun clr_fen `{ bcm2835_gpio_clr_fen(recv); `}
74 # Do not use on raspbian, it is bugged!
75 fun ren
`{ bcm2835_gpio_ren(recv); `}
76 fun clr_ren `{ bcm2835_gpio_clr_ren(recv); `}
79 # Do not use on raspbian, it is bugged!
80 fun hen
`{ bcm2835_gpio_hen(recv); `}
81 fun clr_hen `{ bcm2835_gpio_clr_hen(recv); `}
84 # Do not use on raspbian, it is bugged!
85 fun len
`{ bcm2835_gpio_len(recv); `}
86 fun clr_len `{ bcm2835_gpio_clr_len(recv); `}
88 fun set_eds
`{ bcm2835_gpio_set_eds(recv); `}
89 fun eds: Bool `{ return bcm2835_gpio_eds(recv); `}
91 # Return input on pin, true for high and false for low
92 fun lev
: Bool `{ return bcm2835_gpio_lev(recv); `}
95 extern class FunctionSelect `{ bcm2835FunctionSelect `}
97 new inpt
`{ return BCM2835_GPIO_FSEL_INPT; `}
100 new outp `{ return BCM2835_GPIO_FSEL_OUTP; `}
102 new alt0
`{ return BCM2835_GPIO_FSEL_ALT0; `}
103 new alt1 `{ return BCM2835_GPIO_FSEL_ALT1; `}
104 new alt2
`{ return BCM2835_GPIO_FSEL_ALT2; `}
105 new alt3 `{ return BCM2835_GPIO_FSEL_ALT3; `}
106 new alt4
`{ return BCM2835_GPIO_FSEL_ALT4; `}
107 new alt5 `{ return BCM2835_GPIO_FSEL_ALT5; `}
108 new mask
`{ return BCM2835_GPIO_FSEL_MASK; `}
111 extern class PUDControl `{ bcm2835PUDControl `}
112 new off
`{ return BCM2835_GPIO_PUD_OFF; `}
113 new down `{ return BCM2835_GPIO_PUD_DOWN; `}
114 new up
`{ return BCM2835_GPIO_PUD_UP; `}
118 fun bcm2835_delay `{ bcm2835_delay(recv); `}
119 fun bcm2835_delay_micros
`{ bcm2835_delayMicroseconds(recv); `}