powermux2  2.0.0.0
powermux2.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 POWERMUX2_H
29 #define POWERMUX2_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_digital_in.h"
47 #include "drv_spi_master.h"
48 
49 
64 #define POWERMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
69  // powermux2_map // powermux2
71 
76 typedef struct
77 {
78  // Modules
79 
80  spi_master_t spi;
82  pin_name_t chip_select;
84 } powermux2_t;
85 
90 typedef struct
91 {
92  // Communication gpio pins
93 
94  pin_name_t miso;
95  pin_name_t mosi;
96  pin_name_t sck;
97  pin_name_t cs;
99  // static variable
100 
101  uint32_t spi_speed;
102  spi_master_mode_t spi_mode;
103  spi_master_chip_select_polarity_t cs_polarity;
106 
111 typedef enum
112 {
114  POWERMUX2_ERROR = -1
115 
117 
134 
150 
164 err_t powermux2_generic_write ( powermux2_t *ctx, uint8_t data_in );
165 
180 err_t powermux2_set_resistance ( powermux2_t *ctx, float resistance );
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif // POWERMUX2_H
186  // powermux2
188 
189 // ------------------------------------------------------------------------ END
powermux2_cfg_t::sck
pin_name_t sck
Definition: powermux2.h:96
powermux2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: powermux2.h:103
powermux2_t::chip_select
pin_name_t chip_select
Definition: powermux2.h:82
powermux2_set_resistance
err_t powermux2_set_resistance(powermux2_t *ctx, float resistance)
Power MUX 2 set resistance function.
POWERMUX2_OK
@ POWERMUX2_OK
Definition: powermux2.h:113
powermux2_cfg_t::miso
pin_name_t miso
Definition: powermux2.h:94
powermux2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: powermux2.h:102
powermux2_cfg_t::mosi
pin_name_t mosi
Definition: powermux2.h:95
powermux2_return_value_t
powermux2_return_value_t
Power MUX 2 Click return value data.
Definition: powermux2.h:112
POWERMUX2_ERROR
@ POWERMUX2_ERROR
Definition: powermux2.h:114
powermux2_generic_write
err_t powermux2_generic_write(powermux2_t *ctx, uint8_t data_in)
Power MUX 2 data writing function.
powermux2_cfg_t::cs
pin_name_t cs
Definition: powermux2.h:97
powermux2_t
Power MUX 2 Click context object.
Definition: powermux2.h:77
powermux2_t::spi
spi_master_t spi
Definition: powermux2.h:80
powermux2_cfg_setup
void powermux2_cfg_setup(powermux2_cfg_t *cfg)
Power MUX 2 configuration object setup function.
powermux2_cfg_t
Power MUX 2 Click configuration object.
Definition: powermux2.h:91
powermux2_cfg_t::spi_speed
uint32_t spi_speed
Definition: powermux2.h:101
powermux2_init
err_t powermux2_init(powermux2_t *ctx, powermux2_cfg_t *cfg)
Power MUX 2 initialization function.