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 
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 CLOCKGEN3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
66 
72 #define CLOCKGEN3_OK 0
73 #define CLOCKGEN3_ERROR -1
74 
80 #define CLOCKGEN3_OCT_0 0
81 #define CLOCKGEN3_OCT_1 1
82 #define CLOCKGEN3_OCT_2 2
83 #define CLOCKGEN3_OCT_3 3
84 #define CLOCKGEN3_OCT_4 4
85 #define CLOCKGEN3_OCT_5 5
86 #define CLOCKGEN3_OCT_6 6
87 #define CLOCKGEN3_OCT_7 7
88 #define CLOCKGEN3_OCT_8 8
89 #define CLOCKGEN3_OCT_9 9
90 #define CLOCKGEN3_OCT_10 10
91 #define CLOCKGEN3_OCT_11 11
92 #define CLOCKGEN3_OCT_12 12
93 #define CLOCKGEN3_OCT_13 13
94 #define CLOCKGEN3_OCT_14 14
95 #define CLOCKGEN3_OCT_15 15
96 
102 #define CLOCKGEN3_SLAVE_ADDRESS_GND 0x17
103 #define CLOCKGEN3_SLAVE_ADDRESS_VCC 0x16
104 
110 #define CLOCKGEN3_CFG_ON_CLK_180 0x00
111 #define CLOCKGEN3_CFG_OFF_ON 0x01
112 #define CLOCKGEN3_CFG_ON_OFF 0x02
113 #define CLOCKGEN3_CFG_POWER_DOWN 0x03
114  // End group macro
117 // --------------------------------------------------------------- PUBLIC TYPES
126 typedef struct
127 {
128  // Output pins
129  digital_out_t cs;
130 
131  // Modules
132  i2c_master_t i2c;
133 
134  // ctx variable
135  uint8_t slave_address;
136 
137  uint8_t dev_config;
138 
139 } clockgen3_t;
140 
144 typedef struct
145 {
146  // Communication gpio pins
147  pin_name_t scl;
148  pin_name_t sda;
149 
150  // Additional gpio pins
151  pin_name_t cs;
152 
153  // static variable
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156 
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
180 
193 
208 void clockgen3_config ( clockgen3_t *ctx, uint8_t cfg );
209 
216 void clockgen3_set_cs_pin ( clockgen3_t *ctx, uint8_t state );
217 
227 void clockgen3_generic_write ( clockgen3_t *ctx, uint8_t *data_buf, uint8_t len );
228 
239 void clockgen3_generic_read ( clockgen3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
248 void clockgen3_set_freq ( clockgen3_t *ctx, float freq );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _CLOCKGEN3_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
clockgen3_t
Click ctx object definition.
Definition: clockgen3.h:127
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:137
clockgen3_t::i2c
i2c_master_t i2c
Definition: clockgen3.h:132
clockgen3_config
void clockgen3_config(clockgen3_t *ctx, uint8_t cfg)
Configuration.
clockgen3_t::cs
digital_out_t cs
Definition: clockgen3.h:129
clockgen3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen3.h:154
clockgen3_cfg_t::cs
pin_name_t cs
Definition: clockgen3.h:151
clockgen3_cfg_t::sda
pin_name_t sda
Definition: clockgen3.h:148
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:147
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:155
clockgen3_t::slave_address
uint8_t slave_address
Definition: clockgen3.h:135
clockgen3_cfg_t
Click configuration structure definition.
Definition: clockgen3.h:145