c420mat  2.0.0.0
c420mat.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 C420MAT_H
36 #define C420MAT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define C420MAT_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
59 
65 #define C420MAT_RETVAL uint8_t
66 
67 #define C420MAT_OK 0x00
68 #define C420MAT_INIT_ERROR 0xFF
69  // End group macro
72 // --------------------------------------------------------------- PUBLIC TYPES
81 typedef struct
82 {
83  digital_out_t cs;
84 
85  // Modules
86 
87  spi_master_t spi;
88  pin_name_t chip_select;
89 
90 } c420mat_t;
91 
95 typedef struct
96 {
97  // Communication gpio pins
98 
99  pin_name_t miso;
100  pin_name_t mosi;
101  pin_name_t sck;
102  pin_name_t cs;
103 
104  // static variable
105 
106  uint32_t spi_speed;
107  spi_master_mode_t spi_mode;
108  spi_master_chip_select_polarity_t cs_polarity;
109 
110 } c420mat_cfg_t;
111  // End types group
113 
118 #ifdef __cplusplus
119 extern "C"{
120 #endif
121 
131 
141 
153 void c420mat_generic_transfer ( c420mat_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
154 
163 void c420mat_dac_output ( c420mat_t *ctx, uint16_t value_dac );
164 
173 void c420mat_set_i_out ( c420mat_t *ctx, uint8_t i_out );
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 #endif // _C420MAT_H_
179  // End public_function group
182 
183 // ------------------------------------------------------------------------- END
c420mat_generic_transfer
void c420mat_generic_transfer(c420mat_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
c420mat_cfg_t::cs
pin_name_t cs
Definition: c420mat.h:102
c420mat_t::chip_select
pin_name_t chip_select
Definition: c420mat.h:88
c420mat_cfg_t::sck
pin_name_t sck
Definition: c420mat.h:101
c420mat_cfg_t::spi_speed
uint32_t spi_speed
Definition: c420mat.h:106
c420mat_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c420mat.h:108
c420mat_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c420mat.h:107
c420mat_cfg_t
Click configuration structure definition.
Definition: c420mat.h:96
c420mat_cfg_t::mosi
pin_name_t mosi
Definition: c420mat.h:100
C420MAT_RETVAL
#define C420MAT_RETVAL
Definition: c420mat.h:65
c420mat_dac_output
void c420mat_dac_output(c420mat_t *ctx, uint16_t value_dac)
c420mat_dac_output.
c420mat_set_i_out
void c420mat_set_i_out(c420mat_t *ctx, uint8_t i_out)
t40ma_set_vout.
c420mat_t
Click ctx object definition.
Definition: c420mat.h:82
c420mat_t::spi
spi_master_t spi
Definition: c420mat.h:87
c420mat_cfg_t::miso
pin_name_t miso
Definition: c420mat.h:99
c420mat_cfg_setup
void c420mat_cfg_setup(c420mat_cfg_t *cfg)
Config Object Initialization function.
c420mat_t::cs
digital_out_t cs
Definition: c420mat.h:83
c420mat_init
C420MAT_RETVAL c420mat_init(c420mat_t *ctx, c420mat_cfg_t *cfg)
Initialization function.