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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define WAVEFORM2_CFG_B28_MSK 0x2000
62 #define WAVEFORM2_CFG_HLB_MSK 0x1000
63 #define WAVEFORM2_CFG_FSEL_MSK 0x0800
64 #define WAVEFORM2_CFG_PSEK_MSK 0x0400
65 #define WAVEFORM2_CFG_PIN_SW_MSK 0x0200
66 #define WAVEFORM2_CFG_RESET_MSK 0x0100
67 #define WAVEFORM2_CFG_SLEEP1_MSK 0x0080
68 #define WAVEFORM2_CFG_SLEEP12_MSK 0x0040
69 #define WAVEFORM2_CFG_OPBITEN_MSK 0x0020
70 #define WAVEFORM2_CFG_SIGN_PIB_MSK 0x0010
71 #define WAVEFORM2_CFG_DIV2_MSK 0x0008
72 #define WAVEFORM2_CFG_MODE_MSK 0x0002
73 
74 #define OUTPUT_TRIANGLE 0x01
75 #define OUTPUT_SINUSOID 0x00
76 
82 #define WAVEFORM2_DEVICE_SLAVE_ADDR_GND 0x50
83 #define WAVEFORM2_DEVICE_SLAVE_ADDR_VCC 0x51
84 
93 #define WAVEFORM2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
94 #define WAVEFORM2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
95  // waveform2_set
97 
112 #define WAVEFORM2_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
114  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
115  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
116  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
117  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
118  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
119  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
120  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
121  // waveform2_map // waveform2
124 
129 typedef struct waveform2_s
130 {
131  digital_out_t rst;
132  digital_out_t en;
134  i2c_master_t i2c;
135  spi_master_t spi;
137  uint8_t slave_address;
138  pin_name_t chip_select;
140  uint8_t mode_output;
141 
142 } waveform2_t;
143 
148 typedef struct
149 {
150  pin_name_t scl;
151  pin_name_t sda;
152  pin_name_t miso;
153  pin_name_t mosi;
154  pin_name_t sck;
155  pin_name_t cs;
156  pin_name_t rst;
157  pin_name_t en;
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
162  uint32_t spi_speed;
163  spi_master_mode_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
167 
172 typedef enum
173 {
176 
178 
195 
209 err_t waveform2_init ( waveform2_t *ctx, waveform2_cfg_t *cfg );
210 
224 err_t waveform2_default_cfg ( waveform2_t *ctx );
225 
240 err_t waveform2_i2c_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
241 
256 err_t waveform2_i2c_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
257 
272 err_t waveform2_spi_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
273 
288 err_t waveform2_spi_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
289 
298 uint8_t waveform2_eeprom_read_byte ( waveform2_t *ctx, uint16_t addr );
299 
308 uint16_t waveform2_eeprom_read_word ( waveform2_t *ctx, uint16_t addr );
309 
318 uint32_t waveform2_eeprom_read_long ( waveform2_t *ctx, uint16_t addr );
319 
330 void waveform2_eeprom_read_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
331 
341 void waveform2_eeprom_write_byte ( waveform2_t *ctx, uint16_t addr, uint8_t tx_data );
342 
352 void waveform2_eeprom_write_word ( waveform2_t *ctx, uint16_t addr, uint16_t tx_data );
353 
363 void waveform2_eeprom_write_long ( waveform2_t *ctx, uint16_t addr, uint32_t tx_data );
364 
375 void waveform2_eeprom_write_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
376 
384 void waveform2_mclk_enable ( waveform2_t *ctx );
385 
393 void waveform2_mclk_disable ( waveform2_t *ctx );
394 
402 void waveform2_hw_reset ( waveform2_t *ctx );
403 
412 void waveform2_set_freq ( waveform2_t *ctx, uint32_t freq );
413 
422 void waveform2_configuration ( waveform2_t *ctx, uint16_t cfg );
423 
431 void waveform2_sine_output ( waveform2_t *ctx );
432 
441 
449 void waveform2_output_off ( waveform2_t *ctx );
450 
451 #ifdef __cplusplus
452 }
453 #endif
454 #endif // WAVEFORM2_H
455  // waveform2
457 
458 // ------------------------------------------------------------------------ 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:160
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:157
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:150
spi_specifics.h
This file contains SPI specific macros, functions, etc.
waveform2_s::i2c
i2c_master_t i2c
Definition: waveform2.h:134
waveform2_cfg_t
Waveform 2 Click configuration object.
Definition: waveform2.h:148
WAVEFORM2_ERROR
Definition: waveform2.h:175
waveform2_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform2.h:162
waveform2_cfg_t::sck
pin_name_t sck
Definition: waveform2.h:154
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:138
waveform2_cfg_t::cs
pin_name_t cs
Definition: waveform2.h:155
waveform2_cfg_t::sda
pin_name_t sda
Definition: waveform2.h:151
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:131
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:164
WAVEFORM2_OK
Definition: waveform2.h:174
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:129
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:137
waveform2_cfg_t::miso
pin_name_t miso
Definition: waveform2.h:152
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:140
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:156
waveform2_t
struct waveform2_s waveform2_t
Waveform 2 Click context object.
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:163
waveform2_s::en
digital_out_t en
Definition: waveform2.h:132
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:172
waveform2_s::spi
spi_master_t spi
Definition: waveform2.h:135
waveform2_cfg_t::mosi
pin_name_t mosi
Definition: waveform2.h:153
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:159
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.