clockgen4 2.0.0.0
clockgen4.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 CLOCKGEN4_H
29#define CLOCKGEN4_H
30
31#ifdef __cplusplus
32extern "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_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define CLOCKGEN4_REG_DEV_ID 0x01
76#define CLOCKGEN4_REG_DEV_CTL 0x02
77#define CLOCKGEN4_REG_DEV_CFG_1 0x03
78#define CLOCKGEN4_REG_GLOB_CFG 0x05
79#define CLOCKGEN4_REG_M_MSB 0x06
80#define CLOCKGEN4_REG_L_MSB 0x07
81#define CLOCKGEN4_REG_M_LSB 0x08
82#define CLOCKGEN4_REG_L_LSB 0x09
83#define CLOCKGEN4_REG_FNC_CFG_1 0x16
84#define CLOCKGEN4_REG_FNC_CFG_2 0x17
85
86 // clockgen4_reg
87
107#define CLOCKGEN4_INCR_ENABLE 0x80
108#define CLOCKGEN4_INCR_DISABLE 0x00
109
114#define CLOCKGEN4_PLL_UNLOCKED 0x00
115#define CLOCKGEN4_PLL_LOCKED 0x80
116#define CLOCKGEN4_AUX_OUT_EN 0x00
117#define CLOCKGEN4_AUX_OUT_DIS 0x02
118#define CLOCKGEN4_CLK_OUT_EN 0x00
119#define CLOCKGEN4_CLK_OUT_DIS 0x01
120
125#define CLOCKGEN4_R_MOD_SEL_L_0 0x00
126#define CLOCKGEN4_R_MOD_SEL_L_1 0x20
127#define CLOCKGEN4_R_MOD_SEL_L_2 0x40
128#define CLOCKGEN4_R_MOD_SEL_L_3 0x60
129#define CLOCKGEN4_R_MOD_SEL_R_1 0x80
130#define CLOCKGEN4_R_MOD_SEL_R_2 0xA0
131#define CLOCKGEN4_R_MOD_SEL_R_3 0xC0
132#define CLOCKGEN4_R_MOD_SEL_R_4 0xE0
133#define CLOCKGEN4_REG_CLK 0x00
134#define CLOCKGEN4_CLK_OUT 0x04
135#define CLOCKGEN4_PLL_STAT_IND 0x06
136#define CLOCKGEN4_DEV_CFG_1_EN 0x01
137#define CLOCKGEN4_DEV_CFG_1_DIS 0x00
138
143#define CLOCKGEN4_DEV_CFG_FRZ 0x00
144#define CLOCKGEN4_DEV_CFG_UNFRZ 0x08
145#define CLOCKGEN4_DEV_CFG_2_EN 0x01
146#define CLOCKGEN4_DEV_CFG_2_DIS 0x00
147
152#define CLOCKGEN4_AUX_OUT_ACT_H 0x00
153#define CLOCKGEN4_AUX_OUT_ACT_L 0x40
154#define CLOCKGEN4_REF_CLK_DIV_4 0x00
155#define CLOCKGEN4_REF_CLK_DIV_2 0x08
156#define CLOCKGEN4_REF_CLK_DIV_1 0x10
157
162#define CLOCKGEN4_CLK_OUT_UNL_L 0x00
163#define CLOCKGEN4_CLK_OUT_UNL_U 0x10
164
169#define CLOCKGEN4_REF_CLK_25_MHZ 25.0
170
176#define CLOCKGEN4_I2C_ADR_GND 0x4E
177#define CLOCKGEN4_I2C_ADR_VCC 0x4F
178
179#define CLOCKGEN4_SPI_CHIP_ADR 0x9E
188#define CLOCKGEN4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
189#define CLOCKGEN4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
190 // clockgen4_set
191
206#define CLOCKGEN4_MAP_MIKROBUS( cfg, mikrobus ) \
207 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
208 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
209 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
210 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
211 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
212 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
213
214 // clockgen4_map
215 // clockgen4
216
227
232typedef err_t ( *clockgen4_master_io_t )( struct clockgen4_s*, uint8_t, uint8_t*, uint8_t );
251
256typedef struct
257{
258 pin_name_t scl;
259 pin_name_t sda;
260 pin_name_t miso;
261 pin_name_t mosi;
262 pin_name_t sck;
263 pin_name_t cs;
265 uint32_t i2c_speed;
266 uint8_t i2c_address;
268 uint32_t spi_speed;
269 spi_master_mode_t spi_mode;
270 spi_master_chip_select_polarity_t cs_polarity;
275
286
303
319
335
350
366err_t clockgen4_generic_write ( clockgen4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
367
383err_t clockgen4_generic_read ( clockgen4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
384
395void clockgen4_dev_ctl ( clockgen4_t *ctx, uint8_t dev_ctl );
396
408void clockgen4_dev_cfg ( clockgen4_t *ctx, uint8_t dev_cfg );
409
421void clockgen4_glob_cfg ( clockgen4_t *ctx, uint8_t glob_cfg );
422
434void clockgen4_fnc_cfg_1 ( clockgen4_t *ctx, uint8_t fnc_cfg );
435
446void clockgen4_fnc_cfg_2 ( clockgen4_t *ctx, uint8_t fnc_cfg );
447
460uint32_t clockgen4_set_ratio ( clockgen4_t *ctx, float ratio );
461
462
463#ifdef __cplusplus
464}
465#endif
466#endif // CLOCKGEN4_H
467
468 // clockgen4
469
470// ------------------------------------------------------------------------ END
clockgen4_return_value_t
Clock Gen 4 Click return value data.
Definition clockgen4.h:281
@ CLOCKGEN4_ERROR
Definition clockgen4.h:283
@ CLOCKGEN4_OK
Definition clockgen4.h:282
clockgen4_drv_t
Clock Gen 4 Click driver selector.
Definition clockgen4.h:222
@ CLOCKGEN4_DRV_SEL_SPI
Definition clockgen4.h:223
@ CLOCKGEN4_DRV_SEL_I2C
Definition clockgen4.h:224
struct clockgen4_s clockgen4_t
Clock Gen 4 Click context object.
err_t(* clockgen4_master_io_t)(struct clockgen4_s *, uint8_t, uint8_t *, uint8_t)
Clock Gen 4 Click driver interface.
Definition clockgen4.h:232
uint32_t clockgen4_set_ratio(clockgen4_t *ctx, float ratio)
Clock Gen 4 set ratio function.
void clockgen4_dev_ctl(clockgen4_t *ctx, uint8_t dev_ctl)
Clock Gen 4 device control function.
void clockgen4_glob_cfg(clockgen4_t *ctx, uint8_t glob_cfg)
Clock Gen 4 global configuration function.
err_t clockgen4_default_cfg(clockgen4_t *ctx)
Clock Gen 4 default configuration function.
void clockgen4_cfg_setup(clockgen4_cfg_t *cfg)
Clock Gen 4 configuration object setup function.
void clockgen4_fnc_cfg_1(clockgen4_t *ctx, uint8_t fnc_cfg)
Clock Gen 4 configuration 1 function.
err_t clockgen4_generic_read(clockgen4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Clock Gen 4 data reading function.
void clockgen4_dev_cfg(clockgen4_t *ctx, uint8_t dev_cfg)
Clock Gen 4 device configuration function.
err_t clockgen4_init(clockgen4_t *ctx, clockgen4_cfg_t *cfg)
Clock Gen 4 initialization function.
void clockgen4_drv_interface_selection(clockgen4_cfg_t *cfg, clockgen4_drv_t drv_sel)
Clock Gen 4 driver interface setup function.
err_t clockgen4_generic_write(clockgen4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Clock Gen 4 data writing function.
void clockgen4_fnc_cfg_2(clockgen4_t *ctx, uint8_t fnc_cfg)
Clock Gen 4 configuration 2 function.
This file contains SPI specific macros, functions, etc.
Clock Gen 4 Click configuration object.
Definition clockgen4.h:257
uint32_t i2c_speed
Definition clockgen4.h:265
spi_master_chip_select_polarity_t cs_polarity
Definition clockgen4.h:270
pin_name_t sck
Definition clockgen4.h:262
spi_master_mode_t spi_mode
Definition clockgen4.h:269
pin_name_t mosi
Definition clockgen4.h:261
uint32_t spi_speed
Definition clockgen4.h:268
clockgen4_drv_t drv_sel
Definition clockgen4.h:272
pin_name_t scl
Definition clockgen4.h:258
pin_name_t miso
Definition clockgen4.h:260
pin_name_t sda
Definition clockgen4.h:259
pin_name_t cs
Definition clockgen4.h:263
uint8_t i2c_address
Definition clockgen4.h:266
Clock Gen 4 Click context object.
Definition clockgen4.h:239
spi_master_t spi
Definition clockgen4.h:241
clockgen4_master_io_t write_f
Definition clockgen4.h:247
clockgen4_master_io_t read_f
Definition clockgen4.h:248
i2c_master_t i2c
Definition clockgen4.h:240
clockgen4_drv_t drv_sel
Definition clockgen4.h:245
uint8_t slave_address
Definition clockgen4.h:243
pin_name_t chip_select
Definition clockgen4.h:244