static void startup(void) { const char **itr; int pin = parse_cmdline_pin(); if (pin < 0) pin = parse_kcmdline_pin(); if (pin >= 0) { struct sol_gpio_config cfg = { .api_version = SOL_GPIO_CONFIG_API_VERSION, .dir = SOL_GPIO_DIR_OUT, }; gpio = sol_gpio_open(pin, &cfg); if (gpio) printf("blinking led on gpio pin=%d\n", pin); else fprintf(stderr, "failed to open gpio pin=%d for writing.\n", pin); } timeout = sol_timeout_add(1000, on_timeout, NULL); sol_platform_add_state_monitor(on_platform_state_change, NULL); printf("platform state: %d\n", sol_platform_get_state()); for (itr = services; *itr != NULL; itr++) { sol_platform_add_service_monitor(on_service_change, *itr, NULL); printf("service %s state: %d\n", *itr, sol_platform_get_service_state(*itr)); } }
struct sol_gpio * open_led(void) { struct sol_gpio_config cfg = { .api_version = SOL_GPIO_CONFIG_API_VERSION, .dir = SOL_GPIO_DIR_OUT, }; return sol_gpio_open(31, &cfg); }
SOL_API struct sol_gpio * sol_gpio_open_by_label(const char *label, const struct sol_gpio_config *config) { uint32_t pin; _log_init(); #ifdef USE_PIN_MUX if (!sol_pin_mux_map(label, SOL_IO_GPIO, &pin)) return sol_gpio_open(pin, config); SOL_WRN("Label '%s' couldn't be mapped or can't be used as GPIO", label); #else SOL_INF("Pin Multiplexer support is necessary to open a 'board pin'."); (void)pin; #endif return NULL; }
static void startup(void) { const char **itr; int pin = parse_cmdline_pin(); if (pin < 0) pin = parse_kcmdline_pin(); if (pin >= 0) { struct sol_gpio_config cfg = { SOL_SET_API_VERSION(.api_version = SOL_GPIO_CONFIG_API_VERSION, ) .dir = SOL_GPIO_DIR_OUT, }; gpio = sol_gpio_open(pin, &cfg); if (gpio) printf("blinking led on gpio pin=%d\n", pin); else fprintf(stderr, "failed to open gpio pin=%d for writing.\n", pin); }
#include <soletta.h> #include <sol-gpio.h> static struct sol_gpio *led; static struct sol_timeout *timer; static bool timer_cb(void *data) { static bool toggle; toggle = !toggle; sol_gpio_write(led, toggle); return true; } static void startup(void) { struct sol_gpio_config led_conf = { SOL_SET_API_VERSION(.api_version = SOL_GPIO_CONFIG_API_VERSION, ) .dir = SOL_GPIO_DIR_OUT }; led = sol_gpio_open(25, &led_conf); SOL_NULL_CHECK(led); timer = sol_timeout_add(1000, timer_cb, NULL); } SOL_MAIN_DEFAULT(startup, NULL)