magneticlinear  2.0.0.0
magneticlinear.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 MAGNETICLINEAR_H
36 #define MAGNETICLINEAR_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_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define MAGNETICLINEAR_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 MAGNETICLINEAR_RETVAL uint8_t
75 
76 #define MAGNETICLINEAR_OK 0x00
77 #define MAGNETICLINEAR_INIT_ERROR 0xFF
78  // End group macro
81 // --------------------------------------------------------------- PUBLIC TYPES
90 typedef struct
91 {
92  digital_out_t cs;
93 
94  // Modules
95 
96  spi_master_t spi;
97  pin_name_t chip_select;
98 
100  uint16_t data_new;
101  uint16_t data_old;
102 
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t miso;
113  pin_name_t mosi;
114  pin_name_t sck;
115  pin_name_t cs;
116 
117  // static variable
118 
119  uint32_t spi_speed;
120  spi_master_mode_t spi_mode;
121  spi_master_chip_select_polarity_t cs_polarity;
122 
124  // End types group
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
127 
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
145 
154 
167 (
168  magneticlinear_t *ctx,
169  uint8_t *wr_buf,
170  uint16_t wr_len,
171  uint8_t *rd_buf,
172  uint16_t rd_len
173 );
174 
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 #endif // _MAGNETICLINEAR_H_
188  // End public_function group
191 
192 // ------------------------------------------------------------------------- END
magneticlinear_cfg_t::sck
pin_name_t sck
Definition: magneticlinear.h:114
magneticlinear_t::data_old
uint16_t data_old
Definition: magneticlinear.h:101
magneticlinear_cfg_setup
void magneticlinear_cfg_setup(magneticlinear_cfg_t *cfg)
Config Object Initialization function.
magneticlinear_cfg_t
Click configuration structure definition.
Definition: magneticlinear.h:109
magneticlinear_cfg_t::mosi
pin_name_t mosi
Definition: magneticlinear.h:113
magneticlinear_init
MAGNETICLINEAR_RETVAL magneticlinear_init(magneticlinear_t *ctx, magneticlinear_cfg_t *cfg)
Initialization function.
MAGNETICLINEAR_RETVAL
#define MAGNETICLINEAR_RETVAL
Definition: magneticlinear.h:74
magneticlinear_t
Click ctx object definition.
Definition: magneticlinear.h:91
magneticlinear_t::data_new
uint16_t data_new
Definition: magneticlinear.h:100
magneticlinear_t::chip_select
pin_name_t chip_select
Definition: magneticlinear.h:97
magneticlinear_cfg_t::cs
pin_name_t cs
Definition: magneticlinear.h:115
magneticlinear_t::spi
spi_master_t spi
Definition: magneticlinear.h:96
magneticlinear_t::cs
digital_out_t cs
Definition: magneticlinear.h:92
magneticlinear_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticlinear.h:120
magneticlinear_cfg_t::miso
pin_name_t miso
Definition: magneticlinear.h:112
magneticlinear_t::magnetic_counter
int16_t magnetic_counter
Definition: magneticlinear.h:99
magneticlinear_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticlinear.h:121
magneticlinear_read_data
uint16_t magneticlinear_read_data(magneticlinear_t *ctx)
Read data function.
magneticlinear_cfg_t::spi_speed
uint32_t spi_speed
Definition: magneticlinear.h:119
magneticlinear_generic_transfer
void magneticlinear_generic_transfer(magneticlinear_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.