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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define WAVEFORM_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
61 
67 #define WAVEFORM_RETVAL uint8_t
68 
69 #define WAVEFORM_OK 0x00
70 #define WAVEFORM_INIT_ERROR 0xFF
71 
77 #define WAVEFORM_CR_B28_BITMASK 1<<13
78 #define WAVEFORM_CR_HLB_BITMASK 1<<12
79 #define WAVEFORM_CR_FSELECT_BITMASK 1<<11
80 #define WAVEFORM_CR_PSELECT_BITMASK 1<<10
81 #define WAVEFORM_CR_RESET_BITMASK 1<<8
82 #define WAVEFORM_CR_SLEEP1_BITMASK 1<<7
83 #define WAVEFORM_CR_SLEEP12_BITMASK 1<<6
84 #define WAVEFORM_CR_OPBITEN_BITMASK 1<<5
85 #define WAVEFORM_CR_DIV2_BITMASK 1<<3
86 #define WAVEFORM_CR_MODE_BITMASK 1<<1
87 
93 #define WAVEFORM_SINE_OUT 0x01
94 #define WAVEFORM_TRIANGLE_OUT 0x02
95 #define WAVEFORM_SQUARE_OUT 0x03
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  // Output pins
111 
112  digital_out_t rst;
113  digital_out_t pwm;
114  digital_out_t cs;
115 
116  // Modules
117 
118  spi_master_t spi;
119  pin_name_t chip_select;
120 } waveform_t;
121 
125 typedef struct
126 {
127  // Communication gpio pins
128 
129  pin_name_t miso;
130  pin_name_t mosi;
131  pin_name_t sck;
132  pin_name_t cs;
133 
134  // Additional gpio pins
135 
136  pin_name_t rst;
137  pin_name_t pwm;
138 
139  // static variable
140 
141  uint32_t spi_speed;
142  spi_master_mode_t spi_mode;
143  spi_master_chip_select_polarity_t cs_polarity;
144 
146  // End types group
148 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
167 
176 
185 
192 
199 void waveform_write_reg ( waveform_t *ctx, uint16_t reg_setting );
200 
209 void waveform_write_freqency ( waveform_t *ctx, uint32_t f );
210 
219 void waveform_sine_output ( waveform_t *ctx, uint32_t f );
220 
229 void waveform_triangle_output ( waveform_t *ctx, uint32_t f );
230 
239 void waveform_square_output ( waveform_t *ctx, uint32_t f );
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 #endif // _WAVEFORM_H_
245  // End public_function group
248 
249 // ------------------------------------------------------------------------- END
waveform_cfg_t::miso
pin_name_t miso
Definition: waveform.h:129
waveform_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform.h:143
waveform_t::pwm
digital_out_t pwm
Definition: waveform.h:113
waveform_t::cs
digital_out_t cs
Definition: waveform.h:114
waveform_digipot_dec
void waveform_digipot_dec(waveform_t *ctx)
Decrement function.
WAVEFORM_RETVAL
#define WAVEFORM_RETVAL
Definition: waveform.h:67
waveform_t::chip_select
pin_name_t chip_select
Definition: waveform.h:119
waveform_triangle_output
void waveform_triangle_output(waveform_t *ctx, uint32_t f)
Triangle 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:142
waveform_t
Click ctx object definition.
Definition: waveform.h:109
waveform_cfg_setup
void waveform_cfg_setup(waveform_cfg_t *cfg)
Config Object Initialization function.
waveform_sine_output
void waveform_sine_output(waveform_t *ctx, uint32_t f)
Sinusoide output function.
waveform_cfg_t::sck
pin_name_t sck
Definition: waveform.h:131
waveform_cfg_t::mosi
pin_name_t mosi
Definition: waveform.h:130
waveform_t::spi
spi_master_t spi
Definition: waveform.h:118
waveform_t::rst
digital_out_t rst
Definition: waveform.h:112
waveform_cfg_t::pwm
pin_name_t pwm
Definition: waveform.h:137
waveform_square_output
void waveform_square_output(waveform_t *ctx, uint32_t f)
Square output function.
waveform_write_freqency
void waveform_write_freqency(waveform_t *ctx, uint32_t f)
Freqency function.
waveform_cfg_t::cs
pin_name_t cs
Definition: waveform.h:132
waveform_init
WAVEFORM_RETVAL waveform_init(waveform_t *ctx, waveform_cfg_t *cfg)
Initialization function.
waveform_cfg_t::rst
pin_name_t rst
Definition: waveform.h:136
waveform_cfg_t
Click configuration structure definition.
Definition: waveform.h:126
waveform_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform.h:141
waveform_write_reg
void waveform_write_reg(waveform_t *ctx, uint16_t reg_setting)
Registry finction.