Loading...
Searching...
No Matches
periph_cpu.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Rakendra Thapa <rakendrathapa@gmail.com>
3 * SPDX-FileCopyrightText: 2017 Marc Poulhiès <dkm@kataplop.net>
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
19
20#include "cpu.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
30#define HAVE_GPIO_T
31typedef uint32_t gpio_t;
32#define GPIO_PIN(x, y) ((gpio_t)((x<<4) | y))
34
35#ifndef DOXYGEN
40#define HAVE_GPIO_MODE_T
41typedef enum {
42 GPIO_IN = (GPIO_DIR_MODE_IN | (GPIO_PIN_TYPE_STD << 4)),
43 GPIO_IN_PD = (GPIO_DIR_MODE_IN | (GPIO_PIN_TYPE_STD_WPD << 4)),
44 GPIO_IN_PU = (GPIO_DIR_MODE_IN | (GPIO_PIN_TYPE_STD_WPU << 4)),
45 GPIO_OUT = (GPIO_DIR_MODE_OUT | (GPIO_PIN_TYPE_STD << 4)),
46 GPIO_OD = (GPIO_DIR_MODE_OUT | (GPIO_PIN_TYPE_OD << 4)),
47 GPIO_OD_PU = (GPIO_DIR_MODE_OUT | (GPIO_PIN_TYPE_OD_WPU << 4)),
50#endif /* ndef DOXYGEN */
51
56#define HAVE_GPIO_DIR_T
57typedef enum {
58 GPIO_DIR_IN = GPIO_DIR_MODE_IN,
59 GPIO_DIR_OUT = GPIO_DIR_MODE_OUT
61
62
63#ifndef DOXYGEN
68#define HAVE_GPIO_FLANK_T
69typedef enum {
70 GPIO_FALLING = GPIO_FALLING_EDGE,
71 GPIO_RISING = GPIO_RISING_EDGE,
72 GPIO_BOTH = GPIO_BOTH_EDGES
75#endif /* ndef DOXYGEN */
76
80enum {
81 PORT_A = 0,
82 PORT_B = 1,
83 PORT_C = 2,
84 PORT_D = 3,
85 PORT_E = 4,
86 PORT_F = 5,
87};
88
92#ifndef DOXYGEN
93#define HAVE_ADC_RES_T
94typedef enum {
95 ADC_RES_6BIT = 0xa00,
96 ADC_RES_8BIT = 0xb00,
97 ADC_RES_10BIT = ADC_RES_10BIT_S,
98 ADC_RES_12BIT = ADC_RES_12BIT_S,
99 ADC_RES_14BIT = 0xc00,
100 ADC_RES_16BIT = 0xd00,
101} adc_res_t;
102#endif /* ndef DOXYGEN */
103
107typedef struct {
108 uint32_t dev;
109 uint32_t max;
110 int irqn;
111 uint32_t sysctl;
112 uint32_t intbase;
115
121#define SPI_HWCS(x) (UINT_MAX - 1)
122
127typedef struct {
128 unsigned long ssi_sysctl;
129 unsigned long ssi_base;
130 unsigned long gpio_sysctl;
131 unsigned long gpio_port;
132 struct {
133 unsigned long clk;
134 unsigned long fss;
135 unsigned long rx;
136 unsigned long tx;
137 unsigned long mask;
138 } pins;
139} spi_conf_t;
141
146#define PERIPH_SPI_NEEDS_TRANSFER_BYTE 1
147#define PERIPH_SPI_NEEDS_TRANSFER_REG 1
148#define PERIPH_SPI_NEEDS_TRANSFER_REGS 1
149#define PERIPH_SPI_NEEDS_INIT_CS 1
151
152#ifndef DOXYGEN
157#define HAVE_SPI_CLK_T 1
158typedef enum {
159 SPI_CLK_100KHZ = 100000,
160 SPI_CLK_400KHZ = 400000,
161 SPI_CLK_1MHZ = 1000000,
162 SPI_CLK_4MHZ = 4000000,
163 SPI_CLK_5MHZ = 5000000,
164 SPI_CLK_10MHZ = 10000000,
165} spi_clk_t;
167
172#define HAVE_SPI_MODE_T 1
173typedef enum {
174 SPI_MODE_0 = SSI_FRF_MOTO_MODE_0,
175 SPI_MODE_1 = SSI_FRF_MOTO_MODE_1,
176 SPI_MODE_2 = SSI_FRF_MOTO_MODE_2,
177 SPI_MODE_3 = SSI_FRF_MOTO_MODE_0,
178} spi_mode_t;
180#endif /* ndef DOXYGEN */
181
182#ifdef __cplusplus
183}
184#endif
185
@ PORT_B
port B
Definition periph_cpu.h:44
@ PORT_C
port C
Definition periph_cpu.h:45
@ PORT_F
port F
Definition periph_cpu.h:48
@ PORT_E
port E
Definition periph_cpu.h:47
@ PORT_A
port A
Definition periph_cpu.h:43
@ PORT_D
port D
Definition periph_cpu.h:46
gpio_flank_t
Definition periph_cpu.h:176
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:161
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:160
spi_clk_t
Definition periph_cpu.h:348
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:353
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:352
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:350
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:351
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:349
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:88
adc_res_t
Possible ADC resolution settings.
Definition adc.h:92
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition adc.h:98
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition adc.h:94
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition adc.h:97
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition adc.h:93
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition adc.h:95
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition adc.h:96
gpio_dir_t
Definition periph_cpu.h:57
@ GPIO_DIR_IN
configure pin as input
Definition periph_cpu.h:58
@ GPIO_DIR_OUT
configure pin as output
Definition periph_cpu.h:59
spi_mode_t
Support SPI modes.
Definition periph_cpu.h:39
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition periph_cpu.h:40
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition periph_cpu.h:42
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition periph_cpu.h:41
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition periph_cpu.h:43
SPI device configuration.
Definition periph_cpu.h:333
unsigned long fss
pin used for FSS
Definition periph_cpu.h:134
unsigned long tx
pin used for MOSI
Definition periph_cpu.h:136
unsigned long clk
pin used for SCK
Definition periph_cpu.h:133
unsigned long mask
Pin mask.
Definition periph_cpu.h:137
unsigned long gpio_sysctl
GPIO device in sysctl.
Definition periph_cpu.h:130
unsigned long rx
pin used for MISO
Definition periph_cpu.h:135
unsigned long ssi_base
SSI base address.
Definition periph_cpu.h:129
unsigned long gpio_port
GPIO port.
Definition periph_cpu.h:131
unsigned long ssi_sysctl
SSI device in sysctl.
Definition periph_cpu.h:128
Timer device configuration.
Definition periph_cpu.h:260
uint32_t sysctl
Address of timer system control.
Definition periph_cpu.h:111
uint8_t irqn
global IRQ channel
Definition periph_cpu.h:320
int channels
Number of channels for the timer.
Definition periph_cpu.h:113
uint32_t intbase
Interrupt base of timer.
Definition periph_cpu.h:112
TC0_t * dev
Pointer to the used as Timer device.
Definition periph_cpu.h:261
uint32_t max
maximum value to count to (16/32 bit)
Definition periph_cpu.h:317