[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

@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_GPIO_H
#define LIBOPENCM3_GPIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/pio.h>
#include <libopencm3/sam/common/gpio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,27 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_PIO_H
#define LIBOPENCM3_PIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/common/pio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_GPIO_H
#define LIBOPENCM3_GPIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/pio.h>
#include <libopencm3/sam/common/gpio_common_3n3s.h>
#endif

View File

@ -0,0 +1,27 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_PIO_H
#define LIBOPENCM3_PIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/common/pio_common_3n3s.h>
#endif

View File

@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_GPIO_H
#define LIBOPENCM3_GPIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/pio.h>
#include <libopencm3/sam/common/gpio_common_3n3s.h>
#endif

View File

@ -0,0 +1,47 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_PIO_H
#define LIBOPENCM3_PIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/common/pio_common_3n3s.h>
/* --- PIO registers ----------------------------------------------------- */
/* Parallel Capture Mode Register */
#define PIO_PCMR(port) MMIO32((port) + 0x0150)
/* Parallel Capture Interrupt Enable Register */
#define PIO_PCIER(port) MMIO32((port) + 0x0154)
/* Parallel Capture Interrupt Disable Register */
#define PIO_PCIDR(port) MMIO32((port) + 0x0158)
/* Parallel Capture Interrupt Mask Register */
#define PIO_PCIMR(port) MMIO32((port) + 0x015C)
/* Parallel Capture Interrupt Status Register */
#define PIO_PCISR(port) MMIO32((port) + 0x0160)
/* Parallel Capture Reception Holding Register */
#define PIO_PCRHR(port) MMIO32((port) + 0x0164)
#endif

View File

@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_GPIO_H
#define LIBOPENCM3_GPIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/pio.h>
#include <libopencm3/sam/common/gpio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,27 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_PIO_H
#define LIBOPENCM3_PIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/common/pio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,28 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_GPIO_H
#define LIBOPENCM3_GPIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/pio.h>
#include <libopencm3/sam/common/gpio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,27 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
#ifndef LIBOPENCM3_PIO_H
#define LIBOPENCM3_PIO_H
#include <libopencm3/sam/memorymap.h>
#include <libopencm3/sam/common/pio_common_3a3u3x.h>
#endif

View File

@ -0,0 +1,52 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2013 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H
The order of header inclusion is important. gpio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_GPIO_H)
#ifndef LIBOPENCM3_GPIO_COMMON_3A3U3X_H
#define LIBOPENCM3_GPIO_COMMON_3A3U3X_H
#include <libopencm3/sam/common/gpio_common_all.h>
/* flags may be or'd together, but only contain one of
* GPOUTPUT, PERIPHA and PERIPHB */
enum gpio_flags {
GPIO_FLAG_GPINPUT = 0,
GPIO_FLAG_GPOUTPUT = 1,
GPIO_FLAG_PERIPHA = 2,
GPIO_FLAG_PERIPHB = 3,
GPIO_FLAG_OPEN_DRAIN = (1 << 3),
GPIO_FLAG_PULL_UP = (1 << 4),
};
void gpio_init(uint32_t gpioport, uint32_t pins, enum gpio_flags flags);
#endif
#else
#warning "gpio_common_3a3u3x.h should not be included explicitly, only via gpio.h"
#endif

View File

@ -0,0 +1,54 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2013 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H
The order of header inclusion is important. gpio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_GPIO_H)
#ifndef LIBOPENCM3_GPIO_COMMON_3N3S_H
#define LIBOPENCM3_GPIO_COMMON_3N3S_H
#include <libopencm3/sam/common/gpio_common_all.h>
/* flags may be or'd together, but only contain one of
* GPOUTPUT, PERIPHA, PERIPHB, PERIPHC and PERIPHD */
enum gpio_flags {
GPIO_FLAG_GPINPUT = 0,
GPIO_FLAG_GPOUTPUT = 1,
GPIO_FLAG_PERIPHA = 2,
GPIO_FLAG_PERIPHB = 3,
GPIO_FLAG_PERIPHC = 4,
GPIO_FLAG_PERIPHD = 5,
GPIO_FLAG_OPEN_DRAIN = (1 << 3),
GPIO_FLAG_PULL_UP = (1 << 4),
};
void gpio_init(uint32_t gpioport, uint32_t pins, enum gpio_flags flags);
#endif
#else
#warning "gpio_common_3n3s.h should not be included explicitly, only via gpio.h"
#endif

View File

@ -0,0 +1,41 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2013 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA GPIO.H
The order of header inclusion is important. gpio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_GPIO_H)
#ifndef LIBOPENCM3_GPIO_COMMON_ALL_H
#define LIBOPENCM3_GPIO_COMMON_ALL_H
#include <libopencm3/cm3/common.h>
void gpio_set(uint32_t gpioport, uint32_t gpios);
void gpio_clear(uint32_t gpioport, uint32_t gpios);
void gpio_toggle(uint32_t gpioport, uint32_t gpios);
#endif
#else
#warning "gpio_common_all.h should not be included explicitly, only via gpio.h"
#endif

View File

@ -0,0 +1,50 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PIO.H
The order of header inclusion is important. pio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_PIO_H)
#ifndef LIBOPENCM3_PIO_COMMON_3A3U3X_H
#define LIBOPENCM3_PIO_COMMON_3A3U3X_H
#include <libopencm3/sam/common/pio_common_all.h>
/* --- PIO registers ----------------------------------------------------- */
/* Peripheral AB Select Register */
#define PIO_ABSR(port) MMIO32((port) + 0x0070)
/* System Clock Glitch Input Filter Select Register */
#define PIO_SCIFSR(port) MMIO32((port) + 0x0080)
/* Debouncing Input Filter Select Register */
#define PIO_DIFSR(port) MMIO32((port) + 0x0084)
/* Glitch or Debouncing Input Filter Clock Selection Status Register */
#define PIO_IFDGSR(port) MMIO32((port) + 0x0088)
#endif
#else
#warning "pio_common_3a3u3x.h should not be included explicitly, only via pio.h"
#endif

View File

@ -0,0 +1,65 @@
/*
* This file is part of the libopencm3 project.
*
* 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PIO.H
The order of header inclusion is important. pio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_PIO_H)
#ifndef LIBOPENCM3_PIO_COMMON_3N3S_H
#define LIBOPENCM3_PIO_COMMON_3N3S_H
#include <libopencm3/sam/common/pio_common_all.h>
/* --- PIO registers ----------------------------------------------------- */
/* Peripheral Select Register 1 */
#define PIO_ABCDSR1(port) MMIO32((port) + 0x0070)
/* Peripheral Select Register 2 */
#define PIO_ABCDSR2(port) MMIO32((port) + 0x0074)
/* Input Filter Slow Clock Disable Register */
#define PIO_IFSCDR(port) MMIO32((port) + 0x0080)
/* Input Filter Slow Clock Enable Register */
#define PIO_IFSCER(port) MMIO32((port) + 0x0084)
/* Input Filter Slow Clock Status Register */
#define PIO_IFSCSR(port) MMIO32((port) + 0x0088)
/* Pad Pull-down Disable Register */
#define PIO_PPDDR(port) MMIO32((port) + 0x0090)
/* Pad Pull-down Enable Register */
#define PIO_PPDER(port) MMIO32((port) + 0x0094)
/* Pad Pull-down Status Register */
#define PIO_PPDSR(port) MMIO32((port) + 0x0098)
/* Schmitt Trigger Register */
#define PIO_SCHMITT(port) MMIO32((port) + 0x0100)
#endif
#else
#warning "pio_common_3n3s.h should not be included explicitly, only via pio.h"
#endif

View File

@ -0,0 +1,168 @@
/*
* 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/>.
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA PIO.H
The order of header inclusion is important. pio.h includes the device
specific memorymap.h header before including this header file.*/
#if defined(LIBOPENCM3_PIO_H)
#ifndef LIBOPENCM3_PIO_COMMON_ALL_H
#define LIBOPENCM3_PIO_COMMON_ALL_H
#include <libopencm3/cm3/common.h>
/* --- Convenience macros ------------------------------------------------ */
/* GPIO port base addresses (for convenience) */
#define PIOA PIOA_BASE
#define PIOB PIOB_BASE
#define PIOC PIOC_BASE
#define PIOD PIOD_BASE
#define PIOE PIOE_BASE
#define PIOF PIOF_BASE
#define PIOG PIOG_BASE
#define PIOH PIOH_BASE
/* --- PIO registers ----------------------------------------------------- */
/* PIO Enable Register */
#define PIO_PER(port) MMIO32((port) + 0x0000)
/* PIO Disable Register */
#define PIO_PDR(port) MMIO32((port) + 0x0004)
/* PIO Status Register */
#define PIO_PSR(port) MMIO32((port) + 0x0008)
/* Output Enable Register */
#define PIO_OER(port) MMIO32((port) + 0x0010)
/* Output Disable Register */
#define PIO_ODR(port) MMIO32((port) + 0x0014)
/* Output Status Register */
#define PIO_OSR(port) MMIO32((port) + 0x0018)
/* Glitch Input Filter Enable Register */
#define PIO_IFER(port) MMIO32((port) + 0x0020)
/* Glitch Input Filter Disable Register */
#define PIO_IFDR(port) MMIO32((port) + 0x0024)
/* Glitch Input Filter Status Register */
#define PIO_IFSR(port) MMIO32((port) + 0x0028)
/* Set Output Data Register */
#define PIO_SODR(port) MMIO32((port) + 0x0030)
/* Clear Output Data Register */
#define PIO_CODR(port) MMIO32((port) + 0x0034)
/* Output Data Status Register */
#define PIO_ODSR(port) MMIO32((port) + 0x0038)
/* Pin Data Status Register */
#define PIO_PDSR(port) MMIO32((port) + 0x003C)
/* Interrupt Enable Register */
#define PIO_IER(port) MMIO32((port) + 0x0040)
/* Interrupt Disable Register */
#define PIO_IDR(port) MMIO32((port) + 0x0044)
/* Interrupt Mask Register */
#define PIO_IMR(port) MMIO32((port) + 0x0048)
/* Interrupt Status Register */
#define PIO_ISR(port) MMIO32((port) + 0x004C)
/* Multi-driver Enable Register */
#define PIO_MDER(port) MMIO32((port) + 0x0050)
/* Multi-driver Disable Register */
#define PIO_MDDR(port) MMIO32((port) + 0x0054)
/* Multi-driver Status Register */
#define PIO_MDSR(port) MMIO32((port) + 0x0058)
/* Pull-up Disable Register */
#define PIO_PUDR(port) MMIO32((port) + 0x0060)
/* Pull-up Enable Register */
#define PIO_PUER(port) MMIO32((port) + 0x0064)
/* Pad Pull-up Status Register */
#define PIO_PUSR(port) MMIO32((port) + 0x0068)
/* Slow Clock Divider Debouncing Register */
#define PIO_SCDR(port) MMIO32((port) + 0x008C)
/* Output Write Enable */
#define PIO_OWER(port) MMIO32((port) + 0x00A0)
/* Output Write Disable */
#define PIO_OWDR(port) MMIO32((port) + 0x00A4)
/* Output Write Status Register */
#define PIO_OWSR(port) MMIO32((port) + 0x00A8)
/* Additional Interrupt Modes Enable Register */
#define PIO_AIMER(port) MMIO32((port) + 0x00B0)
/* Additional Interrupt Modes Disables Register */
#define PIO_AIMDR(port) MMIO32((port) + 0x00B4)
/* Additional Interrupt Modes Mask Register */
#define PIO_AIMMR(port) MMIO32((port) + 0x00B8)
/* Edge Select Register */
#define PIO_ESR(port) MMIO32((port) + 0x00C0)
/* Level Select Register */
#define PIO_LSR(port) MMIO32((port) + 0x00C4)
/* Edge/Level Status Register */
#define PIO_ELSR(port) MMIO32((port) + 0x00C8)
/* Falling Edge/Low Level Select Register */
#define PIO_FELLSR(port) MMIO32((port) + 0x00D0)
/* Rising Edge/High Level Select Register */
#define PIO_REHLSR(port) MMIO32((port) + 0x00D4)
/* Fall/Rise - Low/High Status Register */
#define PIO_FRLHSR(port) MMIO32((port) + 0x00D8)
/* Lock Status */
#define PIO_LOCKSR(port) MMIO32((port) + 0x00E0)
/* Write Protect Mode Register */
#define PIO_WPMR(port) MMIO32((port) + 0x00E4)
/* Write Protect Status Register */
#define PIO_WPSR(port) MMIO32((port) + 0x00E8)
#endif
#else
#warning "pio_common_all.h should not be included explicitly, only via pio.h"
#endif

View File

@ -1,7 +1,9 @@
/* This provides unification of code over SAM subfamilies */
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2013 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
@ -17,35 +19,16 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SAM3X_GPIO_H
#define SAM3X_GPIO_H
#include <libopencm3/sam/pio.h>
/* flags may be or'd together, but only contain one of
* GPOUTPUT, PERIPHA and PERIPHB */
enum gpio_flags {
GPIO_FLAG_GPINPUT = 0,
GPIO_FLAG_GPOUTPUT = 1,
GPIO_FLAG_PERIPHA = 2,
GPIO_FLAG_PERIPHB = 3,
GPIO_FLAG_OPEN_DRAIN = 4,
GPIO_FLAG_PULL_UP = 8,
};
void gpio_init(uint32_t gpioport, uint32_t pins, enum gpio_flags flags);
static inline void gpio_set(uint32_t gpioport, uint32_t gpios)
{
PIO_SODR(gpioport) = gpios;
}
static inline void gpio_clear(uint32_t gpioport, uint32_t gpios)
{
PIO_CODR(gpioport) = gpios;
}
void gpio_toggle(uint32_t gpioport, uint32_t gpios);
#if defined(SAM3A)
# include <libopencm3/sam/3a/gpio.h>
#elif defined(SAM3N)
# include <libopencm3/sam/3n/gpio.h>
#elif defined(SAM3S)
# include <libopencm3/sam/3s/gpio.h>
#elif defined(SAM3U)
# include <libopencm3/sam/3u/gpio.h>
#elif defined(SAM3X)
# include <libopencm3/sam/3x/gpio.h>
#else
# error "sam family not defined."
#endif

View File

@ -1,7 +1,9 @@
/* This provides unification of code over SAM subfamilies */
/*
* 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
@ -17,80 +19,16 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SAM_PIO_H
#define SAM_PIO_H
#include <libopencm3/cm3/common.h>
#include <libopencm3/sam/memorymap.h>
/* --- Convenience macros ------------------------------------------------ */
/* GPIO port base addresses (for convenience) */
#define PIOA PIOA_BASE
#define PIOB PIOB_BASE
#define PIOC PIOC_BASE
#define PIOD PIOD_BASE
#define PIOE PIOE_BASE
#define PIOF PIOF_BASE
#define PIOG PIOG_BASE
#define PIOH PIOH_BASE
/* --- PIO registers ----------------------------------------------------- */
#define PIO_PER(port) MMIO32((port) + 0x0000)
#define PIO_PDR(port) MMIO32((port) + 0x0004)
#define PIO_PSR(port) MMIO32((port) + 0x0008)
/* 0x000C - Reserved */
#define PIO_OER(port) MMIO32((port) + 0x0010)
#define PIO_ODR(port) MMIO32((port) + 0x0014)
#define PIO_OSR(port) MMIO32((port) + 0x0018)
/* 0x001C - Reserved */
#define PIO_IFER(port) MMIO32((port) + 0x0020)
#define PIO_IFDR(port) MMIO32((port) + 0x0024)
#define PIO_IFSR(port) MMIO32((port) + 0x0028)
/* 0x002C - Reserved */
#define PIO_SODR(port) MMIO32((port) + 0x0030)
#define PIO_CODR(port) MMIO32((port) + 0x0034)
#define PIO_ODSR(port) MMIO32((port) + 0x0038)
#define PIO_PDSR(port) MMIO32((port) + 0x003C)
#define PIO_IER(port) MMIO32((port) + 0x0040)
#define PIO_IDR(port) MMIO32((port) + 0x0044)
#define PIO_IMR(port) MMIO32((port) + 0x0048)
#define PIO_ISR(port) MMIO32((port) + 0x004C)
#define PIO_MDER(port) MMIO32((port) + 0x0050)
#define PIO_MDDR(port) MMIO32((port) + 0x0054)
#define PIO_MDSR(port) MMIO32((port) + 0x0058)
/* 0x005C - Reserved */
#define PIO_PUDR(port) MMIO32((port) + 0x0060)
#define PIO_PUER(port) MMIO32((port) + 0x0064)
#define PIO_PUSR(port) MMIO32((port) + 0x0068)
/* 0x006C - Reserved */
#define PIO_ABSR(port) MMIO32((port) + 0x0070)
/* 0x0074-0x007C - Reserved */
#define PIO_SCIFSR(port) MMIO32((port) + 0x0080)
#define PIO_DIFSR(port) MMIO32((port) + 0x0084)
#define PIO_IFDGSR(port) MMIO32((port) + 0x0088)
#define PIO_SCDR(port) MMIO32((port) + 0x008C)
/* 0x0090-0x009C - Reserved */
#define PIO_OWER(port) MMIO32((port) + 0x00A0)
#define PIO_OWDR(port) MMIO32((port) + 0x00A4)
#define PIO_OWSR(port) MMIO32((port) + 0x00A8)
/* 0x00AC - Reserved */
#define PIO_AIMER(port) MMIO32((port) + 0x00B0)
#define PIO_AIMDR(port) MMIO32((port) + 0x00B4)
#define PIO_AIMMR(port) MMIO32((port) + 0x00B8)
/* 0x00BC - Reserved */
#define PIO_ESR(port) MMIO32((port) + 0x00C0)
#define PIO_LSR(port) MMIO32((port) + 0x00C4)
#define PIO_ELSR(port) MMIO32((port) + 0x00C8)
/* 0x00CC - Reserved */
#define PIO_FELLSR(port) MMIO32((port) + 0x00D0)
#define PIO_REHLSR(port) MMIO32((port) + 0x00D4)
#define PIO_FRLHSR(port) MMIO32((port) + 0x00D8)
/* 0x00DC - Reserved */
#define PIO_LOCKSR(port) MMIO32((port) + 0x00E0)
#define PIO_WPMR(port) MMIO32((port) + 0x00E4)
#define PIO_WPSR(port) MMIO32((port) + 0x00E8)
/* 0x00EC-0x0144 - Reserved */
#if defined(SAM3A)
# include <libopencm3/sam/3a/pio.h>
#elif defined(SAM3N)
# include <libopencm3/sam/3n/pio.h>
#elif defined(SAM3S)
# include <libopencm3/sam/3s/pio.h>
#elif defined(SAM3U)
# include <libopencm3/sam/3u/pio.h>
#elif defined(SAM3X)
# include <libopencm3/sam/3x/pio.h>
#else
# error "sam family not defined."
#endif

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;
}