clockgen2  2.0.0.0
clockgen2.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 CLOCKGEN2_H
36 #define CLOCKGEN2_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define CLOCKGEN2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.oe = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_PWM )
69 
75 #define CLOCKGEN2_RETVAL uint8_t
76 
77 #define CLOCKGEN2_OK 0x00
78 #define CLOCKGEN2_INIT_ERROR 0xFF
79 
86 // A0 = A1 = A2 = 0
87 #define CLOCKGEN2_ADDR 0x58
88 
89 #define CLOCKGEN2_PRESCALER_REG 0x02
90 #define CLOCKGEN2_ADDR_CHANGE_REG 0x0D
91 #define CLOKCGEN2_AUTO_PRESERVE_ENABLE 0
92 #define CLOCKGEN2_AUTO_PRESERVE_DISABLE 1
93 #define CLOCKGEN2_WRITE_EE_REG 0x3F
94  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef struct
107 {
108  // Output pins
109 
110  digital_out_t pdn;
111  digital_out_t oe;
112  digital_out_t dtr;
113 
114  // Modules
115 
116  i2c_master_t i2c;
117 
118  // ctx variable
119 
120  uint8_t slave_address;
121 
122 } clockgen2_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t scl;
132  pin_name_t sda;
133 
134  // Additional gpio pins
135 
136  pin_name_t pdn;
137  pin_name_t oe;
138  pin_name_t dtr;
139 
140  // static variable
141 
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
144 
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
168 
178 
189 void clockgen2_generic_write ( clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
190 
201 void clockgen2_generic_read ( clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
202 
211 void clockgen2_set_dtr_pin ( clockgen2_t *ctx, uint8_t state );
212 
221 void clockgen2_set_pdn_pin ( clockgen2_t *ctx, uint8_t state );
222 
231 void clockgen2_set_oe_pin ( clockgen2_t *ctx, uint8_t state );
232 
242 void clockgen2_write ( clockgen2_t *ctx, uint8_t w_reg, uint8_t w_data );
243 
253 void clockgen2_set_prescaler ( clockgen2_t *ctx, uint8_t val );
254 
265 void clockgen2_change_address ( clockgen2_t *ctx, uint8_t new_addr );
266 
275 
285 void clockgen2_auto_setting_preserve ( clockgen2_t *ctx, uint8_t state );
286 
295 void clockgen2_output_enable ( clockgen2_t *ctx, uint8_t state );
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif // _CLOCKGEN2_H_
301  // End public_function group
304 
305 // ------------------------------------------------------------------------- END
clockgen2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: clockgen2.h:142
clockgen2_cfg_t::pdn
pin_name_t pdn
Definition: clockgen2.h:136
clockgen2_cfg_t::sda
pin_name_t sda
Definition: clockgen2.h:132
clockgen2_set_oe_pin
void clockgen2_set_oe_pin(clockgen2_t *ctx, uint8_t state)
Set oe pin function.
clockgen2_t::dtr
digital_out_t dtr
Definition: clockgen2.h:112
clockgen2_set_dtr_pin
void clockgen2_set_dtr_pin(clockgen2_t *ctx, uint8_t state)
Set dtr pin function.
clockgen2_set_prescaler
void clockgen2_set_prescaler(clockgen2_t *ctx, uint8_t val)
Prescaler set function.
clockgen2_cfg_t::dtr
pin_name_t dtr
Definition: clockgen2.h:138
clockgen2_write
void clockgen2_write(clockgen2_t *ctx, uint8_t w_reg, uint8_t w_data)
Writing 1B function.
clockgen2_auto_setting_preserve
void clockgen2_auto_setting_preserve(clockgen2_t *ctx, uint8_t state)
Auto setting preservation function.
clockgen2_t::pdn
digital_out_t pdn
Definition: clockgen2.h:110
clockgen2_cfg_t::i2c_address
uint8_t i2c_address
Definition: clockgen2.h:143
clockgen2_cfg_t::scl
pin_name_t scl
Definition: clockgen2.h:131
clockgen2_output_enable
void clockgen2_output_enable(clockgen2_t *ctx, uint8_t state)
Settings save function.
clockgen2_generic_write
void clockgen2_generic_write(clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
clockgen2_t::i2c
i2c_master_t i2c
Definition: clockgen2.h:116
clockgen2_cfg_setup
void clockgen2_cfg_setup(clockgen2_cfg_t *cfg)
Config Object Initialization function.
CLOCKGEN2_RETVAL
#define CLOCKGEN2_RETVAL
Definition: clockgen2.h:75
clockgen2_t
Click ctx object definition.
Definition: clockgen2.h:107
clockgen2_cfg_t::oe
pin_name_t oe
Definition: clockgen2.h:137
clockgen2_generic_read
void clockgen2_generic_read(clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
clockgen2_change_address
void clockgen2_change_address(clockgen2_t *ctx, uint8_t new_addr)
Prescaler set function.
clockgen2_t::oe
digital_out_t oe
Definition: clockgen2.h:111
clockgen2_t::slave_address
uint8_t slave_address
Definition: clockgen2.h:120
clockgen2_init
CLOCKGEN2_RETVAL clockgen2_init(clockgen2_t *ctx, clockgen2_cfg_t *cfg)
Initialization function.
clockgen2_cfg_t
Click configuration structure definition.
Definition: clockgen2.h:128
clockgen2_store_config
void clockgen2_store_config(clockgen2_t *ctx)
Settings save function.
clockgen2_set_pdn_pin
void clockgen2_set_pdn_pin(clockgen2_t *ctx, uint8_t state)
Set pdn pin function.