[sam3] add support for the PIO peripheral of all devices

Add register definitions and access functions.
This commit is contained in:
Felix Held
2014-03-01 21:32:37 +01:00
committed by Karl Palsson
parent 8a24685d0c
commit 235734ea42
26 changed files with 936 additions and 129 deletions

View File

@@ -29,7 +29,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -DSAM3A
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
OBJS = gpio_common_all.o gpio_common_3a3u3x.o pmc.o usart.o
VPATH += ../../usb:../../cm3:../common

View File

@@ -29,7 +29,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -DSAM3N
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
OBJS = gpio_common_all.o gpio_common_3n3s.o pmc.o usart.o
VPATH += ../../cm3:../common

View File

@@ -30,7 +30,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -DSAM3S
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
OBJS = gpio_common_all.o gpio_common_3n3s.o pmc.o usart.o
VPATH += ../../usb:../../cm3:../common

View File

@@ -30,7 +30,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -DSAM3U
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
OBJS = gpio_common_all.o gpio_common_3a3u3x.o pmc.o usart.o
VPATH += ../../usb:../../cm3:../common

View File

@@ -29,7 +29,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -DSAM3X
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = gpio.o pmc.o usart.o
OBJS = gpio_common_all.o gpio_common_3a3u3x.o pmc.o usart.o
VPATH += ../../usb:../../cm3:../common

View File

@@ -1,7 +1,20 @@
/** @addtogroup gpio_defines
*
* @brief <b>Access functions for the SAM3A/U/X I/O Controller</b>
* @ingroup SAM3_defines
* LGPL License Terms @ref lgpl_license
* @author @htmlonly &copy; @endhtmlonly 2012
* Gareth McMullin <gareth@blacksphere.co.nz>
* @author @htmlonly &copy; @endhtmlonly 2014
* Felix Held <felix-libopencm3@felixheld.de>
*
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2014 Felix Held <felix-libopencm3@felixheld.de>
*
* 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
@@ -19,16 +32,20 @@
#include <libopencm3/sam/gpio.h>
/** @brief Initialize GPIO pins
*
* @param[in] port uint32_t: GPIO Port base address
* @param[in] pin uint32_t
* @param[in] flags enum gpio_flags
*/
void gpio_init(uint32_t port, uint32_t pins, enum gpio_flags flags)
{
switch (flags & 3) {
switch (flags & 0x7) {
case GPIO_FLAG_GPINPUT:
/* input mode doesn't really exist, so we make a high
* output in open-drain mode
*/
PIO_SODR(port) = pins;
flags |= GPIO_FLAG_OPEN_DRAIN;
/* fall through */
PIO_ODR(port) = pins;
PIO_PER(port) = pins;
break;
case GPIO_FLAG_GPOUTPUT:
PIO_OER(port) = pins;
PIO_PER(port) = pins;
@@ -54,11 +71,3 @@ void gpio_init(uint32_t port, uint32_t pins, enum gpio_flags flags)
PIO_PUDR(port) = pins;
}
}
void gpio_toggle(uint32_t gpioport, uint32_t gpios)
{
uint32_t odsr = PIO_ODSR(gpioport);
PIO_CODR(gpioport) = odsr & gpios;
PIO_SODR(gpioport) = ~odsr & gpios;
}

View File

@@ -0,0 +1,86 @@
/** @addtogroup gpio_defines
*
* @brief <b>Access functions for the SAM3N/S I/O Controller</b>
* @ingroup SAM3_defines
* LGPL License Terms @ref lgpl_license
* @author @htmlonly &copy; @endhtmlonly 2012
* Gareth McMullin <gareth@blacksphere.co.nz>
* @author @htmlonly &copy; @endhtmlonly 2014
* Felix Held <felix-libopencm3@felixheld.de>
*
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2014 Felix Held <felix-libopencm3@felixheld.de>
*
* 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 <libopencm3/sam/gpio.h>
/** @brief Initialize GPIO pins
*
* @param[in] port uint32_t: GPIO Port base address
* @param[in] pin uint32_t
* @param[in] flags enum gpio_flags
*/
void gpio_init(uint32_t port, uint32_t pins, enum gpio_flags flags)
{
switch (flags & 0x7) {
case GPIO_FLAG_GPINPUT:
PIO_ODR(port) = pins;
PIO_PER(port) = pins;
break;
case GPIO_FLAG_GPOUTPUT:
PIO_OER(port) = pins;
PIO_PER(port) = pins;
break;
case GPIO_FLAG_PERIPHA:
PIO_ABCDSR1(port) &= ~pins;
PIO_ABCDSR2(port) &= ~pins;
PIO_PDR(port) = pins;
break;
case GPIO_FLAG_PERIPHB:
PIO_ABCDSR1(port) |= pins;
PIO_ABCDSR2(port) &= ~pins;
PIO_PDR(port) = pins;
break;
case GPIO_FLAG_PERIPHC:
PIO_ABCDSR1(port) &= ~pins;
PIO_ABCDSR2(port) |= pins;
PIO_PDR(port) = pins;
break;
case GPIO_FLAG_PERIPHD:
PIO_ABCDSR1(port) |= pins;
PIO_ABCDSR2(port) |= pins;
PIO_PDR(port) = pins;
break;
}
if (flags & GPIO_FLAG_OPEN_DRAIN) {
PIO_MDER(port) = pins;
} else {
PIO_MDDR(port) = pins;
}
if (flags & GPIO_FLAG_PULL_UP) {
PIO_PUER(port) = pins;
} else {
PIO_PUDR(port) = pins;
}
}

View File

@@ -0,0 +1,66 @@
/** @addtogroup gpio_defines
*
* @brief <b>Access functions for the SAM3 I/O Controller</b>
* @ingroup SAM3_defines
* LGPL License Terms @ref lgpl_license
* @author @htmlonly &copy; @endhtmlonly 2012
* Gareth McMullin <gareth@blacksphere.co.nz>
* @author @htmlonly &copy; @endhtmlonly 2014
* Felix Held <felix-libopencm3@felixheld.de>
*
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2014 Felix Held <felix-libopencm3@felixheld.de>
*
* 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 <libopencm3/sam/gpio.h>
/** @brief Atomic set output
*
* @param[in] gpioport uint32_t: GPIO Port base address
* @param[in] gpios uint32_t
*/
void gpio_set(uint32_t gpioport, uint32_t gpios)
{
PIO_SODR(gpioport) = gpios;
}
/** @brief Atomic clear output
*
* @param[in] gpioport uint32_t: GPIO Port base address
* @param[in] gpios uint32_t
*/
void gpio_clear(uint32_t gpioport, uint32_t gpios)
{
PIO_CODR(gpioport) = gpios;
}
/** @brief Toggle output
*
* @param[in] gpioport uint32_t: GPIO Port base address
* @param[in] gpios uint32_t
*/
void gpio_toggle(uint32_t gpioport, uint32_t gpios)
{
uint32_t odsr = PIO_ODSR(gpioport);
PIO_CODR(gpioport) = odsr & gpios;
PIO_SODR(gpioport) = ~odsr & gpios;
}