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
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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define CLOCKGEN2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.pdn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.oe = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_PWM )
79#define CLOCKGEN2_RETVAL uint8_t
80
81#define CLOCKGEN2_OK 0x00
82#define CLOCKGEN2_INIT_ERROR 0xFF
90// A0 = A1 = A2 = 0
91#define CLOCKGEN2_ADDR 0x58
92
93#define CLOCKGEN2_PRESCALER_REG 0x02
94#define CLOCKGEN2_ADDR_CHANGE_REG 0x0D
95#define CLOKCGEN2_AUTO_PRESERVE_ENABLE 0
96#define CLOCKGEN2_AUTO_PRESERVE_DISABLE 1
97#define CLOCKGEN2_WRITE_EE_REG 0x3F
100 // End group macro
101// --------------------------------------------------------------- PUBLIC TYPES
110typedef struct
111{
112 // Output pins
113
114 digital_out_t pdn;
115 digital_out_t oe;
116 digital_out_t dtr;
117
118 // Modules
119
120 i2c_master_t i2c;
121
122 // ctx variable
123
125
127
131typedef struct
132{
133 // Communication gpio pins
134
135 pin_name_t scl;
136 pin_name_t sda;
137
138 // Additional gpio pins
139
140 pin_name_t pdn;
141 pin_name_t oe;
142 pin_name_t dtr;
143
144 // static variable
145
146 uint32_t i2c_speed;
147 uint8_t i2c_address;
148
150
151 // End types group
152// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153
159#ifdef __cplusplus
160extern "C"{
161#endif
162
172
182
193void clockgen2_generic_write ( clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
194
205void clockgen2_generic_read ( clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
206
215void clockgen2_set_dtr_pin ( clockgen2_t *ctx, uint8_t state );
216
225void clockgen2_set_pdn_pin ( clockgen2_t *ctx, uint8_t state );
226
235void clockgen2_set_oe_pin ( clockgen2_t *ctx, uint8_t state );
236
246void clockgen2_write ( clockgen2_t *ctx, uint8_t w_reg, uint8_t w_data );
247
257void clockgen2_set_prescaler ( clockgen2_t *ctx, uint8_t val );
258
269void clockgen2_change_address ( clockgen2_t *ctx, uint8_t new_addr );
270
279
289void clockgen2_auto_setting_preserve ( clockgen2_t *ctx, uint8_t state );
290
299void clockgen2_output_enable ( clockgen2_t *ctx, uint8_t state );
300
301#ifdef __cplusplus
302}
303#endif
304#endif // _CLOCKGEN2_H_
305
306 // End public_function group
308
309// ------------------------------------------------------------------------- END
#define CLOCKGEN2_RETVAL
Definition clockgen2.h:79
void clockgen2_auto_setting_preserve(clockgen2_t *ctx, uint8_t state)
Auto setting preservation function.
void clockgen2_generic_read(clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void clockgen2_set_oe_pin(clockgen2_t *ctx, uint8_t state)
Set oe pin function.
CLOCKGEN2_RETVAL clockgen2_init(clockgen2_t *ctx, clockgen2_cfg_t *cfg)
Initialization function.
void clockgen2_change_address(clockgen2_t *ctx, uint8_t new_addr)
Prescaler set function.
void clockgen2_set_dtr_pin(clockgen2_t *ctx, uint8_t state)
Set dtr pin function.
void clockgen2_store_config(clockgen2_t *ctx)
Settings save function.
void clockgen2_output_enable(clockgen2_t *ctx, uint8_t state)
Settings save function.
void clockgen2_set_prescaler(clockgen2_t *ctx, uint8_t val)
Prescaler set function.
void clockgen2_generic_write(clockgen2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void clockgen2_set_pdn_pin(clockgen2_t *ctx, uint8_t state)
Set pdn pin function.
void clockgen2_cfg_setup(clockgen2_cfg_t *cfg)
Config Object Initialization function.
void clockgen2_write(clockgen2_t *ctx, uint8_t w_reg, uint8_t w_data)
Writing 1B function.
Click configuration structure definition.
Definition clockgen2.h:132
pin_name_t dtr
Definition clockgen2.h:142
uint32_t i2c_speed
Definition clockgen2.h:146
pin_name_t oe
Definition clockgen2.h:141
pin_name_t pdn
Definition clockgen2.h:140
pin_name_t scl
Definition clockgen2.h:135
pin_name_t sda
Definition clockgen2.h:136
uint8_t i2c_address
Definition clockgen2.h:147
Click ctx object definition.
Definition clockgen2.h:111
digital_out_t pdn
Definition clockgen2.h:114
i2c_master_t i2c
Definition clockgen2.h:120
digital_out_t oe
Definition clockgen2.h:115
digital_out_t dtr
Definition clockgen2.h:116
uint8_t slave_address
Definition clockgen2.h:124