The friendly Operating System for the Internet of Things
sam0_common/include/periph_cpu_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef CPU_PERIPH_COMMON_H
20 #define CPU_PERIPH_COMMON_H
21 
22 #include "cpu.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
31 #define CPUID_LEN (16U)
32 
37 #define PERIPH_SPI_NEEDS_INIT_CS
38 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
39 #define PERIPH_SPI_NEEDS_TRANSFER_REG
40 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
41 
47 #define HAVE_GPIO_T
48 typedef uint32_t gpio_t;
54 #define GPIO_UNDEF (0xffffffff)
55 
60 #define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y)
61 
62 #ifndef DOXYGEN
63 
67 #define HAVE_GPIO_FLANK_T
68 typedef enum {
69  GPIO_FALLING = 2,
70  GPIO_RISING = 1,
71  GPIO_BOTH = 3
72 } gpio_flank_t;
74 #endif /* ndef DOXYGEN */
75 
79 typedef enum {
80  GPIO_MUX_A = 0x0,
81  GPIO_MUX_B = 0x1,
82  GPIO_MUX_C = 0x2,
83  GPIO_MUX_D = 0x3,
84  GPIO_MUX_E = 0x4,
85  GPIO_MUX_F = 0x5,
86  GPIO_MUX_G = 0x6,
87  GPIO_MUX_H = 0x7,
88 } gpio_mux_t;
89 
93 typedef enum {
94  UART_PAD_RX_0 = 0x0,
95  UART_PAD_RX_1 = 0x1,
96  UART_PAD_RX_2 = 0x2,
97  UART_PAD_RX_3 = 0x3,
98 } uart_rxpad_t;
99 
103 typedef enum {
108 } uart_txpad_t;
109 
113 typedef enum {
118 } spi_misopad_t;
119 
123 typedef enum {
128 } spi_mosipad_t;
129 
134 #define HAVE_SPI_MODE_T
135 typedef enum {
136  SPI_MODE_0 = 0x0,
137  SPI_MODE_1 = 0x1,
138  SPI_MODE_2 = 0x2,
139  SPI_MODE_3 = 0x3
140 } spi_mode_t;
147 #define HAVE_SPI_CLK_T
148 typedef enum {
149  SPI_CLK_100KHZ = 100000U,
150  SPI_CLK_400KHZ = 400000U,
151  SPI_CLK_1MHZ = 1000000U,
152  SPI_CLK_5MHZ = 5000000U,
153  SPI_CLK_10MHZ = 10000000U
154 } spi_clk_t;
160 typedef struct {
161  SercomSpi *dev;
162  gpio_t miso_pin;
163  gpio_t mosi_pin;
164  gpio_t clk_pin;
170 } spi_conf_t;
171 
178 void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
179 
187 static inline int sercom_id(void *sercom)
188 {
189  return ((((uint32_t)sercom) >> 10) & 0x7) - 2;
190 }
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif /* CPU_PERIPH_COMMON_H */
197 
select peripheral function D
static int sercom_id(void *sercom)
Return the numeric id of a SERCOM device derived from its address.
emit interrupt on rising flank
Definition: gpio.h:114
select peripheral function E
gpio_mux_t clk_mux
alternate function for CLK pin (mux)
select peripheral function B
spi_misopad_t
Available values for SERCOM SPI MISO pad selection.
SercomSpi * dev
pointer to the used SPI device
uart_txpad_t
Available values for SERCOM UART TX pad selection.
select peripheral function F
drive the SPI bus with 100KHz
spi_mosipad_t mosi_pad
pad to use for MOSI and CLK line
drive the SPI bus with 400KHz
emit interrupt on both flanks
Definition: gpio.h:115
select peripheral function H
select peripheral function C
gpio_flank_t
Definition of possible active flanks for external interrupt mode.
Definition: gpio.h:112
gpio_mux_t mosi_mux
alternate function for MOSI pin (mux)
spi_misopad_t miso_pad
pad to use for MISO line
select peripheral function G
select peripheral function A
uart_rxpad_t
Available values for SERCOM UART RX pad selection.
gpio_mux_t miso_mux
alternate function for MISO pin (mux)
unsigned int gpio_t
GPIO type identifier.
Definition: gpio.h:69
gpio_mux_t
Available MUX values for configuring a pin's alternate function.
drive the SPI bus with 5MHz
drive the SPI bus with 10MHz
emit interrupt on falling flank
Definition: gpio.h:113
drive the SPI bus with 1MHz
void gpio_init_mux(gpio_t pin, gpio_mux_t mux)
Set up alternate function (PMUX setting) for a PORT pin.
use pad 3 for MOSI, pad 1 for SCK
use pad 0 for MOSI, pad 3 for SCK
spi_mosipad_t
Available values for SERCOM SPI MOSI and SCK pad selection.
use pad 2 for MOSI, pad 3 for SCK
SPI configuration data structure.
TX is pad 0, on top RTS on pad 2 and CTS on pad 3.
use pad 0 for MOSI, pad 1 for SCK