radiostation  2.0.0.0
radiostation.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 RADIOSTATION_H
36 #define RADIOSTATION_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define RADIOSTATION_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.sen = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define RADIOSTATION_RETVAL uint8_t
75 
76 #define RADIOSTATION_OK 0x00
77 #define RADIOSTATION_INIT_ERROR 0xFF
78 
84 #define RADIOSTATION_SLAVE_ADDR0 0x11 // If SEN = 0
85 #define RADIOSTATION_SLAVE_ADDR1 0x63 // If SEN = 1
86 
92 #define RADIOSTATION_CTS 0x80
93 #define RADIOSTATION_ERR 0x40
94 #define RADIOSTATION_RDSINT 0x04
95 #define RADIOSTATION_ASQINT 0x02
96 #define RADIOSTATION_STCINT 0x01
97 
104 // Power Up Settings
105 #define RADIOSTATION_CTS_INTERRUPT_ENABLE 0x04
106 #define RADIOSTATION_GPO2_OUTPUT_ENABLE 0x02
107 #define RADIOSTATION_PATCH_ENABLE 0x01
108 
109 // Set Tune Frequency Possible Arguments
110 #define RADIOSTATION_MIN_TUNE_FREQ 7600
111 #define RADIOSTATION_MAX_TUNE_FREQ 10800
112 #define RADIOSTATION_MIN_STEP 5
113 
119 #define RADIOSTATION_PROP_GPO_IEN 0x0001
120 #define RADIOSTATION_GPO_IEN_ASQREP 0x0200
121 #define RADIOSTATION_GPO_IEN_STCREP 0x0100
122 #define RADIOSTATION_GPO_IEN_CTSIEN 0x0080
123 #define RADIOSTATION_GPO_IEN_ERRIEN 0x0040
124 #define RADIOSTATION_GPO_IEN_RDSIEN 0x0004
125 #define RADIOSTATION_GPO_IEN_ASQIEN 0x0002
126 #define RADIOSTATION_GPO_IEN_STCIENP 0x0001
127 
128 #define RADIOSTATION_PROP_REFCLK_FREQ 0x0201 // Value Range: 31130 to 34406
129 
130 #define RADIOSTATION_PROP_REFCLK_PRESCALE 0x0202 // Value Range: 1 to 4095
131 #define RADIOSTATION_REFCLK_PRESCALE_RCLK 0x0000 & 0x1000
132 #define RADIOSTATION_REFCLK_PRESCALE_DCLK 0x1000 & 0x1000
133 
134 #define RADIOSTATION_PROP_TX_COMPONENT_ENABLE 0x2100
135 #define RADIOSTATION_TX_COMPONENT_ENABLE_RDS 0x0004
136 #define RADIOSTATION_TX_COMPONENT_ENABLE_LEFT_MINUS_RIGHT 0x0002
137 #define RADIOSTATION_TX_COMPONENT_ENABLE_PILOT_TONE 0x0001
138 
139 #define RADIOSTATION_PROP_TX_AUDIO_DEVIATION 0x2101 // Value Range: 0 to 9000
140 
141 #define RADIOSTATION_PROP_TX_PILOT_DEVIATION 0x2102 // Value Range: 0 to 9000
142 
143 #define RADIOSTATION_PROP_TX_LINE_INPUT_LEVEL 0x2104
144 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_1 0x0000 & 0x3000
145 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_2 0x1000 & 0x3000
146 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_3 0x2000 & 0x3000
147 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_4 0x3000 & 0x3000
148 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_MAX_LILEVEL 636 & 0x03FF
149 
150 #define RADIOSTATION_PROP_TX_LINE_INPUT_MUTE 0x2105
151 #define RADIOSTATION_TX_LINE_INPUT_MUTE_R 0x0001
152 #define RADIOSTATION_TX_LINE_INPUT_MUTE_L 0x0002
153 
154 #define RADIOSTATION_PROP_TX_PREEMPHASIS 0x2106
155 #define RADIOSTATION_TX_PREEMPHASIS_75 0x0000
156 #define RADIOSTATION_TX_PREEMPHASIS_50 0x0001
157 #define RADIOSTATION_TX_PREEMPHASIS_DISABLED 0x0002
158 
159 #define RADIOSTATION_PROP_TX_PILOT_FREQUENCY 0x2107 // Value Range: 0 to 19000
160 
161 #define RADIOSTATION_PROP_TX_ACOMP_ENABLE 0x2200
162 #define RADIOSTATION_TX_ACOMP_ENABLE_LIMITEN 0x0002
163 #define RADIOSTATION_TX_ACOMP_ENABLE_ACEN 0x0001
164 
165 #define RADIOSTATION_PROP_TX_ACOMP_THRESHOLD 0x2201 // Value Range: �40 to 0
166 
167 #define RADIOSTATION_PROP_TX_ACOMP_ATTACK_TIME 0x2202
168 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_0_5_MS 0x0000
169 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_1_0_MS 0x0001
170 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_1_5_MS 0x0002
171 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_2_0_MS 0x0003
172 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_2_5_MS 0x0004
173 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_3_0_MS 0x0005
174 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_3_5_MS 0x0006
175 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_4_0_MS 0x0007
176 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_4_5_MS 0x0008
177 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_5_0_MS 0x0009
178 
179 #define RADIOSTATION_PROP_TX_ACOMP_RELEASE_TIME 0x2203
180 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_100_MS 0x0000
181 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_200_MS 0x0001
182 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_350_MS 0x0002
183 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_525_MS 0x0003
184 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_1000_MS 0x0004
185 
186 #define RADIOSTATION_PROP_TX_ACOMP_GAIN 0x2204 // Value Range: 0 to 20
187 
188 #define RADIOSTATION_PROP_TX_LIMITER_RELEASE_TIME 0x2205 // Value Range: 5 to 2000
189 
190 #define RADIOSTATION_PROP_TX_ASQ_INTERRUPT_SELECT 0x2300
191 #define RADIOSTATION_TX_ASQ_INTERRUPT_OVERMODIEN 0x0004
192 #define RADIOSTATION_TX_ASQ_INTERRUPT_IALHIEN 0x0002
193 #define RADIOSTATION_TX_ASQ_INTERRUPT_IALLIEN 0x0001
194 
195 #define RADIOSTATION_PROP_TX_ASQ_LEVEL_LOW 0x2301 // Value Range: -70 to 0
196 
197 #define RADIOSTATION_PROP_TX_ASQ_LEVEL_HIGH 0x2303 // Value Range: -70 to 0
198 
199 #define RADIOSTATION_PROP_TX_ASQ_DURATION_LOW 0x2302
200 
201 #define RADIOSTATION_PROP_TX_ASQ_DURATION_HIGH 0x2304
202  // End group macro
205 // --------------------------------------------------------------- PUBLIC TYPES
214 typedef struct
215 {
216  // Output pins
217 
218  digital_out_t rst;
219  digital_out_t sen;
220 
221  // Input pins
222 
223  digital_in_t int_pin;
224 
225  // Modules
226 
227  i2c_master_t i2c;
228 
229  // ctx variable
230 
231  uint8_t slave_address;
232 
233  uint16_t transmit_frequency; // Frequency is represented in following way xxx.yy MHz
234  uint8_t status;
235 
237 
241 typedef struct
242 {
243  // Static variable
244 
245  uint8_t *params;
246  uint8_t params_count;
247  uint8_t *ret_vals;
248  uint8_t ret_vals_count;
249 
251 
255 typedef struct
256 {
257  // Communication gpio pins
258 
259  pin_name_t scl;
260  pin_name_t sda;
261 
262  // Additional gpio pins
263 
264  pin_name_t rst;
265  pin_name_t sen;
266  pin_name_t int_pin;
267 
268  // static variable
269 
270  uint32_t i2c_speed;
272 
274  // End types group
276 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
277 
283 #ifdef __cplusplus
284 extern "C"{
285 #endif
286 
295 void radiostation_cfg_setup ( radiostation_cfg_t *cfg, bool slave_select );
296 
306 
316 
326 void radiostation_write ( radiostation_t *ctx, uint8_t *data_buf, uint8_t len );
327 
337 void radiostation_read ( radiostation_t *ctx, uint8_t *data_buf, uint8_t len );
338 
349 uint8_t radiostation_power_up_advanced ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t config );
350 
361 
371 
382 uint8_t radiostation_get_revision ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals );
383 
395 uint8_t radiostation_get_revision1 ( radiostation_t *ctx, uint8_t *ret_vals );
396 
409 
421 uint8_t radiostation_set_tune_power ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t voltage, uint8_t capacitance );
422 
433 uint8_t radiostation_get_tune_measure ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t freq, uint8_t capacitance );
434 
444 
455 
466 
477 
490 uint8_t radiostation_get_tune_status ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t clear_stc_status_bit, uint8_t *ret_vals );
491 
502 uint8_t radiostation_get_asq_status ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals ) ;
503 
514 uint8_t radiostation_set_property ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id, uint16_t property_value );
515 
525 uint16_t radiostation_get_property ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id );
526 
527 
528 #ifdef __cplusplus
529 }
530 #endif
531 #endif // _RADIOSTATION_H_
532  // End public_function group
535 
536 // ------------------------------------------------------------------------- END
radiostation_t::slave_address
uint8_t slave_address
Definition: radiostation.h:231
radiostation_cmd_t::params
uint8_t * params
Definition: radiostation.h:245
radiostation_t
Click ctx object definition.
Definition: radiostation.h:215
radiostation_t::status
uint8_t status
Definition: radiostation.h:234
radiostation_busy_wait_for_stcint
void radiostation_busy_wait_for_stcint(radiostation_t *ctx, radiostation_cmd_t *cmd)
Radio Station Click Busy Wait for STCINT.
radiostation_cfg_t::slave_select
bool slave_select
Definition: radiostation.h:271
radiostation_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: radiostation.h:270
radiostation_cfg_t
Click configuration structure definition.
Definition: radiostation.h:256
radiostation_get_int_status
uint8_t radiostation_get_int_status(radiostation_t *ctx, radiostation_cmd_t *cmd)
Getting int pin status.
radiostation_cfg_t::int_pin
pin_name_t int_pin
Definition: radiostation.h:266
radiostation_write
void radiostation_write(radiostation_t *ctx, uint8_t *data_buf, uint8_t len)
Generic write function.
radiostation_power_down
uint8_t radiostation_power_down(radiostation_t *ctx, radiostation_cmd_t *cmd)
Radio Station Click Power Down.
radiostation_cmd_t::params_count
uint8_t params_count
Definition: radiostation.h:246
radiostation_get_asq_status
uint8_t radiostation_get_asq_status(radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals)
Radio Station Click ASQ Status.
radiostation_t::rst
digital_out_t rst
Definition: radiostation.h:218
radiostation_busy_wait_for_asqint
void radiostation_busy_wait_for_asqint(radiostation_t *ctx, radiostation_cmd_t *cmd)
Radio Station Click Busy Wait for ASQINT.
radiostation_get_revision
uint8_t radiostation_get_revision(radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals)
Radio Station Click Get Revision.
radiostation_cmd_t
Click send command object definition.
Definition: radiostation.h:242
radiostation_t::transmit_frequency
uint16_t transmit_frequency
Definition: radiostation.h:233
radiostation_get_tune_measure
uint8_t radiostation_get_tune_measure(radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t freq, uint8_t capacitance)
Radio Station Click Get Tuning Measurements.
radiostation_get_property
uint16_t radiostation_get_property(radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id)
Radio Station Click Get Property.
radiostation_t::sen
digital_out_t sen
Definition: radiostation.h:219
radiostation_t::int_pin
digital_in_t int_pin
Definition: radiostation.h:223
radiostation_cfg_t::rst
pin_name_t rst
Definition: radiostation.h:264
radiostation_init
RADIOSTATION_RETVAL radiostation_init(radiostation_t *ctx, radiostation_cfg_t *cfg)
Initialization function.
radiostation_cmd_t::ret_vals
uint8_t * ret_vals
Definition: radiostation.h:247
radiostation_set_tune_power
uint8_t radiostation_set_tune_power(radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t voltage, uint8_t capacitance)
Radio Station Click Get Revision.
radiostation_cfg_t::sda
pin_name_t sda
Definition: radiostation.h:260
radiostation_set_tune_frequency
uint8_t radiostation_set_tune_frequency(radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t freq)
Radio Station Click Set Tune Frequency.
radiostation_cmd_t::ret_vals_count
uint8_t ret_vals_count
Definition: radiostation.h:248
RADIOSTATION_RETVAL
#define RADIOSTATION_RETVAL
Definition: radiostation.h:74
radiostation_power_up_advanced
uint8_t radiostation_power_up_advanced(radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t config)
Radio Station Click Power Up Advanced.
radiostation_cfg_setup
void radiostation_cfg_setup(radiostation_cfg_t *cfg, bool slave_select)
Config Object Initialization function.
radiostation_t::i2c
i2c_master_t i2c
Definition: radiostation.h:227
radiostation_set_property
uint8_t radiostation_set_property(radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id, uint16_t property_value)
Radio Station Click Set Property.
radiostation_read
void radiostation_read(radiostation_t *ctx, uint8_t *data_buf, uint8_t len)
Generic read function.
radiostation_get_tune_status
uint8_t radiostation_get_tune_status(radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t clear_stc_status_bit, uint8_t *ret_vals)
Radio Station Click Get Tune Status.
radiostation_cfg_t::scl
pin_name_t scl
Definition: radiostation.h:259
radiostation_default_cfg
void radiostation_default_cfg(radiostation_t *ctx, radiostation_cmd_t *cmd)
Click Default Configuration function.
radiostation_power_up
uint8_t radiostation_power_up(radiostation_t *ctx, radiostation_cmd_t *cmd)
Radio Station Click Power Up.
radiostation_cfg_t::sen
pin_name_t sen
Definition: radiostation.h:265
radiostation_get_revision1
uint8_t radiostation_get_revision1(radiostation_t *ctx, uint8_t *ret_vals)
Radio Station Click Set Tune Frequency.
radiostation_busy_wait_for_rdsint
void radiostation_busy_wait_for_rdsint(radiostation_t *ctx, radiostation_cmd_t *cmd)
Radio Station Click Busy Wait for RDSINT.