42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
68#define UWB_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
89#define UWB_SUB_NO 0x00
96#define UWB_REG_DEV_ID 0x00
97#define UWB_REG_EU_ID 0x01
98#define UWB_REG_PAN_ID 0x03
99#define UWB_REG_SYS_CFG 0x04
100#define UWB_REG_SYS_CNT 0x06
101#define UWB_REG_SYS_TX_CTRL 0x08
102#define UWB_REG_TX_DATA_BUF 0x09
103#define UWB_REG_DX_TIME 0x0A
104#define UWB_REG_RX_TIMEOUT 0x0C
105#define UWB_REG_SYS_CTRL 0x0D
106#define UWB_REG_SYS_EVENT_MASK 0x0E
107#define UWB_REG_EVENT_STATUS 0x0F
108#define UWB_REG_RX_INFO 0x10
109#define UWB_REG_RX_BUF 0x11
110#define UWB_REG_RX_QUALITY_INFO 0x12
111#define UWB_REG_RX_TIME_INTERVAL 0x13
112#define UWB_REG_RX_TIME_OFFSET 0x14
113#define UWB_REG_RX_MESSAGE_TOA 0x15
114#define UWB_REG_TX_MESSAGE_TOS 0x17
115#define UWB_REG_TX_ANTD 0x18
116#define UWB_REG_SYS_STATE 0x19
117#define UWB_REG_ACK_RESPONSE_TIME 0x1A
118#define UWB_REG_RX_SNIFF_CFG 0x1D
119#define UWB_REG_TX_POWER 0x1E
120#define UWB_REG_CHN_CTRL 0x1F
121#define UWB_REG_SFD 0x21
122#define UWB_REG_AUTO_GAIN_CFG 0x23
123#define UWB_REG_EXTERNAL_SYNC 0x24
124#define UWB_REG_READ_AA_DATA 0x25
125#define UWB_REG_GPIO_CTRL 0x26
126#define UWB_REG_DRX_CFG 0x27
127#define UWB_REG_RF_CFG 0x28
128#define UWB_REG_TX_CALIBRATION 0x2A
129#define UWB_REG_FREQ_SYNTH_CTRL 0x2B
130#define UWB_REG_ALWAYS_ON_REG 0x2C
131#define UWB_REG_OTP_INTERFACE 0x2D
132#define UWB_REG_LEAD_EDGE_DET_CTRL 0x2E
133#define UWB_REG_DIGITAL_DIAG_IF 0x2F
134#define UWB_REG_POWER_MANAGE_SYS_CTRL 0x36
141#define UWB_OTP_WRITE 0x00
142#define UWB_OTP_ADR 0x04
143#define UWB_OTP_CTRL 0x06
144#define UWB_OTP_STATUS 0x08
145#define UWB_OTP_RDAT 0x0A
146#define UWB_OTP_SRDAT 0x0E
147#define UWB_OTP_SF 0x12
154#define UWB_DATA_RATE_110KBSPS 0x00
155#define UWB_DATA_RATE_850KBSPS 0x01
156#define UWB_DATA_RATE_6800KBSPS 0x02
163#define UWB_PULSTE_FREQ_4MHZ 0x00
164#define UWB_PULSTE_FREQ_16MHZ 0x01
165#define UWB_PULSTE_FREQ_64MHZ 0x02
172#define UWB_PREAMBLE_LEN_64 0x01
173#define UWB_PREAMBLE_LEN_128 0x05
174#define UWB_PREAMBLE_LEN_256 0x09
175#define UWB_PREAMBLE_LEN_512 0x0D
176#define UWB_PREAMBLE_LEN_1024 0x02
177#define UWB_PREAMBLE_LEN_1536 0x06
178#define UWB_PREAMBLE_LEN_2048 0x0A
179#define UWB_PREAMBLE_LEN_4096 0x03
186#define UWB_PAC_SIZE_8 8
187#define UWB_PAC_SIZE_16 16
188#define UWB_PAC_SIZE_32 32
189#define UWB_PAC_SIZE_64 64
196#define UWB_CHANNEL_1 1
197#define UWB_CHANNEL_2 2
198#define UWB_CHANNEL_3 3
199#define UWB_CHANNEL_4 4
200#define UWB_CHANNEL_5 5
201#define UWB_CHANNEL_7 7
208#define UWB_PREAMBLE_CODE_1 1
209#define UWB_PREAMBLE_CODE_2 2
210#define UWB_PREAMBLE_CODE_3 3
211#define UWB_PREAMBLE_CODE_4 4
212#define UWB_PREAMBLE_CODE_5 5
213#define UWB_PREAMBLE_CODE_6 6
214#define UWB_PREAMBLE_CODE_7 7
215#define UWB_PREAMBLE_CODE_8 8
216#define UWB_PREAMBLE_CODE_9 9
217#define UWB_PREAMBLE_CODE_10 10
218#define UWB_PREAMBLE_CODE_11 11
219#define UWB_PREAMBLE_CODE_12 12
220#define UWB_PREAMBLE_CODE_13 13
221#define UWB_PREAMBLE_CODE_14 14
222#define UWB_PREAMBLE_CODE_15 15
223#define UWB_PREAMBLE_CODE_16 16
224#define UWB_PREAMBLE_CODE_17 17
225#define UWB_PREAMBLE_CODE_18 18
226#define UWB_PREAMBLE_CODE_19 19
227#define UWB_PREAMBLE_CODE_20 20
228#define UWB_PREAMBLE_CODE_21 21
229#define UWB_PREAMBLE_CODE_22 22
230#define UWB_PREAMBLE_CODE_23 23
231#define UWB_PREAMBLE_CODE_24 24
238#define UWB_FRAME_LEN_NORMAL 0x00
239#define UWB_FRAME_LEN_EXTENDED 0x03
254#define UWB_DEV_ERROR 0xFF
255#define UWB_DEV_OK 0x00
262#define UWB_MODE_IDLE 1
271#define UWB_TAG 0xDECA
278#define WRITE_MASK 0x80
280#define READ_MASK 0x00
281#define SUB_EXT_MASK 0x80
288#define AGC_TUNE1_SUB 0x04
289#define AGC_TUNE2_SUB 0x0C
290#define AGC_TUNE3_SUB 0x12
291#define LEN_AGC_TUNE1 2
292#define LEN_AGC_TUNE2 4
293#define LEN_AGC_TUNE3 2
294#define DRX_TUNE0b_SUB 0x02
295#define DRX_TUNE1a_SUB 0x04
296#define DRX_TUNE1b_SUB 0x06
297#define DRX_TUNE2_SUB 0x08
298#define DRX_TUNE4H_SUB 0x26
299#define LEN_DRX_TUNE0b 2
300#define LEN_DRX_TUNE1a 2
301#define LEN_DRX_TUNE1b 2
302#define LEN_DRX_TUNE2 4
303#define LEN_DRX_TUNE4H 2
304#define LDE_CFG1_SUB 0x0806
305#define LDE_RXANTD_SUB 0x1804
306#define LDE_CFG2_SUB 0x1806
307#define LDE_REPC_SUB 0x2804
308#define LEN_LDE_CFG1 1
309#define LEN_LDE_CFG2 2
310#define LEN_LDE_REPC 2
311#define LEN_LDE_RXANTD 2
312#define LEN_TX_POWER 4
313#define RF_RXCTRLH_SUB 0x0B
314#define RF_TXCTRL_SUB 0x0C
315#define LEN_RF_RXCTRLH 1
316#define LEN_RF_TXCTRL 4
317#define TC_PGDELAY_SUB 0x0B
318#define LEN_TC_PGDELAY 1
321#define FS_PLLCFG_SUB 0x07
322#define FS_PLLTUNE_SUB 0x0B
323#define FS_XTALT_SUB 0x0E
324#define LEN_FS_PLLCFG 4
325#define LEN_FS_PLLTUNE 1
326#define LEN_FS_XTALT 1
333#define DUMMY_BUFFER 1024
344#define UWB_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
345#define UWB_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
const uint8_t UWB_TMODE_SHORTDATA_FAST_ACCURACY[3]
const uint8_t UWB_TMODE_LONGDATA_RANGE_LOWPOWER[3]
const uint8_t UWB_TMODE_LONGDATA_FAST_LOWPOWER[3]
const uint8_t UWB_TMODE_LONGDATA_RANGE_ACCURACY[3]
const uint8_t UWB_TMODE_SHORTDATA_FAST_LOWPOWER[3]
const uint8_t UWB_TMODE_LONGDATA_FAST_ACCURACY[3]
void uwb_generic_read(uwb_t *ctx, uint8_t reg_adr, uint8_t *rx_buf, uint16_t buf_len)
Function for reading data from register.
void uwb_generic_write(uwb_t *ctx, uint8_t reg_adr, uint8_t *tx_buf, uint16_t buf_len)
Function for writing data to register.
void uwb_set_transmit(uwb_t *ctx, uint8_t *tx_buf, uint16_t len_buf)
Function for setting transmit data.
void uwb_frame_check(uint8_t fc_val)
Function for setting frame check option.
void uwb_dev_reset(uwb_t *ctx)
Function for reseting device.
uint16_t uwb_reg_data_len(uint8_t reg_adr)
Function for getting length of register data.
uint8_t uwb_get_transmit_status(uwb_t *ctx)
Function for getting transmit status.
void uwb_set_rst_pin_status(uwb_t *ctx, uint8_t status)
Function for setting rst pin status.
void uwb_enable(uwb_t *ctx)
Function for enabling device.
void uwb_int_mask_set(uwb_t *ctx)
Function for setting interrupt mask.
void uwb_set_preable_code(uwb_t *ctx, uint8_t preamble)
Function for setting preamble code.
void uwb_clear_status(uwb_t *ctx)
Function for clearing status.
void uwb_set_transmit_type(uwb_t *ctx, const uint8_t *t_t)
Function for setting transmit type mode.
uint8_t uwb_set_data_rate(uwb_t *ctx, uint8_t rate)
Function for setting data rate.
void uwb_set_bit(uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num, uint8_t bit_state)
Function for setting single bit state.
void uwb_set_preamble_len(uwb_t *ctx, uint8_t prealen)
Function for setting preamble length.
void uwb_set_dev_adr_n_network_id(uwb_t *ctx, uint16_t dev_adr, uint16_t net_id)
Function for setting device address and network ID.
void uwb_cfg_setup(uwb_cfg_t *cfg)
Config Object Initialization function.
void uwb_read_otp(uwb_t *ctx, uint16_t otp_adr, uint8_t *rx_buf)
Function for reading OTM memory.
void uwb_start_transceiver(uwb_t *ctx)
Function for starting communication of device.
void uwb_get_transmit(uwb_t *ctx, uint8_t *rx_buf, uint16_t len_buf)
Function for getting transmit data.
void uwb_frame_filter(uwb_t *ctx, uint8_t ff_val)
Function for setting frame filter option.
void uwb_tune_config(uwb_t *ctx)
Function for tuneing configuration for set values.
void uwb_use_smart_power(uwb_t *ctx, uint8_t smart_power)
Function for setting smart power option.
uint8_t uwb_get_transmit_len(uwb_t *ctx)
Function for getting transmit length.
err_t uwb_init(uwb_t *ctx, uwb_cfg_t *cfg)
Initialization function.
void uwb_set_channel(uwb_t *ctx, uint8_t channel)
Function for setting channel.
uint8_t uwb_get_qint_pin_status(uwb_t *ctx)
Function for getting irq pin status.
void uwb_set_pulse_freq(uwb_t *ctx, uint8_t freq)
Function for setting pulse frequency.
uint8_t uwb_get_bit(uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num)
Function for getting single bit state.
void uwb_set_mode(uwb_t *ctx, uint8_t mode)
Function for setting device working mode.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition uwb.h:382
pin_name_t irq
Definition uwb.h:393
spi_master_chip_select_polarity_t cs_polarity
Definition uwb.h:399
pin_name_t sck
Definition uwb.h:387
spi_master_mode_t spi_mode
Definition uwb.h:398
pin_name_t mosi
Definition uwb.h:386
uint32_t spi_speed
Definition uwb.h:397
pin_name_t miso
Definition uwb.h:385
pin_name_t rst
Definition uwb.h:392
pin_name_t cs
Definition uwb.h:388
Structure for device configuration.
Definition uwb.h:407
uint8_t extended_frame
Definition uwb.h:409
uint8_t pulse_freq
Definition uwb.h:411
uint8_t smart_power
Definition uwb.h:418
uint16_t antenna_delay
Definition uwb.h:416
uint8_t antenna_calib
Definition uwb.h:417
uint8_t preamble_len
Definition uwb.h:413
uint8_t pac_size
Definition uwb.h:410
uint8_t dev_mode
Definition uwb.h:408
uint8_t channel
Definition uwb.h:415
uint8_t preamble_code
Definition uwb.h:414
uint8_t debounce_clk_en
Definition uwb.h:421
uint8_t data_rate
Definition uwb.h:412
uint8_t permanent_rx
Definition uwb.h:420
uint8_t frame_check
Definition uwb.h:419
Click ctx object definition.
Definition uwb.h:357
digital_out_t cs
Definition uwb.h:361
spi_master_t spi
Definition uwb.h:369
digital_in_t irq
Definition uwb.h:365
digital_out_t rst
Definition uwb.h:360
uint16_t offset
Definition uwb.h:374
pin_name_t chip_select
Definition uwb.h:370