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 
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 ISMRX3_DEMOD 0x00
74 #define ISMRX3_AGC 0x01
75 #define ISMRX3_IF_CHF_SEL 0x02
76 #define ISMRX3_PDF_CFG 0x03
77 #define ISMRX3_ATH_CFG_1 0x04
78 #define ISMRX3_ATH_CFG_2 0x05
79 #define ISMRX3_ATH_CFG_3 0x06
80 #define ISMRX3_AFC_CFG_1 0x07
81 #define ISMRX3_AFC_CFG_2 0x08
82 #define ISMRX3_LO_CTR_FREQ_3 0x09
83 #define ISMRX3_LO_CTR_FREQ_2 0x0A
84 #define ISMRX3_LO_CTR_FREQ_1 0x0B
85 #define ISMRX3_PREAMBLE_CFG_1 0x0C
86 #define ISMRX3_PREAMBLE_WORD_1 0x0D
87 #define ISMRX3_PREAMBLE_WROD_2 0x0E
88 #define ISMRX3_RSS 0x10
89 #define ISMRX3_FEI 0x11
90 #define ISMRX3_PDF_OUT 0x12
91 #define ISMRX3_ISR 0x13
92 #define ISMRX3_CDR_CFG 0x35
93 #define ISMRX3_STATE_CTRL_1 0x14
94 #define ISMRX3_STATE_CTRL_2 0x15
95 #define ISMRX3_STATE_CTRL_3 0x16
96 #define ISMRX3_WUT_1 0x17
97 #define ISMRX3_WUT_2 0x18
98 #define ISMRX3_AFE_CTL_1 0x19
99 #define ISMRX3_IR_ADJUST 0x1A
100 #define ISMRX3_PART_NUM 0x1E
101 #define ISMRX3_REV_NUM 0x1F
102 #define ISMRX3_STATUS 0x27
103  // ismrx3_reg
105 
120 #define ISMRX3_MODULATION_ASK 0x01
121 #define ISMRX3_MODULATION_FSK 0x02
122 
127 #define ISMRX3_FREQUENCY_MHZ_315 0x01
128 #define ISMRX3_FREQUENCY_MHZ_433p92 0x02
129 #define ISMRX3_FREQUENCY_MHZ_868p3 0x03
130 
135 #define ISMRX3_DEVIATION_KHZ_5 0x01
136 #define ISMRX3_DEVIATION_KHZ_10 0x02
137 #define ISMRX3_DEVIATION_KHZ_40 0x03
138 #define ISMRX3_DEVIATION_KHZ_80 0x04
139 
144 #define ISMRX3_DATA_RATE_KBPS_1 0x01
145 #define ISMRX3_DATA_RATE_KBPS_2 0x02
146 #define ISMRX3_DATA_RATE_KBPS_5 0x03
147 #define ISMRX3_DATA_RATE_KBPS_10 0x04
148 #define ISMRX3_DATA_RATE_KBPS_50 0x05
149 #define ISMRX3_DATA_RATE_KBPS_100 0x06
150  // ismrx3_set
152 
167 #define ISMRX3_MAP_MIKROBUS( cfg, mikrobus ) \
168  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
169  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
170  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
171  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
172  cfg.dat = MIKROBUS( mikrobus, MIKROBUS_AN ); \
173  cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
174  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_PWM );\
175  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
176  // ismrx3_map // ismrx3
179 
184 typedef struct
185 {
186  // Output pins
187  digital_out_t pdn;
188  digital_out_t sw;
190  // Input pins
191  digital_in_t dat;
192  digital_in_t int_pin;
194  // Modules
195  spi_master_t spi;
196  pin_name_t chip_select;
198  uint8_t modulation;
199  uint8_t reference_freq;
200  uint8_t freq_deviation;
201  uint8_t data_rate;
202 } ismrx3_t;
203 
208 typedef struct
209 {
210  // Communication gpio pins
211  pin_name_t miso;
212  pin_name_t mosi;
213  pin_name_t sck;
214  pin_name_t cs;
216  // Additional gpio pins
217  pin_name_t dat;
218  pin_name_t pdn;
219  pin_name_t sw;
220  pin_name_t int_pin;
222  // static variable
223  uint32_t spi_speed;
224  spi_master_mode_t spi_mode;
225  spi_master_chip_select_polarity_t cs_polarity;
227 } ismrx3_cfg_t;
228 
233 typedef enum
234 {
238 
240 
257 
271 err_t ismrx3_init ( ismrx3_t *ctx, ismrx3_cfg_t *cfg );
272 
287 
300 err_t ismrx3_generic_write ( ismrx3_t *ctx, uint8_t reg, uint8_t data_in );
301 
314 err_t ismrx3_generic_read ( ismrx3_t *ctx, uint8_t reg, uint8_t *data_out );
315 
323 void ismrx3_reset( ismrx3_t *ctx );
324 
332 uint8_t ismrx3_get_clk( ismrx3_t *ctx );
333 
341 uint8_t ismrx3_get_data( ismrx3_t *ctx );
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 #endif // ISMRX3_H
347  // ismrx3
349 
350 // ------------------------------------------------------------------------ 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:196
ismrx3_reset
void ismrx3_reset(ismrx3_t *ctx)
Reset function.
ismrx3_cfg_t::int_pin
pin_name_t int_pin
Definition: ismrx3.h:220
ismrx3_t::spi
spi_master_t spi
Definition: ismrx3.h:195
ismrx3_get_data
uint8_t ismrx3_get_data(ismrx3_t *ctx)
Read data output.
ISMRX3_OK
@ ISMRX3_OK
Definition: ismrx3.h:235
ismrx3_cfg_t::cs
pin_name_t cs
Definition: ismrx3.h:214
ismrx3_cfg_t::sw
pin_name_t sw
Definition: ismrx3.h:219
ISMRX3_ERROR
@ ISMRX3_ERROR
Definition: ismrx3.h:236
ismrx3_cfg_t::mosi
pin_name_t mosi
Definition: ismrx3.h:212
ismrx3_cfg_t::sck
pin_name_t sck
Definition: ismrx3.h:213
ismrx3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ismrx3.h:225
ismrx3_t::data_rate
uint8_t data_rate
Definition: ismrx3.h:201
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:237
ismrx3_cfg_t::miso
pin_name_t miso
Definition: ismrx3.h:211
ismrx3_cfg_t::dat
pin_name_t dat
Definition: ismrx3.h:217
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:223
ismrx3_t::int_pin
digital_in_t int_pin
Definition: ismrx3.h:192
ismrx3_get_clk
uint8_t ismrx3_get_clk(ismrx3_t *ctx)
Read clock output.
ismrx3_t::pdn
digital_out_t pdn
Definition: ismrx3.h:187
ismrx3_t::reference_freq
uint8_t reference_freq
Definition: ismrx3.h:199
ismrx3_cfg_t
ISM RX 3 Click configuration object.
Definition: ismrx3.h:209
ismrx3_t::freq_deviation
uint8_t freq_deviation
Definition: ismrx3.h:200
ismrx3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ismrx3.h:224
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:218
ismrx3_return_value_t
ismrx3_return_value_t
ISM RX 3 Click return value data.
Definition: ismrx3.h:234
ismrx3_t::sw
digital_out_t sw
Definition: ismrx3.h:188
ismrx3_t::modulation
uint8_t modulation
Definition: ismrx3.h:198
ismrx3_t::dat
digital_in_t dat
Definition: ismrx3.h:191
ismrx3_t
ISM RX 3 Click context object.
Definition: ismrx3.h:185