waveform  2.0.0.0
waveform.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 WAVEFORM_H
36 #define WAVEFORM_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_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define WAVEFORM_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
71 
77 #define WAVEFORM_OK 0
78 #define WAVEFORM_ERROR -1
79 
85 #define WAVEFORM_CR_B28_BITMASK 0x2000
86 #define WAVEFORM_CR_HLB_BITMASK 0x1000
87 #define WAVEFORM_CR_FSELECT_BITMASK 0x0800
88 #define WAVEFORM_CR_PSELECT_BITMASK 0x0400
89 #define WAVEFORM_CR_RESET_BITMASK 0x0100
90 #define WAVEFORM_CR_SLEEP1_BITMASK 0x0080
91 #define WAVEFORM_CR_SLEEP12_BITMASK 0x0040
92 #define WAVEFORM_CR_OPBITEN_BITMASK 0x0020
93 #define WAVEFORM_CR_DIV2_BITMASK 0x0008
94 #define WAVEFORM_CR_MODE_BITMASK 0x0002
95 
101 #define WAVEFORM_SINE_OUT 0x01
102 #define WAVEFORM_TRIANGLE_OUT 0x02
103 #define WAVEFORM_SQUARE_OUT 0x03
104 
110 #define WAVEFORM_OSC_FREQUENCY 25000000ul
111 #define WAVEFORM_FREQ_RESOLUTION 0x0FFFFFFFul
112  // End group macro
115 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  // Output pins
127  digital_out_t rst;
128  digital_out_t pwm;
129 
130  // Modules
131  spi_master_t spi;
132  pin_name_t chip_select;
133 
134 } waveform_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t miso;
143  pin_name_t mosi;
144  pin_name_t sck;
145  pin_name_t cs;
146 
147  // Additional gpio pins
148  pin_name_t rst;
149  pin_name_t pwm;
150 
151  // static variable
152  uint32_t spi_speed;
153  spi_master_mode_t spi_mode;
154  spi_master_chip_select_polarity_t cs_polarity;
155 
157  // End types group
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
187 
196 
205 
212 void waveform_write_reg ( waveform_t *ctx, uint16_t reg_setting );
213 
222 void waveform_write_frequency ( waveform_t *ctx, uint32_t freq );
223 
232 void waveform_sine_output ( waveform_t *ctx, uint32_t freq );
233 
242 void waveform_triangle_output ( waveform_t *ctx, uint32_t freq );
243 
252 void waveform_square_output ( waveform_t *ctx, uint32_t freq );
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // _WAVEFORM_H_
258  // End public_function group
261 
262 // ------------------------------------------------------------------------- END
waveform_cfg_t::miso
pin_name_t miso
Definition: waveform.h:142
waveform_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform.h:154
waveform_t::pwm
digital_out_t pwm
Definition: waveform.h:128
waveform_digipot_dec
void waveform_digipot_dec(waveform_t *ctx)
Decrement function.
waveform_t::chip_select
pin_name_t chip_select
Definition: waveform.h:132
waveform_triangle_output
void waveform_triangle_output(waveform_t *ctx, uint32_t freq)
Triangle output function.
waveform_sine_output
void waveform_sine_output(waveform_t *ctx, uint32_t freq)
Sinusoide output function.
waveform_digipot_inc
void waveform_digipot_inc(waveform_t *ctx)
Increment function.
waveform_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: waveform.h:153
waveform_t
Click ctx object definition.
Definition: waveform.h:125
waveform_square_output
void waveform_square_output(waveform_t *ctx, uint32_t freq)
Square output function.
waveform_cfg_setup
void waveform_cfg_setup(waveform_cfg_t *cfg)
Config Object Initialization function.
waveform_cfg_t::sck
pin_name_t sck
Definition: waveform.h:144
waveform_cfg_t::mosi
pin_name_t mosi
Definition: waveform.h:143
waveform_t::spi
spi_master_t spi
Definition: waveform.h:131
waveform_t::rst
digital_out_t rst
Definition: waveform.h:127
waveform_cfg_t::pwm
pin_name_t pwm
Definition: waveform.h:149
waveform_init
err_t waveform_init(waveform_t *ctx, waveform_cfg_t *cfg)
Initialization function.
waveform_cfg_t::cs
pin_name_t cs
Definition: waveform.h:145
waveform_cfg_t::rst
pin_name_t rst
Definition: waveform.h:148
waveform_cfg_t
Click configuration structure definition.
Definition: waveform.h:140
waveform_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform.h:152
waveform_write_frequency
void waveform_write_frequency(waveform_t *ctx, uint32_t freq)
Frequency function.
waveform_write_reg
void waveform_write_reg(waveform_t *ctx, uint16_t reg_setting)
Registry function.