dac2  2.0.0.0
dac2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DAC2_H
36 #define DAC2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define DAC2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.clr = MIKROBUS( mikrobus, MIKROBUS_RST );
59 
65 #define DAC2_RETVAL uint8_t
66 
67 #define DAC2_OK 0x00
68 #define DAC2_INIT_ERROR 0xFF
69  // End group macro
72 
73 // --------------------------------------------------------------- PUBLIC TYPES
82 typedef struct
83 {
84  // Output pins
85 
86  digital_out_t clr;
87 
88  // Modules
89 
90  spi_master_t spi;
91 
92 } dac2_t;
93 
97 typedef struct
98 {
99  // Communication gpio pins
100 
101  pin_name_t miso;
102  pin_name_t mosi;
103  pin_name_t sck;
104  pin_name_t cs;
105 
106  // Additional gpio pins
107 
108  pin_name_t clr;
109 
110  // static variable
111 
112  hal_spi_speed_t spi_speed;
113  hal_spi_mode_t spi_mode;
114 
115 } dac2_cfg_t;
116  // End types group
118 
119 // ------------------------------------------------------------------ CONSTANTS // End constants group
127 
128 // ------------------------------------------------------------------ VARIABLES // End variable group
136 
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
155 void dac2_cfg_setup ( dac2_cfg_t *cfg );
156 
165 DAC2_RETVAL dac2_init ( dac2_t *ctx, dac2_cfg_t *cfg );
166 
175 void dac2_generic_transfer ( dac2_t *ctx, spi_master_transfer_data_t *block );
176 
184 void dac2_default_cfg ( dac2_t *ctx );
185 
194 void dac2_clr_dac_2_reg ( dac2_t *ctx );
195 
206 void dac2_write_output_voltage_procentage ( dac2_t *ctx, uint8_t value_pct );
207 
218 void dac2_write_output_voltage_data ( dac2_t *ctx, uint16_t value_data );
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 #endif // _DAC2_H_
224  // End public_function group
227 
228 // ------------------------------------------------------------------------- END
dac2_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: dac2.h:112
dac2_cfg_t::clr
pin_name_t clr
Definition: dac2.h:108
dac2_cfg_t
Click configuration structure definition.
Definition: dac2.h:97
dac2_t
Click ctx object definition.
Definition: dac2.h:82
dac2_write_output_voltage_procentage
void dac2_write_output_voltage_procentage(dac2_t *ctx, uint8_t value_pct)
Procentage generic write function.
dac2_init
DAC2_RETVAL dac2_init(dac2_t *ctx, dac2_cfg_t *cfg)
Initialization function.
dac2_generic_transfer
void dac2_generic_transfer(dac2_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
dac2_t::clr
digital_out_t clr
Definition: dac2.h:86
dac2_write_output_voltage_data
void dac2_write_output_voltage_data(dac2_t *ctx, uint16_t value_data)
Data generic write function.
dac2_default_cfg
void dac2_default_cfg(dac2_t *ctx)
Click Default Configuration function.
DAC2_RETVAL
#define DAC2_RETVAL
Definition: dac2.h:65
dac2_cfg_t::sck
pin_name_t sck
Definition: dac2.h:103
dac2_t::spi
spi_master_t spi
Definition: dac2.h:90
dac2_cfg_t::mosi
pin_name_t mosi
Definition: dac2.h:102
dac2_clr_dac_2_reg
void dac2_clr_dac_2_reg(dac2_t *ctx)
Asynchronous Clear Input function.
dac2_cfg_t::cs
pin_name_t cs
Definition: dac2.h:104
dac2_cfg_t::miso
pin_name_t miso
Definition: dac2.h:101
dac2_cfg_setup
void dac2_cfg_setup(dac2_cfg_t *cfg)
Config Object Initialization function.
dac2_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: dac2.h:113