void leds_arch_set(unsigned char leds) { if (leds & LED_0) { gpio_pin_clear(LED_0_PORT, LED_0_PIN); } else { gpio_pin_set(LED_0_PORT, LED_0_PIN); } if (leds & LED_1) { gpio_pin_clear(LED_1_PORT, LED_1_PIN); } else { gpio_pin_set(LED_1_PORT, LED_1_PIN); } if (leds & LED_2) { gpio_pin_clear(LED_2_PORT, LED_2_PIN); } else { gpio_pin_set(LED_2_PORT, LED_2_PIN); } }
static void task_green(void* unused) { /* Blink LED and print dot mark each iteration */ while (1) { vTaskDelay(800); gpio_pin_set(LED_GPIO, LED_pin_green, 1); vTaskDelay(800); gpio_pin_set(LED_GPIO, LED_pin_green, 0); } }
void leds_off(uint8_t leds) { if (leds & LED_0) { gpio_pin_set(GPIO_B, GPIO_PIN_10); } if (leds & LED_1) { gpio_pin_set(GPIO_B, GPIO_PIN_12); } }
void leds_off(uint8_t leds) { int i; for (i = 0; i < leds_num; i++) { if (leds & (1 << i)) { gpio_pin_set(leds_gpio[i], leds_pin[i]); } } }
/* * Control an LED to show cfi activity */ static inline void cfi_led(int val) { #ifdef SD_LED gpio_pin_output(CFI_LED); if (val) { activity = 1; gpio_pin_set(CFI_LED); } else { gpio_pin_clr(CFI_LED); activity = 0; } #endif }
int gpio_pin_toggle(gpio_handle_t handle, gpio_pin_t pin) { gpio_value_t value; value = gpio_pin_get(handle, pin); if (value == GPIO_VALUE_INVALID) return (-1); value = !value; return (gpio_pin_set(handle, pin, value)); }
void platform_usb_enable() { // gpio_enable(GPIO_A); // gpio_set_alternate_function(GPIO_A, GPIO_PIN_11, GPIO_AF_10); // gpio_set_alternate_function(GPIO_A, GPIO_PIN_12, GPIO_AF_10); // external pull-up gpio_enable(GPIO_B); gpio_set_output(GPIO_B, GPIO_PIN_5); gpio_pin_set(GPIO_B, GPIO_PIN_5); // internal pull-up //syscfg_pmc_config(SYSCFG_PMC_USB, 1); nvic_enable_interrupt_line(NVIC_IRQ_LINE_USB_LP); }
static void sda_set(bool_t v) { gpio_pin_set(0, SHT_SDA, v); wait(); }
int main(int argc, char **argv) { int i; gpio_config_t pin; gpio_handle_t handle; char *ctlfile = NULL; int pinn, pinv, pin_type, ch; int flags, flag, ok; int config, list, name, toggle, verbose; config = toggle = verbose = list = name = pin_type = 0; while ((ch = getopt(argc, argv, "cf:lntvNp")) != -1) { switch (ch) { case 'c': config = 1; break; case 'f': ctlfile = optarg; break; case 'l': list = 1; break; case 'n': name = 1; break; case 'N': pin_type = PIN_TYPE_NAME; break; case'p': pin_type = PIN_TYPE_NUMBER; break; case 't': toggle = 1; break; case 'v': verbose = 1; break; default: usage(); break; } } argv += optind; argc -= optind; if (ctlfile == NULL) handle = gpio_open(0); else handle = gpio_open_device(ctlfile); if (handle == GPIO_INVALID_HANDLE) { perror("gpio_open"); exit(1); } if (list) { dump_pins(handle, verbose); gpio_close(handle); exit(0); } if (argc == 0) usage(); /* Find the pin number by the name */ switch (pin_type) { default: /* First test if it is a pin number */ pinn = str2int(argv[0], &ok); if (ok) { /* Test if we have any pin named by this number and tell the user */ if (get_pinnum_by_name(handle, argv[0]) != -1) fail("%s is also a pin name, use -p or -N\n", argv[0]); } else { /* Test if it is a name */ if ((pinn = get_pinnum_by_name(handle, argv[0])) == -1) fail("Can't find pin named \"%s\"\n", argv[0]); } break; case PIN_TYPE_NUMBER: pinn = str2int(argv[0], &ok); if (!ok) fail("Invalid pin number: %s\n", argv[0]); break; case PIN_TYPE_NAME: if ((pinn = get_pinnum_by_name(handle, argv[0])) == -1) fail("Can't find pin named \"%s\"\n", argv[0]); break; } /* Set the pin name. */ if (name) { if (argc != 2) usage(); if (gpio_pin_set_name(handle, pinn, argv[1]) < 0) { perror("gpio_pin_set_name"); exit(1); } exit(0); } if (toggle) { /* * -t pin assumes no additional arguments */ if (argc > 1) usage(); if (gpio_pin_toggle(handle, pinn) < 0) { perror("gpio_pin_toggle"); exit(1); } gpio_close(handle); exit(0); } if (config) { flags = 0; for (i = 1; i < argc; i++) { flag = str2cap(argv[i]); if (flag < 0) fail("Invalid flag: %s\n", argv[i]); flags |= flag; } pin.g_pin = pinn; pin.g_flags = flags; if (gpio_pin_set_flags(handle, &pin) < 0) { perror("gpio_pin_set_flags"); exit(1); } exit(0); } /* * Last two cases - set value or print value */ if ((argc == 0) || (argc > 2)) usage(); /* * Read pin value */ if (argc == 1) { pinv = gpio_pin_get(handle, pinn); if (pinv < 0) { perror("gpio_pin_get"); exit(1); } printf("%d\n", pinv); exit(0); } /* Is it valid number (0 or 1) ? */ pinv = str2int(argv[1], &ok); if (ok == 0 || ((pinv != 0) && (pinv != 1))) fail("Invalid pin value: %s\n", argv[1]); /* * Set pin value */ if (gpio_pin_set(handle, pinn, pinv) < 0) { perror("gpio_pin_set"); exit(1); } gpio_close(handle); exit(0); }
int gpio_pin_high(gpio_handle_t handle, gpio_pin_t pin) { return (gpio_pin_set(handle, pin, GPIO_VALUE_HIGH)); }
int gpio_pin_low(gpio_handle_t handle, gpio_pin_t pin) { return (gpio_pin_set(handle, pin, GPIO_VALUE_LOW)); }
int main(int argc, char **argv) { int i; gpio_config_t pin; gpio_handle_t handle; char *ctlfile = NULL; int pinn, pinv, ch; int flags, flag, ok; int config, toggle, verbose, list; config = toggle = verbose = list = pinn = 0; while ((ch = getopt(argc, argv, "c:f:lt:v")) != -1) { switch (ch) { case 'c': config = 1; pinn = str2int(optarg, &ok); if (!ok) fail("Invalid pin number: %s\n", optarg); break; case 'f': ctlfile = optarg; break; case 'l': list = 1; break; case 't': toggle = 1; pinn = str2int(optarg, &ok); if (!ok) fail("Invalid pin number: %s\n", optarg); break; case 'v': verbose = 1; break; default: usage(); break; } } argv += optind; argc -= optind; if (ctlfile == NULL) handle = gpio_open(0); else handle = gpio_open_device(ctlfile); if (handle == GPIO_INVALID_HANDLE) { perror("gpio_open"); exit(1); } if (list) { dump_pins(handle, verbose); gpio_close(handle); exit(0); } if (toggle) { /* * -t pin assumes no additional arguments */ if (argc > 0) { usage(); exit(1); } if (gpio_pin_toggle(handle, pinn) < 0) { perror("gpio_pin_toggle"); exit(1); } gpio_close(handle); exit(0); } if (config) { flags = 0; for (i = 0; i < argc; i++) { flag = str2cap(argv[i]); if (flag < 0) fail("Invalid flag: %s\n", argv[i]); flags |= flag; } pin.g_pin = pinn; pin.g_flags = flags; if (gpio_pin_set_flags(handle, &pin) < 0) { perror("gpio_pin_set_flags"); exit(1); } exit(0); } /* * Last two cases - set value or print value */ if ((argc == 0) || (argc > 2)) { usage(); exit(1); } pinn = str2int(argv[0], &ok); if (!ok) fail("Invalid pin number: %s\n", argv[0]); /* * Read pin value */ if (argc == 1) { pinv = gpio_pin_get(handle, pinn); if (pinv < 0) { perror("gpio_pin_get"); exit(1); } printf("%d\n", pinv); exit(0); } /* Is it valid number (0 or 1) ? */ pinv = str2int(argv[1], &ok); if (!ok || ((pinv != 0) && (pinv != 1))) fail("Invalid pin value: %s\n", argv[1]); /* * Set pin value */ if (gpio_pin_set(handle, pinn, pinv) < 0) { perror("gpio_pin_set"); exit(1); } gpio_close(handle); exit(0); }