diff --git a/examples/vf6xx/colibri-vf61/gpio/Makefile b/examples/vf6xx/colibri-vf61/gpio/Makefile new file mode 100644 index 0000000..bf6884c --- /dev/null +++ b/examples/vf6xx/colibri-vf61/gpio/Makefile @@ -0,0 +1,26 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2009 Uwe Hermann +## Copyright (C) 2014 Stefan Agner +## +## This library is free software: you can redistribute it and/or modify +## it under the terms of the GNU Lesser General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public License +## along with this library. If not, see . +## + +BINARY = gpio + +LDSCRIPT = ../colibri-vf61.ld + +include ../Makefile.include + diff --git a/examples/vf6xx/colibri-vf61/gpio/gpio.c b/examples/vf6xx/colibri-vf61/gpio/gpio.c new file mode 100644 index 0000000..7cbc933 --- /dev/null +++ b/examples/vf6xx/colibri-vf61/gpio/gpio.c @@ -0,0 +1,95 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2014 Stefan Agner + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + + +static const uint32_t gpio_out = IOMUXC_PAD(MUX_MODE_ALT0, SPEED_LOW, \ + DSE_150OHM, PUS_PU_100KOHM, IOMUXC_OBE | IOMUXC_IBE); + +static const uint32_t gpio_in = IOMUXC_PAD(MUX_MODE_ALT0, SPEED_LOW, \ + DSE_150OHM, PUS_PU_100KOHM, IOMUXC_IBE); + +int _write(int file, char *ptr, int len); +void sys_tick_handler(void); + +int _write(int file, char *ptr, int len) +{ + int i; + + if (file == 1) { + for (i = 0; i < len; i++) + uart_send_blocking(UART2, ptr[i]); + return i; + } + + errno = EIO; + return -1; +} + +static void uart_init() +{ + ccm_clock_gate_enable(CG9_UART2); + uart_enable(UART2); + uart_set_baudrate(UART2, 115200); +} + +int main(void) +{ + int old_state = -1; + int new_state = 0; + + + /* Init Clock Control and UART */ + ccm_calculate_clocks(); + uart_init(); + + /* Iris Carrier Board, X16, Pin 15 */ + iomuxc_mux(PTC3, gpio_out); + + /* Iris Carrier Board, X16, Pin 16 */ + iomuxc_mux(PTC2, gpio_in); + + gpio_set(PTC3); + printf("GPIO %d is %s\r\n", PTC3, gpio_get(PTC3) ? "high" : "low"); + + /* + * Read input GPIO in a loop and print changes + * A jumper between PTC3<=> PTC2 can be used to set PTC2 to high + */ + while (1) { + new_state = gpio_get(PTC2); + if (old_state != new_state) { + printf("GPIO %d is %s\r\n", PTC2, + new_state ? "high" : "low"); + old_state = new_state; + } + } + + + return 0; +} +