digivref  2.0.0.0
digivref.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 DIGIVREF_H
36 #define DIGIVREF_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 DIGIVREF_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 
64 #define DIGIVREF_RETVAL uint8_t
65 
66 #define DIGIVREF_OK 0x00
67 #define DIGIVREF_INIT_ERROR 0xFF
68 
74 #define DIGIVREF_REF_VOLTAGE_4096mV 0xF0
75 #define DIGIVREF_REF_VOLTAGE_3072mV 0xF2
76 #define DIGIVREF_REF_VOLTAGE_2048mV 0xF4
77 #define DIGIVREF_REF_VOLTAGE_1024mV 0xF6
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  // Modules
93 
94  spi_master_t spi;
95 
96 } digivref_t;
97 
101 typedef struct
102 {
103  // Communication gpio pins
104 
105  pin_name_t miso;
106  pin_name_t mosi;
107  pin_name_t sck;
108  pin_name_t cs;
109 
110  // static variable
111 
112  hal_spi_speed_t spi_speed;
113  hal_spi_mode_t spi_mode;
114 
116  // End types group
118 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
119 
124 #ifdef __cplusplus
125 extern "C"{
126 #endif
127 
136 void digivref_cfg_setup ( digivref_cfg_t *cfg );
137 
146 
155 void digivref_generic_transfer ( digivref_t *ctx, spi_master_transfer_data_t *block );
156 
165 void digivref_set_output_voltage ( digivref_t *ctx, uint8_t v_ref );
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 #endif // _DIGIVREF_H_
171  // End public_function group
174 
175 // ------------------------------------------------------------------------- END
digivref_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: digivref.h:113
digivref_cfg_t::sck
pin_name_t sck
Definition: digivref.h:107
digivref_cfg_setup
void digivref_cfg_setup(digivref_cfg_t *cfg)
Config Object Initialization function.
digivref_cfg_t::miso
pin_name_t miso
Definition: digivref.h:105
digivref_cfg_t::cs
pin_name_t cs
Definition: digivref.h:108
digivref_generic_transfer
void digivref_generic_transfer(digivref_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
digivref_t::spi
spi_master_t spi
Definition: digivref.h:94
digivref_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: digivref.h:112
digivref_cfg_t
Click configuration structure definition.
Definition: digivref.h:101
digivref_set_output_voltage
void digivref_set_output_voltage(digivref_t *ctx, uint8_t v_ref)
Function for set reference output voltage.
digivref_init
DIGIVREF_RETVAL digivref_init(digivref_t *ctx, digivref_cfg_t *cfg)
Initialization function.
digivref_cfg_t::mosi
pin_name_t mosi
Definition: digivref.h:106
DIGIVREF_RETVAL
#define DIGIVREF_RETVAL
Definition: digivref.h:64
digivref_t
Click ctx object definition.
Definition: digivref.h:90