mraa_result_t mraa_intel_galileo_gen2_i2c_init_pre(unsigned int bus) { mraa_gpio_context io18 = mraa_gpio_init_raw(57); int status = 0; if (io18 == NULL) { return MRAA_ERROR_UNSPECIFIED; } status += mraa_gpio_dir(io18, MRAA_GPIO_IN); status += mraa_gpio_mode(io18, MRAA_GPIO_HIZ); mraa_gpio_close(io18); mraa_gpio_context io19 = mraa_gpio_init_raw(59); if (io19 == NULL) { return MRAA_ERROR_UNSPECIFIED; } status += mraa_gpio_dir(io19, MRAA_GPIO_IN); status += mraa_gpio_mode(io19, MRAA_GPIO_HIZ); mraa_gpio_close(io19); if (status > 0) { return MRAA_ERROR_UNSPECIFIED; } 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_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; }
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; }
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; }
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; }
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; }
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; }
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_galileo_g1_pwm_init_pre(int pin) { // Gen1 galileo has no kernel muxing for GPIOs/PWM so ends up with leakage // on the PWM pins from the GPIO pins if not set to output high if (plat->pins[pin].capabilities.gpio == 1) { mraa_gpio_context mux_i; mux_i = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap); if (mux_i == NULL) { syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_init", pin); return MRAA_ERROR_INVALID_RESOURCE; } if (mraa_gpio_dir(mux_i, MRAA_GPIO_OUT) != MRAA_SUCCESS) { syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_dir", pin); return MRAA_ERROR_INVALID_RESOURCE; } if (mraa_gpio_write(mux_i, 1) != MRAA_SUCCESS) { syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_write", pin); return MRAA_ERROR_INVALID_RESOURCE; } if (mraa_gpio_close(mux_i) != MRAA_SUCCESS) { syslog(LOG_ERR, "pwm_init: error in gpio->pwm%i transition. gpio_close", pin); return MRAA_ERROR_INVALID_RESOURCE; } } return MRAA_SUCCESS; }
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; }
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; }
mraa_board_t* mraa_intel_edison_fab_c() { mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t)); if (b == NULL) return NULL; b->phy_pin_count = 20; b->gpio_count = 14; b->aio_count = 6; advance_func->gpio_dir_pre = &mraa_intel_edison_gpio_dir_pre; advance_func->gpio_init_post = &mraa_intel_edison_gpio_init_post; advance_func->gpio_dir_post = &mraa_intel_edison_gpio_dir_post; advance_func->i2c_init_pre = &mraa_intel_edison_i2c_init_pre; advance_func->aio_get_valid_fp = &mraa_intel_edison_aio_get_fp; advance_func->aio_init_pre = &mraa_intel_edison_aio_init_pre; advance_func->aio_init_post = &mraa_intel_edison_aio_init_post; advance_func->pwm_init_pre = &mraa_intel_edison_pwm_init_pre; advance_func->pwm_init_post = &mraa_intel_edison_pwm_init_post; advance_func->spi_init_pre = &mraa_intel_edison_spi_init_pre; advance_func->spi_init_post = &mraa_intel_edison_spi_init_post; advance_func->gpio_mode_replace = &mraa_intel_edison_gpio_mode_replace; b->pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t)*MRAA_INTEL_EDISON_PINCOUNT); tristate = mraa_gpio_init_raw(214); if (tristate == NULL) { syslog(LOG_CRIT, "Intel Edison Failed to initialise Arduino board TriState,\ check i2c devices! FATAL\n"); return NULL; }
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; }
/** * Instanciates a Gpio object * * @param pin pin number to use * @param owner (optional) Set pin owner, default behaviour is to 'own' * the pin if we exported it. This means we will close it on destruct. * Otherwise it will get left open. This is only valid in sysfs use * cases * @param raw (optional) Raw pins will use gpiolibs pin numbering from * the kernel module. Note that you will not get any muxers set up for * you so this may not always work as expected. */ Gpio(int pin, bool owner=true, bool raw=false) { if (raw) m_gpio = mraa_gpio_init_raw(pin); else m_gpio = mraa_gpio_init(pin); if (!owner) mraa_gpio_owner(m_gpio, 0); }
int main(int argc, char** argv) { mraa_platform_t platform = mraa_get_platform_type(); mraa_gpio_context gpio, gpio_in = NULL; const char* board_name = mraa_get_platform_name(); int ledstate = 0; switch (platform) { case MRAA_INTEL_GALILEO_GEN1: gpio = mraa_gpio_init_raw(3); break; case MRAA_INTEL_MINNOWBOARD_MAX: // there is no onboard LED that we can flash on the minnowboard max // but on the calamari lure pin 21 is an LED. If you don't have the // lure put an LED on pin 21 gpio = mraa_gpio_init(21); break; case MRAA_INTEL_JOULE_EXPANSION: gpio = mraa_gpio_init(101); break; default: gpio = mraa_gpio_init(13); } fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name); if (gpio == NULL) { fprintf(stdout, "Could not initilaize gpio\n"); return 1; } // on platforms with physical button use gpio_in if (platform == MRAA_INTEL_MINNOWBOARD_MAX) { gpio_in = mraa_gpio_init(14); if (gpio_in != NULL) { mraa_gpio_dir(gpio_in, MRAA_GPIO_IN); // S1 on minnowboardmax's calamari lure maps to pin 14, SW1 != S1 fprintf(stdout, "Press and hold S1 to stop, Press SW1 to shutdown!\n"); } } mraa_gpio_dir(gpio, MRAA_GPIO_OUT); for (;;) { if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) { return 0; } ledstate = !ledstate; mraa_gpio_write(gpio, !ledstate); sleep(1); } return 0; }
mraa_result_t mraa_intel_edison_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode) { if (dev->value_fp != -1) { if (close(dev->value_fp) != 0) { return MRAA_ERROR_INVALID_RESOURCE; } dev->value_fp = -1; } mraa_gpio_context pullup_e; pullup_e = mraa_gpio_init_raw(pullup_map[dev->phy_pin]); if (pullup_e == NULL) { return MRAA_ERROR_INVALID_RESOURCE; } if (mraa_gpio_dir(pullup_e, MRAA_GPIO_IN) != MRAA_SUCCESS) { syslog(LOG_ERR, "edison: Failed to set gpio mode-pullup"); mraa_gpio_close(pullup_e); return MRAA_ERROR_INVALID_RESOURCE; } int value = -1; switch (mode) { case MRAA_GPIO_STRONG: break; case MRAA_GPIO_PULLUP: value = 1; break; case MRAA_GPIO_PULLDOWN: value = 0; break; case MRAA_GPIO_HIZ: return MRAA_SUCCESS; break; default: return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED; } if (value != -1) { if (mraa_gpio_dir(pullup_e, MRAA_GPIO_OUT) != MRAA_SUCCESS) { syslog(LOG_ERR, "edison: Error setting pullup"); mraa_gpio_close(pullup_e); return MRAA_ERROR_INVALID_RESOURCE; } if (mraa_gpio_write(pullup_e, value) != MRAA_SUCCESS) { syslog(LOG_ERR, "edison: Error setting pullup"); mraa_gpio_close(pullup_e); return MRAA_ERROR_INVALID_RESOURCE; } } return mraa_gpio_close(pullup_e); }
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; }
int main(int argc, char **argv) { mraa_platform_t platform = mraa_get_platform_type(); mraa_gpio_context gpio, gpio_in = NULL; char* board_name = mraa_get_platform_name(); int ledstate = 0; switch (platform) { case MRAA_INTEL_GALILEO_GEN1: gpio = mraa_gpio_init_raw(3); break; case MRAA_INTEL_MINNOWBOARD_MAX: gpio = mraa_gpio_init(21); break; default: gpio = mraa_gpio_init(13); } fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s\n", mraa_get_version(), board_name); if (gpio == NULL) { fprintf(stdout, "Could not initilaize gpio\n"); return 1; } // on platforms with physical button use gpio_in if (platform == MRAA_INTEL_MINNOWBOARD_MAX) { gpio_in = mraa_gpio_init(14); if (gpio_in != NULL) { mraa_gpio_dir(gpio_in, MRAA_GPIO_IN); fprintf(stdout, "Press and hold S1 to stop\n"); } } mraa_gpio_dir(gpio, MRAA_GPIO_OUT); for (;;) { if (gpio_in != NULL && mraa_gpio_read(gpio_in) == 0) { return 0; } ledstate = !ledstate; mraa_gpio_write(gpio, !ledstate); sleep(1); } return 0; }
static 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; mraa_gpio_dir(mux_i, MRAA_GPIO_OUT); if (mraa_gpio_write(mux_i, meta.mux[mi].value) != MRAA_SUCCESS) return MRAA_ERROR_INVALID_RESOURCE; } return MRAA_SUCCESS; }
/** * Instantiates a Gpio object * * @param pin pin number to use * @param owner (optional) Set pin owner, default behaviour is to 'own' * the pin if we exported it. This means we will close it on destruct. * Otherwise it will get left open. This is only valid in sysfs use * cases * @param raw (optional) Raw pins will use gpiolibs pin numbering from * the kernel module. Note that you will not get any muxers set up for * you so this may not always work as expected. */ Gpio(int pin, bool owner = true, bool raw = false) { if (raw) { m_gpio = mraa_gpio_init_raw(pin); } else { m_gpio = mraa_gpio_init(pin); } if (m_gpio == NULL) { throw std::invalid_argument("Invalid GPIO pin specified"); } if (!owner) { mraa_gpio_owner(m_gpio, 0); } }
mraa_board_t* mraa_intel_edison_fab_c() { mraa_board_t* b = (mraa_board_t*) malloc(sizeof(mraa_board_t)); if (b == NULL) return NULL; // This seciton will also check if the arduino board is there tristate = mraa_gpio_init_raw(214); if (tristate == NULL) { syslog(LOG_INFO, "edison: Failed to initialise Arduino board TriState,\ assuming Intel Edison Miniboard\n"); if (mraa_intel_edsion_miniboard(b) != MRAA_SUCCESS) { free(b); return NULL; } return b; }
mraa_board_t* mraa_intel_edison_fab_c() { mraa_board_t* b = (mraa_board_t*) calloc(1, sizeof(mraa_board_t)); if (b == NULL) { return NULL; } b->platform_name = PLATFORM_NAME; // This seciton will also check if the arduino board is there tristate = mraa_gpio_init_raw(214); if (tristate == NULL) { syslog(LOG_INFO, "edison: Failed to initialise Arduino board TriState,\ assuming Intel Edison Miniboard\n"); if (mraa_intel_edison_miniboard(b) != MRAA_SUCCESS) { goto error; } return b; }
mraa_result_t mraa_intel_edison_gpio_dir_pre(mraa_gpio_context dev, gpio_dir_t dir) { mraa_gpio_write(tristate, 0); if (dev->phy_pin >= 0) { int pin = dev->phy_pin; 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; int output_val = 0; if (dir == MRAA_GPIO_OUT) output_val = 1; if (mraa_gpio_write(output_e, output_val) != MRAA_SUCCESS) return MRAA_ERROR_INVALID_RESOURCE; } return MRAA_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_dir_pre(mraa_gpio_context dev, 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) { mraa_gpio_context output_e; output_e = mraa_gpio_init_raw(plat->pins[pin].gpio.output_enable); if (mraa_gpio_dir(output_e, 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(output_e, output_val) != MRAA_SUCCESS) return MRAA_ERROR_INVALID_RESOURCE; } } return MRAA_SUCCESS; }
mraa_gpio_context mraa_gpio_init(int pin) { if (plat == NULL) { syslog(LOG_ERR, "gpio: platform not initialised"); return NULL; } if (pin < 0 || pin > plat->phy_pin_count) { syslog(LOG_ERR, "gpio: pin %i beyond platform definition", pin); return NULL; } if (plat->pins[pin].capabilites.gpio != 1) { syslog(LOG_ERR, "gpio: pin %i not capable of gpio", pin); return NULL; } if (plat->pins[pin].gpio.mux_total > 0) { if (mraa_setup_mux_mapped(plat->pins[pin].gpio) != MRAA_SUCCESS) { syslog(LOG_ERR, "gpio: unable to setup muxes"); return NULL; } } mraa_gpio_context r = mraa_gpio_init_raw(plat->pins[pin].gpio.pinmap); if (r == NULL) { syslog(LOG_CRIT, "gpio: mraa_gpio_init_raw(%d) returned error", pin); return NULL; } r->phy_pin = pin; if (advance_func->gpio_init_post != NULL) { mraa_result_t ret = advance_func->gpio_init_post(r); if (ret != MRAA_SUCCESS) { free(r); return NULL; } } return r; }
static mraa_result_t mraa_intel_edison_misc_spi() { mraa_gpio_write(tristate, 0); mraa_gpio_context io10_p1 = mraa_gpio_init_raw(263); mraa_gpio_context io10_p2 = mraa_gpio_init_raw(240); mraa_gpio_context io11_p1 = mraa_gpio_init_raw(262); mraa_gpio_context io11_p2 = mraa_gpio_init_raw(241); mraa_gpio_context io12_p1 = mraa_gpio_init_raw(242); mraa_gpio_context io13_p1 = mraa_gpio_init_raw(243); mraa_gpio_dir(io10_p1, MRAA_GPIO_OUT); mraa_gpio_dir(io10_p2, MRAA_GPIO_OUT); mraa_gpio_dir(io11_p1, MRAA_GPIO_OUT); mraa_gpio_dir(io11_p2, MRAA_GPIO_OUT); mraa_gpio_dir(io12_p1, MRAA_GPIO_OUT); mraa_gpio_dir(io13_p1, MRAA_GPIO_OUT); mraa_gpio_write(io10_p1, 1); mraa_gpio_write(io10_p2, 0); mraa_gpio_write(io11_p1, 1); mraa_gpio_write(io11_p2, 0); mraa_gpio_write(io12_p1, 0); mraa_gpio_write(io13_p1, 0); mraa_gpio_close(io10_p1); mraa_gpio_close(io10_p2); mraa_gpio_close(io11_p1); mraa_gpio_close(io11_p2); mraa_gpio_close(io12_p1); mraa_gpio_close(io13_p1); 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); mraa_gpio_write(tristate, 1); return MRAA_SUCCESS; }
mraa_result_t mraa_intel_edison_i2c_init_pre(unsigned int bus) { if(bus != 6) { syslog(LOG_ERR, "Edison: You can't use that bus :/"); return MRAA_ERROR_INVALID_RESOURCE; } 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); return MRAA_SUCCESS; }
mraa_result_t mraa_setup_mux_mapped(mraa_pin_t meta) { unsigned int mi; mraa_result_t ret; mraa_gpio_context mux_i = NULL; // avoids the unsigned comparison and we should never have a pin that is UINT_MAX! unsigned int last_pin = UINT_MAX; for (mi = 0; mi < meta.mux_total; mi++) { switch(meta.mux[mi].pincmd) { case PINCMD_UNDEFINED: // used for backward compatibility if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } // 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); ret = mraa_gpio_write(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SET_VALUE: if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } ret = mraa_gpio_write(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SET_DIRECTION: if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } ret = mraa_gpio_dir(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SET_IN_VALUE: if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } ret = mraa_gpio_dir(mux_i, MRAA_GPIO_IN); if(ret == MRAA_SUCCESS) ret = mraa_gpio_write(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SET_OUT_VALUE: if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } ret = mraa_gpio_dir(mux_i, MRAA_GPIO_OUT); if(ret == MRAA_SUCCESS) ret = mraa_gpio_write(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SET_MODE: if(meta.mux[mi].pin != last_pin) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } mux_i = mraa_gpio_init_raw(meta.mux[mi].pin); if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE; last_pin = meta.mux[mi].pin; } ret = mraa_gpio_mode(mux_i, meta.mux[mi].value); if(ret != MRAA_SUCCESS) { if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_ERROR_INVALID_RESOURCE; } break; case PINCMD_SKIP: break; default: syslog(LOG_NOTICE, "mraa_setup_mux_mapped: wrong command %d on pin %d with value %d", meta.mux[mi].pincmd, meta.mux[mi].pin, meta.mux[mi].value); break; } } if (mux_i != NULL) { mraa_gpio_owner(mux_i, 0); mraa_gpio_close(mux_i); } return MRAA_SUCCESS; }