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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_analog_in.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
53 
63 #define STRETCH_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
66 
72 #define STRETCH_RETVAL uint8_t
73 
74 #define STRETCH_OK 0x00
75 #define STRETCH_INIT_ERROR 0xFF
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef uint16_t stretch_data_t;
89 
93 typedef struct
94 {
95  // Output pins
96 
97  digital_out_t pwm;
98 
99  // Modules
100 
101  analog_in_t adc;
102 
103 } stretch_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t an_pin;
113 
114  // Additional gpio pins
115 
116  pin_name_t pwm;
117 
118 
119  // static variable
120 
121  analog_in_resolution_t resolution; // Resolution
122  float vref; // VRef
123 
124 } stretch_cfg_t;
125  // End types group
127 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
146 
156 
165 
175 
184 
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif // _STRETCH_H_
198  // End public_function group
201 
202 // ------------------------------------------------------------------------ END
stretch_data_t
uint16_t stretch_data_t
Analog data type.
Definition: stretch.h:88
stretch_cfg_t
Click configuration structure definition.
Definition: stretch.h:109
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:101
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:97
stretch_t
Click ctx object definition.
Definition: stretch.h:94
stretch_cfg_t::an_pin
pin_name_t an_pin
Definition: stretch.h:112
stretch_cfg_t::pwm
pin_name_t pwm
Definition: stretch.h:116
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:72
stretch_cfg_t::resolution
analog_in_resolution_t resolution
Definition: stretch.h:121
stretch_generic_read
stretch_data_t stretch_generic_read(stretch_t *ctx)
Generic read function.
stretch_cfg_t::vref
float vref
Definition: stretch.h:122