libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
gpio_common_all.c
Go to the documentation of this file.
1/** @addtogroup gpio_defines
2 *
3 * @brief <b>Access functions for the SAM3 I/O Controller</b>
4 * @ingroup SAM3_defines
5 * LGPL License Terms @ref lgpl_license
6 * @author @htmlonly &copy; @endhtmlonly 2012
7 * Gareth McMullin <gareth@blacksphere.co.nz>
8 * @author @htmlonly &copy; @endhtmlonly 2014
9 * Felix Held <felix-libopencm3@felixheld.de>
10 *
11 */
12
13/*
14 * This file is part of the libopencm3 project.
15 *
16 * Copyright (C) 2012 Gareth McMullin <gareth@blacksphere.co.nz>
17 * Copyright (C) 2014 Felix Held <felix-libopencm3@felixheld.de>
18 *
19 * This library is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with this library. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33#include <libopencm3/sam/gpio.h>
34
35/** @brief Atomic set output
36 *
37 * @param[in] gpioport uint32_t: GPIO Port base address
38 * @param[in] gpios uint32_t
39 */
40void gpio_set(uint32_t gpioport, uint32_t gpios)
41{
42 PIO_SODR(gpioport) = gpios;
43}
44
45/** @brief Atomic clear output
46 *
47 * @param[in] gpioport uint32_t: GPIO Port base address
48 * @param[in] gpios uint32_t
49 */
50void gpio_clear(uint32_t gpioport, uint32_t gpios)
51{
52 PIO_CODR(gpioport) = gpios;
53}
54
55/** @brief Toggle output
56 *
57 * @param[in] gpioport uint32_t: GPIO Port base address
58 * @param[in] gpios uint32_t
59 */
60void gpio_toggle(uint32_t gpioport, uint32_t gpios)
61{
62 uint32_t odsr = PIO_ODSR(gpioport);
63 PIO_CODR(gpioport) = odsr & gpios;
64 PIO_SODR(gpioport) = ~odsr & gpios;
65}
66
void gpio_set(uint32_t gpioport, uint32_t gpios)
Atomic set output.
void gpio_clear(uint32_t gpioport, uint32_t gpios)
Atomic clear output.
void gpio_toggle(uint32_t gpioport, uint32_t gpios)
Toggle output.