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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define RADIOSTATION_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.sen = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define RADIOSTATION_RETVAL uint8_t
79 
80 #define RADIOSTATION_OK 0x00
81 #define RADIOSTATION_INIT_ERROR 0xFF
82 
88 #define RADIOSTATION_SLAVE_ADDR0 0x11 // If SEN = 0
89 #define RADIOSTATION_SLAVE_ADDR1 0x63 // If SEN = 1
90 
96 #define RADIOSTATION_CTS 0x80
97 #define RADIOSTATION_ERR 0x40
98 #define RADIOSTATION_RDSINT 0x04
99 #define RADIOSTATION_ASQINT 0x02
100 #define RADIOSTATION_STCINT 0x01
101 
108 // Power Up Settings
109 #define RADIOSTATION_CTS_INTERRUPT_ENABLE 0x04
110 #define RADIOSTATION_GPO2_OUTPUT_ENABLE 0x02
111 #define RADIOSTATION_PATCH_ENABLE 0x01
112 
113 // Set Tune Frequency Possible Arguments
114 #define RADIOSTATION_MIN_TUNE_FREQ 7600
115 #define RADIOSTATION_MAX_TUNE_FREQ 10800
116 #define RADIOSTATION_MIN_STEP 5
117 
123 #define RADIOSTATION_PROP_GPO_IEN 0x0001
124 #define RADIOSTATION_GPO_IEN_ASQREP 0x0200
125 #define RADIOSTATION_GPO_IEN_STCREP 0x0100
126 #define RADIOSTATION_GPO_IEN_CTSIEN 0x0080
127 #define RADIOSTATION_GPO_IEN_ERRIEN 0x0040
128 #define RADIOSTATION_GPO_IEN_RDSIEN 0x0004
129 #define RADIOSTATION_GPO_IEN_ASQIEN 0x0002
130 #define RADIOSTATION_GPO_IEN_STCIENP 0x0001
131 
132 #define RADIOSTATION_PROP_REFCLK_FREQ 0x0201 // Value Range: 31130 to 34406
133 
134 #define RADIOSTATION_PROP_REFCLK_PRESCALE 0x0202 // Value Range: 1 to 4095
135 #define RADIOSTATION_REFCLK_PRESCALE_RCLK 0x0000 & 0x1000
136 #define RADIOSTATION_REFCLK_PRESCALE_DCLK 0x1000 & 0x1000
137 
138 #define RADIOSTATION_PROP_TX_COMPONENT_ENABLE 0x2100
139 #define RADIOSTATION_TX_COMPONENT_ENABLE_RDS 0x0004
140 #define RADIOSTATION_TX_COMPONENT_ENABLE_LEFT_MINUS_RIGHT 0x0002
141 #define RADIOSTATION_TX_COMPONENT_ENABLE_PILOT_TONE 0x0001
142 
143 #define RADIOSTATION_PROP_TX_AUDIO_DEVIATION 0x2101 // Value Range: 0 to 9000
144 
145 #define RADIOSTATION_PROP_TX_PILOT_DEVIATION 0x2102 // Value Range: 0 to 9000
146 
147 #define RADIOSTATION_PROP_TX_LINE_INPUT_LEVEL 0x2104
148 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_1 0x0000 & 0x3000
149 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_2 0x1000 & 0x3000
150 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_3 0x2000 & 0x3000
151 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_LIATTEN_4 0x3000 & 0x3000
152 #define RADIOSTATION_TX_LINE_INPUT_LEVEL_MAX_LILEVEL 636 & 0x03FF
153 
154 #define RADIOSTATION_PROP_TX_LINE_INPUT_MUTE 0x2105
155 #define RADIOSTATION_TX_LINE_INPUT_MUTE_R 0x0001
156 #define RADIOSTATION_TX_LINE_INPUT_MUTE_L 0x0002
157 
158 #define RADIOSTATION_PROP_TX_PREEMPHASIS 0x2106
159 #define RADIOSTATION_TX_PREEMPHASIS_75 0x0000
160 #define RADIOSTATION_TX_PREEMPHASIS_50 0x0001
161 #define RADIOSTATION_TX_PREEMPHASIS_DISABLED 0x0002
162 
163 #define RADIOSTATION_PROP_TX_PILOT_FREQUENCY 0x2107 // Value Range: 0 to 19000
164 
165 #define RADIOSTATION_PROP_TX_ACOMP_ENABLE 0x2200
166 #define RADIOSTATION_TX_ACOMP_ENABLE_LIMITEN 0x0002
167 #define RADIOSTATION_TX_ACOMP_ENABLE_ACEN 0x0001
168 
169 #define RADIOSTATION_PROP_TX_ACOMP_THRESHOLD 0x2201 // Value Range: �40 to 0
170 
171 #define RADIOSTATION_PROP_TX_ACOMP_ATTACK_TIME 0x2202
172 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_0_5_MS 0x0000
173 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_1_0_MS 0x0001
174 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_1_5_MS 0x0002
175 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_2_0_MS 0x0003
176 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_2_5_MS 0x0004
177 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_3_0_MS 0x0005
178 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_3_5_MS 0x0006
179 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_4_0_MS 0x0007
180 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_4_5_MS 0x0008
181 #define RADIOSTATION_TX_ACOMP_ATTACK_TIME_5_0_MS 0x0009
182 
183 #define RADIOSTATION_PROP_TX_ACOMP_RELEASE_TIME 0x2203
184 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_100_MS 0x0000
185 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_200_MS 0x0001
186 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_350_MS 0x0002
187 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_525_MS 0x0003
188 #define RADIOSTATION_TX_ACOMP_RELEASE_TIME_1000_MS 0x0004
189 
190 #define RADIOSTATION_PROP_TX_ACOMP_GAIN 0x2204 // Value Range: 0 to 20
191 
192 #define RADIOSTATION_PROP_TX_LIMITER_RELEASE_TIME 0x2205 // Value Range: 5 to 2000
193 
194 #define RADIOSTATION_PROP_TX_ASQ_INTERRUPT_SELECT 0x2300
195 #define RADIOSTATION_TX_ASQ_INTERRUPT_OVERMODIEN 0x0004
196 #define RADIOSTATION_TX_ASQ_INTERRUPT_IALHIEN 0x0002
197 #define RADIOSTATION_TX_ASQ_INTERRUPT_IALLIEN 0x0001
198 
199 #define RADIOSTATION_PROP_TX_ASQ_LEVEL_LOW 0x2301 // Value Range: -70 to 0
200 
201 #define RADIOSTATION_PROP_TX_ASQ_LEVEL_HIGH 0x2303 // Value Range: -70 to 0
202 
203 #define RADIOSTATION_PROP_TX_ASQ_DURATION_LOW 0x2302
204 
205 #define RADIOSTATION_PROP_TX_ASQ_DURATION_HIGH 0x2304
206  // End group macro
209 // --------------------------------------------------------------- PUBLIC TYPES
218 typedef struct
219 {
220  // Output pins
221 
222  digital_out_t rst;
223  digital_out_t sen;
224 
225  // Input pins
226 
227  digital_in_t int_pin;
228 
229  // Modules
230 
231  i2c_master_t i2c;
232 
233  // ctx variable
234 
235  uint8_t slave_address;
236 
237  uint16_t transmit_frequency; // Frequency is represented in following way xxx.yy MHz
238  uint8_t status;
239 
241 
245 typedef struct
246 {
247  // Static variable
248 
249  uint8_t *params;
250  uint8_t params_count;
251  uint8_t *ret_vals;
252  uint8_t ret_vals_count;
253 
255 
259 typedef struct
260 {
261  // Communication gpio pins
262 
263  pin_name_t scl;
264  pin_name_t sda;
265 
266  // Additional gpio pins
267 
268  pin_name_t rst;
269  pin_name_t sen;
270  pin_name_t int_pin;
271 
272  // static variable
273 
274  uint32_t i2c_speed;
276 
278  // End types group
280 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
281 
287 #ifdef __cplusplus
288 extern "C"{
289 #endif
290 
299 void radiostation_cfg_setup ( radiostation_cfg_t *cfg, bool slave_select );
300 
310 
320 
330 void radiostation_write ( radiostation_t *ctx, uint8_t *data_buf, uint8_t len );
331 
341 void radiostation_read ( radiostation_t *ctx, uint8_t *data_buf, uint8_t len );
342 
353 uint8_t radiostation_power_up_advanced ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t config );
354 
365 
375 
386 uint8_t radiostation_get_revision ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals );
387 
399 uint8_t radiostation_get_revision1 ( radiostation_t *ctx, uint8_t *ret_vals );
400 
413 
425 uint8_t radiostation_set_tune_power ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t voltage, uint8_t capacitance );
426 
437 uint8_t radiostation_get_tune_measure ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t freq, uint8_t capacitance );
438 
448 
459 
470 
481 
494 uint8_t radiostation_get_tune_status ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t clear_stc_status_bit, uint8_t *ret_vals );
495 
506 uint8_t radiostation_get_asq_status ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint8_t *ret_vals ) ;
507 
518 uint8_t radiostation_set_property ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id, uint16_t property_value );
519 
529 uint16_t radiostation_get_property ( radiostation_t *ctx, radiostation_cmd_t *cmd, uint16_t property_id );
530 
531 
532 #ifdef __cplusplus
533 }
534 #endif
535 #endif // _RADIOSTATION_H_
536  // End public_function group
539 
540 // ------------------------------------------------------------------------- END
radiostation_t::slave_address
uint8_t slave_address
Definition: radiostation.h:235
radiostation_cmd_t::params
uint8_t * params
Definition: radiostation.h:249
radiostation_t
Click ctx object definition.
Definition: radiostation.h:219
radiostation_t::status
uint8_t status
Definition: radiostation.h:238
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:275
radiostation_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: radiostation.h:274
radiostation_cfg_t
Click configuration structure definition.
Definition: radiostation.h:260
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:270
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:250
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:222
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:246
radiostation_t::transmit_frequency
uint16_t transmit_frequency
Definition: radiostation.h:237
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:223
radiostation_t::int_pin
digital_in_t int_pin
Definition: radiostation.h:227
radiostation_cfg_t::rst
pin_name_t rst
Definition: radiostation.h:268
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:251
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:264
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:252
RADIOSTATION_RETVAL
#define RADIOSTATION_RETVAL
Definition: radiostation.h:78
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:231
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:263
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:269
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.