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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define ISMTX_REG_CFG1 0x00
70 #define ISMTX_REG_CFG2 0x01
71 #define ISMTX_REG_CFG3 0x02
72 #define ISMTX_REG_CFG4 0x03
73 #define ISMTX_REG_CFG5 0x04
74 #define ISMTX_REG_SHDN 0x05
75 #define ISMTX_REG_PA1 0x06
76 #define ISMTX_REG_PA2 0x07
77 #define ISMTX_REG_PLL1 0x08
78 #define ISMTX_REG_PLL2 0x09
79 #define ISMTX_REG_CFG6 0x0A
80 #define ISMTX_REG_PLL3 0x0B
81 #define ISMTX_REG_PLL4 0x0C
82 #define ISMTX_REG_PLL5 0x0D
83 #define ISMTX_REG_PLL6 0x0E
84 #define ISMTX_REG_PLL7 0x0F
85 #define ISMTX_REG_CFG7 0x10
86 #define ISMTX_REG_CFG8 0x17
87 #define ISMTX_REG_CFG9 0x18
88 #define ISMTX_REG_ADDL1 0x19
89 #define ISMTX_REG_ADDL2 0x1A
90  // ismtx_reg
92 
107 #define ISM_TX_MODULATION_NULL 0
108 #define ISM_TX_MODULATION_ASK 1
109 #define ISM_TX_MODULATION_FSK 2
110 
115 #define ISMTX_CFG_XO_CLK_DELAY 30
116 #define ISMTX_CFG_XO_CLK_DIV 31
117 #define ISMTX_CFG_FSK_SHAPE 32
118 #define ISMTX_CFG_SYNC 33
119 #define ISMTX_CFG_MODE 34
120 #define ISMTX_CFG_CLKOUT_DELAY 35
121 #define ISMTX_CFG_BCLK_POSTDIV 36
122 #define ISMTX_CFG_BCLK_PREDIV 37
123 #define ISMTX_CFG_PWDN_MODE 38
124 #define ISMTX_CFG_PA_MODE 39
125 #define ISMTX_CFG_PA_DRIVERS 40
126 #define ISMTX_CFG_PA_SHUNT 41
127 #define ISMTX_CFG_PA_OFFSET_CUR 42
128 #define ISMTX_CFG_PA_PLL_N 43
129 #define ISMTX_CFG_PA_LCVCO_DIV 44
130 #define ISMTX_CFG_PA_LCVCO_MODE 45
131 #define ISMTX_CFG_CP_CURRENT 46
132 #define ISMTX_CFG_SPITXEN1 47
133 #define ISMTX_CFG_FOURWIRE1 48
134 #define ISMTX_CFG_SPITXEN2 49
135 #define ISMTX_CFG_FOURWIRE2 50
136 #define ISMTX_CFG_DELTAF 51
137 #define ISMTX_CFG_DELTAF_SHAPE 52
138 #define ISMTX_CFG_TSTEP 53
139 #define ISMTX_CFG_EN_LDO 54
140 #define ISMTX_CFG_DIS_LDO_FUNC_EN 55
141 #define ISMTX_CFG_PLL_LOOP_BAND 56
142 #define ISMTX_CFG_LCVCO_FAST_START 57
143 #define ISMTX_CFG_LCVCO_PWR 58
144 
149 #define ISMTX_XO_CLK_DELAY_NO_CYC 0x00
150 #define ISMTX_XO_CLK_DELAY_16_CYC 0x01
151 #define ISMTX_XO_CLK_DELAY_32_CYC 0x02
152 #define ISMTX_XO_CLK_DELAY_64_CYC 0x03
153 
154 #define ISMTX_XO_CLK_DIV_4 0x00
155 #define ISMTX_XO_CLK_DIV_5 0x01
156 #define ISMTX_XO_CLK_DIV_6 0x02
157 #define ISMTX_XO_CLK_DIV_7 0x03
158 
159 #define ISMTX_FSK_SHAPE_DISABLED 0x00
160 #define ISMTX_FSK_SHAPE_ENABLED 0x01
161 
162 #define ISMTX_SYNC_DISABLE 0x00
163 #define ISMTX_SYNC_ENABLE 0x01
164 
165 #define ISMTX_MODE_ASK 0x00
166 #define ISMTX_MODE_FSK 0x01
167 
168 #define ISMTX_CLKOUT_DELAY_64_CYC 0x00
169 #define ISMTX_CLKOUT_DELAY_128_CYC 0x01
170 #define ISMTX_CLKOUT_DELAY_256_CYC 0x02
171 #define ISMTX_CLKOUT_DELAY_512_CYC 0x03
172 
173 #define ISMTX_PWDN_MODE_SHUTDOWN 0x00
174 #define ISMTX_PWDN_MODE_STAMDBY 0x01
175 #define ISMTX_PWDN_MODE_FAST_WAKEUP 0x02
176 #define ISMTX_PWDN_MODE_FAST_WAKEUP_ 0x03
177 
178 #define ISMTX_PA_MODE_NORMAL 0x00
179 #define ISMTX_PA_MODE_BOOST 0x01
180 
181 #define ISMTX_PA_DRIVERS_1 0x00
182 #define ISMTX_PA_DRIVERS_2 0x01
183 #define ISMTX_PA_DRIVERS_3 0x02
184 #define ISMTX_PA_DRIVERS_4 0x03
185 #define ISMTX_PA_DRIVERS_5 0x04
186 #define ISMTX_PA_DRIVERS_6 0x05
187 #define ISMTX_PA_DRIVERS_7 0x06
188 #define ISMTX_PA_DRIVERS_8 0x07
189 
190 #define ISMTX_PA_SHUNT_0 0x00
191 #define ISMTX_PA_SHUNT_175 0x01
192 #define ISMTX_PA_SHUNT_350 0x02
193 #define ISMTX_PA_SHUNT_525 0x03
194 #define ISMTX_PA_SHUNT_700 0x04
195 #define ISMTX_PA_SHUNT_875 0x05
196 #define ISMTX_PA_SHUNT_1050 0x06
197 #define ISMTX_PA_SHUNT_1225 0x07
198 #define ISMTX_PA_SHUNT_1400 0x08
199 #define ISMTX_PA_SHUNT_1575 0x09
200 #define ISMTX_PA_SHUNT_1750 0x0A
201 #define ISMTX_PA_SHUNT_1925 0x0B
202 #define ISMTX_PA_SHUNT_2100 0x0C
203 #define ISMTX_PA_SHUNT_2275 0x0D
204 #define ISMTX_PA_SHUNT_2450 0x0E
205 #define ISMTX_PA_SHUNT_2625 0x0F
206 #define ISMTX_PA_SHUNT_2800 0x10
207 #define ISMTX_PA_SHUNT_2975 0x11
208 #define ISMTX_PA_SHUNT_3150 0x12
209 #define ISMTX_PA_SHUNT_3325 0x13
210 #define ISMTX_PA_SHUNT_3500 0x14
211 #define ISMTX_PA_SHUNT_3675 0x15
212 #define ISMTX_PA_SHUNT_3850 0x16
213 #define ISMTX_PA_SHUNT_4025 0x17
214 #define ISMTX_PA_SHUNT_4200 0x18
215 #define ISMTX_PA_SHUNT_4375 0x19
216 #define ISMTX_PA_SHUNT_4550 0x1A
217 #define ISMTX_PA_SHUNT_4725 0x1B
218 #define ISMTX_PA_SHUNT_4900 0x1C
219 #define ISMTX_PA_SHUNT_5075 0x1D
220 #define ISMTX_PA_SHUNT_5250 0x1E
221 #define ISMTX_PA_SHUNT_5425 0x1F
222 
223 #define ISMTX_PA_OFFSET_CUR_NO 0x00
224 #define ISMTX_PA_OFFSET_CUR_5_PCT 0x01
225 #define ISMTX_PA_OFFSET_CUR_10_PCT 0x02
226 #define ISMTX_PA_OFFSET_CUR_15_PCT 0x03
227 
228 #define ISMTX_PA_PLL_N_INT 0x00
229 #define ISMTX_PA_PLL_N_FRAC 0x01
230 
231 #define ISMTX_PA_LCVCO_DIV_NO 0x00
232 #define ISMTX_PA_LCVCO_DIV_4 0x01
233 #define ISMTX_PA_LCVCO_DIV_8 0x02
234 #define ISMTX_PA_LCVCO_DIV_12 0x03
235 
236 #define ISMTX_PA_LCVCO_MODE_RING 0x00
237 #define ISMTX_PA_LCVCO_MODE_LC 0x01
238 
239 #define ISMTX_CP_CURRENT_5uA 0x00
240 #define ISMTX_CP_CURRENT_10uA 0x01
241 #define ISMTX_CP_CURRENT_15uA 0x02
242 #define ISMTX_CP_CURRENT_20uA 0x03
243 
244 #define ISMTX_SPITXEN1_DISABLED 0x00
245 #define ISMTX_SPITXEN1_ENABLED 0x01
246 
247 #define ISMTX_FOURWIRE1_DISABLED 0x00
248 #define ISMTX_FOURWIRE1_ENABLED 0x01
249 
250 #define ISMTX_SPITXEN2_DISABLED 0x00
251 #define ISMTX_SPITXEN2_ENABLED 0x01
252 
253 #define ISMTX_FOURWIRE2_DISABLED 0x00
254 #define ISMTX_FOURWIRE2_ENABLED 0x01
255 
256 #define ISMTX_BCLK_POSTDIV_1 0x01
257 #define ISMTX_BCLK_POSTDIV_2 0x02
258 #define ISMTX_BCLK_POSTDIV_3 0x03
259 #define ISMTX_BCLK_POSTDIV_4 0x04
260 #define ISMTX_BCLK_POSTDIV_5 0x05
261  // ismtx_set
263 
278 #define ISMTX_MAP_MIKROBUS( cfg, mikrobus ) \
279  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
280  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
281  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
282  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
283  // ismtx_map // ismtx
286 
291 typedef struct
292 {
293  // Output pins
294  digital_out_t mosi;
296  // Modules
297  spi_master_t spi;
298  spi_master_config_t spi_config;
299 
300  pin_name_t chip_select;
301  pin_name_t tx_data;
302 
303  uint8_t modulation;
304 
305 } ismtx_t;
306 
311 typedef struct
312 {
313  // Communication gpio pins
314  pin_name_t miso;
315  pin_name_t mosi;
316  pin_name_t sck;
317  pin_name_t cs;
319  // static variable
320  uint32_t spi_speed;
321  spi_master_mode_t spi_mode;
322  spi_master_chip_select_polarity_t cs_polarity;
324 } ismtx_cfg_t;
325 
330 typedef enum
331 {
332  ISMTX_OK = 0,
335 
337 
354 
368 err_t ismtx_init ( ismtx_t *ctx, ismtx_cfg_t *cfg );
369 
382 err_t ismtx_default_cfg ( ismtx_t *ctx );
383 
397 err_t ismtx_generic_write ( ismtx_t *ctx, uint8_t reg, uint8_t data_in );
398 
412 err_t ismtx_generic_read ( ismtx_t *ctx, uint8_t reg, uint8_t *data_out );
413 
422 void ismtx_soft_reset ( ismtx_t *ctx );
423 
438 err_t ismtx_set_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value );
439 
452 err_t ismtx_get_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t *cfg_value );
453 
465 err_t ismtx_set_frequency ( ismtx_t *ctx, uint32_t freq );
466 
474 uint32_t ismtx_get_frequency ( ismtx_t *ctx );
475 
488 err_t ismtx_adjust_freq_deviation ( ismtx_t *ctx, uint32_t deviation_freq );
489 
502 err_t ismtx_adjust_man_bitrate ( ismtx_t *ctx, uint32_t baud );
503 
519 err_t ismtx_transmit_raw_data ( ismtx_t *ctx, uint8_t *tx_data, uint8_t tx_len );
520 
534 err_t ismtx_transmit_data ( ismtx_t *ctx, uint8_t preamble_byte, uint8_t *tx_data, uint8_t tx_data_len );
535 
536 #ifdef __cplusplus
537 }
538 #endif
539 #endif // ISMTX_H
540  // ismtx
542 
543 // ------------------------------------------------------------------------ END
ismtx_cfg_t::cs
pin_name_t cs
Definition: ismtx.h:317
ismtx_generic_read
err_t ismtx_generic_read(ismtx_t *ctx, uint8_t reg, uint8_t *data_out)
ISM TX data reading function.
ismtx_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ismtx.h:322
ismtx_cfg_t::mosi
pin_name_t mosi
Definition: ismtx.h:315
ismtx_get_frequency
uint32_t ismtx_get_frequency(ismtx_t *ctx)
Getting current frequency for transmission .
ismtx_get_cfg
err_t ismtx_get_cfg(ismtx_t *ctx, uint8_t cfg_macro, uint8_t *cfg_value)
ISM TX reading configuration.
ismtx_cfg_t
ISM TX Click configuration object.
Definition: ismtx.h:312
ismtx_t::tx_data
pin_name_t tx_data
Definition: ismtx.h:301
ismtx_cfg_t::miso
pin_name_t miso
Definition: ismtx.h:314
ismtx_adjust_man_bitrate
err_t ismtx_adjust_man_bitrate(ismtx_t *ctx, uint32_t baud)
Adjust manchester baudrate.
ismtx_t::chip_select
pin_name_t chip_select
Definition: ismtx.h:300
ismtx_transmit_data
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.
ismtx_t::spi_config
spi_master_config_t spi_config
Definition: ismtx.h:298
ismtx_init
err_t ismtx_init(ismtx_t *ctx, ismtx_cfg_t *cfg)
ISM TX initialization function.
ismtx_cfg_setup
void ismtx_cfg_setup(ismtx_cfg_t *cfg)
ISM TX configuration object setup function.
ISMTX_OK
@ ISMTX_OK
Definition: ismtx.h:332
ismtx_default_cfg
err_t ismtx_default_cfg(ismtx_t *ctx)
ISM TX default configuration function.
ISMTX_PARAMETER_ERROR
@ ISMTX_PARAMETER_ERROR
Definition: ismtx.h:334
ismtx_t::mosi
digital_out_t mosi
Definition: ismtx.h:294
ismtx_adjust_freq_deviation
err_t ismtx_adjust_freq_deviation(ismtx_t *ctx, uint32_t deviation_freq)
Adjust frequency for transmission.
ismtx_set_cfg
err_t ismtx_set_cfg(ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value)
ISM TX writing configuration.
ismtx_t::spi
spi_master_t spi
Definition: ismtx.h:297
ismtx_soft_reset
void ismtx_soft_reset(ismtx_t *ctx)
ISM TX software reset.
ismtx_return_value_t
ismtx_return_value_t
ISM TX Click return value data.
Definition: ismtx.h:331
ismtx_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ismtx.h:321
ISMTX_ERROR
@ ISMTX_ERROR
Definition: ismtx.h:333
ismtx_cfg_t::sck
pin_name_t sck
Definition: ismtx.h:316
ismtx_t::modulation
uint8_t modulation
Definition: ismtx.h:303
ismtx_cfg_t::spi_speed
uint32_t spi_speed
Definition: ismtx.h:320
ismtx_set_frequency
err_t ismtx_set_frequency(ismtx_t *ctx, uint32_t freq)
Setting specific frequency for transmission.
ismtx_transmit_raw_data
err_t ismtx_transmit_raw_data(ismtx_t *ctx, uint8_t *tx_data, uint8_t tx_len)
Function for trinsmiting data.
ismtx_generic_write
err_t ismtx_generic_write(ismtx_t *ctx, uint8_t reg, uint8_t data_in)
ISM TX data writing function.
ismtx_t
ISM TX Click context object.
Definition: ismtx.h:292