fm  2.0.0.0
fm.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef FM_H
36 #define FM_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define FM_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.gp2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.sen = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_INT )
59 
65 #define FM_RETVAL uint8_t
66 
67 #define FM_OK 0x00
68 #define FM_INIT_ERROR 0xFF
69 
75 #define DEFAULT_SLAVE_ADDRESS 0x10
76 
82 #define FM_DEVICE_ID 0x000E
83 #define FM_CHIP_ID 0x000F
84 #define FM_POWER_CONFIGURATION 0x0000
85 #define FM_CHANNEL 0x0001
86 #define FM_SYSTEM_CONFIGURATION_1 0x0002
87 #define FM_SYSTEM_CONFIGURATION_2 0x0003
88 #define FM_SYSTEM_CONFIGURATION_3 0x0004
89 #define FM_TEST_1 0x0005
90 #define FM_TEST_2 0x0006
91 #define FM_BOOT_CONFIGURATION 0x0007
92 #define FM_STATUS_RSSI 0x0008
93 #define FM_READ_CHANNEL 0x0009
94 #define FM_RDS_A 0x000A
95 #define FM_RDS_B 0x000B
96 #define FM_RDS_C 0x000C
97 #define FM_RDS_D 0x000D
98 
104 #define FM_SOFTMUTE_MASK 0x7FFF
105 #define FM_SOFTMUTE_ENABLE 0x0000
106 #define FM_SOFTMUTE_DISABLE 0x8000
107 
108 #define FM_MUTE_MASK 0xBFFF
109 #define FM_MUTE_ENABLE 0x0000
110 #define FM_MUTE_DISABLE 0x4000
111 
112 #define FM_STEREO_MASK 0xDFFF
113 #define FM_STEREO 0x0000
114 #define FM_FORCE_MONO 0x2000
115 
116 #define FM_RDS_MODE_MASK 0xF7FF
117 #define FM_RDS_MODE_STANDARD 0x0000
118 #define FM_RDS_MODE_VERBOSE 0x0800
119 
120 #define FM_SEEK_MODE_MASK 0xFBFF
121 #define FM_SEEK_MODE_WRAP 0x0000
122 #define FM_SEEK_MODE_STOP 0x0400
123 
124 #define FM_SEEK_DIRECTION_MASK 0xFDFF
125 #define FM_SEEK_DIRECTION_DOWN 0x0000
126 #define FM_SEEK_DIRECTION_UP 0x0200
127 
128 #define FM_SEEK_MASK 0xFEFF
129 #define FM_SEEK_DISABLE 0x0000
130 #define FM_SEEK_ENABLE 0x0100
131 
132 #define FM_POWERUP_DISABLE_MASK 0xFFBF
133 #define FM_POWERUP_DISABLE_LOW 0x0000
134 #define FM_POWERUP_DISABLE_HIGH 0x0040
135 
136 #define FM_POWERUP_ENABLE_MASK 0xFFFE
137 #define FM_POWERUP_ENABLE_LOW 0x0000
138 #define FM_POWERUP_ENABLE_HIGH 0x0001
139 
145 #define FM_TUNE_MASK 0x7FFF
146 #define FM_TUNE_DISABLE 0x0000
147 #define FM_TUNE_ENABLE 0x8000
148 
154 #define FM_RDS_INTERRUPT_MASK 0x7FFF
155 #define FM_RDS_INTERRUPT_DISABLE 0x0000
156 #define FM_RDS_INTERRUPT_ENABLE 0x8000
157 
158 #define FM_SEEK_TUNE_COMPLETE_INTERRUPT_MASK 0xBFFF
159 #define FM_SEEK_TUNE_COMPLETE_INTERRUPT_DISABLE 0x0000
160 #define FM_SEEK_TUNE_COMPLETE_INTERRUPT_ENABLE 0x4000
161 
162 #define FM_RDS_MASK 0xEFFF
163 #define FM_RDS_DISABLE 0x0000
164 #define FM_RDS_ENABLE 0x1000
165 
166 #define FM_DE_EMPHASIS_MASK 0xF7FF
167 #define FM_DE_EMPHASIS_USA 0x0000
168 #define FM_DE_EMPHASIS_EUROPE_AUSTRALIA_JAPAN 0x0800
169 
170 #define FM_AGC_MASK 0xFBFF
171 #define FM_AGC_ENABLE 0x0000
172 #define FM_AGC_DISABLE 0x0400
173 
174 #define FM_STEREO_MONO_BLEND_LEVEL_MASK 0xFF3F
175 #define FM_STEREO_MONO_BLEND_LEVEL_31_49_RSSI 0x0000
176 #define FM_STEREO_MONO_BLEND_LEVEL_37_55_RSSI 0x0040
177 #define FM_STEREO_MONO_BLEND_LEVEL_19_37_RSSI 0x0080
178 #define FM_STEREO_MONO_BLEND_LEVEL_25_43_RSSI 0x00C0
179 
180 #define FM_GPIO3_MASK 0xFFCF
181 #define FM_GPIO3_HIGH_IMPENDANCE 0x0000
182 #define FM_GPIO3_MONO_STEREO_INDICATOR 0x0001
183 #define FM_GPIO3_LOW 0x0002
184 #define FM_GPIO3_HIGH 0x0003
185 
186 #define FM_GPIO2_MASK 0xFFF3
187 #define FM_GPIO2_HIGH_IMPEDANCE 0x0000
188 #define FM_GPIO2_STC_RDS_INTERRUPT 0x0004
189 #define FM_GPIO2_LOW 0x0008
190 #define FM_GPIO2_HIGH 0x000C
191 
192 #define FM_GPIO1_MASK 0xFFFC
193 #define FM_GPIO1_HIGH_IMPEDANCE 0x0000
194 #define FM_GPIO1_RESERVED 0x0001
195 #define FM_GPIO1_LOW 0x0002
196 #define FM_GPIO1_HIGH 0x0003
197 
203 #define FM_BAND_MASK 0xFF3F
204 #define FM_BAND_USA_EUROPE_87P5_108_MHZ 0x0000
205 #define FM_BAND_JAPAN_WIDE_76_108_MHZ 0x0040
206 #define FM_BAND_JAPAN_76_90_MHZ 0x0080
207 #define FM_BAND_RESERVED 0x00C0
208 
209 #define FM_CHANNEL_SPACING_MASK 0xFFCF
210 #define FM_CHANNEL_SPACING_USA_AUSTRALIA_200_KHZ 0x0000
211 #define FM_CHANNEL_SPACING_EUROPE_JAPAN_100_KHZ 0x0010
212 #define FM_CHANNEL_SPACING_50_KHZ 0x0020
213 
219 #define FM_SOFTMUTE_ATTACK_RECOVER_RATE_MASK 0x3FFF
220 #define FM_SOFTMUTE_ATTACK_RECOVER_RATE_FASTEST 0x0000
221 #define FM_SOFTMUTE_ATTACK_RECOVER_RATE_FAST 0x4000
222 #define FM_SOFTMUTE_ATTACK_RECOVER_RATE_SLOW 0x8000
223 #define FM_SOFTMUTE_ATTACK_RECOVER_RATE_SLOWEST 0xC000
224 
225 #define FM_SOFTMUTE_ATTENUATION_MASK 0xCFFF
226 #define FM_SOFTMUTE_ATTENUATION_16_DB 0x0000
227 #define FM_SOFTMUTE_ATTENUATION_14_DB 0x1000
228 #define FM_SOFTMUTE_ATTENUATION_12_DB 0x2000
229 #define FM_SOFTMUTE_ATTENUATION_10_DB 0x3000
230 
231 #define FM_EXTENDED_VOLUME_RANGE_MASK 0xFEFF
232 #define FM_EXTENDED_VOLUME_RANGE_DISABLED 0x0000
233 #define FM_EXTENDED_VOLUME_RANGE_ENABLED 0x0100
234 
240 #define FM_CRYSTAL_OSCYLATOR_MASK 0x7FFF
241 #define FM_CRYSTAL_OSCYLATOR_DISABLE 0x0000
242 #define FM_CRYSTAL_OSCYLATOR_ENABLE 0x8000
243 
244 #define FM_AUDIO_HIGH_Z_MASK 0xBFFF
245 #define FM_AUDIO_HIGH_Z_DISABLE 0x0000
246 #define FM_AUDIO_HIGH_Z_ENABLE 0x4000
247 
253 #define FM_RDS_READY_MASK 0x8000
254 #define FM_SEEK_TUNE_COMPLETE_MASK 0x4000
255 #define FM_SEEK_FAIL_BAND_LIMIT_MASK 0x2000
256 #define FM_AFC_RAIL_MASK 0x1000
257 #define FM_RDS_SYNCHRONIZED_MASK 0x0800
258 #define FM_STEREO_MONO_INDICATOR_MASK 0x0100
259  // End group macro
262 // --------------------------------------------------------------- PUBLIC TYPES
271 typedef struct
272 {
273  // Output pins
274 
275  digital_out_t rst;
276  digital_out_t sen;
277 
278  // Input pins
279 
280  digital_in_t gp2;
281  digital_in_t gp1;
282 
283  // Modules
284 
285  i2c_master_t i2c;
286 
287  // ctx variable
288 
289  uint8_t slave_address;
290 
291 } fm_t;
292 
296 typedef struct
297 {
298  // Communication gpio pins
299 
300  pin_name_t scl;
301  pin_name_t sda;
302 
303  // Additional gpio pins
304 
305  pin_name_t gp2;
306  pin_name_t rst;
307  pin_name_t sen;
308  pin_name_t gp1;
309 
310  // static variable
311 
312  uint32_t i2c_speed;
313  uint8_t i2c_address;
314 
315 } fm_cfg_t;
316  // End types group
318 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
319 
325 #ifdef __cplusplus
326 extern "C"{
327 #endif
328 
337 void fm_cfg_setup ( fm_cfg_t *cfg );
338 
348 
356 void fm_default_cfg ( fm_t *ctx );
357 
367 void fm_generic_write ( fm_t *ctx, uint16_t *reg_buf );
368 
380 void fm_generic_read ( fm_t *ctx, uint16_t *reg_buf );
381 
395 void fm_set_bits ( uint16_t *register_buffer, uint16_t register_address, uint16_t bits_mask, uint16_t bits_value );
396 
408 uint8_t fm_set_seek_threshold ( fm_t *ctx, uint16_t seek_threshold );
409 
422 uint8_t fm_set_volume ( fm_t *ctx, uint8_t volume_level );
423 
435 uint8_t fm_set_snr_threshold ( fm_t *ctx, uint8_t snr_threshold );
436 
448 uint8_t fm_set_seek_impulse_detection_threshold ( fm_t *ctx, uint8_t impulse_detection_threshold );
449 
462 uint8_t fm_get_errors_block_a ( fm_t *ctx );
463 
473 
486 uint8_t fm_get_errors_block_b ( fm_t *ctx );
487 
500 uint8_t fm_get_errors_block_c ( fm_t *ctx );
501 
514 uint8_t fm_get_errors_block_d ( fm_t *ctx );
515 
525 
536 void fm_power_up ( fm_t *ctx );
537 
546 void fm_basic_settings ( fm_t *ctx );
547 
555 void fm_power_down ( fm_t *ctx );
556 
565 uint16_t fm_get_channel ( fm_t *ctx );
566 
575 void fm_tune_channel ( fm_t *ctx, uint16_t channel );
576 
588 uint8_t fm_tune ( fm_t *ctx, float channel_frequency );
589 
599 void fm_end_tune ( fm_t *ctx );
600 
609 void fm_seek ( fm_t *ctx );
610 
621 void fm_end_seek ( fm_t *ctx );
622 
633 uint8_t fm_volume_up ( fm_t *ctx );
634 
645 uint8_t fm_volume_down ( fm_t *ctx );
646 
654 void fm_mute_enable ( fm_t *ctx );
655 
663 void fm_mute_disable ( fm_t *ctx );
664 
673 uint8_t fm_fine_tune_up ( fm_t *ctx);
674 
682 uint8_t fm_fine_tune_down ( fm_t *ctx );
683 
692 uint8_t fm_get_int_pin ( fm_t *ctx );
693 
701 uint8_t fm_get_an_pin ( fm_t *ctx );
702 
703 #ifdef __cplusplus
704 }
705 #endif
706 #endif // _FM_H_
707  // End public_function group
710 
711 // ------------------------------------------------------------------------- END
fm_set_volume
uint8_t fm_set_volume(fm_t *ctx, uint8_t volume_level)
Setting volume value.
fm_cfg_t::gp2
pin_name_t gp2
Definition: fm.h:305
fm_power_up
void fm_power_up(fm_t *ctx)
Powering up device.
fm_set_seek_threshold
uint8_t fm_set_seek_threshold(fm_t *ctx, uint16_t seek_threshold)
Setting seek threshold value.
fm_cfg_t::sda
pin_name_t sda
Definition: fm.h:301
fm_fine_tune_up
uint8_t fm_fine_tune_up(fm_t *ctx)
Fine tunning.
fm_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fm.h:312
fm_basic_settings
void fm_basic_settings(fm_t *ctx)
Setting basic settings.
fm_t::rst
digital_out_t rst
Definition: fm.h:275
fm_mute_disable
void fm_mute_disable(fm_t *ctx)
Disable mute.
fm_end_tune
void fm_end_tune(fm_t *ctx)
End tunning.
fm_t::gp2
digital_in_t gp2
Definition: fm.h:280
fm_get_errors_block_d
uint8_t fm_get_errors_block_d(fm_t *ctx)
Reading number of errors to be corrected.
fm_seek
void fm_seek(fm_t *ctx)
Start seeking radio station.
fm_tune
uint8_t fm_tune(fm_t *ctx, float channel_frequency)
Tunning radio station.
fm_cfg_t::i2c_address
uint8_t i2c_address
Definition: fm.h:313
fm_cfg_t
Click configuration structure definition.
Definition: fm.h:297
fm_get_errors_block_b
uint8_t fm_get_errors_block_b(fm_t *ctx)
Reading number of errors to be corrected.
fm_init
FM_RETVAL fm_init(fm_t *ctx, fm_cfg_t *cfg)
Initialization function.
fm_cfg_setup
void fm_cfg_setup(fm_cfg_t *cfg)
Config Object Initialization function.
fm_get_channel
uint16_t fm_get_channel(fm_t *ctx)
Reading CHANNEL bits.
fm_cfg_t::sen
pin_name_t sen
Definition: fm.h:307
fm_set_seek_impulse_detection_threshold
uint8_t fm_set_seek_impulse_detection_threshold(fm_t *ctx, uint8_t impulse_detection_threshold)
Setting seek impulse detection threshold value.
fm_get_channel_frequency
float fm_get_channel_frequency(fm_t *ctx)
Calculating current channel frequency.
fm_t::i2c
i2c_master_t i2c
Definition: fm.h:285
fm_end_seek
void fm_end_seek(fm_t *ctx)
End seeking.
fm_cfg_t::gp1
pin_name_t gp1
Definition: fm.h:308
FM_RETVAL
#define FM_RETVAL
Definition: fm.h:65
fm_get_int_pin
uint8_t fm_get_int_pin(fm_t *ctx)
Checking INT pin status.
fm_set_bits
void fm_set_bits(uint16_t *register_buffer, uint16_t register_address, uint16_t bits_mask, uint16_t bits_value)
Setting bits in specific register on a specific bit location.
fm_volume_down
uint8_t fm_volume_down(fm_t *ctx)
Decreasing volume level.
fm_get_received_signal_strength_indicator
uint8_t fm_get_received_signal_strength_indicator(fm_t *ctx)
Reading recived strength indicator.
fm_fine_tune_down
uint8_t fm_fine_tune_down(fm_t *ctx)
Fine tunning.
fm_t::sen
digital_out_t sen
Definition: fm.h:276
fm_mute_enable
void fm_mute_enable(fm_t *ctx)
Enable mute.
fm_get_errors_block_a
uint8_t fm_get_errors_block_a(fm_t *ctx)
Reading number of errors to be corrected.
fm_generic_read
void fm_generic_read(fm_t *ctx, uint16_t *reg_buf)
Reading all registers.
fm_cfg_t::scl
pin_name_t scl
Definition: fm.h:300
fm_default_cfg
void fm_default_cfg(fm_t *ctx)
Click Default Configuration function.
fm_t::gp1
digital_in_t gp1
Definition: fm.h:281
fm_volume_up
uint8_t fm_volume_up(fm_t *ctx)
Increasing volume level.
fm_t::slave_address
uint8_t slave_address
Definition: fm.h:289
fm_generic_write
void fm_generic_write(fm_t *ctx, uint16_t *reg_buf)
Generic write function.
fm_power_down
void fm_power_down(fm_t *ctx)
Powering down device.
fm_set_snr_threshold
uint8_t fm_set_snr_threshold(fm_t *ctx, uint8_t snr_threshold)
Setting seek SNR threshold value.
fm_get_an_pin
uint8_t fm_get_an_pin(fm_t *ctx)
Checking AN pin status.
fm_tune_channel
void fm_tune_channel(fm_t *ctx, uint16_t channel)
Setting CHANNEL bits.
fm_get_errors_block_c
uint8_t fm_get_errors_block_c(fm_t *ctx)
Reading number of errors to be corrected.
fm_cfg_t::rst
pin_name_t rst
Definition: fm.h:306
fm_t
Click ctx object definition.
Definition: fm.h:272