void led_init(void) { port_init(); gpio_set_pin_mode(RED_LED_PORT, RED_LED_PIN, OUTPUT); gpio_set_pin_mode(GREEN_LED_PORT, GREEN_LED_PIN, OUTPUT); gpio_set_pin_mode(BLUE_LED_PORT, BLUE_LED_PIN, OUTPUT); GPIO_PIN_WRITE(RED_LED_PORT, RED_LED_PIN, HIGH); GPIO_PIN_WRITE(GREEN_LED_PORT, GREEN_LED_PIN, HIGH); GPIO_PIN_WRITE(BLUE_LED_PORT, BLUE_LED_PIN, HIGH); }
static void chip_init(st7735_t *screen) { gpio_set_pin_mode(screen->params.rst, GPIO_PM_OUTPUT); gpio_set_pin_mode(screen->params.cs, GPIO_PM_OUTPUT); gpio_set_pin_mode(screen->params.cd, GPIO_PM_OUTPUT); gpio_set_pin_mode(screen->params.backlight, GPIO_PM_OUTPUT); /* Reset */ gpio_digital_pulse(screen->params.rst, 0, 10); gpio_digital_write(screen->params.cd, 0); gpio_digital_write(screen->params.cs, 1); gpio_digital_write(screen->params.backlight, 1); /* Init SPI */ spi_init(screen->params.spi_port); spi_set_max_speed(screen->params.spi_port, 4000000); /* Send init sequence */ st7735_init_seq(screen); }
int gpio_set_port_mode(resource_t port, u16 mask, gpio_pin_mode_t mode) { u16 pin; if (RES_BASE(port) != GPIO_RESOURCE_ID_BASE) return -1; for (pin = 0; pin < GPIO_NUM_PORT_PINS; pin++) { if (!(mask & (1 << pin))) continue; if (gpio_set_pin_mode(GPIO_RES(GPIO(RES_MAJ(port), pin)), mode)) return -1; } return 0; }