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 "drv_digital_out.h"
36 #include "drv_spi_master.h"
37 #include "spi_specifics.h"
38 
59 #define MUX9_SELECT_CH_1 1
60 #define MUX9_SELECT_CH_2 2
61 #define MUX9_SELECT_CH_3 3
62 #define MUX9_SELECT_CH_4 4
63 #define MUX9_SELECT_CH_5 5
64 #define MUX9_SELECT_CH_6 6
65 #define MUX9_SELECT_CH_7 7
66 #define MUX9_SELECT_CH_8 8
67 
76 #define MUX9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
77 #define MUX9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
78  // mux9_set
80 
95 #define MUX9_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
97  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
98  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
99  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
100  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
101  // mux9_map // mux9
104 
109 typedef struct
110 {
111  // Output pins
112  digital_out_t rst;
114  // Modules
115  spi_master_t spi;
117  pin_name_t chip_select;
119 } mux9_t;
120 
125 typedef struct
126 {
127  // Communication gpio pins
128  pin_name_t miso;
129  pin_name_t mosi;
130  pin_name_t sck;
131  pin_name_t cs;
133  // Additional gpio pins
134  pin_name_t rst;
136  // static variable
137  uint32_t spi_speed;
138  spi_master_mode_t spi_mode;
139  spi_master_chip_select_polarity_t cs_polarity;
141 } mux9_cfg_t;
142 
147 typedef enum
148 {
149  MUX9_OK = 0,
150  MUX9_ERROR = -1
151 
153 
170 
184 err_t mux9_init ( mux9_t *ctx, mux9_cfg_t *cfg );
185 
198 void mux9_reset ( mux9_t *ctx );
199 
212 void mux9_enable ( mux9_t *ctx );
213 
226 void mux9_disable ( mux9_t *ctx );
227 
240 err_t mux9_generic_write ( mux9_t *ctx, uint8_t data_in );
241 
256 err_t mux9_active_channel ( mux9_t *ctx, uint8_t sel_ch );
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 #endif // MUX9_H
262  // mux9
264 
265 // ------------------------------------------------------------------------ END
mux9_cfg_t::mosi
pin_name_t mosi
Definition: mux9.h:129
mux9_disable
void mux9_disable(mux9_t *ctx)
MUX 9 disable function.
mux9_cfg_t::cs
pin_name_t cs
Definition: mux9.h:131
mux9_cfg_t::spi_speed
uint32_t spi_speed
Definition: mux9.h:137
spi_specifics.h
This file contains SPI specific macros, functions, etc.
mux9_cfg_t::rst
pin_name_t rst
Definition: mux9.h:134
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:130
mux9_t::rst
digital_out_t rst
Definition: mux9.h:112
mux9_return_value_t
mux9_return_value_t
MUX 9 Click return value data.
Definition: mux9.h:148
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:139
mux9_t::spi
spi_master_t spi
Definition: mux9.h:115
MUX9_OK
@ MUX9_OK
Definition: mux9.h:149
MUX9_ERROR
@ MUX9_ERROR
Definition: mux9.h:150
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:110
mux9_cfg_t::miso
pin_name_t miso
Definition: mux9.h:128
mux9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mux9.h:138
mux9_enable
void mux9_enable(mux9_t *ctx)
MUX 9 enable function.
mux9_cfg_t
MUX 9 Click configuration object.
Definition: mux9.h:126
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:117