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
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_spi_master.h"
54
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define LEM_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
78#define LEM_RETVAL uint8_t
79
80#define LEM_OK 0x00
81#define LEM_INIT_ERROR 0xFF
87#define LEM_USEFULL_DATA 0xFFF
88#define LEM_CALC_COEF 2266
89#define LEM_AMP_COEF 0.0103
90#define LEM_MILIAMP_COEF 10.3
93 // End group macro
94// --------------------------------------------------------------- PUBLIC TYPES
103typedef struct
104{
105 digital_out_t cs;
106
107 // Modules
108
109 spi_master_t spi;
110 pin_name_t chip_select;
111
112} lem_t;
113
117typedef struct
118{
119 // Communication gpio pins
120
121 pin_name_t miso;
122 pin_name_t mosi;
123 pin_name_t sck;
124 pin_name_t cs;
125
126 // static variable
127
128 uint32_t spi_speed;
129 spi_master_mode_t spi_mode;
130 spi_master_chip_select_polarity_t cs_polarity;
131
132} lem_cfg_t;
133
134 // End types group
135// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136
141#ifdef __cplusplus
142extern "C"{
143#endif
144
154
163
173int16_t lem_data_read ( lem_t *ctx );
174
185float lem_get_current ( lem_t *ctx, float coef );
186
187#ifdef __cplusplus
188}
189#endif
190#endif // _LEM_H_
191
192 // End public_function group
194
195// ------------------------------------------------------------------------- END
#define LEM_RETVAL
Definition lem.h:78
float lem_get_current(lem_t *ctx, float coef)
Get current in milliamperes function.
void lem_cfg_setup(lem_cfg_t *cfg)
Config Object Initialization function.
LEM_RETVAL lem_init(lem_t *ctx, lem_cfg_t *cfg)
Initialization function.
int16_t lem_data_read(lem_t *ctx)
Data read function.
Click configuration structure definition.
Definition lem.h:118
spi_master_chip_select_polarity_t cs_polarity
Definition lem.h:130
pin_name_t sck
Definition lem.h:123
spi_master_mode_t spi_mode
Definition lem.h:129
pin_name_t mosi
Definition lem.h:122
uint32_t spi_speed
Definition lem.h:128
pin_name_t miso
Definition lem.h:121
pin_name_t cs
Definition lem.h:124
Click ctx object definition.
Definition lem.h:104
digital_out_t cs
Definition lem.h:105
spi_master_t spi
Definition lem.h:109
pin_name_t chip_select
Definition lem.h:110