gsr  2.0.0.0
gsr.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 GSR_H
36 #define GSR_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 GSR_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 GSR_RETVAL uint8_t
65 
66 #define GSR_OK 0x00
67 #define GSR_INIT_ERROR 0xFF
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef struct
81 {
82  digital_out_t cs;
83  // Modules
84 
85  spi_master_t spi;
86  pin_name_t chip_select;
87 
88 } gsr_t;
89 
93 typedef struct
94 {
95  // Communication gpio pins
96 
97  pin_name_t miso;
98  pin_name_t mosi;
99  pin_name_t sck;
100  pin_name_t cs;
101 
102  // static variable
103 
104  uint32_t spi_speed;
105  spi_master_mode_t spi_mode;
106  spi_master_chip_select_polarity_t cs_polarity;
107 
108 } gsr_cfg_t;
109  // End types group
111 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
112 
117 #ifdef __cplusplus
118 extern "C"{
119 #endif
120 
129 void gsr_cfg_setup ( gsr_cfg_t *cfg );
130 
139 
149 (
150  gsr_t *ctx,
151  uint8_t *wr_buf,
152  uint16_t wr_len,
153  uint8_t *rd_buf,
154  uint16_t rd_len
155 );
156 
164 uint16_t gsr_read_value ( gsr_t *ctx );
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 #endif // _GSR_H_
170  // End public_function group
173 
174 // ------------------------------------------------------------------------- END
gsr_t
Click ctx object definition.
Definition: gsr.h:81
gsr_t::spi
spi_master_t spi
Definition: gsr.h:85
gsr_cfg_t::spi_speed
uint32_t spi_speed
Definition: gsr.h:104
gsr_cfg_t::cs
pin_name_t cs
Definition: gsr.h:100
gsr_init
GSR_RETVAL gsr_init(gsr_t *ctx, gsr_cfg_t *cfg)
Initialization function.
gsr_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gsr.h:106
gsr_cfg_setup
void gsr_cfg_setup(gsr_cfg_t *cfg)
Config Object Initialization function.
gsr_cfg_t::miso
pin_name_t miso
Definition: gsr.h:97
gsr_cfg_t::sck
pin_name_t sck
Definition: gsr.h:99
gsr_cfg_t
Click configuration structure definition.
Definition: gsr.h:94
gsr_t::cs
digital_out_t cs
Definition: gsr.h:82
gsr_cfg_t::mosi
pin_name_t mosi
Definition: gsr.h:98
GSR_RETVAL
#define GSR_RETVAL
Definition: gsr.h:64
gsr_read_value
uint16_t gsr_read_value(gsr_t *ctx)
Read Analog Value.
gsr_generic_transfer
void gsr_generic_transfer(gsr_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
gsr_t::chip_select
pin_name_t chip_select
Definition: gsr.h:86
gsr_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gsr.h:105