Loading...
Searching...
No Matches
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
21#ifndef PERIPH_CPU_COMMON_H
22#define PERIPH_CPU_COMMON_H
23
24#include "cpu.h"
25#include "exti_config.h"
26#include "timer_config.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
35#define CPUID_LEN (16U)
36
41#define PERIPH_SPI_NEEDS_INIT_CS
42#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
43#ifndef MODULE_PERIPH_DMA
44#define PERIPH_SPI_NEEDS_TRANSFER_REG
45#define PERIPH_SPI_NEEDS_TRANSFER_REGS
46#endif
53#define PERIPH_I2C_NEED_READ_REG
54#define PERIPH_I2C_NEED_READ_REGS
55#define PERIPH_I2C_NEED_WRITE_REG
56#define PERIPH_I2C_NEED_WRITE_REGS
62#define PERIPH_I2C_MAX_BYTES_PER_FRAME 256
63
68#define HAVE_GPIO_T
69typedef uint32_t gpio_t;
75#define GPIO_UNDEF (0xffffffff)
76
81#ifdef MODULE_PERIPH_GPIO_FAST_READ
82#ifdef PORT_IOBUS_SEC
83#define GPIO_PIN(x, y) (((gpio_t)(&PORT_IOBUS_SEC->Group[x])) | y)
84#else /* Use IOBUS access when available */
85#define GPIO_PIN(x, y) (((gpio_t)(&PORT_IOBUS->Group[x])) | y)
86#endif /* PORT_IOBUS_SEC */
87#else
88#ifdef PORT_SEC
89#define GPIO_PIN(x, y) (((gpio_t)(&PORT_SEC->Group[x])) | y)
90#else
91#define GPIO_PIN(x, y) (((gpio_t)(&PORT->Group[x])) | y)
92#endif /* PORT_IOBUS_SEC */
93#endif
94
98enum {
99 PA = 0,
100 PB = 1,
101 PC = 2,
102 PD = 3,
103};
104
113#define GPIO_MODE(pr, ie, pe) (pr | (ie << 1) | (pe << 2))
114
115#ifndef DOXYGEN
119#define HAVE_GPIO_MODE_T
120typedef enum {
121 GPIO_IN = GPIO_MODE(0, 1, 0),
122 GPIO_IN_PD = GPIO_MODE(0, 1, 1),
123 GPIO_IN_PU = GPIO_MODE(1, 1, 1),
124 GPIO_OUT = GPIO_MODE(0, 0, 0),
125 GPIO_OD = 0xfe,
126 GPIO_OD_PU = 0xff
128
129#define HAVE_GPIO_SLEW_T
130typedef enum {
132 GPIO_SLEW_SLOW = 0,
133 GPIO_SLEW_FAST = 0,
136
137#define HAVE_GPIO_PULL_STRENGTH_T
138typedef enum {
140 GPIO_PULL_WEAK = 0,
144
145#define HAVE_GPIO_DRIVE_STRENGTH_T
146typedef enum {
148 GPIO_DRIVE_WEAK = 0,
152
153#define HAVE_GPIO_PULL_T
154typedef enum {
160
161#define HAVE_GPIO_STATE_T
162typedef enum {
170
171#define HAVE_GPIO_IRQ_TRIG_T
172typedef enum {
173 GPIO_TRIGGER_EDGE_RISING = EIC_CONFIG_SENSE0_RISE_Val,
174 GPIO_TRIGGER_EDGE_FALLING = EIC_CONFIG_SENSE0_FALL_Val,
175 GPIO_TRIGGER_EDGE_BOTH = EIC_CONFIG_SENSE0_BOTH_Val,
176 GPIO_TRIGGER_LEVEL_HIGH = EIC_CONFIG_SENSE0_HIGH_Val,
177 GPIO_TRIGGER_LEVEL_LOW = EIC_CONFIG_SENSE0_LOW_Val,
179
180#define HAVE_GPIO_CONF_T
181typedef union gpio_conf_sam0 gpio_conf_t;
182
187#define HAVE_GPIO_FLANK_T
188typedef enum {
189 GPIO_FALLING = 2,
190 GPIO_RISING = 1,
191 GPIO_BOTH = 3
194#endif /* ndef DOXYGEN */
195
201 uint8_t bits;
202 struct {
235 uint8_t : 1; /*< padding */
236 };
237};
238
242#ifndef SAM_MUX_T
260#endif
261
271
275typedef enum {
281
291
292#ifndef DOXYGEN
300#define HAVE_UART_DATA_BITS_T
301typedef enum {
302 UART_DATA_BITS_5 = 0x5,
303 UART_DATA_BITS_6 = 0x6,
304 UART_DATA_BITS_7 = 0x7,
305 UART_DATA_BITS_8 = 0x0,
313#define uart_pin_rx(dev) uart_config[dev].rx_pin
314#define uart_pin_tx(dev) uart_config[dev].tx_pin
317#endif /* ndef DOXYGEN */
318
322#ifndef UART_TXBUF_SIZE
323#define UART_TXBUF_SIZE (64)
324#endif
325
339typedef struct {
340 SercomUsart *dev;
341 gpio_t rx_pin;
342 gpio_t tx_pin;
343#ifdef MODULE_PERIPH_UART_HW_FC
344 gpio_t rts_pin;
345 gpio_t cts_pin;
346#endif
351 uint8_t gclk_src;
353
354enum {
357};
358
362typedef struct {
363 union {
364#ifdef REV_TC
365 Tc *tc;
366#endif
367#ifdef REV_TCC
368 Tcc *tcc;
369#endif
370 } dev;
371#ifdef MCLK
372 volatile uint32_t *mclk;
373 uint32_t mclk_mask;
374#else
375 uint32_t pm_mask;
376#endif
377 uint16_t gclk_id;
378 uint8_t type;
380
384#ifdef MCLK
385#define TC_CONFIG(tim) { \
386 .dev = {.tc = tim}, \
387 .mclk = MCLK_ ## tim, \
388 .mclk_mask = MCLK_ ## tim ## _MASK, \
389 .gclk_id = tim ## _GCLK_ID, \
390 .type = TIMER_TYPE_TC, }
391#else
392#define TC_CONFIG(tim) { \
393 .dev = {.tc = tim}, \
394 .pm_mask = PM_APBCMASK_ ## tim, \
395 .gclk_id = tim ## _GCLK_ID, \
396 .type = TIMER_TYPE_TC, }
397#endif
398
402#ifdef MCLK
403#define TCC_CONFIG(tim) { \
404 .dev = {.tcc = tim}, \
405 .mclk = MCLK_ ## tim, \
406 .mclk_mask = MCLK_ ## tim ## _MASK, \
407 .gclk_id = tim ## _GCLK_ID, \
408 .type = TIMER_TYPE_TCC, }
409#else
410#define TCC_CONFIG(tim) { \
411 .dev = {.tcc = tim}, \
412 .pm_mask = PM_APBCMASK_ ## tim, \
413 .gclk_id = tim ## _GCLK_ID, \
414 .type = TIMER_TYPE_TCC, }
415#endif
416
420typedef struct {
421 gpio_t pin;
423 uint8_t chan;
425
429typedef struct {
432 uint8_t chan_numof;
433 uint8_t gclk_src;
434} pwm_conf_t;
435
445
455
456#ifndef DOXYGEN
461#define HAVE_SPI_MODE_T
462typedef enum {
463 SPI_MODE_0 = 0x0,
464 SPI_MODE_1 = 0x1,
465 SPI_MODE_2 = 0x2,
466 SPI_MODE_3 = 0x3
467} spi_mode_t;
474#define HAVE_SPI_CLK_T
475typedef enum {
476 SPI_CLK_100KHZ = 100000U,
477 SPI_CLK_400KHZ = 400000U,
478 SPI_CLK_1MHZ = 1000000U,
479 SPI_CLK_5MHZ = 5000000U,
480 SPI_CLK_10MHZ = 10000000U
481} spi_clk_t;
488#define spi_pin_mosi(dev) spi_config[dev].mosi_pin
489#define spi_pin_miso(dev) spi_config[dev].miso_pin
490#define spi_pin_clk(dev) spi_config[dev].clk_pin
493#endif /* ndef DOXYGEN */
494
498typedef struct {
499 void *dev;
500 gpio_t miso_pin;
501 gpio_t mosi_pin;
502 gpio_t clk_pin;
508 uint8_t gclk_src;
509#ifdef MODULE_PERIPH_DMA
510 uint8_t tx_trigger;
511 uint8_t rx_trigger;
512#endif
513} spi_conf_t;
519typedef enum {
522} i2c_flag_t;
523
524#ifndef DOXYGEN
529#define HAVE_I2C_SPEED_T
530typedef enum {
531 I2C_SPEED_LOW = 10000U,
532 I2C_SPEED_NORMAL = 100000U,
533 I2C_SPEED_FAST = 400000U,
534 I2C_SPEED_FAST_PLUS = 1000000U,
535 I2C_SPEED_HIGH = 3400000U,
543#define i2c_pin_sda(dev) i2c_config[dev].sda_pin
544#define i2c_pin_scl(dev) i2c_config[dev].scl_pin
547#endif /* ndef DOXYGEN */
548
561typedef struct {
562 SercomI2cm *dev;
563 i2c_speed_t speed;
564 gpio_t scl_pin;
565 gpio_t sda_pin;
567 uint8_t gclk_src;
568 uint8_t flags;
569} i2c_conf_t;
570
574typedef struct {
575 Tc *dev;
577#ifdef MCLK
578 volatile uint32_t *mclk;
579 uint32_t mclk_mask;
580 uint16_t gclk_id;
581#else
582 uint32_t pm_mask;
583 uint16_t gclk_ctrl;
584#endif
585 uint8_t gclk_src;
586 uint16_t flags;
588
592#define TIMER_CHANNEL_NUMOF (2)
593
600void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
601
607void gpio_pm_cb_enter(int deep);
608
614void gpio_pm_cb_leave(int deep);
615
621void cpu_pm_cb_enter(int deep);
622
628void cpu_pm_cb_leave(int deep);
629
635static inline void sam0_cortexm_sleep(int deep)
636{
637#ifdef MODULE_PERIPH_GPIO
638 gpio_pm_cb_enter(deep);
639#endif
640
641 cpu_pm_cb_enter(deep);
642
643 cortexm_sleep(deep);
644
645 cpu_pm_cb_leave(deep);
646
647#ifdef MODULE_PERIPH_GPIO
648 gpio_pm_cb_leave(deep);
649#endif
650}
651
657void gpio_disable_mux(gpio_t pin);
658
662typedef enum {
663 SAM0_VREG_LDO, /*< LDO, always available but not very power efficient */
664 SAM0_VREG_BUCK /*< Buck converter, efficient but may clash with internal
665 fast clock generators (see errata sheets) */
667
682{
683#ifdef REG_SUPC_VREG
684 if (src == SAM0_VREG_BUCK) {
685 SUPC->VREG.reg |= (1 << SUPC_VREG_SEL_Pos);
686 }
687 else {
688 SUPC->VREG.reg &= ~(1 << SUPC_VREG_SEL_Pos);
689 }
690 while (!(SUPC->STATUS.reg & SUPC_STATUS_VREGRDY)) {}
691#else
692 (void) src;
693 assert(0);
694#endif
695}
696
704uint32_t sam0_gclk_freq(uint8_t id);
705
711void sam0_gclk_enable(uint8_t id);
712
720static inline uint8_t sercom_id(const void *sercom)
721{
722#ifdef SERCOM0
723 if (sercom == SERCOM0) {
724 return 0;
725 }
726#endif
727#ifdef SERCOM1
728 if (sercom == SERCOM1) {
729 return 1;
730 }
731#endif
732#ifdef SERCOM2
733 if (sercom == SERCOM2) {
734 return 2;
735 }
736#endif
737#ifdef SERCOM3
738 if (sercom == SERCOM3) {
739 return 3;
740 }
741#endif
742#ifdef SERCOM4
743 if (sercom == SERCOM4) {
744 return 4;
745 }
746#endif
747#ifdef SERCOM5
748 if (sercom == SERCOM5) {
749 return 5;
750 }
751#endif
752#ifdef SERCOM6
753 if (sercom == SERCOM6) {
754 return 6;
755 }
756#endif
757#ifdef SERCOM7
758 if (sercom == SERCOM7) {
759 return 7;
760 }
761#endif
762
763 /* should not be reached, so fail with assert */
764 assert(false);
765
766 return SERCOM_INST_NUM;
767}
768
774static inline void sercom_clk_en(void *sercom)
775{
776 const uint8_t id = sercom_id(sercom);
777#if defined(CPU_COMMON_SAMD21)
778 PM->APBCMASK.reg |= (PM_APBCMASK_SERCOM0 << id);
779#elif defined (CPU_COMMON_SAMD5X)
780 if (id < 2) {
781 MCLK->APBAMASK.reg |= (1 << (id + 12));
782 } else if (id < 4) {
783 MCLK->APBBMASK.reg |= (1 << (id + 7));
784 } else {
785 MCLK->APBDMASK.reg |= (1 << (id - 4));
786 }
787#else
788 if (id < 5) {
789 MCLK->APBCMASK.reg |= (MCLK_APBCMASK_SERCOM0 << id);
790 }
791#if defined(CPU_COMMON_SAML21)
792 else {
793 MCLK->APBDMASK.reg |= (MCLK_APBDMASK_SERCOM5);
794 }
795#endif /* CPU_COMMON_SAML21 */
796#endif
797}
798
804static inline void sercom_clk_dis(void *sercom)
805{
806 const uint8_t id = sercom_id(sercom);
807#if defined(CPU_COMMON_SAMD21)
808 PM->APBCMASK.reg &= ~(PM_APBCMASK_SERCOM0 << id);
809#elif defined (CPU_COMMON_SAMD5X)
810 if (id < 2) {
811 MCLK->APBAMASK.reg &= ~(1 << (id + 12));
812 } else if (id < 4) {
813 MCLK->APBBMASK.reg &= ~(1 << (id + 7));
814 } else {
815 MCLK->APBDMASK.reg &= ~(1 << (id - 4));
816 }
817#else
818 if (id < 5) {
819 MCLK->APBCMASK.reg &= ~(MCLK_APBCMASK_SERCOM0 << id);
820 }
821#if defined (CPU_COMMON_SAML21)
822 else {
823 MCLK->APBDMASK.reg &= ~(MCLK_APBDMASK_SERCOM5);
824 }
825#endif /* CPU_COMMON_SAML21 */
826#endif
827}
828
829#ifdef CPU_COMMON_SAMD5X
830static inline uint8_t _sercom_gclk_id_core(uint8_t sercom_id) {
831 if (sercom_id < 2) {
832 return sercom_id + 7;
833 } else if (sercom_id < 4) {
834 return sercom_id + 21;
835 } else {
836 return sercom_id + 30;
837 }
838}
839#endif
840
847static inline void sercom_set_gen(void *sercom, uint8_t gclk)
848{
849 const uint8_t id = sercom_id(sercom);
850 sam0_gclk_enable(gclk);
851#if defined(CPU_COMMON_SAMD21)
852 GCLK->CLKCTRL.reg = (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN(gclk) |
853 (SERCOM0_GCLK_ID_CORE + id));
854 while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {}
855#elif defined(CPU_COMMON_SAMD5X)
856 GCLK->PCHCTRL[_sercom_gclk_id_core(id)].reg = (GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(gclk));
857#else
858 if (id < 5) {
859 GCLK->PCHCTRL[SERCOM0_GCLK_ID_CORE + id].reg = (GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(gclk));
860 }
861#if defined(CPU_COMMON_SAML21)
862 else {
863 GCLK->PCHCTRL[SERCOM5_GCLK_ID_CORE].reg = (GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(gclk));
864 }
865#endif /* CPU_COMMON_SAML21 */
866#endif
867}
868
872static inline bool cpu_woke_from_backup(void)
873{
874#ifdef RSTC_RCAUSE_BACKUP
875 return RSTC->RCAUSE.reg & RSTC_RCAUSE_BACKUP;
876#else
877 return false;
878#endif
879}
880
884typedef struct {
885 uint32_t inputctrl;
886#ifdef ADC0
887 Adc *dev;
888#endif
890
895#ifndef ADC_INPUTCTRL_DIFFMODE
896#define ADC_INPUTCTRL_DIFFMODE (1 << 7)
897#endif
898
902#define ADC_REFSEL_AREFA_PIN GPIO_PIN(PA, 3)
903
907#define ADC_REFSEL_AREFB_PIN GPIO_PIN(PA, 4)
908
909#if defined(ADC_REFCTRL_REFSEL_AREFC) || DOXYGEN
913#define ADC_REFSEL_AREFC_PIN GPIO_PIN(PA, 6)
914#endif
915
916#ifndef DOXYGEN
917#define HAVE_ADC_RES_T
918typedef enum {
919 ADC_RES_6BIT = 0xff,
920#if defined(ADC_CTRLB_RESSEL)
921 ADC_RES_8BIT = ADC_CTRLB_RESSEL_8BIT_Val,
922 ADC_RES_10BIT = ADC_CTRLB_RESSEL_10BIT_Val,
923 ADC_RES_12BIT = ADC_CTRLB_RESSEL_12BIT_Val,
924#elif defined(ADC_CTRLC_RESSEL)
925 ADC_RES_8BIT = ADC_CTRLC_RESSEL_8BIT_Val,
926 ADC_RES_10BIT = ADC_CTRLC_RESSEL_10BIT_Val,
927 ADC_RES_12BIT = ADC_CTRLC_RESSEL_12BIT_Val,
928#endif
929 ADC_RES_16BIT_2SAMPL = ( 0x1 << 2) | 0x1,
930 ADC_RES_16BIT_4SAMPL = ( 0x2 << 2) | 0x1,
931 ADC_RES_16BIT_8SAMPL = ( 0x3 << 2) | 0x1,
932 ADC_RES_16BIT_16SAMPL = ( 0x4 << 2) | 0x1,
933 ADC_RES_16BIT_32SAMPL = ( 0x5 << 2) | 0x1,
934 ADC_RES_16BIT_64SAMPL = ( 0x6 << 2) | 0x1,
935 ADC_RES_16BIT_128SAMPL = ( 0x7 << 2) | 0x1,
936 ADC_RES_16BIT_256SAMPL = ( 0x8 << 2) | 0x1,
937 ADC_RES_16BIT_512SAMPL = ( 0x9 << 2) | 0x1,
938 ADC_RES_16BIT_1024SAMPL = ( 0xA << 2) | 0x1,
939 ADC_RES_14BIT = 0xfe,
940} adc_res_t;
941
942#define ADC_RES_16BIT ADC_RES_16BIT_16SAMPL
943#endif /* DOXYGEN */
944
949#ifndef ETH_RX_BUFFER_COUNT
950#define ETH_RX_BUFFER_COUNT (4)
951#endif
952
953#ifndef ETH_TX_BUFFER_COUNT
954#define ETH_TX_BUFFER_COUNT (2)
955#endif
956
957#ifndef ETH_RX_BUFFER_SIZE
958#define ETH_RX_BUFFER_SIZE (1536)
959#endif
960
961#ifndef ETH_TX_BUFFER_SIZE
962#define ETH_TX_BUFFER_SIZE (1536)
963#endif
969#if defined(GMAC_INST_NUM) || defined(DOXYGEN)
970typedef struct {
971 Gmac *dev;
972 gpio_t refclk;
973 gpio_t txen;
974 gpio_t txd0;
975 gpio_t txd1;
976 gpio_t crsdv;
977 gpio_t rxd0;
978 gpio_t rxd1;
979 gpio_t rxer;
980 gpio_t mdc;
981 gpio_t mdio;
982 gpio_t rst_pin;
983 gpio_t int_pin;
985#endif
986
990#define USBDEV_CPU_DMA_ALIGNMENT (4)
991
995#define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT)))
996
1000#if defined(USB_INST_NUM) || defined(DOXYGEN)
1001typedef struct {
1002 gpio_t dm;
1003 gpio_t dp;
1005 UsbDevice *device;
1006 uint8_t gclk_src;
1008#endif /* USB_INST_NUM */
1009
1013#define SDMMC_CPU_DMA_ALIGNMENT 4
1014
1018#define SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT)))
1019
1023typedef struct {
1024 void *sdhc;
1025 gpio_t cd;
1026 gpio_t wp;
1027} sdhc_conf_t;
1028
1033/* Limits are in clock cycles according to data sheet.
1034 As the WDT is clocked by a 1024 Hz clock, 1 cycle ≈ 1 ms */
1035#define NWDT_TIME_LOWER_LIMIT (8U)
1036#define NWDT_TIME_UPPER_LIMIT (16384U)
1042#define WDT_HAS_STOP (1)
1046#define WDT_HAS_INIT (1)
1047
1051typedef struct {
1052 gpio_t pin;
1053 uint8_t gclk_src;
1055
1056#if defined(REV_DMAC) || DOXYGEN
1106#define DMA_TRIGGER_DISABLED 0
1107
1111#if defined(CPU_COMMON_SAML21) || defined(DOXYGEN)
1112#define DMA_DESCRIPTOR_IN_LPSRAM
1113#endif
1114
1118#ifdef DMA_DESCRIPTOR_IN_LPSRAM
1119#define DMA_DESCRIPTOR_ATTRS __attribute__((section(".backup.bss")))
1120#else
1121#define DMA_DESCRIPTOR_ATTRS
1122#endif
1123
1127typedef unsigned dma_t;
1128
1138
1142void dma_init(void);
1143
1155
1162
1171void dma_setup(dma_t dma, unsigned trigger, uint8_t prio, bool irq);
1172
1186void dma_prepare(dma_t dma, uint8_t width, const void *src, void *dst,
1187 size_t num, dma_incr_t incr);
1188
1209void dma_prepare_src(dma_t dma, const void *src, size_t num, bool incr);
1210
1231void dma_prepare_dst(dma_t dma, void *dst, size_t num, bool incr);
1232
1252void dma_append(dma_t dma, DmacDescriptor *descriptor, uint8_t width,
1253 const void *src, void *dst, size_t num, dma_incr_t incr);
1254
1273void dma_append_src(dma_t dma, DmacDescriptor *next, const void *src,
1274 size_t num, bool incr);
1275
1294void dma_append_dst(dma_t dma, DmacDescriptor *next, void *dst, size_t num,
1295 bool incr);
1296
1303
1313void dma_wait(dma_t dma);
1314
1325#endif /* REV_DMAC || DOXYGEN */
1326
1336
1345int rtc_tamper_register(gpio_t pin, gpio_flank_t flank);
1346
1351
1360
1371uint8_t rtc_tamper_pin_mask(gpio_t pin);
1389
1393#ifdef FLASH_USER_PAGE_SIZE
1394#define FLASH_USER_PAGE_AUX_SIZE (FLASH_USER_PAGE_SIZE - sizeof(nvm_user_page_t))
1395#else
1396#define FLASH_USER_PAGE_AUX_SIZE (AUX_PAGE_SIZE * AUX_NB_OF_PAGES - sizeof(nvm_user_page_t))
1397#endif
1398
1408
1424void sam0_flashpage_aux_write(uint32_t offset, const void *data, size_t len);
1425
1433#define sam0_flashpage_aux_get(offset) \
1434 (const void*)((uint8_t*)NVMCTRL_USER + sizeof(nvm_user_page_t) + (offset))
1435
1441#define sam0_flashpage_aux_cfg() \
1442 ((const nvm_user_page_t*)NVMCTRL_USER)
1443
1446#ifdef __cplusplus
1447}
1448#endif
1449
1450#endif /* PERIPH_CPU_COMMON_H */
#define assert(cond)
abort the program if assertion is false
Definition assert.h:136
gpio_flank_t
Definition periph_cpu.h:180
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:165
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:164
i2c_speed_t
Definition periph_cpu.h:276
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:278
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition periph_cpu.h:280
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition periph_cpu.h:277
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition periph_cpu.h:282
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:279
spi_clk_t
Definition periph_cpu.h:352
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:357
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:356
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:354
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:355
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:353
enum IRQn IRQn_Type
Interrupt Number Definition.
static void cortexm_sleep(int deep)
Put the CPU into (deep) sleep mode, using the WFI instruction.
Definition cpu.h:157
adc_res_t
Possible ADC resolution settings.
Definition adc.h:93
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition adc.h:95
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition adc.h:98
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition adc.h:94
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition adc.h:96
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition adc.h:97
gpio_irq_trig_t
Definition of possible IRQ triggers.
Definition gpio_ll_irq.h:72
@ GPIO_TRIGGER_EDGE_FALLING
edge triggered IRQ on falling flanks only
Definition gpio_ll_irq.h:73
@ GPIO_TRIGGER_LEVEL_HIGH
level triggered IRQ on high input
Definition gpio_ll_irq.h:78
@ GPIO_TRIGGER_EDGE_RISING
edge triggered IRQ on rising flanks only
Definition gpio_ll_irq.h:75
@ GPIO_TRIGGER_EDGE_BOTH
edge triggered IRQ on falling AND rising flanks
Definition gpio_ll_irq.h:76
@ GPIO_TRIGGER_LEVEL_LOW
level triggered IRQ on low input
Definition gpio_ll_irq.h:79
gpio_pull_t
Enumeration of pull resistor configurations.
Definition gpio_ll.h:250
gpio_pull_strength_t
Enumeration of pull resistor values.
Definition gpio_ll.h:268
gpio_state_t
Enumeration of GPIO states (direction)
Definition gpio_ll.h:158
gpio_slew_t
Enumeration of slew rate settings.
Definition gpio_ll.h:332
gpio_drive_strength_t
Enumeration of drive strength options.
Definition gpio_ll.h:299
typedef gpio_conf_t
GPIO pin configuration.
Definition gpio_ll.h:416
@ GPIO_FLOATING
No pull ups nor pull downs enabled.
Definition gpio_ll.h:251
@ GPIO_PULL_KEEP
Keep the signal at current logic level with pull up/down resistors.
Definition gpio_ll.h:254
@ GPIO_PULL_DOWN
Pull down resistor enabled.
Definition gpio_ll.h:253
@ GPIO_PULL_UP
Pull up resistor enabled.
Definition gpio_ll.h:252
@ GPIO_PULL_WEAKEST
Use the weakest (highest Ohm value) resistor.
Definition gpio_ll.h:269
@ GPIO_PULL_WEAK
Use a weak pull resistor.
Definition gpio_ll.h:270
@ GPIO_PULL_STRONG
Use a strong pull resistor.
Definition gpio_ll.h:271
@ GPIO_PULL_STRONGEST
Use the strongest pull resistor.
Definition gpio_ll.h:272
@ GPIO_OUTPUT_OPEN_SOURCE
Use pin as output in open emitter configuration.
Definition gpio_ll.h:195
@ GPIO_USED_BY_PERIPHERAL
The GPIO pin is used by a peripheral.
Definition gpio_ll.h:214
@ GPIO_OUTPUT_OPEN_DRAIN
Use pin as output in open collector configuration.
Definition gpio_ll.h:182
@ GPIO_OUTPUT_PUSH_PULL
Use pin as output in push-pull configuration.
Definition gpio_ll.h:169
@ GPIO_DISCONNECT
Disconnect pin from all peripherals.
Definition gpio_ll.h:242
@ GPIO_INPUT
Use pin as input.
Definition gpio_ll.h:201
@ GPIO_SLEW_SLOWEST
let the output voltage level rise/fall as slow as possible
Definition gpio_ll.h:333
@ GPIO_SLEW_FAST
let the output voltage level rise/fall fast
Definition gpio_ll.h:336
@ GPIO_SLEW_SLOW
let the output voltage level rise/fall slowly
Definition gpio_ll.h:335
@ GPIO_SLEW_FASTEST
let the output voltage level rise/fall as fast as possible
Definition gpio_ll.h:337
@ GPIO_DRIVE_STRONG
Use a strong drive strength.
Definition gpio_ll.h:302
@ GPIO_DRIVE_WEAK
Use a weak drive strength.
Definition gpio_ll.h:301
@ GPIO_DRIVE_STRONGEST
Use the strongest drive strength.
Definition gpio_ll.h:303
@ GPIO_DRIVE_WEAKEST
Use the weakest drive strength.
Definition gpio_ll.h:300
spi_mode_t
Support SPI modes.
Definition periph_cpu.h:43
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition periph_cpu.h:44
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition periph_cpu.h:46
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition periph_cpu.h:45
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition periph_cpu.h:47
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:82
#define GPIO_MODE(oe, ic, pr, dr)
Generate GPIO mode bitfields.
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:518
@ UART_DATA_BITS_6
6 data bits
Definition periph_cpu.h:520
@ UART_DATA_BITS_5
5 data bits
Definition periph_cpu.h:519
@ UART_DATA_BITS_7
7 data bits
Definition periph_cpu.h:521
@ UART_DATA_BITS_8
8 data bits
Definition periph_cpu.h:522
uint8_t rtc_get_tamper_event(void)
Get and clear the RTC tamper event that has woken the CPU from Deep Sleep.
uart_rxpad_t
Available values for SERCOM UART RX pad selection.
@ UART_PAD_RX_1
select pad 1
@ UART_PAD_RX_0
use pad 0 for RX line
@ UART_PAD_RX_3
select pad 3
@ UART_PAD_RX_2
select pad 2
void gpio_disable_mux(gpio_t pin)
Disable alternate function (PMUX setting) for a PORT pin.
@ PB
port B
@ PC
port C
@ PA
port A
@ PD
port D
void dma_prepare(dma_t dma, uint8_t width, const void *src, void *dst, size_t num, dma_incr_t incr)
Prepare the DMA channel for an individual transfer.
void dma_init(void)
Initialize DMA.
@ TIMER_TYPE_TC
Timer is a TC timer
@ TIMER_TYPE_TCC
Timer is a TCC timer.
int rtc_tamper_register(gpio_t pin, gpio_flank_t flank)
Enable Tamper Detection IRQs.
static uint8_t sercom_id(const void *sercom)
Return the numeric id of a SERCOM device derived from its address.
void dma_wait(dma_t dma)
Wait for a DMA channel to finish the transfer.
void dma_cancel(dma_t dma)
Cancel an active DMA transfer.
i2c_flag_t
Available SERCOM I2C flag selections.
@ I2C_FLAG_NONE
No flags set.
@ I2C_FLAG_RUN_STANDBY
run SERCOM in standby mode
void dma_prepare_dst(dma_t dma, void *dst, size_t num, bool incr)
Prepare a transfer without modifying the source address settings.
void cpu_pm_cb_leave(int deep)
Called after the power management left a power mode.
void gpio_init_mux(gpio_t pin, gpio_mux_t mux)
Set up alternate function (PMUX setting) for a PORT pin.
void dma_setup(dma_t dma, unsigned trigger, uint8_t prio, bool irq)
Initialize a previously allocated DMA channel with one-time settings.
uint32_t sam0_gclk_freq(uint8_t id)
Returns the frequency of a GCLK provider.
dma_t dma_acquire_channel(void)
Acquire a DMA channel.
spi_misopad_t
Available values for SERCOM SPI MISO pad selection.
@ SPI_PAD_MISO_1
use pad 1 for MISO line
@ SPI_PAD_MISO_2
use pad 2 for MISO line
@ SPI_PAD_MISO_0
use pad 0 for MISO line
@ SPI_PAD_MISO_3
use pad 3 for MISO line
void dma_release_channel(dma_t dma)
Release a previously acquired DMA channel.
void gpio_pm_cb_leave(int deep)
Called after the power management left a power mode.
static void sercom_set_gen(void *sercom, uint8_t gclk)
Configure generator clock for given SERCOM device.
uint8_t rtc_tamper_pin_mask(gpio_t pin)
Get the tamper event mask for a certain pin.
uart_flag_t
Available SERCOM UART flag selections.
@ UART_FLAG_TX_ONDEMAND
Only enable TX pin on demand.
@ UART_FLAG_NONE
No flags set.
@ UART_FLAG_RUN_STANDBY
run SERCOM in standby mode
@ UART_FLAG_WAKEUP
wake from sleep on receive
void sam0_flashpage_aux_reset(const nvm_user_page_t *cfg)
Reset the configuration area, apply a new configuration.
static void sam0_cortexm_sleep(int deep)
Wrapper for cortexm_sleep calling power management callbacks.
static void sercom_clk_dis(void *sercom)
Disable peripheral clock for given SERCOM device.
static bool cpu_woke_from_backup(void)
Returns true if the CPU woke deep sleep (backup/standby)
void cpu_pm_cb_enter(int deep)
Called before the power management enters a power mode.
void dma_append_dst(dma_t dma, DmacDescriptor *next, void *dst, size_t num, bool incr)
Append a second transfer descriptor after the default channel descriptor, copying source and block si...
void sam0_flashpage_aux_write(uint32_t offset, const void *data, size_t len)
Write data to the user configuration area.
uart_txpad_t
Available values for SERCOM UART TX pad selection.
@ UART_PAD_TX_0_RTS_2_CTS_3
TX is pad 0, on top RTS on pad 2 and CTS on pad 3.
@ UART_PAD_TX_0
select pad 0
@ UART_PAD_TX_2
select pad 2
dma_incr_t
Available DMA address increment modes.
@ DMA_INCR_NONE
Don't increment any addresses after a beat.
@ DMA_INCR_DEST
Increment destination address after a beat.
@ DMA_INCR_BOTH
Increment both addresses after a beat.
@ DMA_INCR_SRC
Increment the source address after a beat.
void dma_append(dma_t dma, DmacDescriptor *descriptor, uint8_t width, const void *src, void *dst, size_t num, dma_incr_t incr)
Append a second transfer descriptor after the default channel descriptor.
void rtc_tamper_enable(void)
Enable Tamper Detection IRQs.
void rtc_tamper_init(void)
Power on the RTC (if the RTC/RTT is not otherwise used)
unsigned dma_t
DMA channel type.
void sam0_gclk_enable(uint8_t id)
Enables an on-demand GCLK that has been configured in cpu.c.
void dma_append_src(dma_t dma, DmacDescriptor *next, const void *src, size_t num, bool incr)
Append a second transfer descriptor after the default channel descriptor, copying destination and blo...
gpio_mux_t
Available MUX values for configuring a pin's alternate function.
@ GPIO_MUX_E
select peripheral function E
@ GPIO_MUX_J
select peripheral function J
@ GPIO_MUX_K
select peripheral function K
@ GPIO_MUX_M
select peripheral function M
@ GPIO_MUX_H
select peripheral function H
@ GPIO_MUX_I
select peripheral function I
@ GPIO_MUX_D
select peripheral function D
@ GPIO_MUX_G
select peripheral function G
@ GPIO_MUX_C
select peripheral function C
@ GPIO_MUX_N
select peripheral function N
@ GPIO_MUX_A
select peripheral function A
@ GPIO_MUX_L
select peripheral function L
@ GPIO_MUX_B
select peripheral function B
@ GPIO_MUX_DISABLED
Disable
@ GPIO_MUX_F
select peripheral function F
static void sam0_set_voltage_regulator(sam0_supc_t src)
Switch the internal voltage regulator used for generating the internal MCU voltages.
spi_mosipad_t
Available values for SERCOM SPI MOSI and SCK pad selection.
@ SPI_PAD_MOSI_2_SCK_3
use pad 2 for MOSI, pad 3 for SCK
@ SPI_PAD_MOSI_0_SCK_3
use pad 0 for MOSI, pad 3 for SCK
@ SPI_PAD_MOSI_3_SCK_1
use pad 3 for MOSI, pad 1 for SCK
@ SPI_PAD_MOSI_0_SCK_1
use pad 0 for MOSI, pad 1 for SCK
static void sercom_clk_en(void *sercom)
Enable peripheral clock for given SERCOM device.
sam0_supc_t
Available voltage regulators on the supply controller.
void dma_prepare_src(dma_t dma, const void *src, size_t num, bool incr)
Prepare a transfer without modifying the destination address settings.
void dma_start(dma_t dma)
Start a DMA transfer.
void gpio_pm_cb_enter(int deep)
Called before the power management enters a power mode.
ADC Channel Configuration.
uint32_t inputctrl
ADC channel pin multiplexer value
Frequency meter configuration.
uint8_t gclk_src
GCLK source select for reference.
gpio_t pin
GPIO at which the frequency is to be measured.
I2C configuration structure.
Definition periph_cpu.h:299
uint8_t gclk_src
GCLK source which supplys SERCOM.
gpio_mux_t mux
alternate function (mux)
uint8_t flags
allow SERCOM to run in standby mode
SercomI2cm * dev
pointer to the used I2C device
PWM channel configuration data structure.
gpio_t pin
GPIO pin.
uint8_t chan
TCC channel to use.
gpio_mux_t mux
pin function multiplex value
PWM device configuration.
tc_tcc_cfg_t tim
timer configuration
uint8_t chan_numof
number of channels
const pwm_conf_chan_t * chan
channel configuration
uint8_t gclk_src
GCLK source which clocks TIMER.
NVM User Row Mapping - Dedicated Entries Config values will be applied at power-on.
Definition periph_cpu.h:177
Ethernet parameters struct.
Gmac * dev
ptr to the device registers
gpio_t mdc
MII interface, clock gpio.
gpio_t mdio
MII interface, data gpio.
gpio_t rst_pin
PHY reset gpio.
gpio_t int_pin
PHY interrupt gpio.
USB peripheral parameters.
gpio_mux_t d_mux
alternate function (mux) for data pins
uint8_t gclk_src
GCLK source which supplys 48 MHz
UsbDevice * device
ptr to the device registers
SDHC peripheral configuration.
gpio_t wp
Write Protect pin (must be GPIO_UNDEF if not connected)
void * sdhc
SDHC peripheral.
gpio_t cd
Card Detect pin (must be GPIO_UNDEF if not connected)
SPI device configuration.
Definition periph_cpu.h:337
gpio_mux_t miso_mux
alternate function for MISO pin (mux)
spi_misopad_t miso_pad
pad to use for MISO line
gpio_mux_t clk_mux
alternate function for CLK pin (mux)
spi_mosipad_t mosi_pad
pad to use for MOSI and CLK line
gpio_mux_t mosi_mux
alternate function for MOSI pin (mux)
uint8_t gclk_src
GCLK source which supplys SERCOM.
void * dev
pointer to the used SPI device
Timer device configuration.
uint16_t flags
flags for CTRA, e.g.
uint32_t pm_mask
PM_APBCMASK bits to enable Timer.
uint8_t gclk_src
GCLK source which supplys Timer.
IRQn_Type irq
IRQ# of Timer Interrupt.
uint16_t gclk_ctrl
GCLK_CLKCTRL_ID for the Timer.
Tc * dev
pointer to the used Timer device
Common configuration for timer devices.
uint16_t gclk_id
TCn_GCLK_ID.
uint8_t type
Timer type (TC/TCC)
uint32_t pm_mask
PM_APBCMASK bits to enable Timer.
UART device configuration.
Definition periph_cpu.h:218
gpio_mux_t mux
alternative function for pins
uint8_t gclk_src
GCLK source which supplys SERCOM.
uart_txpad_t tx_pad
pad selection for TX line
SercomUsart * dev
pointer to the used UART device
uart_rxpad_t rx_pad
pad selection for RX line
uart_flag_t flags
set optional SERCOM flags
GPIO pin configuration for SAM0 MCUs.
bool initial_value
Initial value of the output.
uint8_t bits
the raw bits
gpio_pull_t pull
Pull resistor configuration.
gpio_state_t state
State of the pin.
gpio_drive_strength_t drive_strength
Drive strength of the GPIO.