static int hexiwear_kw40z_pinmux_init(struct device *dev) { ARG_UNUSED(dev); #ifdef CONFIG_PINMUX_MCUX_PORTB struct device *portb = device_get_binding(CONFIG_PINMUX_MCUX_PORTB_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTC struct device *portc = device_get_binding(CONFIG_PINMUX_MCUX_PORTC_NAME); #endif #ifdef CONFIG_UART_MCUX_LPUART_0 /* UART0 RX, TX */ pinmux_pin_set(portc, 6, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portc, 7, PORT_PCR_MUX(kPORT_MuxAlt4)); #endif #if CONFIG_I2C_1 /* I2C1 SCL, SDA */ pinmux_pin_set(portc, 6, PORT_PCR_MUX(kPORT_MuxAlt3) | PORT_PCR_PS_MASK); pinmux_pin_set(portc, 6, PORT_PCR_MUX(kPORT_MuxAlt3) | PORT_PCR_PS_MASK); #endif #if CONFIG_ADC /* ADC0_SE1 */ pinmux_pin_set(portb, 1, PORT_PCR_MUX(kPORT_PinDisabledOrAnalog)); #endif return 0; }
static int board_pinmux_init(struct device *dev) { struct device *muxa = device_get_binding(CONFIG_PINMUX_SAM0_A_LABEL); struct device *muxb = device_get_binding(CONFIG_PINMUX_SAM0_B_LABEL); ARG_UNUSED(dev); #if CONFIG_UART_SAM0_SERCOM0_BASE_ADDRESS /* SERCOM0 on RX=PA11, TX=PA10 */ pinmux_pin_set(muxa, 11, PINMUX_FUNC_C); pinmux_pin_set(muxa, 10, PINMUX_FUNC_C); #endif #if CONFIG_UART_SAM0_SERCOM5_BASE_ADDRESS /* SERCOM5 on RX=PB23, TX=PB22 */ pinmux_pin_set(muxb, 23, PINMUX_FUNC_D); pinmux_pin_set(muxb, 22, PINMUX_FUNC_D); #endif #if CONFIG_UART_SAM0_SERCOM1_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_UART_SAM0_SERCOM2_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_UART_SAM0_SERCOM3_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_UART_SAM0_SERCOM4_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_SPI_SAM0_SERCOM4_BASE_ADDRESS /* SPI SERCOM4 on MISO=PB12/pad 0, MOSI=PB10/pad 2, SCK=PB11/pad 3 */ pinmux_pin_set(muxb, 12, PINMUX_FUNC_C); pinmux_pin_set(muxb, 10, PINMUX_FUNC_D); pinmux_pin_set(muxb, 11, PINMUX_FUNC_D); #endif #if CONFIG_SPI_SAM0_SERCOM0_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_SPI_SAM0_SERCOM1_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_SPI_SAM0_SERCOM2_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_SPI_SAM0_SERCOM3_BASE_ADDRESS #error Pin mapping is not configured #endif #if CONFIG_SPI_SAM0_SERCOM5_BASE_ADDRESS #error Pin mapping is not configured #endif return 0; }
void taskA(void) { int rc1; int rc2; gpio = device_get_binding(CONFIG_GPIO_PCAL9535A_1_DEV_NAME); gpio_sus = device_get_binding(CONFIG_GPIO_SCH_1_DEV_NAME); i2c = device_get_binding(CONFIG_GPIO_PCAL9535A_1_I2C_MASTER_DEV_NAME); pinmux = device_get_binding(PINMUX_NAME); if (!i2c) { PRINT("I2C not found!!\n"); } else { rc1 = i2c_configure(i2c, (I2C_SPEED_FAST << 1) | I2C_MODE_MASTER); if (rc1 != DEV_OK) { PRINT("I2C configuration error: %d\n", rc1); } } if (!gpio) { PRINT("GPIO not found!!\n"); } else { rc1 = gpio_pin_configure(gpio, 6, GPIO_DIR_OUT); rc2 = gpio_pin_configure(gpio, 8, GPIO_DIR_OUT); if (rc1 != DEV_OK || rc2 != DEV_OK) { PRINT("GPIO config error %d, %d!!\n", rc1, rc2); } } if (!gpio_sus) { PRINT("Legacy GPIO not found!!\n"); } else { rc1 = gpio_pin_configure(gpio_sus, 5, GPIO_DIR_OUT); if (rc1 != DEV_OK) { PRINT("Legacy GPIO config error %d!!\n", rc1); } } if (!pinmux) { PRINT("Pinmux device not found!\n"); } else { /* * By default pin D13 (pin 5 on Legacy GPIO_SUS * is configured for input. To blink it, it needs to * be configured for output */ rc1 = pinmux_pin_set(pinmux, 13, PINMUX_FUNC_A); if (rc1 != DEV_OK) { PRINT("Pinmux config error %d!!\n", rc1); } } /* taskA gives its own semaphore, allowing it to say hello right away */ task_sem_give(TASKASEM); /* invoke routine that allows task to ping-pong hello messages with taskB */ helloLoop(__FUNCTION__, TASKASEM, TASKBSEM); }
static int frdm_k64f_pinmux_init(struct device *dev) { ARG_UNUSED(dev); #ifdef CONFIG_PINMUX_MCUX_PORTA struct device *porta = device_get_binding(CONFIG_PINMUX_MCUX_PORTA_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTB struct device *portb = device_get_binding(CONFIG_PINMUX_MCUX_PORTB_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTC struct device *portc = device_get_binding(CONFIG_PINMUX_MCUX_PORTC_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTD struct device *portd = device_get_binding(CONFIG_PINMUX_MCUX_PORTD_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTE struct device *porte = device_get_binding(CONFIG_PINMUX_MCUX_PORTE_NAME); #endif #ifdef CONFIG_UART_K20_PORT_0 /* UART0 RX, TX */ pinmux_pin_set(portb, 16, PORT_PCR_MUX(kPORT_MuxAlt3)); pinmux_pin_set(portb, 17, PORT_PCR_MUX(kPORT_MuxAlt3)); #endif #ifdef CONFIG_UART_K20_PORT_3 /* UART3 RX, TX */ pinmux_pin_set(portc, 16, PORT_PCR_MUX(kPORT_MuxAlt3)); pinmux_pin_set(portc, 17, PORT_PCR_MUX(kPORT_MuxAlt3)); #endif /* SW2 / FXOS8700 INT1 */ pinmux_pin_set(portc, 6, PORT_PCR_MUX(kPORT_MuxAsGpio)); /* FXOS8700 INT2 */ pinmux_pin_set(portc, 13, PORT_PCR_MUX(kPORT_MuxAsGpio)); /* SW3 */ pinmux_pin_set(porta, 4, PORT_PCR_MUX(kPORT_MuxAsGpio)); /* Red, green, blue LEDs */ pinmux_pin_set(portb, 22, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(porte, 26, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portb, 21, PORT_PCR_MUX(kPORT_MuxAsGpio)); #ifdef CONFIG_SPI_0 /* SPI0 CS0, SCK, SOUT, SIN */ pinmux_pin_set(portd, 0, PORT_PCR_MUX(kPORT_MuxAlt2)); pinmux_pin_set(portd, 1, PORT_PCR_MUX(kPORT_MuxAlt2)); pinmux_pin_set(portd, 2, PORT_PCR_MUX(kPORT_MuxAlt2)); pinmux_pin_set(portd, 3, PORT_PCR_MUX(kPORT_MuxAlt2)); #endif #if CONFIG_I2C_0 /* I2C0 SCL, SDA */ pinmux_pin_set(porte, 24, PORT_PCR_MUX(kPORT_MuxAlt5) | PORT_PCR_ODE_MASK); pinmux_pin_set(porte, 25, PORT_PCR_MUX(kPORT_MuxAlt5) | PORT_PCR_ODE_MASK); #endif #if CONFIG_ETH_MCUX_0 pinmux_pin_set(porta, 5, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 12, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 13, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 14, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 15, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 16, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 17, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(porta, 28, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portb, 0, PORT_PCR_MUX(kPORT_MuxAlt4) | PORT_PCR_ODE_MASK | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK); pinmux_pin_set(portb, 1, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portc, 16, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portc, 17, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portc, 18, PORT_PCR_MUX(kPORT_MuxAlt4)); pinmux_pin_set(portc, 19, PORT_PCR_MUX(kPORT_MuxAlt4)); #endif return 0; }
static int test_gpio(u32_t pin, u32_t func) { u32_t function; struct gpio_callback gpio_cb; struct device *pinmux = device_get_binding(PINMUX_NAME); if (!pinmux) { TC_PRINT("Cannot get PINMUX\n"); return TC_FAIL; } struct device *gpio_dev = device_get_binding(GPIO_DEV_NAME); if (!gpio_dev) { TC_PRINT("Cannot get GPIO device\n"); return TC_FAIL; } cb_triggered = false; /* 1. Configure PIN_OUT and set init voltage */ if (gpio_pin_configure(gpio_dev, GPIO_OUT, GPIO_DIR_OUT)) { TC_PRINT("PIN_OUT configure fail\n"); return TC_FAIL; } if (gpio_pin_write(gpio_dev, GPIO_OUT, 0)) { TC_PRINT("Set PIN_OUT init LOW fail\n"); return TC_FAIL; } /* 2. Configure PIN_IN and set callback */ if (gpio_pin_configure(gpio_dev, GPIO_IN, GPIO_DIR_IN | GPIO_INT | GPIO_INT_DEBOUNCE | GPIO_INT_LEVEL | GPIO_INT_ACTIVE_HIGH)) { TC_PRINT("PIN_IN configure fail\n"); return TC_FAIL; } gpio_init_callback(&gpio_cb, callback, BIT(GPIO_IN)); if (gpio_add_callback(gpio_dev, &gpio_cb)) { TC_PRINT("Set PIN_IN callback fail\n"); return TC_FAIL; } gpio_pin_enable_callback(gpio_dev, GPIO_IN); /* 3. Verify pinmux_pin_set() */ if (pinmux_pin_set(pinmux, pin, func)) { TC_PRINT("Fail to set pin func, %u : %u\n", pin, func); return TC_FAIL; } /* 4. Verify pinmux_pin_get() */ if (pinmux_pin_get(pinmux, pin, &function)) { TC_PRINT("Fail to get pin func\n"); return TC_FAIL; } /* 5. Verify the setting works */ if (function != func) { TC_PRINT("Error. PINMUX get doesn't match PINMUX set\n"); return TC_FAIL; } /* 6. Set PIN_OUT HIGH and verify pin func works */ if (gpio_pin_write(gpio_dev, GPIO_OUT, 1)) { TC_PRINT("Set PIN_OUT HIGH fail\n"); return TC_FAIL; } k_sleep(1000); if (cb_triggered) { TC_PRINT("GPIO callback is triggered\n"); return TC_PASS; } else { TC_PRINT("GPIO callback is not triggered\n"); return TC_FAIL; } }
static int board_pinmux_init(struct device *dev) { struct device *muxa = device_get_binding(DT_PINMUX_SAM0_A_LABEL); #if DT_SPI_SAM0_SERCOM4_BASE_ADDRESS struct device *muxb = device_get_binding(DT_PINMUX_SAM0_B_LABEL); #endif ARG_UNUSED(dev); #if DT_UART_SAM0_SERCOM0_BASE_ADDRESS /* SERCOM0 on RX=PA11/pad 3, TX=PA10/pad 2 */ pinmux_pin_set(muxa, 11, PINMUX_FUNC_C); pinmux_pin_set(muxa, 10, PINMUX_FUNC_C); #endif #if DT_UART_SAM0_SERCOM1_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_UART_SAM0_SERCOM2_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_UART_SAM0_SERCOM3_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_UART_SAM0_SERCOM4_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_UART_SAM0_SERCOM5_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_SPI_SAM0_SERCOM4_BASE_ADDRESS /* SPI SERCOM4 on MISO=PA12/pad 0, MOSI=PB10/pad 2, SCK=PB11/pad 3 */ pinmux_pin_set(muxa, 12, PINMUX_FUNC_D); pinmux_pin_set(muxb, 10, PINMUX_FUNC_D); pinmux_pin_set(muxb, 11, PINMUX_FUNC_D); #endif #if DT_SPI_SAM0_SERCOM0_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_SPI_SAM0_SERCOM1_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_SPI_SAM0_SERCOM2_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_SPI_SAM0_SERCOM3_BASE_ADDRESS #error Pin mapping is not configured #endif #if DT_SPI_SAM0_SERCOM5_BASE_ADDRESS #error Pin mapping is not configured #endif #ifdef CONFIG_USB_DC_SAM0 /* USB DP on PA25, USB DM on PA24 */ pinmux_pin_set(muxa, 25, PINMUX_FUNC_G); pinmux_pin_set(muxa, 24, PINMUX_FUNC_G); #endif return 0; }
static int twr_ke18f_pinmux_init(struct device *dev) { ARG_UNUSED(dev); #ifdef CONFIG_PINMUX_MCUX_PORTA __unused struct device *porta = device_get_binding(CONFIG_PINMUX_MCUX_PORTA_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTB __unused struct device *portb = device_get_binding(CONFIG_PINMUX_MCUX_PORTB_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTC __unused struct device *portc = device_get_binding(CONFIG_PINMUX_MCUX_PORTC_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTD __unused struct device *portd = device_get_binding(CONFIG_PINMUX_MCUX_PORTD_NAME); #endif #ifdef CONFIG_PINMUX_MCUX_PORTE __unused struct device *porte = device_get_binding(CONFIG_PINMUX_MCUX_PORTE_NAME); #endif /* LEDs */ pinmux_pin_set(portb, 5, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portc, 10, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portc, 11, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portc, 12, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portc, 13, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portd, 15, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portd, 16, PORT_PCR_MUX(kPORT_MuxAsGpio)); /* Buttons */ pinmux_pin_set(portd, 3, PORT_PCR_MUX(kPORT_MuxAsGpio)); pinmux_pin_set(portd, 6, PORT_PCR_MUX(kPORT_MuxAsGpio)); #ifdef CONFIG_UART_MCUX_LPUART_0 /* UART0 RX, TX */ pinmux_pin_set(portb, 0, PORT_PCR_MUX(kPORT_MuxAlt2)); pinmux_pin_set(portb, 1, PORT_PCR_MUX(kPORT_MuxAlt2)); #endif #ifdef CONFIG_BOARD_TWR_KE18F_FLEXIO_CLKOUT /* CLKOUT */ pinmux_pin_set(porte, 10, PORT_PCR_MUX(kPORT_MuxAlt2)); #endif return 0; }