waveform2 2.0.0.0
waveform2.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 WAVEFORM2_H
29#define WAVEFORM2_H
30
31#ifdef __cplusplus
32extern "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_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define WAVEFORM2_CFG_B28_MSK 0x2000
76#define WAVEFORM2_CFG_HLB_MSK 0x1000
77#define WAVEFORM2_CFG_FSEL_MSK 0x0800
78#define WAVEFORM2_CFG_PSEK_MSK 0x0400
79#define WAVEFORM2_CFG_PIN_SW_MSK 0x0200
80#define WAVEFORM2_CFG_RESET_MSK 0x0100
81#define WAVEFORM2_CFG_SLEEP1_MSK 0x0080
82#define WAVEFORM2_CFG_SLEEP12_MSK 0x0040
83#define WAVEFORM2_CFG_OPBITEN_MSK 0x0020
84#define WAVEFORM2_CFG_SIGN_PIB_MSK 0x0010
85#define WAVEFORM2_CFG_DIV2_MSK 0x0008
86#define WAVEFORM2_CFG_MODE_MSK 0x0002
87
88#define OUTPUT_TRIANGLE 0x01
89#define OUTPUT_SINUSOID 0x00
90
96#define WAVEFORM2_DEVICE_SLAVE_ADDR_GND 0x50
97#define WAVEFORM2_DEVICE_SLAVE_ADDR_VCC 0x51
98
107#define WAVEFORM2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
108#define WAVEFORM2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
109
110 // waveform2_set
111
126#define WAVEFORM2_MAP_MIKROBUS( cfg, mikrobus ) \
127 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
128 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
129 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
130 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
131 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
132 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
133 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
135
136 // waveform2_map
137 // waveform2
138
143typedef struct waveform2_s
144{
145 digital_out_t rst;
146 digital_out_t en;
148 i2c_master_t i2c;
149 spi_master_t spi;
152 pin_name_t chip_select;
154 uint8_t mode_output;
155
157
162typedef struct
163{
164 pin_name_t scl;
165 pin_name_t sda;
166 pin_name_t miso;
167 pin_name_t mosi;
168 pin_name_t sck;
169 pin_name_t cs;
170 pin_name_t rst;
171 pin_name_t en;
173 uint32_t i2c_speed;
174 uint8_t i2c_address;
176 uint32_t spi_speed;
177 spi_master_mode_t spi_mode;
178 spi_master_chip_select_polarity_t cs_polarity;
181
192
209
224
239
254err_t waveform2_i2c_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
255
270err_t waveform2_i2c_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
271
286err_t waveform2_spi_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
287
302err_t waveform2_spi_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
303
312uint8_t waveform2_eeprom_read_byte ( waveform2_t *ctx, uint16_t addr );
313
322uint16_t waveform2_eeprom_read_word ( waveform2_t *ctx, uint16_t addr );
323
332uint32_t waveform2_eeprom_read_long ( waveform2_t *ctx, uint16_t addr );
333
344void waveform2_eeprom_read_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
345
355void waveform2_eeprom_write_byte ( waveform2_t *ctx, uint16_t addr, uint8_t tx_data );
356
366void waveform2_eeprom_write_word ( waveform2_t *ctx, uint16_t addr, uint16_t tx_data );
367
377void waveform2_eeprom_write_long ( waveform2_t *ctx, uint16_t addr, uint32_t tx_data );
378
389void waveform2_eeprom_write_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
390
399
408
417
426void waveform2_set_freq ( waveform2_t *ctx, uint32_t freq );
427
436void waveform2_configuration ( waveform2_t *ctx, uint16_t cfg );
437
446
455
464
465#ifdef __cplusplus
466}
467#endif
468#endif // WAVEFORM2_H
469
470 // waveform2
471
472// ------------------------------------------------------------------------ END
void waveform2_triangle_output(waveform2_t *ctx)
Waveform 2 set triangle output function.
void waveform2_set_freq(waveform2_t *ctx, uint32_t freq)
Waveform 2 set frequency function.
err_t waveform2_spi_read(waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Waveform 2 SPI reading function.
void waveform2_eeprom_read_string(waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len)
Waveform 2 read string function.
void waveform2_output_off(waveform2_t *ctx)
Waveform 2 disable output function.
void waveform2_eeprom_write_word(waveform2_t *ctx, uint16_t addr, uint16_t tx_data)
Waveform 2 write word function.
err_t waveform2_i2c_write(waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Waveform 2 I2C writing function.
void waveform2_mclk_enable(waveform2_t *ctx)
Waveform 2 enable oscilator function.
err_t waveform2_i2c_read(waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Waveform 2 I2C reading function.
void waveform2_eeprom_write_string(waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len)
Waveform 2 write string function.
err_t waveform2_spi_write(waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Waveform 2 SPI writing function.
uint32_t waveform2_eeprom_read_long(waveform2_t *ctx, uint16_t addr)
Waveform 2 read long function.
void waveform2_eeprom_write_byte(waveform2_t *ctx, uint16_t addr, uint8_t tx_data)
Waveform 2 write bute function.
err_t waveform2_init(waveform2_t *ctx, waveform2_cfg_t *cfg)
Waveform 2 initialization function.
void waveform2_eeprom_write_long(waveform2_t *ctx, uint16_t addr, uint32_t tx_data)
Waveform 2 write long function.
uint8_t waveform2_eeprom_read_byte(waveform2_t *ctx, uint16_t addr)
Waveform 2 read byte function.
void waveform2_mclk_disable(waveform2_t *ctx)
Waveform 2 disable oscilator function.
uint16_t waveform2_eeprom_read_word(waveform2_t *ctx, uint16_t addr)
Waveform 2 read word function.
void waveform2_sine_output(waveform2_t *ctx)
Waveform 2 set sine output function.
err_t waveform2_default_cfg(waveform2_t *ctx)
Waveform 2 default configuration function.
void waveform2_cfg_setup(waveform2_cfg_t *cfg)
Waveform 2 configuration object setup function.
void waveform2_configuration(waveform2_t *ctx, uint16_t cfg)
Waveform 2 configuration function.
void waveform2_hw_reset(waveform2_t *ctx)
Waveform 2 hardware reset function.
This file contains SPI specific macros, functions, etc.
Waveform 2 Click configuration object.
Definition waveform2.h:163
uint32_t i2c_speed
Definition waveform2.h:173
spi_master_chip_select_polarity_t cs_polarity
Definition waveform2.h:178
pin_name_t sck
Definition waveform2.h:168
spi_master_mode_t spi_mode
Definition waveform2.h:177
pin_name_t mosi
Definition waveform2.h:167
uint32_t spi_speed
Definition waveform2.h:176
pin_name_t scl
Definition waveform2.h:164
pin_name_t en
Definition waveform2.h:171
pin_name_t miso
Definition waveform2.h:166
pin_name_t sda
Definition waveform2.h:165
pin_name_t rst
Definition waveform2.h:170
pin_name_t cs
Definition waveform2.h:169
uint8_t i2c_address
Definition waveform2.h:174
Waveform 2 Click context object.
Definition waveform2.h:144
spi_master_t spi
Definition waveform2.h:149
uint8_t mode_output
Definition waveform2.h:154
i2c_master_t i2c
Definition waveform2.h:148
digital_out_t en
Definition waveform2.h:146
digital_out_t rst
Definition waveform2.h:145
uint8_t slave_address
Definition waveform2.h:151
pin_name_t chip_select
Definition waveform2.h:152
waveform2_return_value_t
Waveform 2 Click return value data.
Definition waveform2.h:187
@ WAVEFORM2_OK
Definition waveform2.h:188
@ WAVEFORM2_ERROR
Definition waveform2.h:189
struct waveform2_s waveform2_t
Waveform 2 Click context object.