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
32 extern "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  // 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  // waveform2_map // waveform2
138 
143 typedef struct waveform2_s
144 {
145  digital_out_t rst;
146  digital_out_t en;
148  i2c_master_t i2c;
149  spi_master_t spi;
151  uint8_t slave_address;
152  pin_name_t chip_select;
154  uint8_t mode_output;
155 
157 
162 typedef 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 
186 typedef enum
187 {
189  WAVEFORM2_ERROR = -1
190 
192 
209 
224 
239 
254 err_t waveform2_i2c_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
255 
270 err_t waveform2_i2c_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
271 
286 err_t waveform2_spi_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
287 
302 err_t waveform2_spi_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
303 
312 uint8_t waveform2_eeprom_read_byte ( waveform2_t *ctx, uint16_t addr );
313 
322 uint16_t waveform2_eeprom_read_word ( waveform2_t *ctx, uint16_t addr );
323 
332 uint32_t waveform2_eeprom_read_long ( waveform2_t *ctx, uint16_t addr );
333 
344 void waveform2_eeprom_read_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
345 
355 void waveform2_eeprom_write_byte ( waveform2_t *ctx, uint16_t addr, uint8_t tx_data );
356 
366 void waveform2_eeprom_write_word ( waveform2_t *ctx, uint16_t addr, uint16_t tx_data );
367 
377 void waveform2_eeprom_write_long ( waveform2_t *ctx, uint16_t addr, uint32_t tx_data );
378 
389 void waveform2_eeprom_write_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
390 
399 
408 
417 
426 void waveform2_set_freq ( waveform2_t *ctx, uint32_t freq );
427 
436 void waveform2_configuration ( waveform2_t *ctx, uint16_t cfg );
437 
446 
455 
464 
465 #ifdef __cplusplus
466 }
467 #endif
468 #endif // WAVEFORM2_H
469  // waveform2
471 
472 // ------------------------------------------------------------------------ END
waveform2_output_off
void waveform2_output_off(waveform2_t *ctx)
Waveform 2 disable output function.
waveform2_cfg_setup
void waveform2_cfg_setup(waveform2_cfg_t *cfg)
Waveform 2 configuration object setup function.
waveform2_cfg_t::i2c_address
uint8_t i2c_address
Definition: waveform2.h:174
waveform2_eeprom_write_long
void waveform2_eeprom_write_long(waveform2_t *ctx, uint16_t addr, uint32_t tx_data)
Waveform 2 write long function.
waveform2_configuration
void waveform2_configuration(waveform2_t *ctx, uint16_t cfg)
Waveform 2 configuration function.
waveform2_cfg_t::en
pin_name_t en
Definition: waveform2.h:171
waveform2_mclk_disable
void waveform2_mclk_disable(waveform2_t *ctx)
Waveform 2 disable oscilator function.
waveform2_cfg_t::scl
pin_name_t scl
Definition: waveform2.h:164
spi_specifics.h
This file contains SPI specific macros, functions, etc.
waveform2_s::i2c
i2c_master_t i2c
Definition: waveform2.h:148
waveform2_cfg_t
Waveform 2 Click configuration object.
Definition: waveform2.h:163
waveform2_t
struct waveform2_s waveform2_t
Waveform 2 Click context object.
WAVEFORM2_ERROR
@ WAVEFORM2_ERROR
Definition: waveform2.h:189
waveform2_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform2.h:176
waveform2_cfg_t::sck
pin_name_t sck
Definition: waveform2.h:168
waveform2_i2c_write
err_t waveform2_i2c_write(waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Waveform 2 I2C writing function.
waveform2_s::chip_select
pin_name_t chip_select
Definition: waveform2.h:152
waveform2_cfg_t::cs
pin_name_t cs
Definition: waveform2.h:169
waveform2_cfg_t::sda
pin_name_t sda
Definition: waveform2.h:165
waveform2_i2c_read
err_t waveform2_i2c_read(waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Waveform 2 I2C reading function.
waveform2_eeprom_write_word
void waveform2_eeprom_write_word(waveform2_t *ctx, uint16_t addr, uint16_t tx_data)
Waveform 2 write word function.
waveform2_s::rst
digital_out_t rst
Definition: waveform2.h:145
waveform2_sine_output
void waveform2_sine_output(waveform2_t *ctx)
Waveform 2 set sine output function.
waveform2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: waveform2.h:178
WAVEFORM2_OK
@ WAVEFORM2_OK
Definition: waveform2.h:188
waveform2_mclk_enable
void waveform2_mclk_enable(waveform2_t *ctx)
Waveform 2 enable oscilator function.
waveform2_eeprom_read_long
uint32_t waveform2_eeprom_read_long(waveform2_t *ctx, uint16_t addr)
Waveform 2 read long function.
waveform2_set_freq
void waveform2_set_freq(waveform2_t *ctx, uint32_t freq)
Waveform 2 set frequency function.
waveform2_s
Waveform 2 Click context object.
Definition: waveform2.h:144
waveform2_eeprom_read_string
void waveform2_eeprom_read_string(waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len)
Waveform 2 read string function.
waveform2_eeprom_read_word
uint16_t waveform2_eeprom_read_word(waveform2_t *ctx, uint16_t addr)
Waveform 2 read word function.
waveform2_s::slave_address
uint8_t slave_address
Definition: waveform2.h:151
waveform2_cfg_t::miso
pin_name_t miso
Definition: waveform2.h:166
waveform2_default_cfg
err_t waveform2_default_cfg(waveform2_t *ctx)
Waveform 2 default configuration function.
waveform2_s::mode_output
uint8_t mode_output
Definition: waveform2.h:154
waveform2_spi_read
err_t waveform2_spi_read(waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Waveform 2 SPI reading function.
waveform2_eeprom_write_byte
void waveform2_eeprom_write_byte(waveform2_t *ctx, uint16_t addr, uint8_t tx_data)
Waveform 2 write bute function.
waveform2_hw_reset
void waveform2_hw_reset(waveform2_t *ctx)
Waveform 2 hardware reset function.
waveform2_cfg_t::rst
pin_name_t rst
Definition: waveform2.h:170
waveform2_eeprom_write_string
void waveform2_eeprom_write_string(waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len)
Waveform 2 write string function.
waveform2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: waveform2.h:177
waveform2_s::en
digital_out_t en
Definition: waveform2.h:146
waveform2_init
err_t waveform2_init(waveform2_t *ctx, waveform2_cfg_t *cfg)
Waveform 2 initialization function.
waveform2_return_value_t
waveform2_return_value_t
Waveform 2 Click return value data.
Definition: waveform2.h:187
waveform2_s::spi
spi_master_t spi
Definition: waveform2.h:149
waveform2_cfg_t::mosi
pin_name_t mosi
Definition: waveform2.h:167
waveform2_triangle_output
void waveform2_triangle_output(waveform2_t *ctx)
Waveform 2 set triangle output function.
waveform2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: waveform2.h:173
waveform2_spi_write
err_t waveform2_spi_write(waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Waveform 2 SPI writing function.
waveform2_eeprom_read_byte
uint8_t waveform2_eeprom_read_byte(waveform2_t *ctx, uint16_t addr)
Waveform 2 read byte function.