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 
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_digital_in.h"
51 #include "drv_spi_master.h"
52 
53 
68 #define POWERMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
73  // powermux2_map // powermux2
75 
80 typedef struct
81 {
82  // Modules
83 
84  spi_master_t spi;
86  pin_name_t chip_select;
88 } powermux2_t;
89 
94 typedef struct
95 {
96  // Communication gpio pins
97 
98  pin_name_t miso;
99  pin_name_t mosi;
100  pin_name_t sck;
101  pin_name_t cs;
103  // static variable
104 
105  uint32_t spi_speed;
106  spi_master_mode_t spi_mode;
107  spi_master_chip_select_polarity_t cs_polarity;
110 
115 typedef enum
116 {
118  POWERMUX2_ERROR = -1
119 
121 
138 
154 
168 err_t powermux2_generic_write ( powermux2_t *ctx, uint8_t data_in );
169 
184 err_t powermux2_set_resistance ( powermux2_t *ctx, float resistance );
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 #endif // POWERMUX2_H
190  // powermux2
192 
193 // ------------------------------------------------------------------------ END
powermux2_cfg_t::sck
pin_name_t sck
Definition: powermux2.h:100
powermux2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: powermux2.h:107
powermux2_t::chip_select
pin_name_t chip_select
Definition: powermux2.h:86
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:117
powermux2_cfg_t::miso
pin_name_t miso
Definition: powermux2.h:98
powermux2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: powermux2.h:106
powermux2_cfg_t::mosi
pin_name_t mosi
Definition: powermux2.h:99
powermux2_return_value_t
powermux2_return_value_t
Power MUX 2 Click return value data.
Definition: powermux2.h:116
POWERMUX2_ERROR
@ POWERMUX2_ERROR
Definition: powermux2.h:118
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:101
powermux2_t
Power MUX 2 Click context object.
Definition: powermux2.h:81
powermux2_t::spi
spi_master_t spi
Definition: powermux2.h:84
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:95
powermux2_cfg_t::spi_speed
uint32_t spi_speed
Definition: powermux2.h:105
powermux2_init
err_t powermux2_init(powermux2_t *ctx, powermux2_cfg_t *cfg)
Power MUX 2 initialization function.