c420mar  2.0.0.0
c420mar.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 c420MAR_H
36 #define c420MAR_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
52 #define c420MAR_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.en = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define c420MAR_RETVAL uint8_t
65 
66 #define c420MAR_OK 0x00
67 #define c420MAR_INIT_ERROR 0xFF
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef struct
81 {
82  digital_out_t cs;
83 
84  // Output pins
85 
86  digital_out_t en;
87 
88  // Modules
89 
90  spi_master_t spi;
91  pin_name_t chip_select;
92 
93 } c420mar_t;
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  // Additional gpio pins
108 
109  pin_name_t en;
110 
111  // static variable
112 
113  uint32_t spi_speed;
114  spi_master_mode_t spi_mode;
115  spi_master_chip_select_polarity_t cs_polarity;
116 
117 } c420mar_cfg_t;
118  // End types group
120 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
121 
126 #ifdef __cplusplus
127 extern "C"{
128 #endif
129 
139 
149 
161 void c420mar_generic_transfer ( c420mar_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
162 
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 #endif // _c420MAR_H_
177  // End public_function group
180 
181 // ------------------------------------------------------------------------- END
c420mar_cfg_setup
void c420mar_cfg_setup(c420mar_cfg_t *cfg)
Config Object Initialization function.
c420mar_t::spi
spi_master_t spi
Definition: c420mar.h:90
c420mar_t::cs
digital_out_t cs
Definition: c420mar.h:82
c420mar_cfg_t::en
pin_name_t en
Definition: c420mar.h:109
c420mar_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c420mar.h:115
c420mar_cfg_t::cs
pin_name_t cs
Definition: c420mar.h:105
c420mar_t::en
digital_out_t en
Definition: c420mar.h:86
c420mar_cfg_t::mosi
pin_name_t mosi
Definition: c420mar.h:103
c420mar_cfg_t::sck
pin_name_t sck
Definition: c420mar.h:104
c420mar_cfg_t
Click configuration structure definition.
Definition: c420mar.h:99
c420mar_cfg_t::miso
pin_name_t miso
Definition: c420mar.h:102
c420mar_read_data
float c420mar_read_data(c420mar_t *ctx)
Read data function.
c420MAR_RETVAL
#define c420MAR_RETVAL
Definition: c420mar.h:64
c420mar_t
Click ctx object definition.
Definition: c420mar.h:81
c420mar_t::chip_select
pin_name_t chip_select
Definition: c420mar.h:91
c420mar_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c420mar.h:114
c420mar_init
c420MAR_RETVAL c420mar_init(c420mar_t *ctx, c420mar_cfg_t *cfg)
Initialization function.
c420mar_cfg_t::spi_speed
uint32_t spi_speed
Definition: c420mar.h:113
c420mar_generic_transfer
void c420mar_generic_transfer(c420mar_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.