currentlimit 2.0.0.0
currentlimit.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2021 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef CURRENTLIMIT_H
29#define CURRENTLIMIT_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define CURRENTLIMIT_ENABLE 1
75#define CURRENTLIMIT_DISABLE 0
76
77#define CURRENTLIMIT_LSB_VAL 392.2
78#define CURRENTLIMIT_R_BASE 1200.0
79#define CURRENTLIMIT_I_MAX 1.2
80#define CURRENTLIMIT_CALC_COEF 1380.0
81
82#define CURRENTLIMIT_CUR_LIM_VAL_0_1 224
83#define CURRENTLIMIT_CUR_LIM_VAL_0_2 241
84#define CURRENTLIMIT_CUR_LIM_VAL_0_3 247
85#define CURRENTLIMIT_CUR_LIM_VAL_0_4 250
86#define CURRENTLIMIT_CUR_LIM_VAL_0_5 252
87#define CURRENTLIMIT_CUR_LIM_VAL_0_6 253
88#define CURRENTLIMIT_CUR_LIM_VAL_0_7 254
89#define CURRENTLIMIT_CUR_LIM_VAL_0_867 255
90
99#define CURRENTLIMIT_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
100#define CURRENTLIMIT_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
101
102 // currentlimit_set
103
118#define CURRENTLIMIT_MAP_MIKROBUS( cfg, mikrobus ) \
119 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
120 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
121 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
122 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
123 cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN )
124
125 // currentlimit_map
126 // currentlimit
127
132typedef struct
133{
134 // Output pins
135 digital_out_t en;
137 // Modules
138 spi_master_t spi;
140 pin_name_t chip_select;
143
148typedef struct
149{
150 // Communication gpio pins
151 pin_name_t miso;
152 pin_name_t mosi;
153 pin_name_t sck;
154 pin_name_t cs;
156 // Additional gpio pins
157 pin_name_t en;
159 // static variable
160 uint32_t spi_speed;
161 spi_master_mode_t spi_mode;
162 spi_master_chip_select_polarity_t cs_polarity;
165
176
193
208
223err_t currentlimit_generic_write ( currentlimit_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
224
239err_t currentlimit_generic_read ( currentlimit_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
240
249void currentlimit_dev_enable ( currentlimit_t *ctx, uint8_t state );
250
264
278
279#ifdef __cplusplus
280}
281#endif
282#endif // CURRENTLIMIT_H
283
284 // currentlimit
285
286// ------------------------------------------------------------------------ END
currentlimit_return_value_t
Current Limit Click return value data.
Definition currentlimit.h:171
@ CURRENTLIMIT_OK
Definition currentlimit.h:172
@ CURRENTLIMIT_ERROR
Definition currentlimit.h:173
void currentlimit_set_limit(currentlimit_t *ctx, uint8_t lim_val)
Set Current With Predefined Values Limit function.
void currentlimit_dev_enable(currentlimit_t *ctx, uint8_t state)
Device enable function.
void currentlimit_set_limit_calc(currentlimit_t *ctx, float lim_val)
Set Calculated Current Limit function.
err_t currentlimit_init(currentlimit_t *ctx, currentlimit_cfg_t *cfg)
Current Limit initialization function.
void currentlimit_cfg_setup(currentlimit_cfg_t *cfg)
Current Limit configuration object setup function.
err_t currentlimit_generic_read(currentlimit_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Current Limit data reading function.
err_t currentlimit_generic_write(currentlimit_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Current Limit data writing function.
const uint8_t lim_val[8]
Definition main.c:29
This file contains SPI specific macros, functions, etc.
Current Limit Click configuration object.
Definition currentlimit.h:149
spi_master_chip_select_polarity_t cs_polarity
Definition currentlimit.h:162
pin_name_t sck
Definition currentlimit.h:153
spi_master_mode_t spi_mode
Definition currentlimit.h:161
pin_name_t mosi
Definition currentlimit.h:152
uint32_t spi_speed
Definition currentlimit.h:160
pin_name_t en
Definition currentlimit.h:157
pin_name_t miso
Definition currentlimit.h:151
pin_name_t cs
Definition currentlimit.h:154
Current Limit Click context object.
Definition currentlimit.h:133
spi_master_t spi
Definition currentlimit.h:138
digital_out_t en
Definition currentlimit.h:135
pin_name_t chip_select
Definition currentlimit.h:140