lem  2.0.0.0
lem.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 LEM_H
36 #define LEM_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_spi_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define LEM_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define LEM_RETVAL uint8_t
75 
76 #define LEM_OK 0x00
77 #define LEM_INIT_ERROR 0xFF
78 
83 #define LEM_USEFULL_DATA 0xFFF
84 #define LEM_CALC_COEF 2266
85 #define LEM_AMP_COEF 0.0103
86 #define LEM_MILIAMP_COEF 10.3
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  digital_out_t cs;
102 
103  // Modules
104 
105  spi_master_t spi;
106  pin_name_t chip_select;
107 
108 } lem_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116 
117  pin_name_t miso;
118  pin_name_t mosi;
119  pin_name_t sck;
120  pin_name_t cs;
121 
122  // static variable
123 
124  uint32_t spi_speed;
125  spi_master_mode_t spi_mode;
126  spi_master_chip_select_polarity_t cs_polarity;
127 
128 } lem_cfg_t;
129  // End types group
131 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132 
137 #ifdef __cplusplus
138 extern "C"{
139 #endif
140 
149 void lem_cfg_setup ( lem_cfg_t *cfg );
150 
159 
169 int16_t lem_data_read ( lem_t *ctx );
170 
181 float lem_get_current ( lem_t *ctx, float coef );
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 #endif // _LEM_H_
187  // End public_function group
190 
191 // ------------------------------------------------------------------------- END
lem_t
Click ctx object definition.
Definition: lem.h:100
lem_init
LEM_RETVAL lem_init(lem_t *ctx, lem_cfg_t *cfg)
Initialization function.
lem_cfg_t::spi_speed
uint32_t spi_speed
Definition: lem.h:124
lem_get_current
float lem_get_current(lem_t *ctx, float coef)
Get current in milliamperes function.
lem_t::cs
digital_out_t cs
Definition: lem.h:101
lem_cfg_t::miso
pin_name_t miso
Definition: lem.h:117
lem_data_read
int16_t lem_data_read(lem_t *ctx)
Data read function.
lem_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: lem.h:125
lem_cfg_setup
void lem_cfg_setup(lem_cfg_t *cfg)
Config Object Initialization function.
lem_cfg_t::cs
pin_name_t cs
Definition: lem.h:120
lem_cfg_t::sck
pin_name_t sck
Definition: lem.h:119
lem_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: lem.h:126
lem_t::spi
spi_master_t spi
Definition: lem.h:105
lem_t::chip_select
pin_name_t chip_select
Definition: lem.h:106
lem_cfg_t::mosi
pin_name_t mosi
Definition: lem.h:118
LEM_RETVAL
#define LEM_RETVAL
Definition: lem.h:74
lem_cfg_t
Click configuration structure definition.
Definition: lem.h:114