amfm2  2.1.0.0
amfm2.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 AMFM2_H
29 #define AMFM2_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_i2c_master.h"
38 
63 #define AMFM2_CMD_POWER_UP 0x01
64 #define AMFM2_CMD_GET_REV 0x10
65 #define AMFM2_CMD_POWER_DOWN 0x11
66 #define AMFM2_CMD_SET_PROPERTY 0x12
67 #define AMFM2_CMD_GET_PROPERTY 0x13
68 #define AMFM2_CMD_GET_INT_STATUS 0x14
69 #define AMFM2_CMD_PATCH_ARGS 0x15
70 #define AMFM2_CMD_PATCH_DATA 0x16
71 #define AMFM2_CMD_TX_TUNE_FREQ 0x30
72 #define AMFM2_CMD_TX_TUNE_POWER 0x31
73 #define AMFM2_CMD_TX_TUNE_MEASURE 0x32
74 #define AMFM2_CMD_TX_TUNE_STATUS 0x33
75 #define AMFM2_CMD_TX_ASQ_STATUS 0x34
76 #define AMFM2_CMD_TX_RDS_BUFF 0x35
77 #define AMFM2_CMD_TX_TX_RDS_PS 0x36
78 #define AMFM2_CMD_GPIO_CTL 0x80
79 #define AMFM2_CMD_GPIO_SET 0x81
80 
85 #define AMFM2_CMD_AM_TUNE_FREQ 0x40
86 #define AMFM2_CMD_AM_SEEK_START 0x41
87 #define AMFM2_CMD_AM_TUNE_STATUS 0x42
88 #define AMFM2_CMD_AM_RSQ_STATUS 0x43
89 #define AMFM2_CMD_AM_AGC_STATUS 0x47
90 #define AMFM2_CMD_AM_AGC_OVERRIDE 0x48
91 
96 #define AMFM2_CMD_FM_TUNE_FREQ 0x20
97 #define AMFM2_CMD_FM_SEEK_START 0x21
98 #define AMFM2_CMD_FM_TUNE_STATUS 0x22
99 #define AMFM2_CMD_FM_RSQ_STATUS 0x23
100 #define AMFM2_CMD_FM_RDS_STATUS 0x24
101 #define AMFM2_CMD_FM_AGC_STATUS 0x27
102 #define AMFM2_CMD_FM_AGC_OVERRIDE 0x28
103  // amfm2_cmd
105 
120 #define AMFM2_RSP_STATUS_CTS 0x80
121 #define AMFM2_RSP_STATUS_ERROR 0x40
122 #define AMFM2_RSP_STATUS_RDSINT 0x04
123 #define AMFM2_RSP_STATUS_ASQINT 0x02
124 #define AMFM2_RSP_STATUS_STCINT 0x01
125 
130 #define AMFM2_PWRUP_ARG_CTSIEN 0x80
131 #define AMFM2_PWRUP_ARG_GPO2OEN 0x40
132 #define AMFM2_PWRUP_ARG_PATCH 0x20
133 #define AMFM2_PWRUP_ARG_XOSCEN 0x10
134 #define AMFM2_PWRUP_ARG_FUNC_FMRECEIVE 0x00
135 #define AMFM2_PWRUP_ARG_FUNC_QUERYLIBID 0x0F
136 #define AMFM2_PWRUP_ARG_OPMODE_ANALOGOUT 0x05
137 #define AMFM2_PWRUP_ARG_OPMODE_DIGITALOUT 0x0B
138 #define AMFM2_PWRUP_ARG_OPMODE_DIGITALOUTS 0xB0
139 #define AMFM2_FMTUNEFREQ_ARG_FREEZE 0x02
140 #define AMFM2_FMTUNEFREQ_ARG_FAST 0x01
141 #define AMFM2_FMSEEKSTART_ARG_SEEKUP 0x08
142 #define AMFM2_FMSEEKSTART_ARG_WRAP 0x04
143 #define AMFM2_FMTUNESTATUS_ARG_CANCEL 0x02
144 #define AMFM2_FMTUNESTATUS_ARG_INTACK 0x01
145 #define AMFM2_FMRSQSTATUS_ARG_INTACK 0x01
146 #define AMFM2_FMRDSSTATUS_ARG_STATUSONLY 0x04
147 #define AMFM2_FMRDSSTATUS_ARG_MTFIFO 0x02
148 #define AMFM2_FMRDSSTATUS_ARG_INTACK 0x01
149 #define AMFM2_FMAGCOVERRIDE_ARG_RFAGCDIS 0x01
150 #define AMFM2_GPIOCTL_ARG_GPO3OEN 0x08
151 #define AMFM2_GPIOCTL_ARG_GPO2OEN 0x04
152 #define AMFM2_GPIOCTL_ARG_GPO1OEN 0x02
153 #define AMFM2_GPIOSET_ARG_GPO3LEVEL 0x08
154 #define AMFM2_GPIOSET_ARG_GPO2LEVEL 0x04
155 #define AMFM2_GPIOSET_ARG_GPO1LEVEL 0x02
156 
161 #define AMFM2_SET_VOLUME_MUTE 0
162 #define AMFM2_SET_VOLUME_MAX 63
163 
168 #define AMFM2_PROP_GPOIEN_H 0x00
169 #define AMFM2_PROP_GPOIEN_L 0x01
170 #define AMFM2_PROP_DIGITALOUTFORMAT_H 0x01
171 #define AMFM2_PROP_DIGITALOUTFORMAT_L 0x02
172 #define AMFM2_PROP_DIGITALOUTSAMPLERATE_H 0x01
173 #define AMFM2_PROP_DIGITALOUTSAMPLERATE_L 0x04
174 #define AMFM2_PROP_REFCLKFREQ_H 0x02
175 #define AMFM2_PROP_REFCLKFREQ_L 0x01
176 #define AMFM2_PROP_REFCLKPRESCALE_H 0x02
177 #define AMFM2_PROP_REFCLKPRESCALE_L 0x02
178 #define AMFM2_PROP_RXVOLUME_H 0x40
179 #define AMFM2_PROP_RXVOLUME_L 0x00
180 #define AMFM2_PROP_RXHMUTE_H 0x40
181 #define AMFM2_PROP_RXHMUTE_L 0x01
182 
187 #define AMFM2_PROP_FMDEEMPHASIS_H 0x11
188 #define AMFM2_PROP_FMDEEMPHASIS_L 0x00
189 #define AMFM2_PROP_AMDEEMPHASIS_H 0x31
190 #define AMFM2_PROP_AMDEEMPHASIS_L 0x00
191 #define AMFM2_PROP_FMCHANFILTER_H 0x11
192 #define AMFM2_PROP_FMCHANFILTER_L 0x02
193 #define AMFM2_PROP_AMCHANFILTER_H 0x31
194 #define AMFM2_PROP_AMCHANFILTER_L 0x02
195 #define AMFM2_PROP_AMRSQINTS_H 0x32
196 #define AMFM2_PROP_AMRSQINTS_L 0x00
197 #define AMFM2_PROP_AMNBRATE_H 0x39
198 #define AMFM2_PROP_AMNBRATE_L 0x02
199 #define AMFM2_PROP_AMNBIIRFILTER_H 0x39
200 #define AMFM2_PROP_AMNBIIRFILTER_L 0x03
201 #define AMFM2_PROP_AMNBDELAY_H 0x39
202 #define AMFM2_PROP_AMNBDELAY_L 0x04
203 
208 #define AMFM2_PROP_FMBLENDSTEREOTHS_H 0x11
209 #define AMFM2_PROP_FMBLENDSTEREOTHS_L 0x05
210 #define AMFM2_PROP_FMBLENDMONOTHS_H 0x11
211 #define AMFM2_PROP_FMBLENDMONOTHS_L 0x06
212 #define AMFM2_PROP_FMNBDETECTTHS_H 0x19
213 #define AMFM2_PROP_FMNBDETECTTHS_L 0x00
214 #define AMFM2_PROP_FMNBINTERVAL_H 0x19
215 #define AMFM2_PROP_FMNBINTERVAL_L 0x01
216 #define AMFM2_PROP_FMNBRATE_H 0x19
217 #define AMFM2_PROP_FMNBRATE_L 0x02
218 #define AMFM2_PROP_FMNBIIRFILTER_H 0x19
219 #define AMFM2_PROP_FMNBIIRFILTER_L 0x03
220 #define AMFM2_PROP_FMNBDELAY_H 0x19
221 #define AMFM2_PROP_FMNBDELAY_L 0x04
222 
227 #define AMFM2_PROPVALH_RSQREP 0x08
228 #define AMFM2_PROPVALH_RDSREP 0x04
229 #define AMFM2_PROPVALH_STCREP 0x01
230 #define AMFM2_PROPVALL_CTSIEN 0x80
231 #define AMFM2_PROPVALL_ERRIEN 0x40
232 #define AMFM2_PROPVALL_RSQIEN 0x08
233 #define AMFM2_PROPVALL_RDSIEN 0x04
234 #define AMFM2_PROPVALL_STCIEN 0x01
235 #define AMFM2_PROPVALL_OFALL 0x80
236 #define AMFM2_PROPVALL_LMUTE 0x02
237 #define AMFM2_PROPVALL_RMUTE 0x01
238 
244 #define AMFM2_DEVICE_ADDRESS_GND 0x11
245 #define AMFM2_DEVICE_ADDRESS_VCC 0x63
246  // amfm2_set
248 
263 #define AMFM2_MAP_MIKROBUS( cfg, mikrobus ) \
264  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
265  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
266  cfg.ema = MIKROBUS( mikrobus, MIKROBUS_AN ); \
267  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
268  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
269  cfg.gp2 = MIKROBUS( mikrobus, MIKROBUS_INT )
270  // amfm2_map // amfm2
273 
278 typedef struct
279 {
280  // Output pins
281  digital_out_t ema;
282  digital_out_t rst;
284  // Input pins
285  digital_in_t gp1;
286  digital_in_t gp2;
288  // Modules
289  i2c_master_t i2c;
291  // I2C slave address
292  uint8_t slave_address;
294 } amfm2_t;
295 
300 typedef struct
301 {
302  pin_name_t scl;
303  pin_name_t sda;
305  pin_name_t ema;
306  pin_name_t rst;
307  pin_name_t gp1;
308  pin_name_t gp2;
310  uint32_t i2c_speed;
311  uint8_t i2c_address;
313 } amfm2_cfg_t;
314 
319 typedef struct
320 {
321  uint8_t pn;
322  uint8_t fwmajor;
323  uint8_t fwminor;
324  uint16_t patch;
325  uint8_t cmpmajor;
326  uint8_t cmpminor;
327  uint8_t chiprev;
330 
335 typedef enum
336 {
337  AMFM2_OK = 0,
338  AMFM2_ERROR = -1
339 
341 
358 
372 err_t amfm2_init ( amfm2_t *ctx, amfm2_cfg_t *cfg );
373 
386 err_t amfm2_default_cfg ( amfm2_t *ctx );
387 
402 err_t amfm2_write_data ( amfm2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
403 
418 err_t amfm2_generic_read ( amfm2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
419 
430 void amfm2_hw_reset ( amfm2_t *ctx );
431 
443 
455 
467 uint8_t amfm2_get_gp1 ( amfm2_t *ctx );
468 
480 uint8_t amfm2_get_gp2 ( amfm2_t *ctx );
481 
493 void amfm2_set_rst ( amfm2_t *ctx, uint8_t pin_state );
494 
507 err_t amfm2_wait_rsp ( amfm2_t *ctx );
508 
526 err_t amfm2_set_command ( amfm2_t *ctx, uint8_t cmd, uint8_t *arg,
527  uint8_t arg_len, uint8_t *rsp, uint8_t rsp_len );
528 
543 err_t amfm2_get_response ( amfm2_t *ctx, uint8_t *rsp, uint8_t rsp_len );
544 
560 
574 err_t amfm2_seek_station ( amfm2_t *ctx, uint8_t *rsp );
575 
590 err_t amfm2_set_volume ( amfm2_t *ctx, uint8_t volume, uint8_t *rsp );
591 
605 err_t amfm2_sound_off ( amfm2_t *ctx, uint8_t *rsp );
606 
620 err_t amfm2_sound_on ( amfm2_t *ctx, uint8_t *rsp );
621 
636 err_t amfm2_tuning_freq_up ( amfm2_t *ctx, uint8_t *rsp );
637 
652 err_t amfm2_tuning_freq_down ( amfm2_t *ctx, uint8_t *rsp );
653 
668 err_t amfm2_tuning_freq ( amfm2_t *ctx, float frequency, uint8_t *rsp );
669 
684 err_t amfm2_get_tuning_freq ( amfm2_t *ctx, float *frequency );
685 
699 
713 
727 
741 
742 #ifdef __cplusplus
743 }
744 #endif
745 #endif // AMFM2_H
746  // amfm2
748 
749 // ------------------------------------------------------------------------ END
amfm2_device_info_t::chiprev
uint8_t chiprev
Definition: amfm2.h:327
amfm2_get_rev
err_t amfm2_get_rev(amfm2_t *ctx, amfm2_device_info_t *rev)
AM/FM 2 get revision information function.
amfm2_device_info_t
AM/FM 2 Click device information object.
Definition: amfm2.h:320
amfm2_tuning_freq
err_t amfm2_tuning_freq(amfm2_t *ctx, float frequency, uint8_t *rsp)
AM/FM 2 tuning frequency function.
amfm2_sound_on
err_t amfm2_sound_on(amfm2_t *ctx, uint8_t *rsp)
AM/FM 2 sound on function.
amfm2_device_info_t::fwminor
uint8_t fwminor
Definition: amfm2.h:323
AMFM2_OK
@ AMFM2_OK
Definition: amfm2.h:337
amfm2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: amfm2.h:310
amfm2_headphone_amp_disable
void amfm2_headphone_amp_disable(amfm2_t *ctx)
AM/FM 2 disable headphone amp function.
amfm2_wait_rsp
err_t amfm2_wait_rsp(amfm2_t *ctx)
AM/FM 2 wait response function.
amfm2_headphone_amp_enable
void amfm2_headphone_amp_enable(amfm2_t *ctx)
AM/FM 2 enable headphone amp function.
amfm2_cfg_t
AM/FM 2 Click configuration object.
Definition: amfm2.h:301
amfm2_return_value_t
amfm2_return_value_t
AM/FM 2 Click return value data.
Definition: amfm2.h:336
amfm2_get_response
err_t amfm2_get_response(amfm2_t *ctx, uint8_t *rsp, uint8_t rsp_len)
AM/FM 2 get response function.
amfm2_device_info_t::cmpmajor
uint8_t cmpmajor
Definition: amfm2.h:325
amfm2_cfg_t::ema
pin_name_t ema
Definition: amfm2.h:305
amfm2_device_info_t::fwmajor
uint8_t fwmajor
Definition: amfm2.h:322
amfm2_cfg_t::gp2
pin_name_t gp2
Definition: amfm2.h:308
amfm2_check_seek_tune_complete
err_t amfm2_check_seek_tune_complete(amfm2_t *ctx)
AM/FM 2 check CTS function.
amfm2_t::rst
digital_out_t rst
Definition: amfm2.h:282
amfm2_cfg_t::scl
pin_name_t scl
Definition: amfm2.h:302
amfm2_t
AM/FM 2 Click context object.
Definition: amfm2.h:279
amfm2_default_cfg
err_t amfm2_default_cfg(amfm2_t *ctx)
AM/FM 2 default configuration function.
amfm2_cfg_t::gp1
pin_name_t gp1
Definition: amfm2.h:307
amfm2_t::i2c
i2c_master_t i2c
Definition: amfm2.h:289
amfm2_hw_reset
void amfm2_hw_reset(amfm2_t *ctx)
AM/FM 2 hardware reset function.
amfm2_write_data
err_t amfm2_write_data(amfm2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
AM/FM 2 I2C writing function.
amfm2_device_info_t::pn
uint8_t pn
Definition: amfm2.h:321
amfm2_t::slave_address
uint8_t slave_address
Definition: amfm2.h:292
amfm2_tuning_freq_down
err_t amfm2_tuning_freq_down(amfm2_t *ctx, uint8_t *rsp)
AM/FM 2 tuning frequency down function.
amfm2_device_info_t::cmpminor
uint8_t cmpminor
Definition: amfm2.h:326
amfm2_get_tuning_freq
err_t amfm2_get_tuning_freq(amfm2_t *ctx, float *frequency)
AM/FM 2 get tuning frequency function.
amfm2_check_rds_interrupt
err_t amfm2_check_rds_interrupt(amfm2_t *ctx)
AM/FM 2 check RDS interrupt function.
amfm2_sound_off
err_t amfm2_sound_off(amfm2_t *ctx, uint8_t *rsp)
AM/FM 2 sound off function.
amfm2_set_rst
void amfm2_set_rst(amfm2_t *ctx, uint8_t pin_state)
AM/FM 2 set state of RST pin function.
amfm2_get_gp2
uint8_t amfm2_get_gp2(amfm2_t *ctx)
AM/FM 2 get state of GP2 pin function.
AMFM2_ERROR
@ AMFM2_ERROR
Definition: amfm2.h:338
amfm2_cfg_setup
void amfm2_cfg_setup(amfm2_cfg_t *cfg)
AM/FM 2 configuration object setup function.
amfm2_seek_station
err_t amfm2_seek_station(amfm2_t *ctx, uint8_t *rsp)
AM/FM 2 seek station function.
amfm2_check_status_error
err_t amfm2_check_status_error(amfm2_t *ctx)
AM/FM 2 check status error function.
amfm2_init
err_t amfm2_init(amfm2_t *ctx, amfm2_cfg_t *cfg)
AM/FM 2 initialization function.
amfm2_device_info_t::patch
uint16_t patch
Definition: amfm2.h:324
amfm2_cfg_t::sda
pin_name_t sda
Definition: amfm2.h:303
amfm2_cfg_t::i2c_address
uint8_t i2c_address
Definition: amfm2.h:311
amfm2_t::gp1
digital_in_t gp1
Definition: amfm2.h:285
amfm2_cfg_t::rst
pin_name_t rst
Definition: amfm2.h:306
amfm2_tuning_freq_up
err_t amfm2_tuning_freq_up(amfm2_t *ctx, uint8_t *rsp)
AM/FM 2 tuning frequency up function.
amfm2_check_clear_to_send
err_t amfm2_check_clear_to_send(amfm2_t *ctx)
AM/FM 2 check CTS function.
amfm2_t::ema
digital_out_t ema
Definition: amfm2.h:281
amfm2_set_command
err_t amfm2_set_command(amfm2_t *ctx, uint8_t cmd, uint8_t *arg, uint8_t arg_len, uint8_t *rsp, uint8_t rsp_len)
AM/FM 2 set command function.
amfm2_get_gp1
uint8_t amfm2_get_gp1(amfm2_t *ctx)
AM/FM 2 get state of GP1 pin function.
amfm2_set_volume
err_t amfm2_set_volume(amfm2_t *ctx, uint8_t volume, uint8_t *rsp)
AM/FM 2 set volume function.
amfm2_t::gp2
digital_in_t gp2
Definition: amfm2.h:286
amfm2_generic_read
err_t amfm2_generic_read(amfm2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
AM/FM 2 I2C reading function.