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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define MAGNETICLINEAR_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
58 
64 #define MAGNETICLINEAR_RETVAL uint8_t
65 
66 #define MAGNETICLINEAR_OK 0x00
67 #define MAGNETICLINEAR_INIT_ERROR 0xFF
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef struct
81 {
82  digital_out_t cs;
83 
84  // Modules
85 
86  spi_master_t spi;
87  pin_name_t chip_select;
88 
90  uint16_t data_new;
91  uint16_t data_old;
92 
94 
98 typedef struct
99 {
100  // Communication gpio pins
101 
102  pin_name_t miso;
103  pin_name_t mosi;
104  pin_name_t sck;
105  pin_name_t cs;
106 
107  // static variable
108 
109  uint32_t spi_speed;
110  spi_master_mode_t spi_mode;
111  spi_master_chip_select_polarity_t cs_polarity;
112 
114  // End types group
116 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
117 
122 #ifdef __cplusplus
123 extern "C"{
124 #endif
125 
135 
144 
157 (
158  magneticlinear_t *ctx,
159  uint8_t *wr_buf,
160  uint16_t wr_len,
161  uint8_t *rd_buf,
162  uint16_t rd_len
163 );
164 
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 #endif // _MAGNETICLINEAR_H_
178  // End public_function group
181 
182 // ------------------------------------------------------------------------- END
magneticlinear_cfg_t::sck
pin_name_t sck
Definition: magneticlinear.h:104
magneticlinear_t::data_old
uint16_t data_old
Definition: magneticlinear.h:91
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:98
magneticlinear_cfg_t::mosi
pin_name_t mosi
Definition: magneticlinear.h:103
magneticlinear_init
MAGNETICLINEAR_RETVAL magneticlinear_init(magneticlinear_t *ctx, magneticlinear_cfg_t *cfg)
Initialization function.
MAGNETICLINEAR_RETVAL
#define MAGNETICLINEAR_RETVAL
Definition: magneticlinear.h:64
magneticlinear_t
Click ctx object definition.
Definition: magneticlinear.h:80
magneticlinear_t::data_new
uint16_t data_new
Definition: magneticlinear.h:90
magneticlinear_t::chip_select
pin_name_t chip_select
Definition: magneticlinear.h:87
magneticlinear_cfg_t::cs
pin_name_t cs
Definition: magneticlinear.h:105
magneticlinear_t::spi
spi_master_t spi
Definition: magneticlinear.h:86
magneticlinear_t::cs
digital_out_t cs
Definition: magneticlinear.h:82
magneticlinear_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: magneticlinear.h:110
magneticlinear_cfg_t::miso
pin_name_t miso
Definition: magneticlinear.h:102
magneticlinear_t::magnetic_counter
int16_t magnetic_counter
Definition: magneticlinear.h:89
magneticlinear_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: magneticlinear.h:111
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:109
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.