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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_spi_master.h"
47 #include "spi_specifics.h"
48 
69 #define MUX9_SELECT_CH_1 1
70 #define MUX9_SELECT_CH_2 2
71 #define MUX9_SELECT_CH_3 3
72 #define MUX9_SELECT_CH_4 4
73 #define MUX9_SELECT_CH_5 5
74 #define MUX9_SELECT_CH_6 6
75 #define MUX9_SELECT_CH_7 7
76 #define MUX9_SELECT_CH_8 8
77 
86 #define MUX9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
87 #define MUX9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
88  // mux9_set
90 
105 #define MUX9_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
107  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
108  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
109  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
110  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
111  // mux9_map // mux9
114 
119 typedef struct
120 {
121  // Output pins
122  digital_out_t rst;
124  // Modules
125  spi_master_t spi;
127  pin_name_t chip_select;
129 } mux9_t;
130 
135 typedef struct
136 {
137  // Communication gpio pins
138  pin_name_t miso;
139  pin_name_t mosi;
140  pin_name_t sck;
141  pin_name_t cs;
143  // Additional gpio pins
144  pin_name_t rst;
146  // static variable
147  uint32_t spi_speed;
148  spi_master_mode_t spi_mode;
149  spi_master_chip_select_polarity_t cs_polarity;
151 } mux9_cfg_t;
152 
157 typedef enum
158 {
159  MUX9_OK = 0,
160  MUX9_ERROR = -1
161 
163 
180 
194 err_t mux9_init ( mux9_t *ctx, mux9_cfg_t *cfg );
195 
208 void mux9_reset ( mux9_t *ctx );
209 
222 void mux9_enable ( mux9_t *ctx );
223 
236 void mux9_disable ( mux9_t *ctx );
237 
250 err_t mux9_generic_write ( mux9_t *ctx, uint8_t data_in );
251 
266 err_t mux9_active_channel ( mux9_t *ctx, uint8_t sel_ch );
267 
268 #ifdef __cplusplus
269 }
270 #endif
271 #endif // MUX9_H
272  // mux9
274 
275 // ------------------------------------------------------------------------ END
mux9_cfg_t::mosi
pin_name_t mosi
Definition: mux9.h:139
mux9_disable
void mux9_disable(mux9_t *ctx)
MUX 9 disable function.
mux9_cfg_t::cs
pin_name_t cs
Definition: mux9.h:141
mux9_cfg_t::spi_speed
uint32_t spi_speed
Definition: mux9.h:147
spi_specifics.h
This file contains SPI specific macros, functions, etc.
mux9_cfg_t::rst
pin_name_t rst
Definition: mux9.h:144
mux9_cfg_setup
void mux9_cfg_setup(mux9_cfg_t *cfg)
MUX 9 configuration object setup function.
mux9_cfg_t::sck
pin_name_t sck
Definition: mux9.h:140
mux9_t::rst
digital_out_t rst
Definition: mux9.h:122
mux9_return_value_t
mux9_return_value_t
MUX 9 Click return value data.
Definition: mux9.h:158
mux9_init
err_t mux9_init(mux9_t *ctx, mux9_cfg_t *cfg)
MUX 9 initialization function.
mux9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mux9.h:149
mux9_t::spi
spi_master_t spi
Definition: mux9.h:125
MUX9_OK
@ MUX9_OK
Definition: mux9.h:159
MUX9_ERROR
@ MUX9_ERROR
Definition: mux9.h:160
mux9_generic_write
err_t mux9_generic_write(mux9_t *ctx, uint8_t data_in)
MUX 9 data writing function.
mux9_t
MUX 9 Click context object.
Definition: mux9.h:120
mux9_cfg_t::miso
pin_name_t miso
Definition: mux9.h:138
mux9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mux9.h:148
mux9_enable
void mux9_enable(mux9_t *ctx)
MUX 9 enable function.
mux9_cfg_t
MUX 9 Click configuration object.
Definition: mux9.h:136
mux9_reset
void mux9_reset(mux9_t *ctx)
MUX 9 reset function.
mux9_active_channel
err_t mux9_active_channel(mux9_t *ctx, uint8_t sel_ch)
MUX 9 active channel function.
mux9_t::chip_select
pin_name_t chip_select
Definition: mux9.h:127