mux9 2.1.0.0
mux9.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef MUX9_H
29#define MUX9_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_spi_master.h"
51#include "spi_specifics.h"
52
73#define MUX9_SELECT_CH_1 1
74#define MUX9_SELECT_CH_2 2
75#define MUX9_SELECT_CH_3 3
76#define MUX9_SELECT_CH_4 4
77#define MUX9_SELECT_CH_5 5
78#define MUX9_SELECT_CH_6 6
79#define MUX9_SELECT_CH_7 7
80#define MUX9_SELECT_CH_8 8
81
90#define MUX9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
91#define MUX9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
92
93 // mux9_set
94
109#define MUX9_MAP_MIKROBUS( cfg, mikrobus ) \
110 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
111 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
112 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
113 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
114 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
115
116 // mux9_map
117 // mux9
118
123typedef struct
124{
125 // Output pins
126 digital_out_t rst;
128 // Modules
129 spi_master_t spi;
131 pin_name_t chip_select;
133} mux9_t;
134
139typedef struct
140{
141 // Communication gpio pins
142 pin_name_t miso;
143 pin_name_t mosi;
144 pin_name_t sck;
145 pin_name_t cs;
147 // Additional gpio pins
148 pin_name_t rst;
150 // static variable
151 uint32_t spi_speed;
152 spi_master_mode_t spi_mode;
153 spi_master_chip_select_polarity_t cs_polarity;
155} mux9_cfg_t;
156
161typedef enum
162{
164 MUX9_ERROR = -1
165
167
184
198err_t mux9_init ( mux9_t *ctx, mux9_cfg_t *cfg );
199
212void mux9_reset ( mux9_t *ctx );
213
226void mux9_enable ( mux9_t *ctx );
227
240void mux9_disable ( mux9_t *ctx );
241
254err_t mux9_generic_write ( mux9_t *ctx, uint8_t data_in );
255
270err_t mux9_active_channel ( mux9_t *ctx, uint8_t sel_ch );
271
272#ifdef __cplusplus
273}
274#endif
275#endif // MUX9_H
276
277 // mux9
278
279// ------------------------------------------------------------------------ END
void mux9_disable(mux9_t *ctx)
MUX 9 disable function.
err_t mux9_active_channel(mux9_t *ctx, uint8_t sel_ch)
MUX 9 active channel function.
err_t mux9_init(mux9_t *ctx, mux9_cfg_t *cfg)
MUX 9 initialization function.
void mux9_cfg_setup(mux9_cfg_t *cfg)
MUX 9 configuration object setup function.
err_t mux9_generic_write(mux9_t *ctx, uint8_t data_in)
MUX 9 data writing function.
void mux9_enable(mux9_t *ctx)
MUX 9 enable function.
void mux9_reset(mux9_t *ctx)
MUX 9 reset function.
mux9_return_value_t
MUX 9 Click return value data.
Definition mux9.h:162
@ MUX9_OK
Definition mux9.h:163
@ MUX9_ERROR
Definition mux9.h:164
This file contains SPI specific macros, functions, etc.
MUX 9 Click configuration object.
Definition mux9.h:140
spi_master_chip_select_polarity_t cs_polarity
Definition mux9.h:153
pin_name_t sck
Definition mux9.h:144
spi_master_mode_t spi_mode
Definition mux9.h:152
pin_name_t mosi
Definition mux9.h:143
uint32_t spi_speed
Definition mux9.h:151
pin_name_t miso
Definition mux9.h:142
pin_name_t rst
Definition mux9.h:148
pin_name_t cs
Definition mux9.h:145
MUX 9 Click context object.
Definition mux9.h:124
spi_master_t spi
Definition mux9.h:129
digital_out_t rst
Definition mux9.h:126
pin_name_t chip_select
Definition mux9.h:131