linhall  2.0.0.0
linhall.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 LINHALL_H
36 #define LINHALL_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_spi_master.h"
53 
54 // -------------------------------------------------------------- PUBLIC MACROS
65 #define LINHALL_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
70 
77 #define LINHALL_RETVAL uint8_t
78 
79 #define LINHALL_OK 0x00
80 #define LINHALL_INIT_ERROR 0xFF
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef struct
94 {
95  digital_out_t cs;
96 
97  // Modules
98 
99  spi_master_t spi;
100  pin_name_t chip_select;
101 
102 } linhall_t;
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t miso;
112  pin_name_t mosi;
113  pin_name_t sck;
114  pin_name_t cs;
115 
116  // static variable
117 
118  uint32_t spi_speed;
119  spi_master_mode_t spi_mode;
120  spi_master_chip_select_polarity_t cs_polarity;
121 
122 } linhall_cfg_t;
123  // End types group
125 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126 
131 #ifdef __cplusplus
132 extern "C"{
133 #endif
134 
144 
154 
167 (
168  linhall_t *ctx,
169  uint8_t *wr_buf,
170  uint16_t wr_len,
171  uint8_t *rd_buf,
172  uint16_t rd_len
173 );
174 
185 uint16_t linhall_read_data ( linhall_t *ctx );
186 #ifdef __cplusplus
187 }
188 #endif
189 #endif // _LINHALL_H_
190  // End public_function group
193 
194 // ------------------------------------------------------------------------- END
linhall_cfg_t
Click configuration structure definition.
Definition: linhall.h:108
linhall_t::spi
spi_master_t spi
Definition: linhall.h:99
linhall_cfg_t::cs
pin_name_t cs
Definition: linhall.h:114
linhall_t::chip_select
pin_name_t chip_select
Definition: linhall.h:100
linhall_cfg_t::miso
pin_name_t miso
Definition: linhall.h:111
linhall_t::cs
digital_out_t cs
Definition: linhall.h:95
linhall_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: linhall.h:120
linhall_t
Click ctx object definition.
Definition: linhall.h:94
LINHALL_RETVAL
#define LINHALL_RETVAL
Definition: linhall.h:77
linhall_cfg_setup
void linhall_cfg_setup(linhall_cfg_t *cfg)
Config Object Initialization function.
linhall_init
LINHALL_RETVAL linhall_init(linhall_t *ctx, linhall_cfg_t *cfg)
Initialization function.
linhall_cfg_t::mosi
pin_name_t mosi
Definition: linhall.h:112
linhall_cfg_t::spi_speed
uint32_t spi_speed
Definition: linhall.h:118
linhall_generic_transfer
void linhall_generic_transfer(linhall_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
linhall_cfg_t::sck
pin_name_t sck
Definition: linhall.h:113
linhall_read_data
uint16_t linhall_read_data(linhall_t *ctx)
Read 12-bit data function.
linhall_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: linhall.h:119