package rpio import ( "fmt" "os" "reflect" "sync" "syscall" "unsafe" ) type Direction uint8 type Pin uint8 type State uint8 // Memory offsets for gpio, see the spec for more details // http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf const ( bcm2835Base = 0x20000000 gpioBase = bcm2835Base + 0x200000 pinmask uint32 = 7 // 0b111 ) // Pin modes (input, output) const ( INPUT Direction = iota OUTPUT ) // State of pin, high/low const ( LOW State = iota HIGH ) var ( mem []uint32 mem8 []uint8 memlock sync.Mutex ) func (pin Pin) High() { WritePin(uint8(pin), HIGH) } func (pin Pin) Low() { WritePin(uint8(pin), LOW) } func (pin Pin) Mode(dir Direction) { PinMode(uint8(pin), dir) } func (pin Pin) Write(state State) { WritePin(uint8(pin), state) } func (pin Pin) Read() State { return ReadPin(uint8(pin)) } func PinMode(pin uint8, direction Direction) { fsel := pin / 10 shift := (pin % 10) * 3 fmt.Println(pin, fsel, shift) fmt.Printf("0b%b \n", mem[fsel]) memlock.Lock() if direction == INPUT { fmt.Printf("0b%b\n\n", mem[fsel]&^(pinmask<