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_RETVAL uint8_t
63 
64 #define CLOCKGEN3_OK 0x00
65 #define CLOCKGEN3_INIT_ERROR 0xFF
66 
72 #define CLOCKGEN3_OCT_0 0
73 #define CLOCKGEN3_OCT_1 1
74 #define CLOCKGEN3_OCT_2 2
75 #define CLOCKGEN3_OCT_3 3
76 #define CLOCKGEN3_OCT_4 4
77 #define CLOCKGEN3_OCT_5 5
78 #define CLOCKGEN3_OCT_6 6
79 #define CLOCKGEN3_OCT_7 7
80 #define CLOCKGEN3_OCT_8 8
81 #define CLOCKGEN3_OCT_9 9
82 #define CLOCKGEN3_OCT_10 10
83 #define CLOCKGEN3_OCT_11 11
84 #define CLOCKGEN3_OCT_12 12
85 #define CLOCKGEN3_OCT_13 13
86 #define CLOCKGEN3_OCT_14 14
87 #define CLOCKGEN3_OCT_15 15
88 
94 #define CLOCKGEN3_SLAVE_ADDRESS_GND 0x17
95 #define CLOCKGEN3_SLAVE_ADDRESS_VCC 0x16
96 
102 #define CLOCKGEN3_CFG_ON_CLK_180 0x00
103 #define CLOCKGEN3_CFG_OFF_ON 0x01
104 #define CLOCKGEN3_CFG_ON_OFF 0x02
105 #define CLOCKGEN3_CFG_POWER_DOWN 0x03
106  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t cs;
123 
124  // Modules
125 
126  i2c_master_t i2c;
127 
128  // ctx variable
129 
130  uint8_t slave_address;
131 
132  uint8_t dev_slave_addr;
133  uint8_t dev_config;
134 
135 
136 } clockgen3_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t scl;
146  pin_name_t sda;
147 
148  // Additional gpio pins
149 
150  pin_name_t cs;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156 
157  uint8_t dev_conf;
158 
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
192 
207 void clockgen3_config ( clockgen3_t *ctx, uint8_t cfg );
208 
215 void clockgen3_set_cs_pin ( clockgen3_t *ctx, uint8_t state );
216 
226 void clockgen3_generic_write ( clockgen3_t *ctx, uint8_t *data_buf, uint8_t len );
227 
238 void clockgen3_generic_read ( clockgen3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
247 void clockgen3_set_freq ( clockgen3_t *ctx, float freq );
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 #endif // _CLOCKGEN3_H_
253  // End public_function group
256 
257 // ------------------------------------------------------------------------- END
clockgen3_t
Click ctx object definition.
Definition: clockgen3.h:119
clockgen3_t::dev_slave_addr
uint8_t dev_slave_addr
Definition: clockgen3.h:132
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:133
clockgen3_t::i2c
i2c_master_t i2c
Definition: clockgen3.h:126
clockgen3_config
void clockgen3_config(clockgen3_t *ctx, uint8_t cfg)
Configuration.
clockgen3_t::cs
digital_out_t cs
Definition: clockgen3.h:122
clockgen3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen3.h:154
clockgen3_cfg_t::cs
pin_name_t cs
Definition: clockgen3.h:150
clockgen3_cfg_t::sda
pin_name_t sda
Definition: clockgen3.h:146
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:145
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_init
CLOCKGEN3_RETVAL clockgen3_init(clockgen3_t *ctx, clockgen3_cfg_t *cfg)
Initialization function.
CLOCKGEN3_RETVAL
#define CLOCKGEN3_RETVAL
Definition: clockgen3.h:62
clockgen3_cfg_t::i2c_address
uint8_t i2c_address
Definition: clockgen3.h:155
clockgen3_t::slave_address
uint8_t slave_address
Definition: clockgen3.h:130
clockgen3_cfg_t
Click configuration structure definition.
Definition: clockgen3.h:142
clockgen3_cfg_t::dev_conf
uint8_t dev_conf
Definition: clockgen3.h:157