vf6xx: merge gpio/uart examples
The plain "uart" example was just a slightly less featured version. Compile tested only!
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
## along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
##
|
##
|
||||||
|
|
||||||
BINARY = gpio
|
BINARY = uart-gpio
|
||||||
|
|
||||||
LDSCRIPT = ../colibri-vf61.ld
|
LDSCRIPT = ../colibri-vf61.ld
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@ static const uint32_t gpio_in = IOMUXC_PAD(MUX_MODE_ALT0, SPEED_LOW, \
|
|||||||
DSE_150OHM, PUS_PU_100KOHM, IOMUXC_IBE);
|
DSE_150OHM, PUS_PU_100KOHM, IOMUXC_IBE);
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len);
|
int _write(int file, char *ptr, int len);
|
||||||
void sys_tick_handler(void);
|
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len)
|
int _write(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
@@ -50,7 +49,7 @@ int _write(int file, char *ptr, int len)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uart_init()
|
static void uart_init(void)
|
||||||
{
|
{
|
||||||
ccm_clock_gate_enable(CG9_UART2);
|
ccm_clock_gate_enable(CG9_UART2);
|
||||||
uart_enable(UART2);
|
uart_enable(UART2);
|
||||||
@@ -61,6 +60,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int old_state = -1;
|
int old_state = -1;
|
||||||
int new_state = 0;
|
int new_state = 0;
|
||||||
|
int i = 0;
|
||||||
|
float f = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
/* Init Clock Control and UART */
|
/* Init Clock Control and UART */
|
||||||
@@ -79,14 +80,17 @@ int main(void)
|
|||||||
/*
|
/*
|
||||||
* Read input GPIO in a loop and print changes
|
* Read input GPIO in a loop and print changes
|
||||||
* A jumper between PTC3<=> PTC2 can be used to set PTC2 to high
|
* A jumper between PTC3<=> PTC2 can be used to set PTC2 to high
|
||||||
|
* print integer and floating point counters as well, just for fun.
|
||||||
*/
|
*/
|
||||||
while (1) {
|
while (1) {
|
||||||
new_state = gpio_get(PTC2);
|
new_state = gpio_get(PTC2);
|
||||||
if (old_state != new_state) {
|
if (old_state != new_state) {
|
||||||
printf("GPIO %d is %s\r\n", PTC2,
|
printf("loop: %d (step: %f) GPIO %d is %s\r\n",
|
||||||
new_state ? "high" : "low");
|
i, f, PTC2, new_state ? "high" : "low");
|
||||||
old_state = new_state;
|
old_state = new_state;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
f += 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
##
|
|
||||||
## 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 = uart
|
|
||||||
|
|
||||||
LDSCRIPT = ../colibri-vf61.ld
|
|
||||||
|
|
||||||
include ../Makefile.include
|
|
||||||
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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>
|
|
||||||
|
|
||||||
int _write(int file, char *ptr, int len);
|
|
||||||
|
|
||||||
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(void)
|
|
||||||
{
|
|
||||||
ccm_clock_gate_enable(CG9_UART2);
|
|
||||||
uart_enable(UART2);
|
|
||||||
uart_set_baudrate(UART2, 115200);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int counter = 0;
|
|
||||||
float fcounter = 0.0;
|
|
||||||
double dcounter = 0.0;
|
|
||||||
|
|
||||||
ccm_calculate_clocks();
|
|
||||||
uart_init();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write Hello World an integer, float and double all over
|
|
||||||
* again while incrementing the numbers.
|
|
||||||
*/
|
|
||||||
while (1) {
|
|
||||||
printf("Hello World! %i %f %f\r\n", counter, fcounter,
|
|
||||||
dcounter);
|
|
||||||
counter++;
|
|
||||||
fcounter += 0.01;
|
|
||||||
dcounter += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user