adc2  2.0.0.0
adc2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef ADC2_H
36 #define ADC2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define ADC2_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
59 
65 #define ADC2_RETVAL uint8_t
66 
67 #define ADC2_OK 0x00
68 #define ADC2_INIT_ERROR 0xFF
69 
75 #define ADC2_INTERRUPT_FLAG -4000000
76 #define ADC2_OVERFLOW_HIGH_FLAG 3000000
77 #define ADC2_OVERFLOW_LOW_FLAG -3000000
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  digital_out_t cs;
93 
94  // Modules
95 
96  spi_master_t spi;
97  pin_name_t chip_select;
98 
99 } adc2_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t miso;
109  pin_name_t mosi;
110  pin_name_t sck;
111  pin_name_t cs;
112 
113  // static variable
114 
115  uint32_t spi_speed;
116  spi_master_mode_t spi_mode;
117  spi_master_chip_select_polarity_t cs_polarity;
118 
119 } adc2_cfg_t;
120  // End types group
122 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
123 
128 #ifdef __cplusplus
129 extern "C"{
130 #endif
131 
140 void adc2_cfg_setup ( adc2_cfg_t *cfg );
141 
150 ADC2_RETVAL adc2_init ( adc2_t *ctx, adc2_cfg_t *cfg );
151 
163 void adc2_generic_transfer ( adc2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
164 
174 uint32_t adc2_read_4bytes ( adc2_t *ctx );
175 
185 uint32_t adc2_adc_value_read ( adc2_t *ctx );
186 
196 uint8_t adc2_check_over_low ( adc2_t *ctx );
197 
207 uint8_t adc2_check_over_high ( adc2_t *ctx );
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 #endif // _ADC2_H_
213  // End public_function group
216 
217 // ------------------------------------------------------------------------- END
spi_master_chip_select_polarity_t cs_polarity
Definition: adc2.h:117
pin_name_t miso
Definition: adc2.h:108
uint8_t adc2_check_over_low(adc2_t *ctx)
Check over low bit function.
Click configuration structure definition.
Definition: adc2.h:104
uint32_t adc2_adc_value_read(adc2_t *ctx)
Read ADC value function.
uint8_t adc2_check_over_high(adc2_t *ctx)
Check over high bit function.
ADC2_RETVAL adc2_init(adc2_t *ctx, adc2_cfg_t *cfg)
Initialization function.
pin_name_t cs
Definition: adc2.h:111
Click ctx object definition.
Definition: adc2.h:90
pin_name_t chip_select
Definition: adc2.h:97
uint32_t spi_speed
Definition: adc2.h:115
digital_out_t cs
Definition: adc2.h:92
uint32_t adc2_read_4bytes(adc2_t *ctx)
Data read function.
spi_master_t spi
Definition: adc2.h:96
pin_name_t sck
Definition: adc2.h:110
spi_master_mode_t spi_mode
Definition: adc2.h:116
void adc2_generic_transfer(adc2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void adc2_cfg_setup(adc2_cfg_t *cfg)
Config Object Initialization function.
#define ADC2_RETVAL
Definition: adc2.h:65
pin_name_t mosi
Definition: adc2.h:109