func (gpio *MMappedGPIO) GetState() (state bool, err error) {
	mmapreg := getgpiommap()
	var register uint
	if mmapreg.memgpiochipreg[gpio.chipid][intgpio_output_enabled_+(gpio.gpioid/8)]&(1<<(gpio.gpioid%8)) > 0 {
		register = intgpio_datain_  
	} else {
		register = intgpio_dataout_  
	}
	state = gpio.activelow != (mmapreg.memgpiochipreg[gpio.chipid][register+(gpio.gpioid/8)]&(1<<(gpio.gpioid%8)) > 0)
	return
}
returns true if pin is HIGH and false if pin is LOW i.e. HIGH/LOW signal on input pin
note that SetActiveLow inverts return value
internal note: in contrast to SysFS we need to query two different registers depending on the pin direction
package bbhw
import "fmt"
type MMappedGPIO struct {
	chipid    int
	gpioid    uint
	activelow bool
}
func NewMMappedGPIO(number uint, direction int) (gpio *MMappedGPIO) {
	NewSysfsGPIOOrPanic(number, direction).Close()
	gpio = new(MMappedGPIO)
	gpio.chipid, gpio.gpioid = calcGPIOAddrFromLinuxGPIONum(number)
	return gpio
}
func (gpio *MMappedGPIO) CheckDirection() (direction int, err error) {
	mmapreg := getgpiommap()
	input_enabled := mmapreg.memgpiochipreg[gpio.chipid][intgpio_output_enabled_+(gpio.gpioid/8)]&(1<<(gpio.gpioid%8)) > 0
	if input_enabled {
		return IN, nil
	} else {
		return OUT, nil
	}
}
func (gpio *MMappedGPIO) SetDebounce(enable_debounce bool) error {
	mmapreg := getgpiommap()
	if dir, err := gpio.CheckDirection(); dir != IN || err != nil {
		return fmt.Errorf("GPIO %+v is not configured as Input, setting debounce won't have an effect", gpio)
	}
	mmapreg.reglock.Lock()
	debounce_state := mmapreg.memgpiochipreg[gpio.chipid][intgpio_debounceenable_+(gpio.gpioid/8)]
	if enable_debounce {
		debounce_state |= byte(gpio.gpioid % 8)
	} else {
		debounce_state &= byte(^(gpio.gpioid % 8))
	}
	mmapreg.memgpiochipreg[gpio.chipid][intgpio_debounceenable_+(gpio.gpioid/8)] = debounce_state
	mmapreg.reglock.Unlock()
	return nil
}
func (gpio *MMappedGPIO) SetState(state bool) error {
	mmapreg := getgpiommap()
	if state != gpio.activelow {
		mmapreg.memgpiochipreg[gpio.chipid][intgpio_setdataout_+(gpio.gpioid/8)] = 1 << (gpio.gpioid % 8)
	} else {
		mmapreg.memgpiochipreg[gpio.chipid][intgpio_cleardataout_+(gpio.gpioid/8)] = 1 << (gpio.gpioid % 8)
	}
	return nil
}
func (gpio *MMappedGPIO) SetStateNow(state bool) error { return gpio.SetState(state) }
func (gpio *MMappedGPIO) SetActiveLow(activelow bool) error {
	if gpio == nil {
		panic("gpio == nil")
	}
	prev_state, err := gpio.GetState()
	if err != nil {
		return err
	}
	gpio.activelow = activelow
	return gpio.SetState(prev_state)
}