Loading...
Searching...
No Matches
periph_cpu.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 iosabi
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 PERIPH_CPU_H
20#define PERIPH_CPU_H
21
22#include <stdint.h>
23#include <stdbool.h>
24
25#include "cpu.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
35#define HAVE_GPIO_T
36typedef uint16_t gpio_t;
42#define GPIO_UNDEF (0xffff)
43
52#define GPIO_PIN(x, y) (((x) << 12u) | (y))
53
54/* QN908x has a unique default Bluetooth address in the Flash Information Page
55 * descriptor. This value is set in the factory and cannot be modified by
56 * users. However, the actual Bluetooth address used by the stack may be
57 * different, this is just the default. */
61#define CPUID_ADDR (FSL_FEATURE_FLASH_ADDR_OF_VENDOR_BD_ADDR)
62
66#define CPUID_LEN (6U)
67
71#define WDT_HAS_STOP (1)
72
84#define NWDT_TIME_LOWER_LIMIT (1U)
85#define NWDT_TIME_UPPER_LIMIT (268435U)
86#define WWDT_TIME_LOWER_LIMIT (1U)
87#define WWDT_TIME_UPPER_LIMIT (268435U)
99#define GPIO_MODE(open_drain, out_enabled, pull_mode) \
100 ((open_drain) | ((out_enabled) << 1) | ((pull_mode) << 4))
101
102#ifndef DOXYGEN
107#define HAVE_GPIO_MODE_T
108typedef enum {
109 GPIO_IN = GPIO_MODE(0, 0, 0),
110 GPIO_IN_PD = GPIO_MODE(0, 0, 1),
111 GPIO_IN_PU = GPIO_MODE(0, 0, 2),
112 GPIO_OUT = GPIO_MODE(0, 1, 0),
113 GPIO_OD = GPIO_MODE(1, 1, 0),
114 GPIO_OD_PU = GPIO_MODE(1, 1, 2),
117#endif /* ndef DOXYGEN */
118
119#ifndef DOXYGEN
124#define HAVE_GPIO_FLANK_T
125typedef enum {
126 GPIO_LOW = 0,
127 GPIO_HIGH = 1,
128 GPIO_RISING = 2,
129 GPIO_FALLING = 3,
130 GPIO_BOTH = 4,
133#endif /* ndef DOXYGEN */
134
138enum {
139 PORT_A = 0,
140 PORT_B = 1,
143
144#if DOXYGEN
156#define BOARD_HAS_ADC_PA06_CAP
158#endif
159
160#ifndef DOXYGEN
165#define HAVE_ADC_RES_T
166typedef enum {
167 ADC_RES_6BIT = 6u,
168 ADC_RES_8BIT = 8u,
169 ADC_RES_10BIT = 10u,
170 ADC_RES_12BIT = 12u,
171 ADC_RES_14BIT = 14u,
172 ADC_RES_16BIT = 16u,
173 /* Extra modes supported by this CPU. */
174 ADC_RES_MAX = 22u,
175 ADC_RES_UV = 23u,
176} adc_res_t;
178#endif /* ifndef DOXYGEN */
179
203
204#ifdef DOXYGEN
209#define QN908X_ADC_CLOCK
210#endif /* ifdef DOXYGEN */
211
245
254typedef enum {
255 ADC_VREF_1V2 = 0x0000u,
256 ADC_VREF_VREF = 0x4000u,
257 ADC_VREF_VEXT = 0x8000u,
258 ADC_VREF_VCC = 0xC000u,
260
267#define ADC_VREF_GAIN_X15 (0x100u)
268
280#define ADC_PGA_ENABLE (0x08u)
281
295
307typedef enum {
308 ADC_GAIN_X05 = 0x40u,
309 ADC_GAIN_X1 = 0x00u,
310 ADC_GAIN_X15 = 0xC0u,
311 ADC_GAIN_X20 = 0x80u,
313
330typedef uint16_t adc_conf_t;
331
336#define TIMER_CHANNEL_NUMOF (4)
337#define TIMER_MAX_VALUE (0xffffffff)
341#define PERIPH_TIMER_PROVIDES_SET 1
351#define HAVE_I2C_SPEED_T
352typedef enum {
353 I2C_SPEED_LOW = 10000u,
355 I2C_SPEED_FAST = 400000u,
357 I2C_SPEED_HIGH = 400000u,
364typedef struct {
365 I2C_Type *dev;
366 gpio_t pin_scl;
367 gpio_t pin_sda;
368 uint32_t speed;
369} i2c_conf_t;
370
375#define PERIPH_I2C_NEED_READ_REG
376#define PERIPH_I2C_NEED_READ_REGS
377#define PERIPH_I2C_NEED_WRITE_REG
378#define PERIPH_I2C_NEED_WRITE_REGS
385#define i2c_pin_sda(dev) i2c_config[dev].pin_sda
386#define i2c_pin_scl(dev) i2c_config[dev].pin_scl
393#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
394#define PERIPH_SPI_NEEDS_TRANSFER_REG
395#define PERIPH_SPI_NEEDS_TRANSFER_REGS
398#ifndef DOXYGEN
405#define SPI_HWCS(x) (1u << 15u | (x))
406
410#define SPI_HWCS_NUMOF 4
411
417#define SPI_MODE_SEL(pol, pha) (SPI_CFG_CPOL(pol) | SPI_CFG_CPHA(pha))
418
425#define HAVE_SPI_MODE_T
426typedef enum {
427 SPI_MODE_0 = SPI_MODE_SEL(0, 0),
428 SPI_MODE_1 = SPI_MODE_SEL(0, 1),
429 SPI_MODE_2 = SPI_MODE_SEL(1, 0),
430 SPI_MODE_3 = SPI_MODE_SEL(1, 1)
431} spi_mode_t;
443#define HAVE_SPI_CLK_T
444typedef enum {
445 SPI_CLK_100KHZ = 100000u,
446 SPI_CLK_400KHZ = 400000u,
447 SPI_CLK_1MHZ = 1000000u,
448 SPI_CLK_5MHZ = 5000000u,
449 SPI_CLK_10MHZ = 10000000u
450} spi_clk_t;
457#define spi_pin_mosi(bus) spi_config[bus].copi_pin
458#define spi_pin_miso(bus) spi_config[bus].cipo_pin
459#define spi_pin_clk(bus) spi_config[bus].clk_pin
465typedef struct {
466 SPI_Type *dev;
467 gpio_t cipo_pin;
468 gpio_t copi_pin;
469 gpio_t clk_pin;
470 gpio_t cs_pin[SPI_HWCS_NUMOF];
471} spi_conf_t;
472
473#endif /* ifndef DOXYGEN */
474
482typedef struct {
483 USART_Type *dev;
484 gpio_t rx_pin;
485 gpio_t tx_pin;
487
493#define UART_INVALID_MODE (0x80)
494
509#define HAVE_UART_PARITY_T
518typedef enum {
523 /* Note: There's a UART_DATA_BITS_9 possible in this hardware. */
525#define HAVE_UART_DATA_BITS_T
538#define HAVE_UART_STOP_BITS_T
541#ifdef __cplusplus
542}
543#endif
544
545#endif /* PERIPH_CPU_H */
@ PORT_B
port B
Definition periph_cpu.h:48
@ PORT_A
port A
Definition periph_cpu.h:47
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
gpio_t adc_conf_t
ADC configuration wrapper.
Definition periph_cpu.h:337
#define GPIO_MODE(x, y)
Internal macro for combining pin mode (x) and pull-up/down (y).
Definition periph_cpu.h:152
adc_res_t
Possible ADC resolution settings.
Definition adc.h:93
@ ADC_RES_16BIT
ADC resolution: 16 bit.
Definition adc.h:99
@ 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_PORTS_NUMOF
overall number of available ports
Definition periph_cpu.h:249
#define SPI_HWCS_NUMOF
Kinetis CPUs have a maximum number of 5 hardware chip select lines.
Definition periph_cpu.h:116
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
qn908x_adc_clock_t
ADC oversample clock configuration.
Definition periph_cpu.h:192
@ ADC_CLOCK_500K
500 KHz from the high speed clock.
Definition periph_cpu.h:196
@ ADC_CLOCK_1M
1 MHz from the high speed clock.
Definition periph_cpu.h:195
@ ADC_CLOCK_62K5
62.5 KHz from the high speed clock.
Definition periph_cpu.h:199
@ ADC_CLOCK_125K
125 KHz from the high speed clock.
Definition periph_cpu.h:198
@ ADC_CLOCK_2M
2 MHz from the high speed clock.
Definition periph_cpu.h:194
@ ADC_CLOCK_31K25
31.25 KHz from the high speed clock.
Definition periph_cpu.h:200
@ ADC_CLOCK_32K
32 KHz or 32.768 KHz from the low speed clock.
Definition periph_cpu.h:201
@ ADC_CLOCK_4M
4 MHz from the high speed clock.
Definition periph_cpu.h:193
@ ADC_CLOCK_250K
250 KHz from the high speed clock.
Definition periph_cpu.h:197
qn908x_adc_vref_t
ADC Vref configuration.
Definition periph_cpu.h:254
@ ADC_VREF_VEXT
Vref := external ADC_VREFI with the driver.
Definition periph_cpu.h:257
@ ADC_VREF_VCC
Vref := Vcc.
Definition periph_cpu.h:258
@ ADC_VREF_1V2
Vref := internal 1.2V.
Definition periph_cpu.h:255
@ ADC_VREF_VREF
Vref := external ADC_VREFI pin.
Definition periph_cpu.h:256
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:502
@ UART_PARITY_SPACE
space parity
Definition periph_cpu.h:507
@ UART_PARITY_NONE
no parity
Definition periph_cpu.h:503
@ UART_PARITY_EVEN
even parity
Definition periph_cpu.h:504
@ UART_PARITY_ODD
odd parity
Definition periph_cpu.h:505
@ UART_PARITY_MARK
mark parity
Definition periph_cpu.h:506
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:534
@ UART_STOP_BITS_2
2 stop bits
Definition periph_cpu.h:536
@ UART_STOP_BITS_1
1 stop bit
Definition periph_cpu.h:535
#define UART_INVALID_MODE
Invalid UART mode mask.
Definition periph_cpu.h:493
qn908x_adc_gain_t
ADC SD Gain configuration.
Definition periph_cpu.h:307
@ ADC_GAIN_X05
Use gain := 0.5.
Definition periph_cpu.h:308
@ ADC_GAIN_X1
Use gain := 1.
Definition periph_cpu.h:309
@ ADC_GAIN_X20
Use gain := 2.
Definition periph_cpu.h:311
@ ADC_GAIN_X15
Use gain := 1.5.
Definition periph_cpu.h:310
qn908x_adc_vinn_t
ADC Vinn configuration.
Definition periph_cpu.h:289
@ ADC_VINN_VREF_2
Use Vinn := 1/2 * Vref.
Definition periph_cpu.h:292
@ ADC_VINN_VREF
Use Vinn := Vref.
Definition periph_cpu.h:290
@ ADC_VINN_AVSS
Use Vinn := Vss.
Definition periph_cpu.h:293
@ ADC_VINN_VREF_3_4
Use Vinn := 3/4 * Vref.
Definition periph_cpu.h:291
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
qn908x_adc_channel_t
ADC channel pair configuration.
Definition periph_cpu.h:227
@ ADC_CHANNEL_ADC4_VINN
Sample ADC4 / Vinn.
Definition periph_cpu.h:236
@ ADC_CHANNEL_ADC5_VINN
Sample ADC5 / Vinn.
Definition periph_cpu.h:237
@ ADC_CHANNEL_TEMP
Sample internal temperature.
Definition periph_cpu.h:240
@ ADC_CHANNEL_ADC0_ADC1
Sample ADC0 / ADC1.
Definition periph_cpu.h:228
@ ADC_CHANNEL_ADC3_VINN
Sample ADC3 / Vinn.
Definition periph_cpu.h:235
@ ADC_CHANNEL_ADC1_VINN
Sample ADC1 / Vinn.
Definition periph_cpu.h:233
@ ADC_CHANNEL_ADC6_VINN
Sample ADC6 / Vinn.
Definition periph_cpu.h:238
@ ADC_CHANNEL_VINN_VINN
Sample Vinn / Vinn.
Definition periph_cpu.h:242
@ ADC_CHANNEL_ADC0_VINN
Sample ADC0 / Vinn.
Definition periph_cpu.h:232
@ ADC_CHANNEL_ADC2_ADC3
Sample ADC2 / ADC3.
Definition periph_cpu.h:229
@ ADC_CHANNEL_ADC2_VINN
Sample ADC2 / Vinn.
Definition periph_cpu.h:234
@ ADC_CHANNEL_ADC4_ADC5
Sample ADC4 / ADC5.
Definition periph_cpu.h:230
@ ADC_CHANNEL_VINN_VSS
Sample Vinn / Vss.
Definition periph_cpu.h:243
@ ADC_CHANNEL_ADC6_ADC7
Sample ADC6 / ADC7.
Definition periph_cpu.h:231
@ ADC_CHANNEL_ADC7_VINN
Sample ADC7 / Vinn.
Definition periph_cpu.h:239
@ ADC_CHANNEL_VCC4_VINN
Sample 1/4 Vcc / Vinn.
Definition periph_cpu.h:241
I2C configuration structure.
Definition periph_cpu.h:299
SPI device configuration.
Definition periph_cpu.h:337
UART device configuration.
Definition periph_cpu.h:218