clockgen3  2.0.0.0
clockgen3.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 CLOCKGEN3_H
36 #define CLOCKGEN3_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 CLOCKGEN3_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
70 
76 #define CLOCKGEN3_OK 0
77 #define CLOCKGEN3_ERROR -1
78 
84 #define CLOCKGEN3_OCT_0 0
85 #define CLOCKGEN3_OCT_1 1
86 #define CLOCKGEN3_OCT_2 2
87 #define CLOCKGEN3_OCT_3 3
88 #define CLOCKGEN3_OCT_4 4
89 #define CLOCKGEN3_OCT_5 5
90 #define CLOCKGEN3_OCT_6 6
91 #define CLOCKGEN3_OCT_7 7
92 #define CLOCKGEN3_OCT_8 8
93 #define CLOCKGEN3_OCT_9 9
94 #define CLOCKGEN3_OCT_10 10
95 #define CLOCKGEN3_OCT_11 11
96 #define CLOCKGEN3_OCT_12 12
97 #define CLOCKGEN3_OCT_13 13
98 #define CLOCKGEN3_OCT_14 14
99 #define CLOCKGEN3_OCT_15 15
100 
106 #define CLOCKGEN3_SLAVE_ADDRESS_GND 0x17
107 #define CLOCKGEN3_SLAVE_ADDRESS_VCC 0x16
108 
114 #define CLOCKGEN3_CFG_ON_CLK_180 0x00
115 #define CLOCKGEN3_CFG_OFF_ON 0x01
116 #define CLOCKGEN3_CFG_ON_OFF 0x02
117 #define CLOCKGEN3_CFG_POWER_DOWN 0x03
118  // End group macro
121 // --------------------------------------------------------------- PUBLIC TYPES
130 typedef struct
131 {
132  // Output pins
133  digital_out_t cs;
134 
135  // Modules
136  i2c_master_t i2c;
137 
138  // ctx variable
139  uint8_t slave_address;
140 
141  uint8_t dev_config;
142 
143 } clockgen3_t;
144 
148 typedef struct
149 {
150  // Communication gpio pins
151  pin_name_t scl;
152  pin_name_t sda;
153 
154  // Additional gpio pins
155  pin_name_t cs;
156 
157  // static variable
158  uint32_t i2c_speed;
159  uint8_t i2c_address;
160 
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
197 
212 void clockgen3_config ( clockgen3_t *ctx, uint8_t cfg );
213 
220 void clockgen3_set_cs_pin ( clockgen3_t *ctx, uint8_t state );
221 
231 void clockgen3_generic_write ( clockgen3_t *ctx, uint8_t *data_buf, uint8_t len );
232 
243 void clockgen3_generic_read ( clockgen3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
244 
252 void clockgen3_set_freq ( clockgen3_t *ctx, float freq );
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // _CLOCKGEN3_H_
258  // End public_function group
261 
262 // ------------------------------------------------------------------------- END
clockgen3_t
Click ctx object definition.
Definition: clockgen3.h:131
clockgen3_init
err_t clockgen3_init(clockgen3_t *ctx, clockgen3_cfg_t *cfg)
Initialization function.
clockgen3_generic_read
void clockgen3_generic_read(clockgen3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
clockgen3_t::dev_config
uint8_t dev_config
Definition: clockgen3.h:141
clockgen3_t::i2c
i2c_master_t i2c
Definition: clockgen3.h:136
clockgen3_config
void clockgen3_config(clockgen3_t *ctx, uint8_t cfg)
Configuration.
clockgen3_t::cs
digital_out_t cs
Definition: clockgen3.h:133
clockgen3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen3.h:158
clockgen3_cfg_t::cs
pin_name_t cs
Definition: clockgen3.h:155
clockgen3_cfg_t::sda
pin_name_t sda
Definition: clockgen3.h:152
clockgen3_generic_write
void clockgen3_generic_write(clockgen3_t *ctx, uint8_t *data_buf, uint8_t len)
Generic write function.
clockgen3_set_freq
void clockgen3_set_freq(clockgen3_t *ctx, float freq)
Sets Frequency.
clockgen3_cfg_t::scl
pin_name_t scl
Definition: clockgen3.h:151
clockgen3_cfg_setup
void clockgen3_cfg_setup(clockgen3_cfg_t *cfg)
Config Object Initialization function.
clockgen3_set_cs_pin
void clockgen3_set_cs_pin(clockgen3_t *ctx, uint8_t state)
Sets CS pin state.
clockgen3_cfg_t::i2c_address
uint8_t i2c_address
Definition: clockgen3.h:159
clockgen3_t::slave_address
uint8_t slave_address
Definition: clockgen3.h:139
clockgen3_cfg_t
Click configuration structure definition.
Definition: clockgen3.h:149