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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define CLOCKGEN5_OCT_0 0
71 #define CLOCKGEN5_OCT_1 1
72 #define CLOCKGEN5_OCT_2 2
73 #define CLOCKGEN5_OCT_3 3
74 #define CLOCKGEN5_OCT_4 4
75 #define CLOCKGEN5_OCT_5 5
76 #define CLOCKGEN5_OCT_6 6
77 #define CLOCKGEN5_OCT_7 7
78 #define CLOCKGEN5_OCT_8 8
79 #define CLOCKGEN5_OCT_9 9
80 #define CLOCKGEN5_OCT_10 10
81 #define CLOCKGEN5_OCT_11 11
82 #define CLOCKGEN5_OCT_12 12
83 #define CLOCKGEN5_OCT_13 13
84 #define CLOCKGEN5_OCT_14 14
85 #define CLOCKGEN5_OCT_15 15
86 
92 #define CLOCKGEN5_OUTPUT_DISABLE 0x00
93 #define CLOCKGEN5_OUTPUT_ENABLE 0x01
94 
99 #define CLOCKGEN5_CFG_ON_CLK_180 0x00
100 #define CLOCKGEN5_CFG_OFF_ON 0x01
101 #define CLOCKGEN5_CFG_ON_OFF 0x02
102 #define CLOCKGEN5_CFG_POWER_DOWN 0x03
103 
112 #define CLOCKGEN5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
113 #define CLOCKGEN5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
114  // clockgen5_set
116 
131 #define CLOCKGEN5_MAP_MIKROBUS( cfg, mikrobus ) \
132  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
133  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
134  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
135  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
136  cfg.oe = MIKROBUS( mikrobus, MIKROBUS_RST )
137  // clockgen5_map // clockgen5
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t oe;
150  // Modules
151  spi_master_t spi;
153  pin_name_t chip_select;
155  uint8_t dev_config;
156 
157 } clockgen5_t;
158 
163 typedef struct
164 {
165  // Communication gpio pins
166  pin_name_t miso;
167  pin_name_t mosi;
168  pin_name_t sck;
169  pin_name_t cs;
171  // Additional gpio pins
172  pin_name_t oe;
174  // static variable
175  uint32_t spi_speed;
176  spi_master_mode_t spi_mode;
177  spi_master_chip_select_polarity_t cs_polarity;
180 
185 typedef enum
186 {
188  CLOCKGEN5_ERROR = -1
189 
191 
208 
223 
233 void clockgen5_out_enable ( clockgen5_t *ctx, uint8_t en_out );
234 
243 void clockgen5_set_config ( clockgen5_t *ctx, uint8_t cfg );
244 
253 void clockgen5_set_freq ( clockgen5_t *ctx, float freq );
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // CLOCKGEN5_H
259  // clockgen5
261 
262 // ------------------------------------------------------------------------ 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:186
clockgen5_t::spi
spi_master_t spi
Definition: clockgen5.h:151
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:172
CLOCKGEN5_OK
@ CLOCKGEN5_OK
Definition: clockgen5.h:187
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:168
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:177
clockgen5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: clockgen5.h:176
clockgen5_cfg_t::spi_speed
uint32_t spi_speed
Definition: clockgen5.h:175
clockgen5_cfg_t::cs
pin_name_t cs
Definition: clockgen5.h:169
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:155
clockgen5_t::chip_select
pin_name_t chip_select
Definition: clockgen5.h:153
CLOCKGEN5_ERROR
@ CLOCKGEN5_ERROR
Definition: clockgen5.h:188
clockgen5_t::oe
digital_out_t oe
Definition: clockgen5.h:148
clockgen5_cfg_t::mosi
pin_name_t mosi
Definition: clockgen5.h:167
clockgen5_cfg_t::miso
pin_name_t miso
Definition: clockgen5.h:166
clockgen5_cfg_t
Clock Gen 5 Click configuration object.
Definition: clockgen5.h:164
clockgen5_t
Clock Gen 5 Click context object.
Definition: clockgen5.h:146