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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define WAVEFORM2_CFG_B28_MSK 0x2000
72 #define WAVEFORM2_CFG_HLB_MSK 0x1000
73 #define WAVEFORM2_CFG_FSEL_MSK 0x0800
74 #define WAVEFORM2_CFG_PSEK_MSK 0x0400
75 #define WAVEFORM2_CFG_PIN_SW_MSK 0x0200
76 #define WAVEFORM2_CFG_RESET_MSK 0x0100
77 #define WAVEFORM2_CFG_SLEEP1_MSK 0x0080
78 #define WAVEFORM2_CFG_SLEEP12_MSK 0x0040
79 #define WAVEFORM2_CFG_OPBITEN_MSK 0x0020
80 #define WAVEFORM2_CFG_SIGN_PIB_MSK 0x0010
81 #define WAVEFORM2_CFG_DIV2_MSK 0x0008
82 #define WAVEFORM2_CFG_MODE_MSK 0x0002
83 
84 #define OUTPUT_TRIANGLE 0x01
85 #define OUTPUT_SINUSOID 0x00
86 
92 #define WAVEFORM2_DEVICE_SLAVE_ADDR_GND 0x50
93 #define WAVEFORM2_DEVICE_SLAVE_ADDR_VCC 0x51
94 
103 #define WAVEFORM2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
104 #define WAVEFORM2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
105  // waveform2_set
107 
122 #define WAVEFORM2_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
124  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
125  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
126  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
127  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
128  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
129  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
130  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
131  // waveform2_map // waveform2
134 
139 typedef struct waveform2_s
140 {
141  digital_out_t rst;
142  digital_out_t en;
144  i2c_master_t i2c;
145  spi_master_t spi;
147  uint8_t slave_address;
148  pin_name_t chip_select;
150  uint8_t mode_output;
151 
153 
158 typedef struct
159 {
160  pin_name_t scl;
161  pin_name_t sda;
162  pin_name_t miso;
163  pin_name_t mosi;
164  pin_name_t sck;
165  pin_name_t cs;
166  pin_name_t rst;
167  pin_name_t en;
169  uint32_t i2c_speed;
170  uint8_t i2c_address;
172  uint32_t spi_speed;
173  spi_master_mode_t spi_mode;
174  spi_master_chip_select_polarity_t cs_polarity;
177 
182 typedef enum
183 {
185  WAVEFORM2_ERROR = -1
186 
188 
205 
220 
235 
250 err_t waveform2_i2c_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
251 
266 err_t waveform2_i2c_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
267 
282 err_t waveform2_spi_write ( waveform2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
283 
298 err_t waveform2_spi_read ( waveform2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
299 
308 uint8_t waveform2_eeprom_read_byte ( waveform2_t *ctx, uint16_t addr );
309 
318 uint16_t waveform2_eeprom_read_word ( waveform2_t *ctx, uint16_t addr );
319 
328 uint32_t waveform2_eeprom_read_long ( waveform2_t *ctx, uint16_t addr );
329 
340 void waveform2_eeprom_read_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
341 
351 void waveform2_eeprom_write_byte ( waveform2_t *ctx, uint16_t addr, uint8_t tx_data );
352 
362 void waveform2_eeprom_write_word ( waveform2_t *ctx, uint16_t addr, uint16_t tx_data );
363 
373 void waveform2_eeprom_write_long ( waveform2_t *ctx, uint16_t addr, uint32_t tx_data );
374 
385 void waveform2_eeprom_write_string ( waveform2_t *ctx, uint16_t addr, uint8_t *data_buf, uint16_t len );
386 
395 
404 
413 
422 void waveform2_set_freq ( waveform2_t *ctx, uint32_t freq );
423 
432 void waveform2_configuration ( waveform2_t *ctx, uint16_t cfg );
433 
442 
451 
460 
461 #ifdef __cplusplus
462 }
463 #endif
464 #endif // WAVEFORM2_H
465  // waveform2
467 
468 // ------------------------------------------------------------------------ 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:170
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:167
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:160
spi_specifics.h
This file contains SPI specific macros, functions, etc.
waveform2_s::i2c
i2c_master_t i2c
Definition: waveform2.h:144
waveform2_cfg_t
Waveform 2 Click configuration object.
Definition: waveform2.h:159
waveform2_t
struct waveform2_s waveform2_t
Waveform 2 Click context object.
WAVEFORM2_ERROR
@ WAVEFORM2_ERROR
Definition: waveform2.h:185
waveform2_cfg_t::spi_speed
uint32_t spi_speed
Definition: waveform2.h:172
waveform2_cfg_t::sck
pin_name_t sck
Definition: waveform2.h:164
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:148
waveform2_cfg_t::cs
pin_name_t cs
Definition: waveform2.h:165
waveform2_cfg_t::sda
pin_name_t sda
Definition: waveform2.h:161
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:141
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:174
WAVEFORM2_OK
@ WAVEFORM2_OK
Definition: waveform2.h:184
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:140
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:147
waveform2_cfg_t::miso
pin_name_t miso
Definition: waveform2.h:162
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:150
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:166
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:173
waveform2_s::en
digital_out_t en
Definition: waveform2.h:142
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:183
waveform2_s::spi
spi_master_t spi
Definition: waveform2.h:145
waveform2_cfg_t::mosi
pin_name_t mosi
Definition: waveform2.h:163
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:169
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.