ismrx3  2.0.0.0
ismrx3.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 ISMRX3_H
29 #define ISMRX3_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 ISMRX3_DEMOD 0x00
70 #define ISMRX3_AGC 0x01
71 #define ISMRX3_IF_CHF_SEL 0x02
72 #define ISMRX3_PDF_CFG 0x03
73 #define ISMRX3_ATH_CFG_1 0x04
74 #define ISMRX3_ATH_CFG_2 0x05
75 #define ISMRX3_ATH_CFG_3 0x06
76 #define ISMRX3_AFC_CFG_1 0x07
77 #define ISMRX3_AFC_CFG_2 0x08
78 #define ISMRX3_LO_CTR_FREQ_3 0x09
79 #define ISMRX3_LO_CTR_FREQ_2 0x0A
80 #define ISMRX3_LO_CTR_FREQ_1 0x0B
81 #define ISMRX3_PREAMBLE_CFG_1 0x0C
82 #define ISMRX3_PREAMBLE_WORD_1 0x0D
83 #define ISMRX3_PREAMBLE_WROD_2 0x0E
84 #define ISMRX3_RSS 0x10
85 #define ISMRX3_FEI 0x11
86 #define ISMRX3_PDF_OUT 0x12
87 #define ISMRX3_ISR 0x13
88 #define ISMRX3_CDR_CFG 0x35
89 #define ISMRX3_STATE_CTRL_1 0x14
90 #define ISMRX3_STATE_CTRL_2 0x15
91 #define ISMRX3_STATE_CTRL_3 0x16
92 #define ISMRX3_WUT_1 0x17
93 #define ISMRX3_WUT_2 0x18
94 #define ISMRX3_AFE_CTL_1 0x19
95 #define ISMRX3_IR_ADJUST 0x1A
96 #define ISMRX3_PART_NUM 0x1E
97 #define ISMRX3_REV_NUM 0x1F
98 #define ISMRX3_STATUS 0x27
99  // ismrx3_reg
101 
116 #define ISMRX3_MODULATION_ASK 0x01
117 #define ISMRX3_MODULATION_FSK 0x02
118 
123 #define ISMRX3_FREQUENCY_MHZ_315 0x01
124 #define ISMRX3_FREQUENCY_MHZ_433p92 0x02
125 #define ISMRX3_FREQUENCY_MHZ_868p3 0x03
126 
131 #define ISMRX3_DEVIATION_KHZ_5 0x01
132 #define ISMRX3_DEVIATION_KHZ_10 0x02
133 #define ISMRX3_DEVIATION_KHZ_40 0x03
134 #define ISMRX3_DEVIATION_KHZ_80 0x04
135 
140 #define ISMRX3_DATA_RATE_KBPS_1 0x01
141 #define ISMRX3_DATA_RATE_KBPS_2 0x02
142 #define ISMRX3_DATA_RATE_KBPS_5 0x03
143 #define ISMRX3_DATA_RATE_KBPS_10 0x04
144 #define ISMRX3_DATA_RATE_KBPS_50 0x05
145 #define ISMRX3_DATA_RATE_KBPS_100 0x06
146  // ismrx3_set
148 
163 #define ISMRX3_MAP_MIKROBUS( cfg, mikrobus ) \
164  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
165  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
166  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
167  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
168  cfg.dat = MIKROBUS( mikrobus, MIKROBUS_AN ); \
169  cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
170  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_PWM );\
171  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
172  // ismrx3_map // ismrx3
175 
180 typedef struct
181 {
182  // Output pins
183  digital_out_t pdn;
184  digital_out_t sw;
186  // Input pins
187  digital_in_t dat;
188  digital_in_t int_pin;
190  // Modules
191  spi_master_t spi;
192  pin_name_t chip_select;
194  uint8_t modulation;
195  uint8_t reference_freq;
196  uint8_t freq_deviation;
197  uint8_t data_rate;
198 } ismrx3_t;
199 
204 typedef struct
205 {
206  // Communication gpio pins
207  pin_name_t miso;
208  pin_name_t mosi;
209  pin_name_t sck;
210  pin_name_t cs;
212  // Additional gpio pins
213  pin_name_t dat;
214  pin_name_t pdn;
215  pin_name_t sw;
216  pin_name_t int_pin;
218  // static variable
219  uint32_t spi_speed;
220  spi_master_mode_t spi_mode;
221  spi_master_chip_select_polarity_t cs_polarity;
223 } ismrx3_cfg_t;
224 
229 typedef enum
230 {
234 
236 
253 
267 err_t ismrx3_init ( ismrx3_t *ctx, ismrx3_cfg_t *cfg );
268 
283 
296 err_t ismrx3_generic_write ( ismrx3_t *ctx, uint8_t reg, uint8_t data_in );
297 
310 err_t ismrx3_generic_read ( ismrx3_t *ctx, uint8_t reg, uint8_t *data_out );
311 
319 void ismrx3_reset( ismrx3_t *ctx );
320 
328 uint8_t ismrx3_get_clk( ismrx3_t *ctx );
329 
337 uint8_t ismrx3_get_data( ismrx3_t *ctx );
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // ISMRX3_H
343  // ismrx3
345 
346 // ------------------------------------------------------------------------ END
ismrx3_init
err_t ismrx3_init(ismrx3_t *ctx, ismrx3_cfg_t *cfg)
ISM RX 3 initialization function.
ismrx3_t::chip_select
pin_name_t chip_select
Definition: ismrx3.h:192
ismrx3_reset
void ismrx3_reset(ismrx3_t *ctx)
Reset function.
ismrx3_cfg_t::int_pin
pin_name_t int_pin
Definition: ismrx3.h:216
ismrx3_t::spi
spi_master_t spi
Definition: ismrx3.h:191
ismrx3_get_data
uint8_t ismrx3_get_data(ismrx3_t *ctx)
Read data output.
ISMRX3_OK
@ ISMRX3_OK
Definition: ismrx3.h:231
ismrx3_cfg_t::cs
pin_name_t cs
Definition: ismrx3.h:210
ismrx3_cfg_t::sw
pin_name_t sw
Definition: ismrx3.h:215
ISMRX3_ERROR
@ ISMRX3_ERROR
Definition: ismrx3.h:232
ismrx3_cfg_t::mosi
pin_name_t mosi
Definition: ismrx3.h:208
ismrx3_cfg_t::sck
pin_name_t sck
Definition: ismrx3.h:209
ismrx3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ismrx3.h:221
ismrx3_t::data_rate
uint8_t data_rate
Definition: ismrx3.h:197
ismrx3_cfg_setup
void ismrx3_cfg_setup(ismrx3_cfg_t *cfg)
ISM RX 3 configuration object setup function.
ISMRX3_ERROR_BUF_LEN
@ ISMRX3_ERROR_BUF_LEN
Definition: ismrx3.h:233
ismrx3_cfg_t::miso
pin_name_t miso
Definition: ismrx3.h:207
ismrx3_cfg_t::dat
pin_name_t dat
Definition: ismrx3.h:213
ismrx3_generic_write
err_t ismrx3_generic_write(ismrx3_t *ctx, uint8_t reg, uint8_t data_in)
ISM RX 3 data writing function.
ismrx3_generic_read
err_t ismrx3_generic_read(ismrx3_t *ctx, uint8_t reg, uint8_t *data_out)
ISM RX 3 data reading function.
ismrx3_cfg_t::spi_speed
uint32_t spi_speed
Definition: ismrx3.h:219
ismrx3_t::int_pin
digital_in_t int_pin
Definition: ismrx3.h:188
ismrx3_get_clk
uint8_t ismrx3_get_clk(ismrx3_t *ctx)
Read clock output.
ismrx3_t::pdn
digital_out_t pdn
Definition: ismrx3.h:183
ismrx3_t::reference_freq
uint8_t reference_freq
Definition: ismrx3.h:195
ismrx3_cfg_t
ISM RX 3 Click configuration object.
Definition: ismrx3.h:205
ismrx3_t::freq_deviation
uint8_t freq_deviation
Definition: ismrx3.h:196
ismrx3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ismrx3.h:220
ismrx3_default_cfg
err_t ismrx3_default_cfg(ismrx3_t *ctx)
ISM RX 3 default configuration function.
ismrx3_cfg_t::pdn
pin_name_t pdn
Definition: ismrx3.h:214
ismrx3_return_value_t
ismrx3_return_value_t
ISM RX 3 Click return value data.
Definition: ismrx3.h:230
ismrx3_t::sw
digital_out_t sw
Definition: ismrx3.h:184
ismrx3_t::modulation
uint8_t modulation
Definition: ismrx3.h:194
ismrx3_t::dat
digital_in_t dat
Definition: ismrx3.h:187
ismrx3_t
ISM RX 3 Click context object.
Definition: ismrx3.h:181