periph_cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Freie Universit├Ąt Berlin
3  * 2020 Philipp-Alexander Blum <philipp-blum@jakiku.de>
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
21 #ifndef PERIPH_CPU_H
22 #define PERIPH_CPU_H
23 
24 #include "periph_cpu_common.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
34 #ifdef CPU_MODEL_NRF52832XXAA
35 #define ERRATA_SPI_SINGLE_BYTE_WORKAROUND (1)
36 #endif
37 
41 #define CLOCK_CORECLOCK (64000000U)
42 
46 #define PERIPH_CLOCK (16000000U)
47 
52 #define SPI_SCKSEL (dev(bus)->PSEL.SCK)
53 #define SPI_MOSISEL (dev(bus)->PSEL.MOSI)
54 #define SPI_MISOSEL (dev(bus)->PSEL.MISO)
55 #ifdef CPU_MODEL_NRF52832XXAA
56 #define UART_IRQN (UARTE0_UART0_IRQn)
57 #endif
58 
63 #define ADC_NUMOF (9U)
64 
69 #ifndef CONFIG_SPI_MBUF_SIZE
70 #define CONFIG_SPI_MBUF_SIZE 64
71 #endif
72 
76 enum {
77  NRF52_AIN0 = 0,
78  NRF52_AIN1 = 1,
79  NRF52_AIN2 = 2,
80  NRF52_AIN3 = 3,
81  NRF52_AIN4 = 4,
82  NRF52_AIN5 = 5,
83  NRF52_AIN6 = 6,
84  NRF52_AIN7 = 7,
85  NRF52_VDD = 8,
86 };
87 
88 #ifndef DOXYGEN
89 
93 #define HAVE_ADC_RES_T
94 typedef enum {
95  ADC_RES_6BIT = 0xf0,
96  ADC_RES_8BIT = 0x00,
97  ADC_RES_10BIT = 0x01,
98  ADC_RES_12BIT = 0x02,
99  ADC_RES_14BIT = 0xf1,
100  ADC_RES_16BIT = 0xf2
101 } adc_res_t;
103 #endif /* ndef DOXYGEN */
104 
105 #ifndef DOXYGEN
106 
110 #define HAVE_I2C_SPEED_T
111 typedef enum {
112  I2C_SPEED_LOW = 0xff,
113  I2C_SPEED_NORMAL = TWIM_FREQUENCY_FREQUENCY_K100,
114  I2C_SPEED_FAST = TWIM_FREQUENCY_FREQUENCY_K400,
115  I2C_SPEED_FAST_PLUS = 0xfe,
116  I2C_SPEED_HIGH = 0xfd,
117 } i2c_speed_t;
119 #endif /* ndef DOXYGEN */
120 
124 typedef struct {
125  NRF_TWIM_Type *dev;
126  gpio_t scl;
127  gpio_t sda;
128  i2c_speed_t speed;
129 } i2c_conf_t;
136 #define PERIPH_I2C_NEED_READ_REG
137 #define PERIPH_I2C_NEED_WRITE_REG
138 
143 #define PWM_CHANNELS (4U)
144 
152 #define PWM_MODE(ud, pol) (ud | (pol << 15))
153 
158 #define HAVE_PWM_MODE_T
159 typedef enum {
160  PWM_LEFT = PWM_MODE(0, 1),
161  PWM_RIGHT = PWM_MODE(0, 0),
162  PWM_CENTER = PWM_MODE(1, 1),
163  PWM_CENTER_INV = PWM_MODE(1, 0)
164 } pwm_mode_t;
177 typedef struct {
178  NRF_PWM_Type *dev;
179  gpio_t pin[PWM_CHANNELS];
180 } pwm_conf_t;
181 
182 #if defined(CPU_MODEL_NRF52811XXAA) || defined(CPU_MODEL_NRF52840XXAA)
183 
186 typedef struct {
187  NRF_UARTE_Type *dev;
189  gpio_t rx_pin;
190  gpio_t tx_pin;
191 #ifdef MODULE_PERIPH_UART_HW_FC
192  gpio_t rts_pin;
193  gpio_t cts_pin;
194 #endif
195  uint8_t irqn;
196 } uart_conf_t;
197 #endif
198 
202 typedef struct {
203  NRF_SPIM_Type *dev;
204  gpio_t sclk;
205  gpio_t mosi;
206  gpio_t miso;
207 #if ERRATA_SPI_SINGLE_BYTE_WORKAROUND
208  uint8_t ppi;
209 #endif
210 } spi_conf_t;
211 
212 
218 typedef void (*spi_twi_irq_cb_t)(void *arg);
219 
227 void spi_twi_irq_register_spi(NRF_SPIM_Type *bus,
228  spi_twi_irq_cb_t cb, void *arg);
229 
237 void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
238  spi_twi_irq_cb_t cb, void *arg);
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif /* PERIPH_CPU_H */
244 
fast mode: ~400 kbit/s
Definition: i2c.h:184
high speed mode: ~3400 kbit/s
Definition: i2c.h:186
I2C configuration options.
Definition: periph_cpu.h:128
not supported
Definition: periph_cpu.h:162
ADC resolution: 12 bit.
Definition: adc.h:97
NRF_TWIM_Type * dev
TWIM hardware device.
Definition: periph_cpu.h:125
Analog Input 1.
Definition: periph_cpu.h:78
Analog Input 6.
Definition: periph_cpu.h:83
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:93
void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus, spi_twi_irq_cb_t cb, void *arg)
Reqister a I2C IRQ handler for a shared I2C/SPI irq vector.
i2c_speed_t
Default mapping of I2C bus speed values.
Definition: i2c.h:181
PWM device configuration.
NRF_SPIM_Type * dev
SPI device used.
Definition: periph_cpu.h:203
Analog Input 2.
Definition: periph_cpu.h:79
ADC resolution: 14 bit.
Definition: adc.h:98
left aligned PWM
Definition: periph_cpu.h:160
ADC resolution: 10 bit.
Definition: adc.h:96
NRF_PWM_Type * dev
PWM device descriptor.
Definition: periph_cpu.h:178
ADC resolution: 16 bit.
Definition: adc.h:99
void spi_twi_irq_register_spi(NRF_SPIM_Type *bus, spi_twi_irq_cb_t cb, void *arg)
Reqister a SPI IRQ handler for a shared I2C/SPI irq vector.
ADC resolution: 8 bit.
Definition: adc.h:95
void(* spi_twi_irq_cb_t)(void *arg)
Common SPI/I2C interrupt callback.
Definition: periph_cpu.h:218
ADC resolution: 6 bit.
Definition: adc.h:94
Analog Input 4.
Definition: periph_cpu.h:81
pwm_mode_t
Definition: periph_cpu.h:159
UART device configuration.
Definition: periph_cpu.h:166
not supported
Definition: periph_cpu.h:163
VDD, not useful if VDD is reference...
Definition: periph_cpu.h:85
Analog Input 0.
Definition: periph_cpu.h:77
low speed mode: ~10 kbit/s
Definition: i2c.h:182
Analog Input 7.
Definition: periph_cpu.h:84
Analog Input 3.
Definition: periph_cpu.h:80
SPI configuration structure type.
Definition: periph_cpu.h:273
normal mode: ~100 kbit/s
Definition: i2c.h:183
right aligned PWM
Definition: periph_cpu.h:161
Analog Input 5.
Definition: periph_cpu.h:82
fast plus mode: ~1000 kbit/s
Definition: i2c.h:185