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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define CURRENTLIMIT_ENABLE 1
61 #define CURRENTLIMIT_DISABLE 0
62 
63 #define CURRENTLIMIT_LSB_VAL 392.2
64 #define CURRENTLIMIT_R_BASE 1200.0
65 #define CURRENTLIMIT_I_MAX 1.2
66 #define CURRENTLIMIT_CALC_COEF 1380.0
67 
68 #define CURRENTLIMIT_CUR_LIM_VAL_0_1 224
69 #define CURRENTLIMIT_CUR_LIM_VAL_0_2 241
70 #define CURRENTLIMIT_CUR_LIM_VAL_0_3 247
71 #define CURRENTLIMIT_CUR_LIM_VAL_0_4 250
72 #define CURRENTLIMIT_CUR_LIM_VAL_0_5 252
73 #define CURRENTLIMIT_CUR_LIM_VAL_0_6 253
74 #define CURRENTLIMIT_CUR_LIM_VAL_0_7 254
75 #define CURRENTLIMIT_CUR_LIM_VAL_0_867 255
76 
85 #define CURRENTLIMIT_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
86 #define CURRENTLIMIT_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
87  // currentlimit_set
89 
104 #define CURRENTLIMIT_MAP_MIKROBUS( cfg, mikrobus ) \
105  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
106  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
107  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
108  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN )
110  // currentlimit_map // currentlimit
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t en;
123  // Modules
124  spi_master_t spi;
126  pin_name_t chip_select;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
142  // Additional gpio pins
143  pin_name_t en;
145  // static variable
146  uint32_t spi_speed;
147  spi_master_mode_t spi_mode;
148  spi_master_chip_select_polarity_t cs_polarity;
151 
156 typedef enum
157 {
159  CURRENTLIMIT_ERROR = -1
160 
162 
179 
194 
209 err_t currentlimit_generic_write ( currentlimit_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
210 
225 err_t currentlimit_generic_read ( currentlimit_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
226 
235 void currentlimit_dev_enable ( currentlimit_t *ctx, uint8_t state );
236 
250 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // CURRENTLIMIT_H
269  // currentlimit
271 
272 // ------------------------------------------------------------------------ END
currentlimit_dev_enable
void currentlimit_dev_enable(currentlimit_t *ctx, uint8_t state)
Device enable function.
currentlimit_generic_write
err_t currentlimit_generic_write(currentlimit_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Current Limit data writing function.
currentlimit_t::spi
spi_master_t spi
Definition: currentlimit.h:124
spi_specifics.h
This file contains SPI specific macros, functions, etc.
currentlimit_cfg_setup
void currentlimit_cfg_setup(currentlimit_cfg_t *cfg)
Current Limit configuration object setup function.
currentlimit_return_value_t
currentlimit_return_value_t
Current Limit Click return value data.
Definition: currentlimit.h:157
currentlimit_t::chip_select
pin_name_t chip_select
Definition: currentlimit.h:126
currentlimit_init
err_t currentlimit_init(currentlimit_t *ctx, currentlimit_cfg_t *cfg)
Current Limit initialization function.
currentlimit_cfg_t::miso
pin_name_t miso
Definition: currentlimit.h:137
lim_val
const uint8_t lim_val[8]
Definition: main.c:29
currentlimit_cfg_t::sck
pin_name_t sck
Definition: currentlimit.h:139
currentlimit_cfg_t::en
pin_name_t en
Definition: currentlimit.h:143
CURRENTLIMIT_OK
@ CURRENTLIMIT_OK
Definition: currentlimit.h:158
currentlimit_set_limit
void currentlimit_set_limit(currentlimit_t *ctx, uint8_t lim_val)
Set Current With Predefined Values Limit function.
currentlimit_cfg_t::cs
pin_name_t cs
Definition: currentlimit.h:140
currentlimit_cfg_t::spi_speed
uint32_t spi_speed
Definition: currentlimit.h:146
currentlimit_t::en
digital_out_t en
Definition: currentlimit.h:121
currentlimit_cfg_t::mosi
pin_name_t mosi
Definition: currentlimit.h:138
currentlimit_cfg_t
Current Limit Click configuration object.
Definition: currentlimit.h:135
currentlimit_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: currentlimit.h:148
currentlimit_t
Current Limit Click context object.
Definition: currentlimit.h:119
currentlimit_set_limit_calc
void currentlimit_set_limit_calc(currentlimit_t *ctx, float lim_val)
Set Calculated Current Limit function.
currentlimit_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: currentlimit.h:147
CURRENTLIMIT_ERROR
@ CURRENTLIMIT_ERROR
Definition: currentlimit.h:159
currentlimit_generic_read
err_t currentlimit_generic_read(currentlimit_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Current Limit data reading function.