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
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_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define WAVEFORM_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
81#define WAVEFORM_OK 0
82#define WAVEFORM_ERROR -1
89#define WAVEFORM_CR_B28_BITMASK 0x2000
90#define WAVEFORM_CR_HLB_BITMASK 0x1000
91#define WAVEFORM_CR_FSELECT_BITMASK 0x0800
92#define WAVEFORM_CR_PSELECT_BITMASK 0x0400
93#define WAVEFORM_CR_RESET_BITMASK 0x0100
94#define WAVEFORM_CR_SLEEP1_BITMASK 0x0080
95#define WAVEFORM_CR_SLEEP12_BITMASK 0x0040
96#define WAVEFORM_CR_OPBITEN_BITMASK 0x0020
97#define WAVEFORM_CR_DIV2_BITMASK 0x0008
98#define WAVEFORM_CR_MODE_BITMASK 0x0002
105#define WAVEFORM_SINE_OUT 0x01
106#define WAVEFORM_TRIANGLE_OUT 0x02
107#define WAVEFORM_SQUARE_OUT 0x03
114#define WAVEFORM_OSC_FREQUENCY 25000000ul
115#define WAVEFORM_FREQ_RESOLUTION 0x0FFFFFFFul
118 // End group macro
119// --------------------------------------------------------------- PUBLIC TYPES
128typedef struct
129{
130 // Output pins
131 digital_out_t rst;
132 digital_out_t pwm;
133
134 // Modules
135 spi_master_t spi;
136 pin_name_t chip_select;
137
138} waveform_t;
139
143typedef struct
144{
145 // Communication gpio pins
146 pin_name_t miso;
147 pin_name_t mosi;
148 pin_name_t sck;
149 pin_name_t cs;
150
151 // Additional gpio pins
152 pin_name_t rst;
153 pin_name_t pwm;
154
155 // static variable
156 uint32_t spi_speed;
157 spi_master_mode_t spi_mode;
158 spi_master_chip_select_polarity_t cs_polarity;
159
161
162 // End types group
163// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164
169#ifdef __cplusplus
170extern "C"{
171#endif
172
182
191
200
209
216void waveform_write_reg ( waveform_t *ctx, uint16_t reg_setting );
217
226void waveform_write_frequency ( waveform_t *ctx, uint32_t freq );
227
236void waveform_sine_output ( waveform_t *ctx, uint32_t freq );
237
246void waveform_triangle_output ( waveform_t *ctx, uint32_t freq );
247
256void waveform_square_output ( waveform_t *ctx, uint32_t freq );
257
258#ifdef __cplusplus
259}
260#endif
261#endif // _WAVEFORM_H_
262
263 // End public_function group
265
266// ------------------------------------------------------------------------- END
void waveform_write_frequency(waveform_t *ctx, uint32_t freq)
Frequency function.
err_t waveform_init(waveform_t *ctx, waveform_cfg_t *cfg)
Initialization function.
void waveform_cfg_setup(waveform_cfg_t *cfg)
Config Object Initialization function.
void waveform_write_reg(waveform_t *ctx, uint16_t reg_setting)
Registry function.
void waveform_triangle_output(waveform_t *ctx, uint32_t freq)
Triangle output function.
void waveform_square_output(waveform_t *ctx, uint32_t freq)
Square output function.
void waveform_digipot_inc(waveform_t *ctx)
Increment function.
void waveform_digipot_dec(waveform_t *ctx)
Decrement function.
void waveform_sine_output(waveform_t *ctx, uint32_t freq)
Sinusoide output function.
Click configuration structure definition.
Definition waveform.h:144
spi_master_chip_select_polarity_t cs_polarity
Definition waveform.h:158
pin_name_t sck
Definition waveform.h:148
spi_master_mode_t spi_mode
Definition waveform.h:157
pin_name_t mosi
Definition waveform.h:147
uint32_t spi_speed
Definition waveform.h:156
pin_name_t pwm
Definition waveform.h:153
pin_name_t miso
Definition waveform.h:146
pin_name_t rst
Definition waveform.h:152
pin_name_t cs
Definition waveform.h:149
Click ctx object definition.
Definition waveform.h:129
spi_master_t spi
Definition waveform.h:135
digital_out_t pwm
Definition waveform.h:132
digital_out_t rst
Definition waveform.h:131
pin_name_t chip_select
Definition waveform.h:136