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
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_digital_out.h"
53#include "drv_spi_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
66#define c420MAR_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.en = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define c420MAR_RETVAL uint8_t
79
80#define c420MAR_OK 0x00
81#define c420MAR_INIT_ERROR 0xFF
84 // End group macro
85// --------------------------------------------------------------- PUBLIC TYPES
94typedef struct
95{
96 digital_out_t cs;
97
98 // Output pins
99
100 digital_out_t en;
101
102 // Modules
103
104 spi_master_t spi;
105 pin_name_t chip_select;
106
107} c420mar_t;
108
112typedef struct
113{
114 // Communication gpio pins
115
116 pin_name_t miso;
117 pin_name_t mosi;
118 pin_name_t sck;
119 pin_name_t cs;
120
121 // Additional gpio pins
122
123 pin_name_t en;
124
125 // static variable
126
127 uint32_t spi_speed;
128 spi_master_mode_t spi_mode;
129 spi_master_chip_select_polarity_t cs_polarity;
130
132
133 // End types group
134// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135
140#ifdef __cplusplus
141extern "C"{
142#endif
143
153
163
175void c420mar_generic_transfer ( c420mar_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
176
186
187#ifdef __cplusplus
188}
189#endif
190#endif // _c420MAR_H_
191
192 // End public_function group
194
195// ------------------------------------------------------------------------- END
#define c420MAR_RETVAL
Definition c420mar.h:78
float c420mar_read_data(c420mar_t *ctx)
Read data function.
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.
void c420mar_cfg_setup(c420mar_cfg_t *cfg)
Config Object Initialization function.
c420MAR_RETVAL c420mar_init(c420mar_t *ctx, c420mar_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition c420mar.h:113
spi_master_chip_select_polarity_t cs_polarity
Definition c420mar.h:129
pin_name_t sck
Definition c420mar.h:118
spi_master_mode_t spi_mode
Definition c420mar.h:128
pin_name_t mosi
Definition c420mar.h:117
uint32_t spi_speed
Definition c420mar.h:127
pin_name_t en
Definition c420mar.h:123
pin_name_t miso
Definition c420mar.h:116
pin_name_t cs
Definition c420mar.h:119
Click ctx object definition.
Definition c420mar.h:95
digital_out_t cs
Definition c420mar.h:96
spi_master_t spi
Definition c420mar.h:104
digital_out_t en
Definition c420mar.h:100
pin_name_t chip_select
Definition c420mar.h:105