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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define CLOCKGEN3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
56 
62 #define CLOCKGEN3_OK 0
63 #define CLOCKGEN3_ERROR -1
64 
70 #define CLOCKGEN3_OCT_0 0
71 #define CLOCKGEN3_OCT_1 1
72 #define CLOCKGEN3_OCT_2 2
73 #define CLOCKGEN3_OCT_3 3
74 #define CLOCKGEN3_OCT_4 4
75 #define CLOCKGEN3_OCT_5 5
76 #define CLOCKGEN3_OCT_6 6
77 #define CLOCKGEN3_OCT_7 7
78 #define CLOCKGEN3_OCT_8 8
79 #define CLOCKGEN3_OCT_9 9
80 #define CLOCKGEN3_OCT_10 10
81 #define CLOCKGEN3_OCT_11 11
82 #define CLOCKGEN3_OCT_12 12
83 #define CLOCKGEN3_OCT_13 13
84 #define CLOCKGEN3_OCT_14 14
85 #define CLOCKGEN3_OCT_15 15
86 
92 #define CLOCKGEN3_SLAVE_ADDRESS_GND 0x17
93 #define CLOCKGEN3_SLAVE_ADDRESS_VCC 0x16
94 
100 #define CLOCKGEN3_CFG_ON_CLK_180 0x00
101 #define CLOCKGEN3_CFG_OFF_ON 0x01
102 #define CLOCKGEN3_CFG_ON_OFF 0x02
103 #define CLOCKGEN3_CFG_POWER_DOWN 0x03
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119  digital_out_t cs;
120 
121  // Modules
122  i2c_master_t i2c;
123 
124  // ctx variable
125  uint8_t slave_address;
126 
127  uint8_t dev_config;
128 
129 } clockgen3_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t scl;
138  pin_name_t sda;
139 
140  // Additional gpio pins
141  pin_name_t cs;
142 
143  // static variable
144  uint32_t i2c_speed;
145  uint8_t i2c_address;
146 
148  // End types group
150 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
151 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
183 
198 void clockgen3_config ( clockgen3_t *ctx, uint8_t cfg );
199 
206 void clockgen3_set_cs_pin ( clockgen3_t *ctx, uint8_t state );
207 
217 void clockgen3_generic_write ( clockgen3_t *ctx, uint8_t *data_buf, uint8_t len );
218 
229 void clockgen3_generic_read ( clockgen3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230 
238 void clockgen3_set_freq ( clockgen3_t *ctx, float freq );
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif // _CLOCKGEN3_H_
244  // End public_function group
247 
248 // ------------------------------------------------------------------------- END
clockgen3_t
Click ctx object definition.
Definition: clockgen3.h:117
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:127
clockgen3_t::i2c
i2c_master_t i2c
Definition: clockgen3.h:122
clockgen3_config
void clockgen3_config(clockgen3_t *ctx, uint8_t cfg)
Configuration.
clockgen3_t::cs
digital_out_t cs
Definition: clockgen3.h:119
clockgen3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen3.h:144
clockgen3_cfg_t::cs
pin_name_t cs
Definition: clockgen3.h:141
clockgen3_cfg_t::sda
pin_name_t sda
Definition: clockgen3.h:138
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:137
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:145
clockgen3_t::slave_address
uint8_t slave_address
Definition: clockgen3.h:125
clockgen3_cfg_t
Click configuration structure definition.
Definition: clockgen3.h:135