Loading...
Searching...
No Matches
periph_cpu.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 iosabi
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#include <stdint.h>
19#include <stdbool.h>
20
21#include "cpu.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
31#define HAVE_GPIO_T
32typedef uint16_t gpio_t;
34
38#define GPIO_UNDEF (0xffff)
39
48#define GPIO_PIN(x, y) (((x) << 12u) | (y))
49
50/* QN908x has a unique default Bluetooth address in the Flash Information Page
51 * descriptor. This value is set in the factory and cannot be modified by
52 * users. However, the actual Bluetooth address used by the stack may be
53 * different, this is just the default. */
57#define CPUID_ADDR (FSL_FEATURE_FLASH_ADDR_OF_VENDOR_BD_ADDR)
58
62#define CPUID_LEN (6U)
63
67#define WDT_HAS_STOP (1)
68
80#define NWDT_TIME_LOWER_LIMIT (1U)
81#define NWDT_TIME_UPPER_LIMIT (268435U)
82#define WWDT_TIME_LOWER_LIMIT (1U)
83#define WWDT_TIME_UPPER_LIMIT (268435U)
85
95#define GPIO_MODE(open_drain, out_enabled, pull_mode) \
96 ((open_drain) | ((out_enabled) << 1) | ((pull_mode) << 4))
97
98#ifndef DOXYGEN
103#define HAVE_GPIO_MODE_T
104typedef enum {
105 GPIO_IN = GPIO_MODE(0, 0, 0),
106 GPIO_IN_PD = GPIO_MODE(0, 0, 1),
107 GPIO_IN_PU = GPIO_MODE(0, 0, 2),
108 GPIO_OUT = GPIO_MODE(0, 1, 0),
109 GPIO_OD = GPIO_MODE(1, 1, 0),
110 GPIO_OD_PU = GPIO_MODE(1, 1, 2),
113#endif /* ndef DOXYGEN */
114
115#ifndef DOXYGEN
120#define HAVE_GPIO_FLANK_T
121typedef enum {
122 GPIO_LOW = 0,
123 GPIO_HIGH = 1,
124 GPIO_RISING = 2,
125 GPIO_FALLING = 3,
126 GPIO_BOTH = 4,
129#endif /* ndef DOXYGEN */
130
134enum {
135 PORT_A = 0,
136 PORT_B = 1,
138};
139
140#if DOXYGEN
152#define BOARD_HAS_ADC_PA06_CAP
154#endif
155
156#ifndef DOXYGEN
161#define HAVE_ADC_RES_T
162typedef enum {
163 ADC_RES_6BIT = 6u,
164 ADC_RES_8BIT = 8u,
165 ADC_RES_10BIT = 10u,
166 ADC_RES_12BIT = 12u,
167 ADC_RES_14BIT = 14u,
168 ADC_RES_16BIT = 16u,
169 /* Extra modes supported by this CPU. */
170 ADC_RES_MAX = 22u,
171 ADC_RES_UV = 23u,
172} adc_res_t;
174#endif /* ifndef DOXYGEN */
175
199
200#ifdef DOXYGEN
205#define QN908X_ADC_CLOCK
206#endif /* ifdef DOXYGEN */
207
241
250typedef enum {
251 ADC_VREF_1V2 = 0x0000u,
252 ADC_VREF_VREF = 0x4000u,
253 ADC_VREF_VEXT = 0x8000u,
254 ADC_VREF_VCC = 0xC000u,
256
263#define ADC_VREF_GAIN_X15 (0x100u)
264
276#define ADC_PGA_ENABLE (0x08u)
277
291
303typedef enum {
304 ADC_GAIN_X05 = 0x40u,
305 ADC_GAIN_X1 = 0x00u,
306 ADC_GAIN_X15 = 0xC0u,
307 ADC_GAIN_X20 = 0x80u,
309
326typedef uint16_t adc_conf_t;
327
332#define TIMER_CHANNEL_NUMOF (4)
333#define TIMER_MAX_VALUE (0xffffffff)
337#define PERIPH_TIMER_PROVIDES_SET 1
339
347#define HAVE_I2C_SPEED_T
348typedef enum {
349 I2C_SPEED_LOW = 10000u,
351 I2C_SPEED_FAST = 400000u,
353 I2C_SPEED_HIGH = 400000u,
355
356
360typedef struct {
361 I2C_Type *dev;
362 gpio_t pin_scl;
363 gpio_t pin_sda;
364 uint32_t speed;
365} i2c_conf_t;
366
371#define PERIPH_I2C_NEED_READ_REG
372#define PERIPH_I2C_NEED_READ_REGS
373#define PERIPH_I2C_NEED_WRITE_REG
374#define PERIPH_I2C_NEED_WRITE_REGS
376
381#define i2c_pin_sda(dev) i2c_config[dev].pin_sda
382#define i2c_pin_scl(dev) i2c_config[dev].pin_scl
384
389#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
390#define PERIPH_SPI_NEEDS_TRANSFER_REG
391#define PERIPH_SPI_NEEDS_TRANSFER_REGS
393
394#ifndef DOXYGEN
401#define SPI_HWCS(x) (1u << 15u | (x))
402
406#define SPI_HWCS_NUMOF 4
407
413#define SPI_MODE_SEL(pol, pha) (SPI_CFG_CPOL(pol) | SPI_CFG_CPHA(pha))
414
421#define HAVE_SPI_MODE_T
422typedef enum {
423 SPI_MODE_0 = SPI_MODE_SEL(0, 0),
424 SPI_MODE_1 = SPI_MODE_SEL(0, 1),
425 SPI_MODE_2 = SPI_MODE_SEL(1, 0),
426 SPI_MODE_3 = SPI_MODE_SEL(1, 1)
427} spi_mode_t;
429
439#define HAVE_SPI_CLK_T
440typedef enum {
441 SPI_CLK_100KHZ = 100000u,
442 SPI_CLK_400KHZ = 400000u,
443 SPI_CLK_1MHZ = 1000000u,
444 SPI_CLK_5MHZ = 5000000u,
445 SPI_CLK_10MHZ = 10000000u
446} spi_clk_t;
448
453#define spi_pin_mosi(bus) spi_config[bus].copi_pin
454#define spi_pin_miso(bus) spi_config[bus].cipo_pin
455#define spi_pin_clk(bus) spi_config[bus].clk_pin
457
461typedef struct {
462 SPI_Type *dev;
463 gpio_t cipo_pin;
464 gpio_t copi_pin;
465 gpio_t clk_pin;
466 gpio_t cs_pin[SPI_HWCS_NUMOF];
467} spi_conf_t;
468
469#endif /* ifndef DOXYGEN */
470
478typedef struct {
479 USART_Type *dev;
480 gpio_t rx_pin;
481 gpio_t tx_pin;
483
489#define UART_INVALID_MODE (0x80)
490
505#define HAVE_UART_PARITY_T
507
514typedef enum {
519 /* Note: There's a UART_DATA_BITS_9 possible in this hardware. */
521#define HAVE_UART_DATA_BITS_T
523
534#define HAVE_UART_STOP_BITS_T
536
537#ifdef __cplusplus
538}
539#endif
540
@ PORT_B
port B
Definition periph_cpu.h:44
@ PORT_A
port A
Definition periph_cpu.h:43
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
i2c_speed_t
Definition periph_cpu.h:272
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition periph_cpu.h:274
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
Definition periph_cpu.h:276
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
Definition periph_cpu.h:273
@ I2C_SPEED_HIGH
high speed mode: ~3400 kbit/s
Definition periph_cpu.h:278
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
Definition periph_cpu.h:275
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
#define GPIO_MODE(x, y)
Internal macro for combining pin mode (x) and pull-up/down (y).
Definition periph_cpu.h:147
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_PORTS_NUMOF
overall number of available ports
Definition periph_cpu.h:245
#define SPI_HWCS_NUMOF
Kinetis CPUs have a maximum number of 5 hardware chip select lines.
Definition periph_cpu.h:112
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
qn908x_adc_clock_t
ADC oversample clock configuration.
Definition periph_cpu.h:188
@ ADC_CLOCK_500K
500 KHz from the high speed clock.
Definition periph_cpu.h:192
@ ADC_CLOCK_1M
1 MHz from the high speed clock.
Definition periph_cpu.h:191
@ ADC_CLOCK_62K5
62.5 KHz from the high speed clock.
Definition periph_cpu.h:195
@ ADC_CLOCK_125K
125 KHz from the high speed clock.
Definition periph_cpu.h:194
@ ADC_CLOCK_2M
2 MHz from the high speed clock.
Definition periph_cpu.h:190
@ ADC_CLOCK_31K25
31.25 KHz from the high speed clock.
Definition periph_cpu.h:196
@ ADC_CLOCK_32K
32 KHz or 32.768 KHz from the low speed clock.
Definition periph_cpu.h:197
@ ADC_CLOCK_4M
4 MHz from the high speed clock.
Definition periph_cpu.h:189
@ ADC_CLOCK_250K
250 KHz from the high speed clock.
Definition periph_cpu.h:193
qn908x_adc_vref_t
ADC Vref configuration.
Definition periph_cpu.h:250
@ ADC_VREF_VEXT
Vref := external ADC_VREFI with the driver.
Definition periph_cpu.h:253
@ ADC_VREF_VCC
Vref := Vcc.
Definition periph_cpu.h:254
@ ADC_VREF_1V2
Vref := internal 1.2V.
Definition periph_cpu.h:251
@ ADC_VREF_VREF
Vref := external ADC_VREFI pin.
Definition periph_cpu.h:252
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:498
@ UART_PARITY_SPACE
space parity
Definition periph_cpu.h:503
@ UART_PARITY_NONE
no parity
Definition periph_cpu.h:499
@ UART_PARITY_EVEN
even parity
Definition periph_cpu.h:500
@ UART_PARITY_ODD
odd parity
Definition periph_cpu.h:501
@ UART_PARITY_MARK
mark parity
Definition periph_cpu.h:502
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:530
@ UART_STOP_BITS_2
2 stop bits
Definition periph_cpu.h:532
@ UART_STOP_BITS_1
1 stop bit
Definition periph_cpu.h:531
#define UART_INVALID_MODE
Invalid UART mode mask.
Definition periph_cpu.h:489
qn908x_adc_gain_t
ADC SD Gain configuration.
Definition periph_cpu.h:303
@ ADC_GAIN_X05
Use gain := 0.5.
Definition periph_cpu.h:304
@ ADC_GAIN_X1
Use gain := 1.
Definition periph_cpu.h:305
@ ADC_GAIN_X20
Use gain := 2.
Definition periph_cpu.h:307
@ ADC_GAIN_X15
Use gain := 1.5.
Definition periph_cpu.h:306
qn908x_adc_vinn_t
ADC Vinn configuration.
Definition periph_cpu.h:285
@ ADC_VINN_VREF_2
Use Vinn := 1/2 * Vref.
Definition periph_cpu.h:288
@ ADC_VINN_VREF
Use Vinn := Vref.
Definition periph_cpu.h:286
@ ADC_VINN_AVSS
Use Vinn := Vss.
Definition periph_cpu.h:289
@ ADC_VINN_VREF_3_4
Use Vinn := 3/4 * Vref.
Definition periph_cpu.h:287
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:514
@ UART_DATA_BITS_6
6 data bits
Definition periph_cpu.h:516
@ UART_DATA_BITS_5
5 data bits
Definition periph_cpu.h:515
@ UART_DATA_BITS_7
7 data bits
Definition periph_cpu.h:517
@ UART_DATA_BITS_8
8 data bits
Definition periph_cpu.h:518
qn908x_adc_channel_t
ADC channel pair configuration.
Definition periph_cpu.h:223
@ ADC_CHANNEL_ADC4_VINN
Sample ADC4 / Vinn.
Definition periph_cpu.h:232
@ ADC_CHANNEL_ADC5_VINN
Sample ADC5 / Vinn.
Definition periph_cpu.h:233
@ ADC_CHANNEL_TEMP
Sample internal temperature.
Definition periph_cpu.h:236
@ ADC_CHANNEL_ADC0_ADC1
Sample ADC0 / ADC1.
Definition periph_cpu.h:224
@ ADC_CHANNEL_ADC3_VINN
Sample ADC3 / Vinn.
Definition periph_cpu.h:231
@ ADC_CHANNEL_ADC1_VINN
Sample ADC1 / Vinn.
Definition periph_cpu.h:229
@ ADC_CHANNEL_ADC6_VINN
Sample ADC6 / Vinn.
Definition periph_cpu.h:234
@ ADC_CHANNEL_VINN_VINN
Sample Vinn / Vinn.
Definition periph_cpu.h:238
@ ADC_CHANNEL_ADC0_VINN
Sample ADC0 / Vinn.
Definition periph_cpu.h:228
@ ADC_CHANNEL_ADC2_ADC3
Sample ADC2 / ADC3.
Definition periph_cpu.h:225
@ ADC_CHANNEL_ADC2_VINN
Sample ADC2 / Vinn.
Definition periph_cpu.h:230
@ ADC_CHANNEL_ADC4_ADC5
Sample ADC4 / ADC5.
Definition periph_cpu.h:226
@ ADC_CHANNEL_VINN_VSS
Sample Vinn / Vss.
Definition periph_cpu.h:239
@ ADC_CHANNEL_ADC6_ADC7
Sample ADC6 / ADC7.
Definition periph_cpu.h:227
@ ADC_CHANNEL_ADC7_VINN
Sample ADC7 / Vinn.
Definition periph_cpu.h:235
@ ADC_CHANNEL_VCC4_VINN
Sample 1/4 Vcc / Vinn.
Definition periph_cpu.h:237
ADC device configuration.
Definition periph_cpu.h:374
I2C configuration structure.
Definition periph_cpu.h:295
SPI device configuration.
Definition periph_cpu.h:333
UART device configuration.
Definition periph_cpu.h:214