From 235734ea429d6c9ab756a5cf9a1e9d49ca291469 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Sat, 1 Mar 2014 21:32:37 +0100 Subject: [PATCH] [sam3] add support for the PIO peripheral of all devices Add register definitions and access functions. --- include/libopencm3/sam/3a/gpio.h | 28 +++ include/libopencm3/sam/3a/pio.h | 27 +++ include/libopencm3/sam/3n/gpio.h | 28 +++ include/libopencm3/sam/3n/pio.h | 27 +++ include/libopencm3/sam/3s/gpio.h | 28 +++ include/libopencm3/sam/3s/pio.h | 47 +++++ include/libopencm3/sam/3u/gpio.h | 28 +++ include/libopencm3/sam/3u/pio.h | 27 +++ include/libopencm3/sam/3x/gpio.h | 28 +++ include/libopencm3/sam/3x/pio.h | 27 +++ .../sam/common/gpio_common_3a3u3x.h | 52 ++++++ .../libopencm3/sam/common/gpio_common_3n3s.h | 54 ++++++ .../libopencm3/sam/common/gpio_common_all.h | 41 +++++ .../libopencm3/sam/common/pio_common_3a3u3x.h | 50 ++++++ .../libopencm3/sam/common/pio_common_3n3s.h | 65 +++++++ .../libopencm3/sam/common/pio_common_all.h | 168 ++++++++++++++++++ include/libopencm3/sam/gpio.h | 47 ++--- include/libopencm3/sam/pio.h | 92 ++-------- lib/sam/3a/Makefile | 2 +- lib/sam/3n/Makefile | 2 +- lib/sam/3s/Makefile | 2 +- lib/sam/3u/Makefile | 2 +- lib/sam/3x/Makefile | 2 +- .../common/{gpio.c => gpio_common_3a3u3x.c} | 39 ++-- lib/sam/common/gpio_common_3n3s.c | 86 +++++++++ lib/sam/common/gpio_common_all.c | 66 +++++++ 26 files changed, 936 insertions(+), 129 deletions(-) create mode 100644 include/libopencm3/sam/3a/gpio.h create mode 100644 include/libopencm3/sam/3a/pio.h create mode 100644 include/libopencm3/sam/3n/gpio.h create mode 100644 include/libopencm3/sam/3n/pio.h create mode 100644 include/libopencm3/sam/3s/gpio.h create mode 100644 include/libopencm3/sam/3s/pio.h create mode 100644 include/libopencm3/sam/3u/gpio.h create mode 100644 include/libopencm3/sam/3u/pio.h create mode 100644 include/libopencm3/sam/3x/gpio.h create mode 100644 include/libopencm3/sam/3x/pio.h create mode 100644 include/libopencm3/sam/common/gpio_common_3a3u3x.h create mode 100644 include/libopencm3/sam/common/gpio_common_3n3s.h create mode 100644 include/libopencm3/sam/common/gpio_common_all.h create mode 100644 include/libopencm3/sam/common/pio_common_3a3u3x.h create mode 100644 include/libopencm3/sam/common/pio_common_3n3s.h create mode 100644 include/libopencm3/sam/common/pio_common_all.h rename lib/sam/common/{gpio.c => gpio_common_3a3u3x.c} (67%) create mode 100644 lib/sam/common/gpio_common_3n3s.c create mode 100644 lib/sam/common/gpio_common_all.c diff --git a/include/libopencm3/sam/3a/gpio.h b/include/libopencm3/sam/3a/gpio.h new file mode 100644 index 00000000..852085e8 --- /dev/null +++ b/include/libopencm3/sam/3a/gpio.h @@ -0,0 +1,28 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_GPIO_H +#define LIBOPENCM3_GPIO_H + +#include +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3a/pio.h b/include/libopencm3/sam/3a/pio.h new file mode 100644 index 00000000..10fafae0 --- /dev/null +++ b/include/libopencm3/sam/3a/pio.h @@ -0,0 +1,27 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_PIO_H +#define LIBOPENCM3_PIO_H + +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3n/gpio.h b/include/libopencm3/sam/3n/gpio.h new file mode 100644 index 00000000..bb00ac48 --- /dev/null +++ b/include/libopencm3/sam/3n/gpio.h @@ -0,0 +1,28 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_GPIO_H +#define LIBOPENCM3_GPIO_H + +#include +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3n/pio.h b/include/libopencm3/sam/3n/pio.h new file mode 100644 index 00000000..cf06243f --- /dev/null +++ b/include/libopencm3/sam/3n/pio.h @@ -0,0 +1,27 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_PIO_H +#define LIBOPENCM3_PIO_H + +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3s/gpio.h b/include/libopencm3/sam/3s/gpio.h new file mode 100644 index 00000000..bb00ac48 --- /dev/null +++ b/include/libopencm3/sam/3s/gpio.h @@ -0,0 +1,28 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_GPIO_H +#define LIBOPENCM3_GPIO_H + +#include +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3s/pio.h b/include/libopencm3/sam/3s/pio.h new file mode 100644 index 00000000..a559f506 --- /dev/null +++ b/include/libopencm3/sam/3s/pio.h @@ -0,0 +1,47 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_PIO_H +#define LIBOPENCM3_PIO_H + +#include +#include + +/* --- 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 diff --git a/include/libopencm3/sam/3u/gpio.h b/include/libopencm3/sam/3u/gpio.h new file mode 100644 index 00000000..852085e8 --- /dev/null +++ b/include/libopencm3/sam/3u/gpio.h @@ -0,0 +1,28 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_GPIO_H +#define LIBOPENCM3_GPIO_H + +#include +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3u/pio.h b/include/libopencm3/sam/3u/pio.h new file mode 100644 index 00000000..10fafae0 --- /dev/null +++ b/include/libopencm3/sam/3u/pio.h @@ -0,0 +1,27 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_PIO_H +#define LIBOPENCM3_PIO_H + +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3x/gpio.h b/include/libopencm3/sam/3x/gpio.h new file mode 100644 index 00000000..852085e8 --- /dev/null +++ b/include/libopencm3/sam/3x/gpio.h @@ -0,0 +1,28 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_GPIO_H +#define LIBOPENCM3_GPIO_H + +#include +#include +#include + + +#endif diff --git a/include/libopencm3/sam/3x/pio.h b/include/libopencm3/sam/3x/pio.h new file mode 100644 index 00000000..10fafae0 --- /dev/null +++ b/include/libopencm3/sam/3x/pio.h @@ -0,0 +1,27 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#ifndef LIBOPENCM3_PIO_H +#define LIBOPENCM3_PIO_H + +#include +#include + + +#endif diff --git a/include/libopencm3/sam/common/gpio_common_3a3u3x.h b/include/libopencm3/sam/common/gpio_common_3a3u3x.h new file mode 100644 index 00000000..f397d3e7 --- /dev/null +++ b/include/libopencm3/sam/common/gpio_common_3a3u3x.h @@ -0,0 +1,52 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2013 Gareth McMullin + * COpyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + + +/* 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 diff --git a/include/libopencm3/sam/common/gpio_common_3n3s.h b/include/libopencm3/sam/common/gpio_common_3n3s.h new file mode 100644 index 00000000..348dd6e4 --- /dev/null +++ b/include/libopencm3/sam/common/gpio_common_3n3s.h @@ -0,0 +1,54 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2013 Gareth McMullin + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + + +/* 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 diff --git a/include/libopencm3/sam/common/gpio_common_all.h b/include/libopencm3/sam/common/gpio_common_all.h new file mode 100644 index 00000000..375e429c --- /dev/null +++ b/include/libopencm3/sam/common/gpio_common_all.h @@ -0,0 +1,41 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2013 Gareth McMullin + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + +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 diff --git a/include/libopencm3/sam/common/pio_common_3a3u3x.h b/include/libopencm3/sam/common/pio_common_3a3u3x.h new file mode 100644 index 00000000..45f016e1 --- /dev/null +++ b/include/libopencm3/sam/common/pio_common_3a3u3x.h @@ -0,0 +1,50 @@ +/* + * This file is part of the libopencm3 project. + * + * COpyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + +/* --- 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 diff --git a/include/libopencm3/sam/common/pio_common_3n3s.h b/include/libopencm3/sam/common/pio_common_3n3s.h new file mode 100644 index 00000000..09d54dcd --- /dev/null +++ b/include/libopencm3/sam/common/pio_common_3n3s.h @@ -0,0 +1,65 @@ +/* + * This file is part of the libopencm3 project. + * + * COpyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + +/* --- 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 diff --git a/include/libopencm3/sam/common/pio_common_all.h b/include/libopencm3/sam/common/pio_common_all.h new file mode 100644 index 00000000..2c262f4d --- /dev/null +++ b/include/libopencm3/sam/common/pio_common_all.h @@ -0,0 +1,168 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2012 Gareth McMullin + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +/* 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 + +/* --- 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 diff --git a/include/libopencm3/sam/gpio.h b/include/libopencm3/sam/gpio.h index 20fd9ada..79128987 100644 --- a/include/libopencm3/sam/gpio.h +++ b/include/libopencm3/sam/gpio.h @@ -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 + * Copyright (C) 2014 Felix Held * * 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 . */ -#ifndef SAM3X_GPIO_H -#define SAM3X_GPIO_H - -#include - -/* 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 +#elif defined(SAM3N) +# include +#elif defined(SAM3S) +# include +#elif defined(SAM3U) +# include +#elif defined(SAM3X) +# include +#else +# error "sam family not defined." #endif - diff --git a/include/libopencm3/sam/pio.h b/include/libopencm3/sam/pio.h index 3288718c..ac0ca3ae 100644 --- a/include/libopencm3/sam/pio.h +++ b/include/libopencm3/sam/pio.h @@ -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 + * Copyright (C) 2014 Felix Held * * 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 . */ -#ifndef SAM_PIO_H -#define SAM_PIO_H - -#include -#include - -/* --- 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 +#elif defined(SAM3N) +# include +#elif defined(SAM3S) +# include +#elif defined(SAM3U) +# include +#elif defined(SAM3X) +# include +#else +# error "sam family not defined." #endif diff --git a/lib/sam/3a/Makefile b/lib/sam/3a/Makefile index d3e558c3..219f4953 100644 --- a/lib/sam/3a/Makefile +++ b/lib/sam/3a/Makefile @@ -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 diff --git a/lib/sam/3n/Makefile b/lib/sam/3n/Makefile index e6d4ccf9..87418c12 100644 --- a/lib/sam/3n/Makefile +++ b/lib/sam/3n/Makefile @@ -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 diff --git a/lib/sam/3s/Makefile b/lib/sam/3s/Makefile index 45a8a7a9..231159cb 100644 --- a/lib/sam/3s/Makefile +++ b/lib/sam/3s/Makefile @@ -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 diff --git a/lib/sam/3u/Makefile b/lib/sam/3u/Makefile index e0939f3d..1a544dca 100644 --- a/lib/sam/3u/Makefile +++ b/lib/sam/3u/Makefile @@ -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 diff --git a/lib/sam/3x/Makefile b/lib/sam/3x/Makefile index de2fa285..23ef5892 100644 --- a/lib/sam/3x/Makefile +++ b/lib/sam/3x/Makefile @@ -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 diff --git a/lib/sam/common/gpio.c b/lib/sam/common/gpio_common_3a3u3x.c similarity index 67% rename from lib/sam/common/gpio.c rename to lib/sam/common/gpio_common_3a3u3x.c index 75929f82..0a430b4f 100644 --- a/lib/sam/common/gpio.c +++ b/lib/sam/common/gpio_common_3a3u3x.c @@ -1,7 +1,20 @@ +/** @addtogroup gpio_defines + * + * @brief Access functions for the SAM3A/U/X I/O Controller + * @ingroup SAM3_defines + * LGPL License Terms @ref lgpl_license + * @author @htmlonly © @endhtmlonly 2012 + * Gareth McMullin + * @author @htmlonly © @endhtmlonly 2014 + * Felix Held + * + */ + /* * This file is part of the libopencm3 project. * * Copyright (C) 2012 Gareth McMullin + * Copyright (C) 2014 Felix Held * * 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 + +/** @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; -} - diff --git a/lib/sam/common/gpio_common_3n3s.c b/lib/sam/common/gpio_common_3n3s.c new file mode 100644 index 00000000..034c20ff --- /dev/null +++ b/lib/sam/common/gpio_common_3n3s.c @@ -0,0 +1,86 @@ +/** @addtogroup gpio_defines + * + * @brief Access functions for the SAM3N/S I/O Controller + * @ingroup SAM3_defines + * LGPL License Terms @ref lgpl_license + * @author @htmlonly © @endhtmlonly 2012 + * Gareth McMullin + * @author @htmlonly © @endhtmlonly 2014 + * Felix Held + * + */ + +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2012 Gareth McMullin + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#include + + +/** @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; + } +} diff --git a/lib/sam/common/gpio_common_all.c b/lib/sam/common/gpio_common_all.c new file mode 100644 index 00000000..a89161ec --- /dev/null +++ b/lib/sam/common/gpio_common_all.c @@ -0,0 +1,66 @@ +/** @addtogroup gpio_defines + * + * @brief Access functions for the SAM3 I/O Controller + * @ingroup SAM3_defines + * LGPL License Terms @ref lgpl_license + * @author @htmlonly © @endhtmlonly 2012 + * Gareth McMullin + * @author @htmlonly © @endhtmlonly 2014 + * Felix Held + * + */ + +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2012 Gareth McMullin + * Copyright (C) 2014 Felix Held + * + * 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 . + */ + +#include + +/** @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; +} +