expand4  2.0.0.0
expand4.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef EXPAND4_H
36 #define EXPAND4_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define EXPAND4_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.clr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
74 
80 #define EXPAND4_RETVAL uint8_t
81 
82 #define EXPAND4_OK 0x00
83 #define EXPAND4_INIT_ERROR 0xFF
84 
90 #define EXPAND4_D0 0x01
91 #define EXPAND4_D1 0x02
92 #define EXPAND4_D2 0x04
93 #define EXPAND4_D3 0x08
94 #define EXPAND4_D4 0x10
95 #define EXPAND4_D5 0x20
96 #define EXPAND4_D6 0x40
97 #define EXPAND4_D7 0x80
98  // End group macro
101 // --------------------------------------------------------------- PUBLIC TYPES
110 typedef struct
111 {
112  // Output pins
113 
114  digital_out_t cs;
115  digital_out_t clr;
116  digital_out_t en;
117 
118  // Modules
119 
120  spi_master_t spi;
121  pin_name_t chip_select;
122 
123 } expand4_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t miso;
133  pin_name_t mosi;
134  pin_name_t sck;
135  pin_name_t cs;
136 
137  // Additional gpio pins
138 
139  pin_name_t clr;
140  pin_name_t en;
141 
142  // static variable
143 
144  uint32_t spi_speed;
145  spi_master_mode_t spi_mode;
146  spi_master_chip_select_polarity_t cs_polarity;
147 
148 } expand4_cfg_t;
149  // End types group
151 
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
190 
199 
207 void expand4_reset ( expand4_t *ctx );
208 
217 void expand4_write_data ( expand4_t *ctx, uint8_t write_command );
218 
235 void expand4_turn_on_by_position ( expand4_t *ctx, uint8_t position );
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 #endif // _EXPAND4_H_
241  // End public_function group
244 
245 // ------------------------------------------------------------------------- END
expand4_cfg_t
Click configuration structure definition.
Definition: expand4.h:129
expand4_t::chip_select
pin_name_t chip_select
Definition: expand4.h:121
expand4_cfg_t::clr
pin_name_t clr
Definition: expand4.h:139
expand4_cfg_t::spi_speed
uint32_t spi_speed
Definition: expand4.h:144
expand4_disable_output
void expand4_disable_output(expand4_t *ctx)
Disable output function.
expand4_init
EXPAND4_RETVAL expand4_init(expand4_t *ctx, expand4_cfg_t *cfg)
Initialization function.
expand4_cfg_t::mosi
pin_name_t mosi
Definition: expand4.h:133
expand4_cfg_t::sck
pin_name_t sck
Definition: expand4.h:134
expand4_cfg_setup
void expand4_cfg_setup(expand4_cfg_t *cfg)
Config Object Initialization function.
expand4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: expand4.h:145
expand4_cfg_t::en
pin_name_t en
Definition: expand4.h:140
expand4_t::en
digital_out_t en
Definition: expand4.h:116
expand4_t::cs
digital_out_t cs
Definition: expand4.h:114
expand4_write_data
void expand4_write_data(expand4_t *ctx, uint8_t write_command)
expand4_t::clr
digital_out_t clr
Definition: expand4.h:115
EXPAND4_RETVAL
#define EXPAND4_RETVAL
Definition: expand4.h:80
expand4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: expand4.h:146
expand4_cfg_t::miso
pin_name_t miso
Definition: expand4.h:132
expand4_t::spi
spi_master_t spi
Definition: expand4.h:120
expand4_enable_output
void expand4_enable_output(expand4_t *ctx)
Enable output function.
expand4_reset
void expand4_reset(expand4_t *ctx)
Clear register function.
expand4_cfg_t::cs
pin_name_t cs
Definition: expand4.h:135
expand4_turn_on_by_position
void expand4_turn_on_by_position(expand4_t *ctx, uint8_t position)
expand4_t
Click ctx object definition.
Definition: expand4.h:111