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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ONESHOT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.out = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define ONESHOT_RETVAL uint8_t
64 
65 #define ONESHOT_OK 0x00
66 #define ONESHOT_INIT_ERROR 0xFF
67 
73 #define ONESHOT_SLAVE_ADDRESS 0x2C
74 
80 #define ONESHOT_FULL_SCALE 0xFF
81 #define ONESHOT_MIDSCALE 0x80
82 #define ONESHOT_1_LSB 0x01
83 #define ONESHOT_ZERO_SCALE 0x00
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t trg;
101 
102  // Input pins
103 
104  digital_in_t out;
105 
106  // Modules
107 
108  i2c_master_t i2c;
109 
110  // ctx variable
111 
112  uint8_t slave_address;
113 
114 } oneshot_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t scl;
124  pin_name_t sda;
125 
126  // Additional gpio pins
127 
128  pin_name_t out;
129  pin_name_t trg;
130 
131  // static variable
132 
133  uint32_t i2c_speed;
134  uint8_t i2c_address;
135 
136 } oneshot_cfg_t;
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
169 
178 
189 void oneshot_generic_write ( oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
190 
201 void oneshot_generic_read ( oneshot_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
202 
211 
220 
229 void oneshot_digital_write_cs ( oneshot_t *ctx, uint8_t signal );
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 #endif // _ONESHOT_H_
235  // End public_function group
238 
239 // ------------------------------------------------------------------------- END
oneshot_t::i2c
i2c_master_t i2c
Definition: oneshot.h:108
oneshot_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: oneshot.h:133
oneshot_cfg_t
Click configuration structure definition.
Definition: oneshot.h:120
oneshot_t::slave_address
uint8_t slave_address
Definition: oneshot.h:112
oneshot_cfg_t::i2c_address
uint8_t i2c_address
Definition: oneshot.h:134
oneshot_default_cfg
void oneshot_default_cfg(oneshot_t *ctx)
Click Default Configuration function.
ONESHOT_RETVAL
#define ONESHOT_RETVAL
Definition: oneshot.h:63
oneshot_t::trg
digital_out_t trg
Definition: oneshot.h:100
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:129
oneshot_cfg_t::scl
pin_name_t scl
Definition: oneshot.h:123
oneshot_cfg_t::out
pin_name_t out
Definition: oneshot.h:128
oneshot_cfg_t::sda
pin_name_t sda
Definition: oneshot.h:124
oneshot_t
Click ctx object definition.
Definition: oneshot.h:97
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:104
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.