void digitalWrite(const PIN pin, unsigned int value) {
  unsigned gpio;
  const Pair* pair;
  
  pair = get_pair_with_key(pin.def, pin.no, "gpio");
  gpio = atoi(pair->value);
  gpio_write_value(gpio, value);

} 
unsigned digitalRead(const PIN pin) {
  unsigned gpio;
  const Pair* pair;
  unsigned value;

  pair = get_pair_with_key(pin.def, pin.no, "gpio");
  gpio = atoi(pair->value);
  
  gpio_read_value(gpio, &value);

  return value;
}
Esempio n. 3
0
void pinToMem(PIN pin, unsigned long *ret_addr, unsigned long *ret_bitMask) {
    assert(gpio != MAP_FAILED);
    const Pair* pair = get_pair_with_key(pin.def, pin.no, "gpio");
    unsigned gpioNo = atoi(pair->value);
    unsigned bank = gpioNo / 32;
    unsigned bit = gpioNo % 32;
    /*
    if (DEBUG) printf("Set Pin %s\n in bank %d and bit %d\n",
        pin.name,bank,bit);
    */
    assert(bank >= 0);
    assert(bank < 4);
    *ret_bitMask = 1 << bit;
    *ret_addr = bankAddr[bank];
}
void pinMode(PIN pin, unsigned int value) {
  unsigned gpio;
  const Pair* pair;

  pair  = get_pair_with_key(pin.def, pin.no, "gpio");
  gpio = atoi(pair->value);
  
  //printf("pinMode GPIO:%d as %s\n",gpio, (INPUT) ? "INPUT" : "OUTPUT");

  if (value == INPUT) {
    // mux mode 0x27
    gpio_mux(&pin,  (_MUX_0 | _MUX_1 | _MUX_2 | _MUX_RECEIVER_ENABLE));
  }
  else {
    // mux mode 0x7
    gpio_mux(&pin, (_MUX_0 | _MUX_1 | _MUX_2));
  }

  gpio_export(gpio);
  gpio_set_direction(gpio, value);

}