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;
181 #if defined(PWM_PRESENT) || DOXYGEN
182 typedef struct {
183  NRF_PWM_Type *dev;
184  gpio_t pin[PWM_CHANNELS];
185 } pwm_conf_t;
186 #endif
187 
188 #if !defined(CPU_MODEL_NRF52832XXAA)
189 
192 typedef struct {
193  NRF_UARTE_Type *dev;
195  gpio_t rx_pin;
196  gpio_t tx_pin;
197 #ifdef MODULE_PERIPH_UART_HW_FC
198  gpio_t rts_pin;
199  gpio_t cts_pin;
200 #endif
201  uint8_t irqn;
202 } uart_conf_t;
203 #endif
204 
208 typedef struct {
209  NRF_SPIM_Type *dev;
210  gpio_t sclk;
211  gpio_t mosi;
212  gpio_t miso;
213 #if ERRATA_SPI_SINGLE_BYTE_WORKAROUND
214  uint8_t ppi;
215 #endif
216 } spi_conf_t;
217 
218 
224 typedef void (*spi_twi_irq_cb_t)(void *arg);
225 
233 void spi_twi_irq_register_spi(NRF_SPIM_Type *bus,
234  spi_twi_irq_cb_t cb, void *arg);
235 
243 void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
244  spi_twi_irq_cb_t cb, void *arg);
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* PERIPH_CPU_H */
250 
NRF52_AIN0
@ NRF52_AIN0
Analog Input 0.
Definition: periph_cpu.h:77
NRF52_AIN3
@ NRF52_AIN3
Analog Input 3.
Definition: periph_cpu.h:80
ADC_RES_6BIT
@ ADC_RES_6BIT
ADC resolution: 6 bit.
Definition: adc.h:94
spi_twi_irq_cb_t
void(* spi_twi_irq_cb_t)(void *arg)
Common SPI/I2C interrupt callback.
Definition: periph_cpu.h:224
I2C_SPEED_LOW
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition: i2c.h:176
NRF52_AIN2
@ NRF52_AIN2
Analog Input 2.
Definition: periph_cpu.h:79
uart_conf_t::irqn
uint8_t irqn
IRQ channel.
Definition: periph_cpu.h:201
I2C_SPEED_NORMAL
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: i2c.h:177
spi_twi_irq_register_spi
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_RES_14BIT
@ ADC_RES_14BIT
ADC resolution: 14 bit.
Definition: adc.h:98
adc_res_t
adc_res_t
Possible ADC resolution settings.
Definition: adc.h:93
i2c_conf_t::dev
NRF_TWIM_Type * dev
TWIM hardware device.
Definition: periph_cpu.h:125
NRF52_AIN5
@ NRF52_AIN5
Analog Input 5.
Definition: periph_cpu.h:82
ADC_RES_16BIT
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition: adc.h:99
i2c_speed_t
i2c_speed_t
Default mapping of I2C bus speed values.
Definition: i2c.h:175
ADC_RES_8BIT
@ ADC_RES_8BIT
ADC resolution: 8 bit.
Definition: adc.h:95
uart_conf_t::dev
NRF_UARTE_Type * dev
UART with EasyDMA device base register address.
Definition: periph_cpu.h:193
pwm_conf_t::dev
NRF_PWM_Type * dev
PWM device descriptor.
Definition: periph_cpu.h:183
pwm_conf_t
PWM device configuration.
Definition: periph_cpu_common.h:153
PWM_LEFT
@ PWM_LEFT
left aligned PWM
Definition: periph_cpu.h:160
uart_conf_t
UART device configuration.
Definition: periph_cpu.h:166
NRF52_AIN6
@ NRF52_AIN6
Analog Input 6.
Definition: periph_cpu.h:83
PWM_RIGHT
@ PWM_RIGHT
right aligned PWM
Definition: periph_cpu.h:161
spi_conf_t::dev
NRF_SPIM_Type * dev
SPI device used.
Definition: periph_cpu.h:209
NRF52_AIN4
@ NRF52_AIN4
Analog Input 4.
Definition: periph_cpu.h:81
PWM_CENTER_INV
@ PWM_CENTER_INV
not supported
Definition: periph_cpu.h:163
ADC_RES_10BIT
@ ADC_RES_10BIT
ADC resolution: 10 bit.
Definition: adc.h:96
NRF52_AIN1
@ NRF52_AIN1
Analog Input 1.
Definition: periph_cpu.h:78
ADC_RES_12BIT
@ ADC_RES_12BIT
ADC resolution: 12 bit.
Definition: adc.h:97
spi_twi_irq_register_i2c
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.
NRF52_VDD
@ NRF52_VDD
VDD, not useful if VDD is reference...
Definition: periph_cpu.h:85
i2c_conf_t
I2C configuration options.
Definition: periph_cpu.h:128
I2C_SPEED_FAST_PLUS
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition: i2c.h:179
NRF52_AIN7
@ NRF52_AIN7
Analog Input 7.
Definition: periph_cpu.h:84
I2C_SPEED_FAST
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition: i2c.h:178
pwm_mode_t
pwm_mode_t
Definition: periph_cpu.h:159
I2C_SPEED_HIGH
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition: i2c.h:180
spi_conf_t
SPI configuration structure type.
Definition: periph_cpu.h:273
PWM_CENTER
@ PWM_CENTER
not supported
Definition: periph_cpu.h:162