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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 
59 #define ISMTX_REG_CFG1 0x00
60 #define ISMTX_REG_CFG2 0x01
61 #define ISMTX_REG_CFG3 0x02
62 #define ISMTX_REG_CFG4 0x03
63 #define ISMTX_REG_CFG5 0x04
64 #define ISMTX_REG_SHDN 0x05
65 #define ISMTX_REG_PA1 0x06
66 #define ISMTX_REG_PA2 0x07
67 #define ISMTX_REG_PLL1 0x08
68 #define ISMTX_REG_PLL2 0x09
69 #define ISMTX_REG_CFG6 0x0A
70 #define ISMTX_REG_PLL3 0x0B
71 #define ISMTX_REG_PLL4 0x0C
72 #define ISMTX_REG_PLL5 0x0D
73 #define ISMTX_REG_PLL6 0x0E
74 #define ISMTX_REG_PLL7 0x0F
75 #define ISMTX_REG_CFG7 0x10
76 #define ISMTX_REG_CFG8 0x17
77 #define ISMTX_REG_CFG9 0x18
78 #define ISMTX_REG_ADDL1 0x19
79 #define ISMTX_REG_ADDL2 0x1A
80  // ismtx_reg
82 
97 #define ISM_TX_MODULATION_NULL 0
98 #define ISM_TX_MODULATION_ASK 1
99 #define ISM_TX_MODULATION_FSK 2
100 
105 #define ISMTX_CFG_XO_CLK_DELAY 30
106 #define ISMTX_CFG_XO_CLK_DIV 31
107 #define ISMTX_CFG_FSK_SHAPE 32
108 #define ISMTX_CFG_SYNC 33
109 #define ISMTX_CFG_MODE 34
110 #define ISMTX_CFG_CLKOUT_DELAY 35
111 #define ISMTX_CFG_BCLK_POSTDIV 36
112 #define ISMTX_CFG_BCLK_PREDIV 37
113 #define ISMTX_CFG_PWDN_MODE 38
114 #define ISMTX_CFG_PA_MODE 39
115 #define ISMTX_CFG_PA_DRIVERS 40
116 #define ISMTX_CFG_PA_SHUNT 41
117 #define ISMTX_CFG_PA_OFFSET_CUR 42
118 #define ISMTX_CFG_PA_PLL_N 43
119 #define ISMTX_CFG_PA_LCVCO_DIV 44
120 #define ISMTX_CFG_PA_LCVCO_MODE 45
121 #define ISMTX_CFG_CP_CURRENT 46
122 #define ISMTX_CFG_SPITXEN1 47
123 #define ISMTX_CFG_FOURWIRE1 48
124 #define ISMTX_CFG_SPITXEN2 49
125 #define ISMTX_CFG_FOURWIRE2 50
126 #define ISMTX_CFG_DELTAF 51
127 #define ISMTX_CFG_DELTAF_SHAPE 52
128 #define ISMTX_CFG_TSTEP 53
129 #define ISMTX_CFG_EN_LDO 54
130 #define ISMTX_CFG_DIS_LDO_FUNC_EN 55
131 #define ISMTX_CFG_PLL_LOOP_BAND 56
132 #define ISMTX_CFG_LCVCO_FAST_START 57
133 #define ISMTX_CFG_LCVCO_PWR 58
134 
139 #define ISMTX_XO_CLK_DELAY_NO_CYC 0x00
140 #define ISMTX_XO_CLK_DELAY_16_CYC 0x01
141 #define ISMTX_XO_CLK_DELAY_32_CYC 0x02
142 #define ISMTX_XO_CLK_DELAY_64_CYC 0x03
143 
144 #define ISMTX_XO_CLK_DIV_4 0x00
145 #define ISMTX_XO_CLK_DIV_5 0x01
146 #define ISMTX_XO_CLK_DIV_6 0x02
147 #define ISMTX_XO_CLK_DIV_7 0x03
148 
149 #define ISMTX_FSK_SHAPE_DISABLED 0x00
150 #define ISMTX_FSK_SHAPE_ENABLED 0x01
151 
152 #define ISMTX_SYNC_DISABLE 0x00
153 #define ISMTX_SYNC_ENABLE 0x01
154 
155 #define ISMTX_MODE_ASK 0x00
156 #define ISMTX_MODE_FSK 0x01
157 
158 #define ISMTX_CLKOUT_DELAY_64_CYC 0x00
159 #define ISMTX_CLKOUT_DELAY_128_CYC 0x01
160 #define ISMTX_CLKOUT_DELAY_256_CYC 0x02
161 #define ISMTX_CLKOUT_DELAY_512_CYC 0x03
162 
163 #define ISMTX_PWDN_MODE_SHUTDOWN 0x00
164 #define ISMTX_PWDN_MODE_STAMDBY 0x01
165 #define ISMTX_PWDN_MODE_FAST_WAKEUP 0x02
166 #define ISMTX_PWDN_MODE_FAST_WAKEUP_ 0x03
167 
168 #define ISMTX_PA_MODE_NORMAL 0x00
169 #define ISMTX_PA_MODE_BOOST 0x01
170 
171 #define ISMTX_PA_DRIVERS_1 0x00
172 #define ISMTX_PA_DRIVERS_2 0x01
173 #define ISMTX_PA_DRIVERS_3 0x02
174 #define ISMTX_PA_DRIVERS_4 0x03
175 #define ISMTX_PA_DRIVERS_5 0x04
176 #define ISMTX_PA_DRIVERS_6 0x05
177 #define ISMTX_PA_DRIVERS_7 0x06
178 #define ISMTX_PA_DRIVERS_8 0x07
179 
180 #define ISMTX_PA_SHUNT_0 0x00
181 #define ISMTX_PA_SHUNT_175 0x01
182 #define ISMTX_PA_SHUNT_350 0x02
183 #define ISMTX_PA_SHUNT_525 0x03
184 #define ISMTX_PA_SHUNT_700 0x04
185 #define ISMTX_PA_SHUNT_875 0x05
186 #define ISMTX_PA_SHUNT_1050 0x06
187 #define ISMTX_PA_SHUNT_1225 0x07
188 #define ISMTX_PA_SHUNT_1400 0x08
189 #define ISMTX_PA_SHUNT_1575 0x09
190 #define ISMTX_PA_SHUNT_1750 0x0A
191 #define ISMTX_PA_SHUNT_1925 0x0B
192 #define ISMTX_PA_SHUNT_2100 0x0C
193 #define ISMTX_PA_SHUNT_2275 0x0D
194 #define ISMTX_PA_SHUNT_2450 0x0E
195 #define ISMTX_PA_SHUNT_2625 0x0F
196 #define ISMTX_PA_SHUNT_2800 0x10
197 #define ISMTX_PA_SHUNT_2975 0x11
198 #define ISMTX_PA_SHUNT_3150 0x12
199 #define ISMTX_PA_SHUNT_3325 0x13
200 #define ISMTX_PA_SHUNT_3500 0x14
201 #define ISMTX_PA_SHUNT_3675 0x15
202 #define ISMTX_PA_SHUNT_3850 0x16
203 #define ISMTX_PA_SHUNT_4025 0x17
204 #define ISMTX_PA_SHUNT_4200 0x18
205 #define ISMTX_PA_SHUNT_4375 0x19
206 #define ISMTX_PA_SHUNT_4550 0x1A
207 #define ISMTX_PA_SHUNT_4725 0x1B
208 #define ISMTX_PA_SHUNT_4900 0x1C
209 #define ISMTX_PA_SHUNT_5075 0x1D
210 #define ISMTX_PA_SHUNT_5250 0x1E
211 #define ISMTX_PA_SHUNT_5425 0x1F
212 
213 #define ISMTX_PA_OFFSET_CUR_NO 0x00
214 #define ISMTX_PA_OFFSET_CUR_5_PCT 0x01
215 #define ISMTX_PA_OFFSET_CUR_10_PCT 0x02
216 #define ISMTX_PA_OFFSET_CUR_15_PCT 0x03
217 
218 #define ISMTX_PA_PLL_N_INT 0x00
219 #define ISMTX_PA_PLL_N_FRAC 0x01
220 
221 #define ISMTX_PA_LCVCO_DIV_NO 0x00
222 #define ISMTX_PA_LCVCO_DIV_4 0x01
223 #define ISMTX_PA_LCVCO_DIV_8 0x02
224 #define ISMTX_PA_LCVCO_DIV_12 0x03
225 
226 #define ISMTX_PA_LCVCO_MODE_RING 0x00
227 #define ISMTX_PA_LCVCO_MODE_LC 0x01
228 
229 #define ISMTX_CP_CURRENT_5uA 0x00
230 #define ISMTX_CP_CURRENT_10uA 0x01
231 #define ISMTX_CP_CURRENT_15uA 0x02
232 #define ISMTX_CP_CURRENT_20uA 0x03
233 
234 #define ISMTX_SPITXEN1_DISABLED 0x00
235 #define ISMTX_SPITXEN1_ENABLED 0x01
236 
237 #define ISMTX_FOURWIRE1_DISABLED 0x00
238 #define ISMTX_FOURWIRE1_ENABLED 0x01
239 
240 #define ISMTX_SPITXEN2_DISABLED 0x00
241 #define ISMTX_SPITXEN2_ENABLED 0x01
242 
243 #define ISMTX_FOURWIRE2_DISABLED 0x00
244 #define ISMTX_FOURWIRE2_ENABLED 0x01
245 
246 #define ISMTX_BCLK_POSTDIV_1 0x01
247 #define ISMTX_BCLK_POSTDIV_2 0x02
248 #define ISMTX_BCLK_POSTDIV_3 0x03
249 #define ISMTX_BCLK_POSTDIV_4 0x04
250 #define ISMTX_BCLK_POSTDIV_5 0x05
251  // ismtx_set
253 
268 #define ISMTX_MAP_MIKROBUS( cfg, mikrobus ) \
269  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
270  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
271  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
272  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
273  // ismtx_map // ismtx
276 
281 typedef struct
282 {
283  // Output pins
284 
285  digital_out_t cs;
286  digital_out_t mosi;
288  // Modules
289 
290  spi_master_t spi;
291  spi_master_config_t spi_config;
292 
293  pin_name_t chip_select;
294  pin_name_t tx_data;
295 
296  uint8_t modulation;
297 
298 } ismtx_t;
299 
304 typedef struct
305 {
306  // Communication gpio pins
307  pin_name_t miso;
308  pin_name_t mosi;
309  pin_name_t sck;
310  pin_name_t cs;
312  // static variable
313  uint32_t spi_speed;
314  spi_master_mode_t spi_mode;
315  spi_master_chip_select_polarity_t cs_polarity;
317 } ismtx_cfg_t;
318 
323 typedef enum
324 {
325  ISMTX_OK = 0,
328 
330 
346 void ismtx_cfg_setup ( ismtx_cfg_t *cfg );
347 
362 err_t ismtx_init ( ismtx_t *ctx, ismtx_cfg_t *cfg );
363 
377 err_t ismtx_default_cfg ( ismtx_t *ctx );
378 
393 err_t ismtx_generic_write ( ismtx_t *ctx, uint8_t reg, uint8_t data_in );
394 
409 err_t ismtx_generic_read ( ismtx_t *ctx, uint8_t reg, uint8_t *data_out );
410 
419 void ismtx_soft_reset ( ismtx_t *ctx );
420 
435 err_t ismtx_set_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value );
436 
449 err_t ismtx_get_cfg ( ismtx_t *ctx, uint8_t cfg_macro, uint8_t *cfg_value );
450 
462 err_t ismtx_set_frequency ( ismtx_t *ctx, uint32_t freq );
463 
471 uint32_t get_frequency ( ismtx_t *ctx );
472 
485 err_t ismtx_adjust_frequency_deviation ( ismtx_t *ctx, uint32_t deviation_freq );
486 
499 err_t ismtx_adjust_manchester_bitrate ( ismtx_t *ctx, uint8_t baud );
500 
516 err_t ismtx_transmit_raw_data ( ismtx_t *ctx, uint8_t *tx_data, uint8_t tx_len );
517 
531 err_t ismtx_transmit_data ( ismtx_t *ctx, uint8_t preamble_byte, uint8_t *tx_data, uint8_t tx_data_len );
532 
533 #ifdef __cplusplus
534 }
535 #endif
536 #endif // ISMTX_H
537  // ismtx
539 
540 // ------------------------------------------------------------------------ END
ismtx_generic_read
err_t ismtx_generic_read(ismtx_t *ctx, uint8_t reg, uint8_t *data_out)
ISM TX data reading function.
get_frequency
uint32_t 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:303
ismtx_adjust_frequency_deviation
err_t ismtx_adjust_frequency_deviation(ismtx_t *ctx, uint32_t deviation_freq)
Adjust frequency for transmission.
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 trinsmiting data with preamble byte and lenght.
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
Definition: ismtx.h:324
ismtx_default_cfg
err_t ismtx_default_cfg(ismtx_t *ctx)
ISM TX default configuration function.
ISMTX_PARAMETER_ERROR
Definition: ismtx.h:326
ismtx_set_cfg
err_t ismtx_set_cfg(ismtx_t *ctx, uint8_t cfg_macro, uint8_t cfg_value)
ISM TX writing configuration.
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:322
ISMTX_ERROR
Definition: ismtx.h:325
ismtx_set_frequency
err_t ismtx_set_frequency(ismtx_t *ctx, uint32_t freq)
Setting specific frequency for transmission.
ismtx_adjust_manchester_bitrate
err_t ismtx_adjust_manchester_bitrate(ismtx_t *ctx, uint8_t baud)
Adjust manchester baudrate.
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:280