oneshot  2.0.0.0
oneshot.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 ONESHOT_H
36 #define ONESHOT_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_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define ONESHOT_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.out = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_CS )
67 
73 #define ONESHOT_RETVAL uint8_t
74 
75 #define ONESHOT_OK 0x00
76 #define ONESHOT_INIT_ERROR 0xFF
77 
83 #define ONESHOT_SLAVE_ADDRESS 0x2C
84 
90 #define ONESHOT_FULL_SCALE 0xFF
91 #define ONESHOT_MIDSCALE 0x80
92 #define ONESHOT_1_LSB 0x01
93 #define ONESHOT_ZERO_SCALE 0x00
94  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef struct
107 {
108  // Output pins
109 
110  digital_out_t trg;
111 
112  // Input pins
113 
114  digital_in_t out;
115 
116  // Modules
117 
118  i2c_master_t i2c;
119 
120  // ctx variable
121 
122  uint8_t slave_address;
123 
124 } oneshot_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t scl;
134  pin_name_t sda;
135 
136  // Additional gpio pins
137 
138  pin_name_t out;
139  pin_name_t trg;
140 
141  // static variable
142 
143  uint32_t i2c_speed;
144  uint8_t i2c_address;
145 
146 } oneshot_cfg_t;
147  // End types group
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150 
156 #ifdef __cplusplus
157 extern "C"{
158 #endif
159 
169 
179 
188 
199 void oneshot_generic_write ( oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
200 
211 void oneshot_generic_read ( oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
212 
221 
230 
239 void oneshot_digital_write_cs ( oneshot_t *ctx, uint8_t signal );
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 #endif // _ONESHOT_H_
245  // End public_function group
248 
249 // ------------------------------------------------------------------------- END
oneshot_t::i2c
i2c_master_t i2c
Definition: oneshot.h:118
oneshot_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oneshot.h:143
oneshot_cfg_t
Click configuration structure definition.
Definition: oneshot.h:130
oneshot_t::slave_address
uint8_t slave_address
Definition: oneshot.h:122
oneshot_cfg_t::i2c_address
uint8_t i2c_address
Definition: oneshot.h:144
oneshot_default_cfg
void oneshot_default_cfg(oneshot_t *ctx)
Click Default Configuration function.
ONESHOT_RETVAL
#define ONESHOT_RETVAL
Definition: oneshot.h:73
oneshot_t::trg
digital_out_t trg
Definition: oneshot.h:110
oneshot_generic_write
void oneshot_generic_write(oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
oneshot_digital_write_cs
void oneshot_digital_write_cs(oneshot_t *ctx, uint8_t signal)
Digital write chip select function.
oneshot_cfg_t::trg
pin_name_t trg
Definition: oneshot.h:139
oneshot_cfg_t::scl
pin_name_t scl
Definition: oneshot.h:133
oneshot_cfg_t::out
pin_name_t out
Definition: oneshot.h:138
oneshot_cfg_t::sda
pin_name_t sda
Definition: oneshot.h:134
oneshot_t
Click ctx object definition.
Definition: oneshot.h:107
oneshot_digital_read_rst
uint8_t oneshot_digital_read_rst(oneshot_t *ctx)
Digital read reset function.
oneshot_get_resistance
float oneshot_get_resistance(oneshot_t *ctx)
Get resistance function.
oneshot_init
ONESHOT_RETVAL oneshot_init(oneshot_t *ctx, oneshot_cfg_t *cfg)
Initialization function.
oneshot_t::out
digital_in_t out
Definition: oneshot.h:114
oneshot_cfg_setup
void oneshot_cfg_setup(oneshot_cfg_t *cfg)
Config Object Initialization function.
oneshot_generic_read
void oneshot_generic_read(oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.