Example #1
0
mraa_result_t
mraa_intel_edison_uart_init_pre(int index)
{
    if (index != 0) {
        syslog(LOG_ERR, "edison: Failed to write to drive mode");
        return MRAA_ERROR_INVALID_RESOURCE;
    }
    if (miniboard == 0) {
        mraa_gpio_write(tristate, 0);
        mraa_gpio_context io0_output = mraa_gpio_init_raw(248);
        mraa_gpio_context io0_pullup = mraa_gpio_init_raw(216);
        mraa_gpio_context io1_output = mraa_gpio_init_raw(249);
        mraa_gpio_context io1_pullup = mraa_gpio_init_raw(217);
        mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
        mraa_gpio_dir(io0_pullup, MRAA_GPIO_OUT);
        mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);
        mraa_gpio_dir(io1_pullup, MRAA_GPIO_IN);

        mraa_gpio_write(io0_output, 0);
        mraa_gpio_write(io0_pullup, 0);
        mraa_gpio_write(io1_output, 1);

        mraa_gpio_close(io0_output);
        mraa_gpio_close(io0_pullup);
        mraa_gpio_close(io1_output);
        mraa_gpio_close(io1_pullup);
    }
    mraa_result_t ret;
    ret = mraa_intel_edison_pinmode_change(130, 1); // IO0 RX
    ret = mraa_intel_edison_pinmode_change(131, 1); // IO1 TX
    return ret;
}
Example #2
0
mraa_result_t
mraa_intel_edison_gpio_dir_pre(mraa_gpio_context dev, mraa_gpio_dir_t dir)
{

    if (dev->phy_pin >= 0) {
        if (mraa_gpio_write(tristate, 0) != MRAA_SUCCESS) {
            // call can sometimes fail, this does not actually mean much except
            // that the kernel drivers don't always behave very well
            syslog(LOG_NOTICE, "edison: Failed to write to tristate");
        }
        int pin = dev->phy_pin;

        if (!agpioOutputen[pin]) {
            agpioOutputen[pin] = mraa_gpio_init_raw(outputen[pin]);
            if (agpioOutputen[pin] == NULL) {
                return MRAA_ERROR_INVALID_RESOURCE;
            }
            if (mraa_gpio_dir(agpioOutputen[pin], MRAA_GPIO_OUT) != MRAA_SUCCESS) {
                return MRAA_ERROR_INVALID_RESOURCE;
            }
        }
        int output_val = 0;
        if (dir == MRAA_GPIO_OUT) {
            output_val = 1;
        }
        if (mraa_gpio_write(agpioOutputen[pin], output_val) != MRAA_SUCCESS) {
            return MRAA_ERROR_INVALID_RESOURCE;
        }
    }

    return MRAA_SUCCESS;
}
mraa_result_t
mraa_intel_edison_uart_init_pre(int index)
{
    if (miniboard == 0) {
        mraa_gpio_write(tristate, 0);
        mraa_gpio_context io0_output = mraa_gpio_init_raw(248);
        mraa_gpio_context io0_pullup = mraa_gpio_init_raw(216);
        mraa_gpio_context io1_output = mraa_gpio_init_raw(249);
        mraa_gpio_context io1_pullup = mraa_gpio_init_raw(217);
        mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
        mraa_gpio_dir(io0_pullup, MRAA_GPIO_OUT);
        mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);
        mraa_gpio_dir(io1_pullup, MRAA_GPIO_IN);

        mraa_gpio_write(io0_output, 0);
        mraa_gpio_write(io0_pullup, 0);
        mraa_gpio_write(io1_output, 1);

        mraa_gpio_close(io0_output);
        mraa_gpio_close(io0_pullup);
        mraa_gpio_close(io1_output);
        mraa_gpio_close(io1_pullup);
    }
    mraa_result_t ret;
    ret = mraa_intel_edison_pinmode_change(130,1); //IO0 RX
    ret = mraa_intel_edison_pinmode_change(131,1); //IO1 TX
    return ret;
}
Example #4
0
int main(int argc, char* argv[]) {
    int i, pin;

    if (argc != 2) {
        printf("Input GPIO number...");
        exit(1);
    }

    pin = atoi(argv[1]);

    printf("GPIO >>> %d\n", pin);

    mraa_gpio_context gpio;

    gpio = mraa_gpio_init(pin);

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);

    while (1) {
        mraa_gpio_write(gpio, 0);
        printf("Off\n");
        sleep(1);

        mraa_gpio_write(gpio, 1);
        printf("On\n");
        sleep(1);
    }

    mraa_gpio_close(gpio);

    return 0;
}
Example #5
0
void get_data(mraa_gpio_context gpio, int* readData) {
    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
    mraa_gpio_write(gpio, 1);
    mraa_gpio_write(gpio, 0);

    usleep(18000);

    mraa_gpio_write(gpio, 1);

    usleep(30);

    mraa_gpio_dir(gpio, MRAA_GPIO_IN);

    *readData = mraa_gpio_read(gpio);

    usleep(80);

    printf("first readData >>> %d\n", *readData);

    *readData = mraa_gpio_read(gpio);

    usleep(80);

    printf("second readData >>> %d\n", *readData);

    int i;

    for (i = 0; i < 40; i++) {
        *readData = mraa_gpio_read(gpio);

        printf("[%d] >>> %d\n", i, *readData);
    }
}
Example #6
0
void RF22::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
{
    uint8_t *request;
    uint8_t *response;
    
    request =  (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
    response = (uint8_t *) malloc(sizeof(uint8_t) * (len + 1));
    memset(request,  0x00, len + 1);
	memset(response, 0x00, len + 1);
    
    request[0] = reg & ~RF22_SPI_WRITE_MASK;
    memcpy (&request[1], dest, len);
    
    mraa_gpio_write(_cs, 0x1);
	mraa_gpio_write(_cs, 0x0);
	usleep(100);
	mraa_spi_transfer_buf(_spi, request, response, len + 1);
	usleep(100);
	mraa_gpio_write(_cs, 0x1);
    
    memcpy (dest, &response[1], len);
    
    free (request);
    free (response);
}
Example #7
0
void standby(int disable)
{
	if (disable == 1)
		mraa_gpio_write(standbyPin, 0);
	else
		mraa_gpio_write(standbyPin, 1);
}
Example #8
0
mraa_result_t
mraa_intel_galileo_gen2_uart_init_pre(int index)
{
    mraa_gpio_context io0_output = mraa_gpio_init_raw(32);
    if (io0_output == NULL) {
        return MRAA_ERROR_INVALID_RESOURCE;
    }
    mraa_gpio_context io1_output = mraa_gpio_init_raw(28);
    if (io1_output == NULL) {
        mraa_gpio_close(io0_output);
        return MRAA_ERROR_INVALID_RESOURCE;
    }

    int status = 0;
    status += mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
    status += mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);

    status += mraa_gpio_write(io0_output, 1);
    status += mraa_gpio_write(io1_output, 0);

    mraa_gpio_close(io0_output);
    mraa_gpio_close(io1_output);

    if (status > 0) {
        return MRAA_ERROR_UNSPECIFIED;
    }
    return MRAA_SUCCESS;
}
Example #9
0
void Display_Init(void)
{
	mraa_gpio_write(SCS, 1); //Select SHARP Display
	mraa_spi_write(spi, MLCD_CM); //Clear SHARP Display
	mraa_spi_write(spi, MLCD_TR); //Send Trailer
	mraa_gpio_write(SCS, 0); //Deselect SHARP Display
}
Example #10
0
void sw_spi_write_word(mraa_spi_sw_context spi, uint16_t data)
{
	for(uint16_t i = 0x8000; i; i >>= 1) {
		mraa_gpio_write(spi->sdi, data & i);
		mraa_gpio_write(spi->sck, 1);
		mraa_gpio_write(spi->sck, 0);
	}
}
void tb6612::standby(bool disableMotors)
{
  if (disableMotors)
  {
    mraa_gpio_write(_standbyPin, 0);
  }
  else
  {
    mraa_gpio_write(_standbyPin, 1);
  }
}
Example #12
0
static void speaker_sound(const speaker_context dev, int note_delay)
{
    assert(dev != NULL);

    for (int i=0; i<100; i++)
    {
        mraa_gpio_write (dev->gpio, 1);
        upm_delay_us(note_delay);
        mraa_gpio_write (dev->gpio, 0);
        upm_delay_us(note_delay);
    }
}
Example #13
0
void sw_spi_write_data(mraa_spi_sw_context spi, mraa_gpio_context ss, uint8_t *data, unsigned len)
{
	mraa_gpio_write(ss, 0);
	for(unsigned i = 0; i < len; i++) {
		for(uint8_t mask = 0x80; mask; mask >>= 1) {
			mraa_gpio_write(spi->sdi, data[i] & mask);
			mraa_gpio_write(spi->sck, 1);
			mraa_gpio_write(spi->sck, 0);
		}
	}
	mraa_gpio_write(ss, 1);
}
Example #14
0
void Display_Stop(void)
{
  //reset all GPIOs to '0'
  mraa_gpio_write(SCS, 0);
  mraa_gpio_write(VDD, 0);
  //close all GPIOs
  mraa_gpio_close(SCS);
  mraa_gpio_close(VDD);
  //close all Peripherals
  mraa_spi_stop(spi);
  mraa_pwm_close(pwm);
}
Example #15
0
int main()
{
	mraa_gpio_context pin = mraa_gpio_init(13);
	mraa_gpio_dir(pin, MRAA_GPIO_OUT);
	for (;;) {
		mraa_gpio_write(pin, 0);
		sleep(1);
		mraa_gpio_write(pin, 1);
		sleep(1);
	}
	return MRAA_SUCCESS;
}
void tb6612::shortBrake(bool brakeA, bool brakeB)
{
  if (brakeA)
  {
    mraa_gpio_write(_A1, 1);
    mraa_gpio_write(_A2, 1);
  }
  if (brakeB)
  {
    mraa_gpio_write(_B1, 1);
    mraa_gpio_write(_B2, 1);
  }
}
Example #17
0
uint16_t sw_spi_send_word(mraa_spi_sw_context spi, uint16_t data)
{
	uint16_t rx = 0;

	for(uint16_t i = 0x8000; i; i >>= 1) {
		mraa_gpio_write(spi->sdi, data & i);
		mraa_gpio_write(spi->sck, 1);
		rx = (rx << 1 ) | mraa_gpio_read(spi->sdo);
		mraa_gpio_write(spi->sck, 0);
	}

	return rx;
}
Example #18
0
int main(int argc, char **argv)  
{  
	int i, j, output, outputArray[n_reads], i_reads, tmp;
 
    mraa_gpio_context clk = mraa_gpio_init(4); 
    mraa_gpio_context dat = mraa_gpio_init(2);
    mraa_gpio_dir(clk, MRAA_GPIO_OUT); 
    mraa_gpio_dir(dat, MRAA_GPIO_IN); 
  
    mraa_gpio_use_mmaped(clk, 1);

    i_reads = n_reads;

    while (i_reads > 0) { 

        while(mraa_gpio_read(dat)) {}

    	output = 0; 
        for(i = 0; i < 24; i++) {
        	mraa_gpio_write(clk, 1);
        	fuckDelay(2000);
        	output |= (mraa_gpio_read(dat)<< (23-i));
        	mraa_gpio_write(clk, 0);
        	fuckDelay(2000);
        }
        mraa_gpio_write(clk, 1);
        fuckDelay(2000);
        mraa_gpio_write(clk, 0);

        if(output < 16777215) {
        	//fprintf(stdout, "%d\n", output);
            outputArray[i_reads-1] = output;
            i_reads--; // decrement only if the valid read
        }
    } 


    //sorting the array
    for(i = 1; i < n_reads; i++){
        j = i;
        while ((j > 0) && (outputArray[j-1]>outputArray[j])) {
            tmp = outputArray[j];
            outputArray[j] = outputArray[j-1];
            outputArray[j-1] = tmp;
            j--;
        }
    } 

    fprintf(stdout, "%d\n", outputArray[5]);

} 
Example #19
0
upm_result_t mma7361_selftest(const mma7361_context dev, bool selftest)
{
  assert(dev != NULL);

  if (!dev->gpio_selftest)
    return UPM_ERROR_NO_RESOURCES;

  if (selftest)
    mraa_gpio_write(dev->gpio_selftest, 1);
  else
    mraa_gpio_write(dev->gpio_selftest, 0);

  return UPM_SUCCESS;
}
mraa_result_t
mraa_intel_edison_i2c_init_pre(unsigned int bus)
{
    if (miniboard == 0) {
        if(bus != 6) {
            syslog(LOG_ERR, "edison: You can't use that bus, switching to bus 6");
            bus = 6;
        }
        mraa_gpio_write(tristate, 0);
        mraa_gpio_context io18_gpio = mraa_gpio_init_raw(14);
        mraa_gpio_context io19_gpio = mraa_gpio_init_raw(165);
        mraa_gpio_dir(io18_gpio, MRAA_GPIO_IN);
        mraa_gpio_dir(io19_gpio, MRAA_GPIO_IN);
        mraa_gpio_close(io18_gpio);
        mraa_gpio_close(io19_gpio);

        mraa_gpio_context io18_enable = mraa_gpio_init_raw(236);
        mraa_gpio_context io19_enable = mraa_gpio_init_raw(237);
        mraa_gpio_dir(io18_enable, MRAA_GPIO_OUT);
        mraa_gpio_dir(io19_enable, MRAA_GPIO_OUT);
        mraa_gpio_write(io18_enable, 0);
        mraa_gpio_write(io19_enable, 0);
        mraa_gpio_close(io18_enable);
        mraa_gpio_close(io19_enable);

        mraa_gpio_context io18_pullup = mraa_gpio_init_raw(212);
        mraa_gpio_context io19_pullup = mraa_gpio_init_raw(213);
        mraa_gpio_dir(io18_pullup, MRAA_GPIO_IN);
        mraa_gpio_dir(io19_pullup, MRAA_GPIO_IN);
        mraa_gpio_close(io18_pullup);
        mraa_gpio_close(io19_pullup);

        mraa_intel_edison_pinmode_change(28, 1);
        mraa_intel_edison_pinmode_change(27, 1);

        mraa_gpio_write(tristate, 1);
    } else {
        if(bus != 6 && bus != 1) {
            syslog(LOG_ERR, "edison: You can't use that bus, switching to bus 6");
            bus = 6;
        }
        int scl = plat->pins[plat->i2c_bus[bus].scl].gpio.pinmap;
        int sda = plat->pins[plat->i2c_bus[bus].sda].gpio.pinmap;
        mraa_intel_edison_pinmode_change(sda, 1);
        mraa_intel_edison_pinmode_change(scl, 1);
    }

    return MRAA_SUCCESS;
}
mraa_result_t
mraa_intel_galileo_gen2_uart_init_pre(int index)
{
    mraa_gpio_context io0_output = mraa_gpio_init_raw(32);
    mraa_gpio_context io1_output = mraa_gpio_init_raw(28);
    mraa_gpio_dir(io0_output, MRAA_GPIO_OUT);
    mraa_gpio_dir(io1_output, MRAA_GPIO_OUT);

    mraa_gpio_write(io0_output, 1);
    mraa_gpio_write(io1_output, 0);

    mraa_gpio_close(io0_output);
    mraa_gpio_close(io1_output);
    return MRAA_SUCCESS;
}
mraa_result_t
mraa_intel_edison_spi_init_pre(int bus)
{
    if (miniboard == 1) {
        mraa_intel_edison_pinmode_change(111, 1);
        mraa_intel_edison_pinmode_change(115, 1);
        mraa_intel_edison_pinmode_change(114, 1);
        mraa_intel_edison_pinmode_change(109, 1);
        return MRAA_SUCCESS;
    }
    mraa_gpio_write(tristate, 0);

    mraa_gpio_context io10_out = mraa_gpio_init_raw(258);
    mraa_gpio_context io11_out = mraa_gpio_init_raw(259);
    mraa_gpio_context io12_out = mraa_gpio_init_raw(260);
    mraa_gpio_context io13_out = mraa_gpio_init_raw(261);
    mraa_gpio_dir(io10_out, MRAA_GPIO_OUT);
    mraa_gpio_dir(io11_out, MRAA_GPIO_OUT);
    mraa_gpio_dir(io12_out, MRAA_GPIO_OUT);
    mraa_gpio_dir(io13_out, MRAA_GPIO_OUT);

    mraa_gpio_write(io10_out, 1);
    mraa_gpio_write(io11_out, 1);
    mraa_gpio_write(io12_out, 0);
    mraa_gpio_write(io13_out, 1);

    mraa_gpio_close(io10_out);
    mraa_gpio_close(io11_out);
    mraa_gpio_close(io12_out);
    mraa_gpio_close(io13_out);

    mraa_gpio_context io10_pull = mraa_gpio_init_raw(226);
    mraa_gpio_context io11_pull = mraa_gpio_init_raw(227);
    mraa_gpio_context io12_pull = mraa_gpio_init_raw(228);
    mraa_gpio_context io13_pull = mraa_gpio_init_raw(229);

    mraa_gpio_dir(io10_pull, MRAA_GPIO_IN);
    mraa_gpio_dir(io11_pull, MRAA_GPIO_IN);
    mraa_gpio_dir(io12_pull, MRAA_GPIO_IN);
    mraa_gpio_dir(io13_pull, MRAA_GPIO_IN);

    mraa_gpio_close(io10_pull);
    mraa_gpio_close(io11_pull);
    mraa_gpio_close(io12_pull);
    mraa_gpio_close(io13_pull);

    return MRAA_SUCCESS;
}
Example #23
0
mraa_result_t
mraa_intel_galileo_gen2_dir_pre(mraa_gpio_context dev, mraa_gpio_dir_t dir)
{
    if (dev->phy_pin >= 0) {
        int pin = dev->phy_pin;
        if (plat->pins[pin].gpio.complex_cap.complex_pin != 1)
            return MRAA_SUCCESS;

        if (plat->pins[pin].gpio.complex_cap.output_en == 1) {
            if (!agpioOutputen[pin]) {
                agpioOutputen[pin] = mraa_gpio_init_raw(plat->pins[pin].gpio.output_enable);
                if (agpioOutputen[pin] == NULL) {
                    return MRAA_ERROR_INVALID_RESOURCE;
                }
                if (mraa_gpio_dir(agpioOutputen[pin], MRAA_GPIO_OUT) != MRAA_SUCCESS) {
                    return MRAA_ERROR_INVALID_RESOURCE;
                }
            }

            int output_val = 1;
            if (dir == MRAA_GPIO_OUT) {
                output_val = 0;
            }
            if (mraa_gpio_write(agpioOutputen[pin], output_val) != MRAA_SUCCESS) {
                return MRAA_ERROR_INVALID_RESOURCE;
            }
        }
    }
    return MRAA_SUCCESS;
}
mraa_result_t
mraa_intel_edison_pwm_init_pre(int pin)
{
    if (miniboard == 1) {
        return mraa_intel_edison_pinmode_change(plat->pins[pin].gpio.pinmap, 1);
    }
    if (pin < 0 || pin > 19)
        return MRAA_ERROR_INVALID_RESOURCE;

    if (!plat->pins[pin].capabilites.pwm)
        return MRAA_ERROR_INVALID_RESOURCE;

    mraa_gpio_context output_e;
    output_e = mraa_gpio_init_raw(outputen[pin]);
    if (mraa_gpio_dir(output_e, MRAA_GPIO_OUT) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    if (mraa_gpio_write(output_e, 1) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    mraa_gpio_close(output_e);

    mraa_gpio_context pullup_pin;
    pullup_pin = mraa_gpio_init_raw(pullup_map[pin]);
    if (mraa_gpio_dir(pullup_pin, MRAA_GPIO_IN) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    mraa_gpio_close(pullup_pin);
    mraa_intel_edison_pinmode_change(plat->pins[pin].gpio.pinmap, 1);

    return MRAA_SUCCESS;
}
mraa_result_t
mraa_intel_edison_aio_init_pre(unsigned int aio)
{
    if (aio > plat->aio_count) {
        syslog(LOG_ERR, "edison: Invalid analog input channel");
        return MRAA_ERROR_INVALID_RESOURCE;
    }

    int pin = 14 + aio;
    mraa_gpio_context output_e;
    output_e = mraa_gpio_init_raw(outputen[pin]);
    if (mraa_gpio_dir(output_e, MRAA_GPIO_OUT) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    if (mraa_gpio_write(output_e, 0) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    mraa_gpio_close(output_e);

    mraa_gpio_context pullup_pin;
    pullup_pin = mraa_gpio_init_raw(pullup_map[pin]);
    if (mraa_gpio_dir(pullup_pin, MRAA_GPIO_IN) != MRAA_SUCCESS)
        return MRAA_ERROR_INVALID_RESOURCE;
    mraa_gpio_close(pullup_pin);

    return MRAA_SUCCESS;
}
Example #26
0
int
main(int argc, char **argv)
{
    mraa_platform_t platform = mraa_get_platform_type();
    mraa_gpio_context gpio;
    char board_name[] = "Some weird devboard that isn't recognised...";
    int ledstate = 0;

    switch (platform) {
        case MRAA_INTEL_GALILEO_GEN1:
            strcpy(board_name, "Intel Galileo Gen1");
            gpio = mraa_gpio_init_raw(3);
            break;
        case MRAA_INTEL_GALILEO_GEN2:
            strcpy(board_name, "Intel Galileo Gen2");
        default:
            gpio = mraa_gpio_init(13);
    }

    fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n",
        mraa_get_version(), board_name);

    mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
    for (;;) {
        ledstate = !ledstate;
        mraa_gpio_write(gpio, !ledstate);
        sleep(1);
    }

    return 0;
}
Example #27
0
void interrupt_in(void *arg)
{
    mraa_gpio_context dev = (mraa_gpio_context)arg;
    if(mutex == 0){
        mutex = 1;
       system("clear"); 
       if(mraa_gpio_read(dev) == 1){
            mraa_gpio_write(out, 1);
            printf("Released\r\n");
        }else{
            mraa_gpio_write(out, 0);
            printf("Pressed\r\n");
        }
        mutex = 0;
    }
}
Example #28
0
mraa_pin_t*
mraa_setup_pwm(int pin)
{
    if (plat == NULL)
        return NULL;

    if (plat->pins[pin].capabilites.pwm != 1)
        return NULL;

    if (plat->pins[pin].capabilites.gpio == 1) {
        mraa_gpio_context mux_i;
        mux_i = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
        if (mux_i == NULL)
            return NULL;
        if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS)
            return NULL;
        // Current REV D quirk. //TODO GEN 2
        if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS)
            return NULL;
        if (mraa_gpio_close(mux_i) != MRAA_SUCCESS)
            return NULL;
    }

    if (plat->pins[pin].pwm.mux_total > 0)
       if (mraa_setup_mux_mapped(plat->pins[pin].pwm) != MRAA_SUCCESS)
            return NULL;

    mraa_pin_t *ret;
    ret = (mraa_pin_t*) malloc(sizeof(mraa_pin_t));
    ret->pinmap = plat->pins[pin].pwm.pinmap;
    ret->parent_id = plat->pins[pin].pwm.parent_id;
    return ret;
}
Example #29
0
upm_result_t mma7361_sleep(const mma7361_context dev, bool sleep)
{
  assert(dev != NULL);

  if (!dev->gpio_sleep)
    return UPM_ERROR_NO_RESOURCES;

  if (sleep)
    mraa_gpio_write(dev->gpio_sleep, 0);
  else
    mraa_gpio_write(dev->gpio_sleep, 1);

  upm_delay_ms(2);

  return UPM_SUCCESS;
}
Example #30
0
mraa_result_t
mraa_setup_mux_mapped(mraa_pin_t meta)
{
    int mi;

    for (mi = 0; mi < meta.mux_total; mi++) {
        mraa_gpio_context mux_i;
        mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
        if (mux_i == NULL) {
            return MRAA_ERROR_INVALID_HANDLE;
        }
        // this function will sometimes fail, however this is not critical as
        // long as the write succeeds - Test case galileo gen2 pin2
        mraa_gpio_dir(mux_i, MRAA_GPIO_OUT);
        mraa_gpio_owner(mux_i, 0);

        if (mraa_gpio_write(mux_i, meta.mux[mi].value) != MRAA_SUCCESS) {
            mraa_gpio_close(mux_i);
            return MRAA_ERROR_INVALID_RESOURCE;
        }
        mraa_gpio_close(mux_i);
    }

    return MRAA_SUCCESS;
}