clockgen5  2.0.0.0
clockgen5.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef CLOCKGEN5_H
29 #define CLOCKGEN5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define CLOCKGEN5_OCT_0 0
75 #define CLOCKGEN5_OCT_1 1
76 #define CLOCKGEN5_OCT_2 2
77 #define CLOCKGEN5_OCT_3 3
78 #define CLOCKGEN5_OCT_4 4
79 #define CLOCKGEN5_OCT_5 5
80 #define CLOCKGEN5_OCT_6 6
81 #define CLOCKGEN5_OCT_7 7
82 #define CLOCKGEN5_OCT_8 8
83 #define CLOCKGEN5_OCT_9 9
84 #define CLOCKGEN5_OCT_10 10
85 #define CLOCKGEN5_OCT_11 11
86 #define CLOCKGEN5_OCT_12 12
87 #define CLOCKGEN5_OCT_13 13
88 #define CLOCKGEN5_OCT_14 14
89 #define CLOCKGEN5_OCT_15 15
90 
96 #define CLOCKGEN5_OUTPUT_DISABLE 0x00
97 #define CLOCKGEN5_OUTPUT_ENABLE 0x01
98 
103 #define CLOCKGEN5_CFG_ON_CLK_180 0x00
104 #define CLOCKGEN5_CFG_OFF_ON 0x01
105 #define CLOCKGEN5_CFG_ON_OFF 0x02
106 #define CLOCKGEN5_CFG_POWER_DOWN 0x03
107 
116 #define CLOCKGEN5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
117 #define CLOCKGEN5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
118  // clockgen5_set
120 
135 #define CLOCKGEN5_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
137  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
138  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
139  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
140  cfg.oe = MIKROBUS( mikrobus, MIKROBUS_RST )
141  // clockgen5_map // clockgen5
144 
149 typedef struct
150 {
151  // Output pins
152  digital_out_t oe;
154  // Modules
155  spi_master_t spi;
157  pin_name_t chip_select;
159  uint8_t dev_config;
160 
161 } clockgen5_t;
162 
167 typedef struct
168 {
169  // Communication gpio pins
170  pin_name_t miso;
171  pin_name_t mosi;
172  pin_name_t sck;
173  pin_name_t cs;
175  // Additional gpio pins
176  pin_name_t oe;
178  // static variable
179  uint32_t spi_speed;
180  spi_master_mode_t spi_mode;
181  spi_master_chip_select_polarity_t cs_polarity;
184 
189 typedef enum
190 {
192  CLOCKGEN5_ERROR = -1
193 
195 
212 
227 
237 void clockgen5_out_enable ( clockgen5_t *ctx, uint8_t en_out );
238 
247 void clockgen5_set_config ( clockgen5_t *ctx, uint8_t cfg );
248 
257 void clockgen5_set_freq ( clockgen5_t *ctx, float freq );
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif // CLOCKGEN5_H
263  // clockgen5
265 
266 // ------------------------------------------------------------------------ END
clockgen5_set_config
void clockgen5_set_config(clockgen5_t *ctx, uint8_t cfg)
Set configuration function.
clockgen5_return_value_t
clockgen5_return_value_t
Clock Gen 5 Click return value data.
Definition: clockgen5.h:190
clockgen5_t::spi
spi_master_t spi
Definition: clockgen5.h:155
clockgen5_set_freq
void clockgen5_set_freq(clockgen5_t *ctx, float freq)
Set frequency function.
clockgen5_cfg_t::oe
pin_name_t oe
Definition: clockgen5.h:176
CLOCKGEN5_OK
@ CLOCKGEN5_OK
Definition: clockgen5.h:191
spi_specifics.h
This file contains SPI specific macros, functions, etc.
clockgen5_init
err_t clockgen5_init(clockgen5_t *ctx, clockgen5_cfg_t *cfg)
Clock Gen 5 initialization function.
clockgen5_cfg_t::sck
pin_name_t sck
Definition: clockgen5.h:172
clockgen5_out_enable
void clockgen5_out_enable(clockgen5_t *ctx, uint8_t en_out)
Enable output function.
clockgen5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: clockgen5.h:181
clockgen5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: clockgen5.h:180
clockgen5_cfg_t::spi_speed
uint32_t spi_speed
Definition: clockgen5.h:179
clockgen5_cfg_t::cs
pin_name_t cs
Definition: clockgen5.h:173
clockgen5_cfg_setup
void clockgen5_cfg_setup(clockgen5_cfg_t *cfg)
Clock Gen 5 configuration object setup function.
clockgen5_t::dev_config
uint8_t dev_config
Definition: clockgen5.h:159
clockgen5_t::chip_select
pin_name_t chip_select
Definition: clockgen5.h:157
CLOCKGEN5_ERROR
@ CLOCKGEN5_ERROR
Definition: clockgen5.h:192
clockgen5_t::oe
digital_out_t oe
Definition: clockgen5.h:152
clockgen5_cfg_t::mosi
pin_name_t mosi
Definition: clockgen5.h:171
clockgen5_cfg_t::miso
pin_name_t miso
Definition: clockgen5.h:170
clockgen5_cfg_t
Clock Gen 5 Click configuration object.
Definition: clockgen5.h:168
clockgen5_t
Clock Gen 5 Click context object.
Definition: clockgen5.h:150