ismtx 2.0.0.0
ismtx.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef ISMTX_H
29#define ISMTX_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52
73#define ISMTX_REG_CFG1 0x00
74#define ISMTX_REG_CFG2 0x01
75#define ISMTX_REG_CFG3 0x02
76#define ISMTX_REG_CFG4 0x03
77#define ISMTX_REG_CFG5 0x04
78#define ISMTX_REG_SHDN 0x05
79#define ISMTX_REG_PA1 0x06
80#define ISMTX_REG_PA2 0x07
81#define ISMTX_REG_PLL1 0x08
82#define ISMTX_REG_PLL2 0x09
83#define ISMTX_REG_CFG6 0x0A
84#define ISMTX_REG_PLL3 0x0B
85#define ISMTX_REG_PLL4 0x0C
86#define ISMTX_REG_PLL5 0x0D
87#define ISMTX_REG_PLL6 0x0E
88#define ISMTX_REG_PLL7 0x0F
89#define ISMTX_REG_CFG7 0x10
90#define ISMTX_REG_CFG8 0x17
91#define ISMTX_REG_CFG9 0x18
92#define ISMTX_REG_ADDL1 0x19
93#define ISMTX_REG_ADDL2 0x1A
94
95 // ismtx_reg
96
111#define ISM_TX_MODULATION_NULL 0
112#define ISM_TX_MODULATION_ASK 1
113#define ISM_TX_MODULATION_FSK 2
114
119#define ISMTX_CFG_XO_CLK_DELAY 30
120#define ISMTX_CFG_XO_CLK_DIV 31
121#define ISMTX_CFG_FSK_SHAPE 32
122#define ISMTX_CFG_SYNC 33
123#define ISMTX_CFG_MODE 34
124#define ISMTX_CFG_CLKOUT_DELAY 35
125#define ISMTX_CFG_BCLK_POSTDIV 36
126#define ISMTX_CFG_BCLK_PREDIV 37
127#define ISMTX_CFG_PWDN_MODE 38
128#define ISMTX_CFG_PA_MODE 39
129#define ISMTX_CFG_PA_DRIVERS 40
130#define ISMTX_CFG_PA_SHUNT 41
131#define ISMTX_CFG_PA_OFFSET_CUR 42
132#define ISMTX_CFG_PA_PLL_N 43
133#define ISMTX_CFG_PA_LCVCO_DIV 44
134#define ISMTX_CFG_PA_LCVCO_MODE 45
135#define ISMTX_CFG_CP_CURRENT 46
136#define ISMTX_CFG_SPITXEN1 47
137#define ISMTX_CFG_FOURWIRE1 48
138#define ISMTX_CFG_SPITXEN2 49
139#define ISMTX_CFG_FOURWIRE2 50
140#define ISMTX_CFG_DELTAF 51
141#define ISMTX_CFG_DELTAF_SHAPE 52
142#define ISMTX_CFG_TSTEP 53
143#define ISMTX_CFG_EN_LDO 54
144#define ISMTX_CFG_DIS_LDO_FUNC_EN 55
145#define ISMTX_CFG_PLL_LOOP_BAND 56
146#define ISMTX_CFG_LCVCO_FAST_START 57
147#define ISMTX_CFG_LCVCO_PWR 58
148
153#define ISMTX_XO_CLK_DELAY_NO_CYC 0x00
154#define ISMTX_XO_CLK_DELAY_16_CYC 0x01
155#define ISMTX_XO_CLK_DELAY_32_CYC 0x02
156#define ISMTX_XO_CLK_DELAY_64_CYC 0x03
157
158#define ISMTX_XO_CLK_DIV_4 0x00
159#define ISMTX_XO_CLK_DIV_5 0x01
160#define ISMTX_XO_CLK_DIV_6 0x02
161#define ISMTX_XO_CLK_DIV_7 0x03
162
163#define ISMTX_FSK_SHAPE_DISABLED 0x00
164#define ISMTX_FSK_SHAPE_ENABLED 0x01
165
166#define ISMTX_SYNC_DISABLE 0x00
167#define ISMTX_SYNC_ENABLE 0x01
168
169#define ISMTX_MODE_ASK 0x00
170#define ISMTX_MODE_FSK 0x01
171
172#define ISMTX_CLKOUT_DELAY_64_CYC 0x00
173#define ISMTX_CLKOUT_DELAY_128_CYC 0x01
174#define ISMTX_CLKOUT_DELAY_256_CYC 0x02
175#define ISMTX_CLKOUT_DELAY_512_CYC 0x03
176
177#define ISMTX_PWDN_MODE_SHUTDOWN 0x00
178#define ISMTX_PWDN_MODE_STAMDBY 0x01
179#define ISMTX_PWDN_MODE_FAST_WAKEUP 0x02
180#define ISMTX_PWDN_MODE_FAST_WAKEUP_ 0x03
181
182#define ISMTX_PA_MODE_NORMAL 0x00
183#define ISMTX_PA_MODE_BOOST 0x01
184
185#define ISMTX_PA_DRIVERS_1 0x00
186#define ISMTX_PA_DRIVERS_2 0x01
187#define ISMTX_PA_DRIVERS_3 0x02
188#define ISMTX_PA_DRIVERS_4 0x03
189#define ISMTX_PA_DRIVERS_5 0x04
190#define ISMTX_PA_DRIVERS_6 0x05
191#define ISMTX_PA_DRIVERS_7 0x06
192#define ISMTX_PA_DRIVERS_8 0x07
193
194#define ISMTX_PA_SHUNT_0 0x00
195#define ISMTX_PA_SHUNT_175 0x01
196#define ISMTX_PA_SHUNT_350 0x02
197#define ISMTX_PA_SHUNT_525 0x03
198#define ISMTX_PA_SHUNT_700 0x04
199#define ISMTX_PA_SHUNT_875 0x05
200#define ISMTX_PA_SHUNT_1050 0x06
201#define ISMTX_PA_SHUNT_1225 0x07
202#define ISMTX_PA_SHUNT_1400 0x08
203#define ISMTX_PA_SHUNT_1575 0x09
204#define ISMTX_PA_SHUNT_1750 0x0A
205#define ISMTX_PA_SHUNT_1925 0x0B
206#define ISMTX_PA_SHUNT_2100 0x0C
207#define ISMTX_PA_SHUNT_2275 0x0D
208#define ISMTX_PA_SHUNT_2450 0x0E
209#define ISMTX_PA_SHUNT_2625 0x0F
210#define ISMTX_PA_SHUNT_2800 0x10
211#define ISMTX_PA_SHUNT_2975 0x11
212#define ISMTX_PA_SHUNT_3150 0x12
213#define ISMTX_PA_SHUNT_3325 0x13
214#define ISMTX_PA_SHUNT_3500 0x14
215#define ISMTX_PA_SHUNT_3675 0x15
216#define ISMTX_PA_SHUNT_3850 0x16
217#define ISMTX_PA_SHUNT_4025 0x17
218#define ISMTX_PA_SHUNT_4200 0x18
219#define ISMTX_PA_SHUNT_4375 0x19
220#define ISMTX_PA_SHUNT_4550 0x1A
221#define ISMTX_PA_SHUNT_4725 0x1B
222#define ISMTX_PA_SHUNT_4900 0x1C
223#define ISMTX_PA_SHUNT_5075 0x1D
224#define ISMTX_PA_SHUNT_5250 0x1E
225#define ISMTX_PA_SHUNT_5425 0x1F
226
227#define ISMTX_PA_OFFSET_CUR_NO 0x00
228#define ISMTX_PA_OFFSET_CUR_5_PCT 0x01
229#define ISMTX_PA_OFFSET_CUR_10_PCT 0x02
230#define ISMTX_PA_OFFSET_CUR_15_PCT 0x03
231
232#define ISMTX_PA_PLL_N_INT 0x00
233#define ISMTX_PA_PLL_N_FRAC 0x01
234
235#define ISMTX_PA_LCVCO_DIV_NO 0x00
236#define ISMTX_PA_LCVCO_DIV_4 0x01
237#define ISMTX_PA_LCVCO_DIV_8 0x02
238#define ISMTX_PA_LCVCO_DIV_12 0x03
239
240#define ISMTX_PA_LCVCO_MODE_RING 0x00
241#define ISMTX_PA_LCVCO_MODE_LC 0x01
242
243#define ISMTX_CP_CURRENT_5uA 0x00
244#define ISMTX_CP_CURRENT_10uA 0x01
245#define ISMTX_CP_CURRENT_15uA 0x02
246#define ISMTX_CP_CURRENT_20uA 0x03
247
248#define ISMTX_SPITXEN1_DISABLED 0x00
249#define ISMTX_SPITXEN1_ENABLED 0x01
250
251#define ISMTX_FOURWIRE1_DISABLED 0x00
252#define ISMTX_FOURWIRE1_ENABLED 0x01
253
254#define ISMTX_SPITXEN2_DISABLED 0x00
255#define ISMTX_SPITXEN2_ENABLED 0x01
256
257#define ISMTX_FOURWIRE2_DISABLED 0x00
258#define ISMTX_FOURWIRE2_ENABLED 0x01
259
260#define ISMTX_BCLK_POSTDIV_1 0x01
261#define ISMTX_BCLK_POSTDIV_2 0x02
262#define ISMTX_BCLK_POSTDIV_3 0x03
263#define ISMTX_BCLK_POSTDIV_4 0x04
264#define ISMTX_BCLK_POSTDIV_5 0x05
265
266 // ismtx_set
267
282#define ISMTX_MAP_MIKROBUS( cfg, mikrobus ) \
283 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
284 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
285 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
286 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
287
288 // ismtx_map
289 // ismtx
290
295typedef struct
296{
297 // Output pins
298 digital_out_t mosi;
300 // Modules
301 spi_master_t spi;
302 spi_master_config_t spi_config;
303
304 pin_name_t chip_select;
305 pin_name_t tx_data;
306
307 uint8_t modulation;
308
309} ismtx_t;
310
315typedef struct
316{
317 // Communication gpio pins
318 pin_name_t miso;
319 pin_name_t mosi;
320 pin_name_t sck;
321 pin_name_t cs;
323 // static variable
324 uint32_t spi_speed;
325 spi_master_mode_t spi_mode;
326 spi_master_chip_select_polarity_t cs_polarity;
329
341
358
372err_t ismtx_init ( ismtx_t *ctx, ismtx_cfg_t *cfg );
373
387
401err_t ismtx_generic_write ( ismtx_t *ctx, uint8_t reg, uint8_t data_in );
402
416err_t ismtx_generic_read ( ismtx_t *ctx, uint8_t reg, uint8_t *data_out );
417
427
442err_t ismtx_set_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value );
443
456err_t ismtx_get_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t *cfg_value );
457
469err_t ismtx_set_frequency ( ismtx_t *ctx, uint32_t freq );
470
478uint32_t ismtx_get_frequency ( ismtx_t *ctx );
479
492err_t ismtx_adjust_freq_deviation ( ismtx_t *ctx, uint32_t deviation_freq );
493
506err_t ismtx_adjust_man_bitrate ( ismtx_t *ctx, uint32_t baud );
507
523err_t ismtx_transmit_raw_data ( ismtx_t *ctx, uint8_t *tx_data, uint8_t tx_len );
524
538err_t ismtx_transmit_data ( ismtx_t *ctx, uint8_t preamble_byte, uint8_t *tx_data, uint8_t tx_data_len );
539
540#ifdef __cplusplus
541}
542#endif
543#endif // ISMTX_H
544
545 // ismtx
546
547// ------------------------------------------------------------------------ END
err_t ismtx_set_frequency(ismtx_t *ctx, uint32_t freq)
Setting specific frequency for transmission.
err_t ismtx_adjust_man_bitrate(ismtx_t *ctx, uint32_t baud)
Adjust manchester baudrate.
err_t ismtx_get_cfg(ismtx_t *ctx, uint8_t cfg_macro, uint8_t *cfg_value)
ISM TX reading configuration.
void ismtx_cfg_setup(ismtx_cfg_t *cfg)
ISM TX configuration object setup function.
err_t ismtx_set_cfg(ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value)
ISM TX writing configuration.
err_t ismtx_transmit_raw_data(ismtx_t *ctx, uint8_t *tx_data, uint8_t tx_len)
Function for trinsmiting data.
err_t ismtx_init(ismtx_t *ctx, ismtx_cfg_t *cfg)
ISM TX initialization function.
err_t ismtx_generic_write(ismtx_t *ctx, uint8_t reg, uint8_t data_in)
ISM TX data writing function.
void ismtx_soft_reset(ismtx_t *ctx)
ISM TX software reset.
err_t ismtx_default_cfg(ismtx_t *ctx)
ISM TX default configuration function.
err_t ismtx_generic_read(ismtx_t *ctx, uint8_t reg, uint8_t *data_out)
ISM TX data reading function.
err_t ismtx_adjust_freq_deviation(ismtx_t *ctx, uint32_t deviation_freq)
Adjust frequency for transmission.
err_t ismtx_transmit_data(ismtx_t *ctx, uint8_t preamble_byte, uint8_t *tx_data, uint8_t tx_data_len)
Function for transmitting data with preamble byte and lenght.
uint32_t ismtx_get_frequency(ismtx_t *ctx)
Getting current frequency for transmission .
ismtx_return_value_t
ISM TX Click return value data.
Definition ismtx.h:335
@ ISMTX_OK
Definition ismtx.h:336
@ ISMTX_ERROR
Definition ismtx.h:337
@ ISMTX_PARAMETER_ERROR
Definition ismtx.h:338
ISM TX Click configuration object.
Definition ismtx.h:316
spi_master_chip_select_polarity_t cs_polarity
Definition ismtx.h:326
pin_name_t sck
Definition ismtx.h:320
spi_master_mode_t spi_mode
Definition ismtx.h:325
pin_name_t mosi
Definition ismtx.h:319
uint32_t spi_speed
Definition ismtx.h:324
pin_name_t miso
Definition ismtx.h:318
pin_name_t cs
Definition ismtx.h:321
ISM TX Click context object.
Definition ismtx.h:296
spi_master_t spi
Definition ismtx.h:301
uint8_t modulation
Definition ismtx.h:307
digital_out_t mosi
Definition ismtx.h:298
spi_master_config_t spi_config
Definition ismtx.h:302
pin_name_t chip_select
Definition ismtx.h:304
pin_name_t tx_data
Definition ismtx.h:305