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
9#pragma once
10
20
21#include <stdint.h>
22#include <stdbool.h>
23
24#include "cpu.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
34#define HAVE_GPIO_T
35typedef uint16_t gpio_t;
37
41#define GPIO_UNDEF (0xffff)
42
51#define GPIO_PIN(x, y) (((x) << 12u) | (y))
52
53/* QN908x has a unique default Bluetooth address in the Flash Information Page
54 * descriptor. This value is set in the factory and cannot be modified by
55 * users. However, the actual Bluetooth address used by the stack may be
56 * different, this is just the default. */
60#define CPUID_ADDR (FSL_FEATURE_FLASH_ADDR_OF_VENDOR_BD_ADDR)
61
65#define CPUID_LEN (6U)
66
70#define WDT_HAS_STOP (1)
71
83#define NWDT_TIME_LOWER_LIMIT (1U)
84#define NWDT_TIME_UPPER_LIMIT (268435U)
85#define WWDT_TIME_LOWER_LIMIT (1U)
86#define WWDT_TIME_UPPER_LIMIT (268435U)
88
98#define GPIO_MODE(open_drain, out_enabled, pull_mode) \
99 ((open_drain) | ((out_enabled) << 1) | ((pull_mode) << 4))
100
101#ifndef DOXYGEN
106#define HAVE_GPIO_MODE_T
107typedef enum {
108 GPIO_IN = GPIO_MODE(0, 0, 0),
109 GPIO_IN_PD = GPIO_MODE(0, 0, 1),
110 GPIO_IN_PU = GPIO_MODE(0, 0, 2),
111 GPIO_OUT = GPIO_MODE(0, 1, 0),
112 GPIO_OD = GPIO_MODE(1, 1, 0),
113 GPIO_OD_PU = GPIO_MODE(1, 1, 2),
116#endif /* ndef DOXYGEN */
117
118#ifndef DOXYGEN
123#define HAVE_GPIO_FLANK_T
124typedef enum {
125 GPIO_LOW = 0,
126 GPIO_HIGH = 1,
127 GPIO_RISING = 2,
128 GPIO_FALLING = 3,
129 GPIO_BOTH = 4,
132#endif /* ndef DOXYGEN */
133
137enum {
138 PORT_A = 0,
139 PORT_B = 1,
141};
142
143#if DOXYGEN
155#define BOARD_HAS_ADC_PA06_CAP
157#endif
158
159#ifndef DOXYGEN
164#define HAVE_ADC_RES_T
165typedef enum {
166 ADC_RES_6BIT = 6u,
167 ADC_RES_8BIT = 8u,
168 ADC_RES_10BIT = 10u,
169 ADC_RES_12BIT = 12u,
170 ADC_RES_14BIT = 14u,
171 ADC_RES_16BIT = 16u,
172 /* Extra modes supported by this CPU. */
173 ADC_RES_MAX = 22u,
174 ADC_RES_UV = 23u,
175} adc_res_t;
177#endif /* ifndef DOXYGEN */
178
202
203#ifdef DOXYGEN
208#define QN908X_ADC_CLOCK
209#endif /* ifdef DOXYGEN */
210
244
253typedef enum {
254 ADC_VREF_1V2 = 0x0000u,
255 ADC_VREF_VREF = 0x4000u,
256 ADC_VREF_VEXT = 0x8000u,
257 ADC_VREF_VCC = 0xC000u,
259
266#define ADC_VREF_GAIN_X15 (0x100u)
267
279#define ADC_PGA_ENABLE (0x08u)
280
294
306typedef enum {
307 ADC_GAIN_X05 = 0x40u,
308 ADC_GAIN_X1 = 0x00u,
309 ADC_GAIN_X15 = 0xC0u,
310 ADC_GAIN_X20 = 0x80u,
312
329typedef uint16_t adc_conf_t;
330
335#define TIMER_CHANNEL_NUMOF (4)
336#define TIMER_MAX_VALUE (0xffffffff)
340#define PERIPH_TIMER_PROVIDES_SET 1
342
350#define HAVE_I2C_SPEED_T
351typedef enum {
352 I2C_SPEED_LOW = 10000u,
354 I2C_SPEED_FAST = 400000u,
356 I2C_SPEED_HIGH = 400000u,
358
359
363typedef struct {
364 I2C_Type *dev;
365 gpio_t pin_scl;
366 gpio_t pin_sda;
367 uint32_t speed;
368} i2c_conf_t;
369
374#define PERIPH_I2C_NEED_READ_REG
375#define PERIPH_I2C_NEED_READ_REGS
376#define PERIPH_I2C_NEED_WRITE_REG
377#define PERIPH_I2C_NEED_WRITE_REGS
379
384#define i2c_pin_sda(dev) i2c_config[dev].pin_sda
385#define i2c_pin_scl(dev) i2c_config[dev].pin_scl
387
392#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
393#define PERIPH_SPI_NEEDS_TRANSFER_REG
394#define PERIPH_SPI_NEEDS_TRANSFER_REGS
396
397#ifndef DOXYGEN
404#define SPI_HWCS(x) (1u << 15u | (x))
405
409#define SPI_HWCS_NUMOF 4
410
416#define SPI_MODE_SEL(pol, pha) (SPI_CFG_CPOL(pol) | SPI_CFG_CPHA(pha))
417
424#define HAVE_SPI_MODE_T
425typedef enum {
426 SPI_MODE_0 = SPI_MODE_SEL(0, 0),
427 SPI_MODE_1 = SPI_MODE_SEL(0, 1),
428 SPI_MODE_2 = SPI_MODE_SEL(1, 0),
429 SPI_MODE_3 = SPI_MODE_SEL(1, 1)
430} spi_mode_t;
432
442#define HAVE_SPI_CLK_T
443typedef enum {
444 SPI_CLK_100KHZ = 100000u,
445 SPI_CLK_400KHZ = 400000u,
446 SPI_CLK_1MHZ = 1000000u,
447 SPI_CLK_5MHZ = 5000000u,
448 SPI_CLK_10MHZ = 10000000u
449} spi_clk_t;
451
456#define spi_pin_mosi(bus) spi_config[bus].copi_pin
457#define spi_pin_miso(bus) spi_config[bus].cipo_pin
458#define spi_pin_clk(bus) spi_config[bus].clk_pin
460
464typedef struct {
465 SPI_Type *dev;
466 gpio_t cipo_pin;
467 gpio_t copi_pin;
468 gpio_t clk_pin;
469 gpio_t cs_pin[SPI_HWCS_NUMOF];
470} spi_conf_t;
471
472#endif /* ifndef DOXYGEN */
473
481typedef struct {
482 USART_Type *dev;
483 gpio_t rx_pin;
484 gpio_t tx_pin;
486
492#define UART_INVALID_MODE (0x80)
493
508#define HAVE_UART_PARITY_T
510
517typedef enum {
522 /* Note: There's a UART_DATA_BITS_9 possible in this hardware. */
524#define HAVE_UART_DATA_BITS_T
526
537#define HAVE_UART_STOP_BITS_T
539
540#ifdef __cplusplus
541}
542#endif
543
@ PORT_B
port B
Definition periph_cpu.h:47
@ PORT_A
port A
Definition periph_cpu.h:46
gpio_flank_t
Definition periph_cpu.h:179
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:164
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:163
i2c_speed_t
Definition periph_cpu.h:275
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:277
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition periph_cpu.h:279
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition periph_cpu.h:276
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition periph_cpu.h:281
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:278
spi_clk_t
Definition periph_cpu.h:351
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
Definition periph_cpu.h:356
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
Definition periph_cpu.h:355
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
Definition periph_cpu.h:353
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
Definition periph_cpu.h:354
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
Definition periph_cpu.h:352
#define GPIO_MODE(x, y)
Internal macro for combining pin mode (x) and pull-up/down (y).
Definition periph_cpu.h:150
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:91
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_PORTS_NUMOF
overall number of available ports
Definition periph_cpu.h:248
#define SPI_HWCS_NUMOF
Kinetis CPUs have a maximum number of 5 hardware chip select lines.
Definition periph_cpu.h:115
spi_mode_t
Support SPI modes.
Definition periph_cpu.h:42
@ SPI_MODE_0
CPOL=0, CPHA=0.
Definition periph_cpu.h:43
@ SPI_MODE_2
CPOL=1, CPHA=0.
Definition periph_cpu.h:45
@ SPI_MODE_1
CPOL=0, CPHA=1.
Definition periph_cpu.h:44
@ SPI_MODE_3
CPOL=1, CPHA=1.
Definition periph_cpu.h:46
qn908x_adc_clock_t
ADC oversample clock configuration.
Definition periph_cpu.h:191
@ ADC_CLOCK_500K
500 KHz from the high speed clock.
Definition periph_cpu.h:195
@ ADC_CLOCK_1M
1 MHz from the high speed clock.
Definition periph_cpu.h:194
@ ADC_CLOCK_62K5
62.5 KHz from the high speed clock.
Definition periph_cpu.h:198
@ ADC_CLOCK_125K
125 KHz from the high speed clock.
Definition periph_cpu.h:197
@ ADC_CLOCK_2M
2 MHz from the high speed clock.
Definition periph_cpu.h:193
@ ADC_CLOCK_31K25
31.25 KHz from the high speed clock.
Definition periph_cpu.h:199
@ ADC_CLOCK_32K
32 KHz or 32.768 KHz from the low speed clock.
Definition periph_cpu.h:200
@ ADC_CLOCK_4M
4 MHz from the high speed clock.
Definition periph_cpu.h:192
@ ADC_CLOCK_250K
250 KHz from the high speed clock.
Definition periph_cpu.h:196
qn908x_adc_vref_t
ADC Vref configuration.
Definition periph_cpu.h:253
@ ADC_VREF_VEXT
Vref := external ADC_VREFI with the driver.
Definition periph_cpu.h:256
@ ADC_VREF_VCC
Vref := Vcc.
Definition periph_cpu.h:257
@ ADC_VREF_1V2
Vref := internal 1.2V.
Definition periph_cpu.h:254
@ ADC_VREF_VREF
Vref := external ADC_VREFI pin.
Definition periph_cpu.h:255
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:501
@ UART_PARITY_SPACE
space parity
Definition periph_cpu.h:506
@ UART_PARITY_NONE
no parity
Definition periph_cpu.h:502
@ UART_PARITY_EVEN
even parity
Definition periph_cpu.h:503
@ UART_PARITY_ODD
odd parity
Definition periph_cpu.h:504
@ UART_PARITY_MARK
mark parity
Definition periph_cpu.h:505
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:533
@ UART_STOP_BITS_2
2 stop bits
Definition periph_cpu.h:535
@ UART_STOP_BITS_1
1 stop bit
Definition periph_cpu.h:534
#define UART_INVALID_MODE
Invalid UART mode mask.
Definition periph_cpu.h:492
qn908x_adc_gain_t
ADC SD Gain configuration.
Definition periph_cpu.h:306
@ ADC_GAIN_X05
Use gain := 0.5.
Definition periph_cpu.h:307
@ ADC_GAIN_X1
Use gain := 1.
Definition periph_cpu.h:308
@ ADC_GAIN_X20
Use gain := 2.
Definition periph_cpu.h:310
@ ADC_GAIN_X15
Use gain := 1.5.
Definition periph_cpu.h:309
qn908x_adc_vinn_t
ADC Vinn configuration.
Definition periph_cpu.h:288
@ ADC_VINN_VREF_2
Use Vinn := 1/2 * Vref.
Definition periph_cpu.h:291
@ ADC_VINN_VREF
Use Vinn := Vref.
Definition periph_cpu.h:289
@ ADC_VINN_AVSS
Use Vinn := Vss.
Definition periph_cpu.h:292
@ ADC_VINN_VREF_3_4
Use Vinn := 3/4 * Vref.
Definition periph_cpu.h:290
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:517
@ UART_DATA_BITS_6
6 data bits
Definition periph_cpu.h:519
@ UART_DATA_BITS_5
5 data bits
Definition periph_cpu.h:518
@ UART_DATA_BITS_7
7 data bits
Definition periph_cpu.h:520
@ UART_DATA_BITS_8
8 data bits
Definition periph_cpu.h:521
qn908x_adc_channel_t
ADC channel pair configuration.
Definition periph_cpu.h:226
@ ADC_CHANNEL_ADC4_VINN
Sample ADC4 / Vinn.
Definition periph_cpu.h:235
@ ADC_CHANNEL_ADC5_VINN
Sample ADC5 / Vinn.
Definition periph_cpu.h:236
@ ADC_CHANNEL_TEMP
Sample internal temperature.
Definition periph_cpu.h:239
@ ADC_CHANNEL_ADC0_ADC1
Sample ADC0 / ADC1.
Definition periph_cpu.h:227
@ ADC_CHANNEL_ADC3_VINN
Sample ADC3 / Vinn.
Definition periph_cpu.h:234
@ ADC_CHANNEL_ADC1_VINN
Sample ADC1 / Vinn.
Definition periph_cpu.h:232
@ ADC_CHANNEL_ADC6_VINN
Sample ADC6 / Vinn.
Definition periph_cpu.h:237
@ ADC_CHANNEL_VINN_VINN
Sample Vinn / Vinn.
Definition periph_cpu.h:241
@ ADC_CHANNEL_ADC0_VINN
Sample ADC0 / Vinn.
Definition periph_cpu.h:231
@ ADC_CHANNEL_ADC2_ADC3
Sample ADC2 / ADC3.
Definition periph_cpu.h:228
@ ADC_CHANNEL_ADC2_VINN
Sample ADC2 / Vinn.
Definition periph_cpu.h:233
@ ADC_CHANNEL_ADC4_ADC5
Sample ADC4 / ADC5.
Definition periph_cpu.h:229
@ ADC_CHANNEL_VINN_VSS
Sample Vinn / Vss.
Definition periph_cpu.h:242
@ ADC_CHANNEL_ADC6_ADC7
Sample ADC6 / ADC7.
Definition periph_cpu.h:230
@ ADC_CHANNEL_ADC7_VINN
Sample ADC7 / Vinn.
Definition periph_cpu.h:238
@ ADC_CHANNEL_VCC4_VINN
Sample 1/4 Vcc / Vinn.
Definition periph_cpu.h:240
ADC device configuration.
Definition periph_cpu.h:377
I2C configuration structure.
Definition periph_cpu.h:298
SPI device configuration.
Definition periph_cpu.h:336
UART device configuration.
Definition periph_cpu.h:217