vf6xx: add GPIO example
This example muxes two pins as GPIO and enables one GPIO (logical high). The other GPIO is then read in the main loop. One can use a jumper to bridge the two GPIOs to see that also reading succeeds.
This commit is contained in:
committed by
Karl Palsson
parent
0b9e7d0d5d
commit
1123768e78
26
examples/vf6xx/colibri-vf61/gpio/Makefile
Normal file
26
examples/vf6xx/colibri-vf61/gpio/Makefile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
##
|
||||||
|
## This file is part of the libopencm3 project.
|
||||||
|
##
|
||||||
|
## Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
## Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
##
|
||||||
|
## 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 <http://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
BINARY = gpio
|
||||||
|
|
||||||
|
LDSCRIPT = ../colibri-vf61.ld
|
||||||
|
|
||||||
|
include ../Makefile.include
|
||||||
|
|
||||||
95
examples/vf6xx/colibri-vf61/gpio/gpio.c
Normal file
95
examples/vf6xx/colibri-vf61/gpio/gpio.c
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the libopencm3 project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||||
|
* Copyright (C) 2014 Stefan Agner <stefan@agner.ch>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libopencm3/cm3/common.h>
|
||||||
|
#include <libopencm3/vf6xx/ccm.h>
|
||||||
|
#include <libopencm3/vf6xx/uart.h>
|
||||||
|
#include <libopencm3/vf6xx/gpio.h>
|
||||||
|
#include <libopencm3/vf6xx/iomuxc.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user