stretch  2.0.0.0
stretch.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 
35 #ifndef STRETCH_H
36 #define STRETCH_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_analog_in.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
57 
67 #define STRETCH_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
70 
76 #define STRETCH_RETVAL uint8_t
77 
78 #define STRETCH_OK 0x00
79 #define STRETCH_INIT_ERROR 0xFF
80  // End group macro
83 // --------------------------------------------------------------- PUBLIC TYPES
92 typedef uint16_t stretch_data_t;
93 
97 typedef struct
98 {
99  // Output pins
100 
101  digital_out_t pwm;
102 
103  // Modules
104 
105  analog_in_t adc;
106 
107 } stretch_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t an_pin;
117 
118  // Additional gpio pins
119 
120  pin_name_t pwm;
121 
122 
123  // static variable
124 
125  analog_in_resolution_t resolution; // Resolution
126  float vref; // VRef
127 
128 } stretch_cfg_t;
129  // End types group
131 
137 #ifdef __cplusplus
138 extern "C"{
139 #endif
140 
150 
160 
169 
179 
188 
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 #endif // _STRETCH_H_
202  // End public_function group
205 
206 // ------------------------------------------------------------------------ END
stretch_data_t
uint16_t stretch_data_t
Analog data type.
Definition: stretch.h:92
stretch_cfg_t
Click configuration structure definition.
Definition: stretch.h:113
stretch_cfg_setup
void stretch_cfg_setup(stretch_cfg_t *cfg)
Config Object Initialization function.
stretch_t::adc
analog_in_t adc
Definition: stretch.h:105
stretch_init
STRETCH_RETVAL stretch_init(stretch_t *ctx, stretch_cfg_t *cfg)
Initialization function.
stretch_turn_off_led
void stretch_turn_off_led(stretch_t *ctx)
Turn off the LED function.
stretch_t::pwm
digital_out_t pwm
Definition: stretch.h:101
stretch_t
Click ctx object definition.
Definition: stretch.h:98
stretch_cfg_t::an_pin
pin_name_t an_pin
Definition: stretch.h:116
stretch_cfg_t::pwm
pin_name_t pwm
Definition: stretch.h:120
stretch_turn_on_led
void stretch_turn_on_led(stretch_t *ctx)
Turn on the LED function.
stretch_default_cfg
void stretch_default_cfg(stretch_t *ctx)
Click Default Configuration function.
STRETCH_RETVAL
#define STRETCH_RETVAL
Definition: stretch.h:76
stretch_cfg_t::resolution
analog_in_resolution_t resolution
Definition: stretch.h:125
stretch_generic_read
stretch_data_t stretch_generic_read(stretch_t *ctx)
Generic read function.
stretch_cfg_t::vref
float vref
Definition: stretch.h:126