expand8  2.0.0.0
expand8.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 EXPAND8_H
29 #define EXPAND8_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 #include "spi_specifics.h"
53 
74 #define EXPAND8_ADDR_OUT_LVL_PORT_P0 0x00
75 #define EXPAND8_ADDR_OUT_LVL_PORT_P1 0x01
76 #define EXPAND8_ADDR_OUT_LVL_PORT_P2 0x02
77 #define EXPAND8_ADDR_OUT_LVL_PORT_P3 0x03
78 #define EXPAND8_ADDR_OUT_LVL_PORT_P4 0x04
79 #define EXPAND8_ADDR_OUT_LVL_PORT_P5 0x05
80 #define EXPAND8_ADDR_OUT_LVL_PORT_P6 0x06
81 #define EXPAND8_ADDR_OUT_LVL_PORT_P7 0x07
82 #define EXPAND8_ADDR_OUT_LVL_PORT_P8 0x08
83 #define EXPAND8_ADDR_OUT_LVL_PORT_P9 0x09
84 #define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P9 0x0A
85 #define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P3 0x0B
86 #define EXPAND8_ADDR_OUT_LVL_PORT_P4_THROUGH_P7 0x0C
87 #define EXPAND8_ADDR_OUT_LVL_PORT_P8_THROUGH_P9 0x0D
88 #define EXPAND8_ADDR_OUT_LVL_PORT_P7_THROUGH_P0 0x0E
89 #define EXPAND8_ADDR_OUT_LVL_PORT_P9_THROUGH_P8 0x0F
90 #define EXPAND8_ADDR_RAM 0x13
91 #define EXPAND8_ADDR_NOP 0x20
92 
97 #define EXPAND8_SET_LOW_IMPEDANCE 0x00
98 #define EXPAND8_SET_HIGH_IMPEDANCE 0xFF
99 
104 #define EXPAND8_CMD_WRITE 0x00
105 #define EXPAND8_CMD_READ 0x80
106 
115 #define EXPAND8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
116 #define EXPAND8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
117  // expand8_set
119 
134 #define EXPAND8_MAP_MIKROBUS( cfg, mikrobus ) \
135  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
136  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
137  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
138  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
139  // expand8_map // expand8
142 
147 typedef struct
148 {
149  // Modules
150  spi_master_t spi;
152  pin_name_t chip_select;
154 } expand8_t;
155 
160 typedef struct
161 {
162  // Communication gpio pins
163  pin_name_t miso;
164  pin_name_t mosi;
165  pin_name_t sck;
166  pin_name_t cs;
168  // static variable
169  uint32_t spi_speed;
170  spi_master_mode_t spi_mode;
171  spi_master_chip_select_polarity_t cs_polarity;
173 } expand8_cfg_t;
174 
179 typedef enum
180 {
182  EXPAND8_ERROR = -1
183 
185 
202 
216 err_t expand8_init ( expand8_t *ctx, expand8_cfg_t *cfg );
217 
232 err_t expand8_generic_write ( expand8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
233 
248 err_t expand8_generic_read ( expand8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
249 
250 
263 void expand8_write_data ( expand8_t *ctx, uint8_t addr, uint8_t tx_data );
264 
276 uint8_t expand8_read_data ( expand8_t *ctx, uint8_t addr );
277 
292 err_t expand8_set_port ( expand8_t *ctx, uint8_t sel_port, uint8_t sel_imped );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // EXPAND8_H
298  // expand8
300 
301 // ------------------------------------------------------------------------ END
expand8_cfg_t::spi_speed
uint32_t spi_speed
Definition: expand8.h:169
expand8_cfg_t
Expand 8 Click configuration object.
Definition: expand8.h:161
expand8_set_port
err_t expand8_set_port(expand8_t *ctx, uint8_t sel_port, uint8_t sel_imped)
Set port function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
expand8_cfg_t::mosi
pin_name_t mosi
Definition: expand8.h:164
expand8_generic_read
err_t expand8_generic_read(expand8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 8 data reading function.
expand8_t
Expand 8 Click context object.
Definition: expand8.h:148
expand8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: expand8.h:171
expand8_cfg_t::sck
pin_name_t sck
Definition: expand8.h:165
expand8_cfg_t::miso
pin_name_t miso
Definition: expand8.h:163
expand8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: expand8.h:170
EXPAND8_OK
@ EXPAND8_OK
Definition: expand8.h:181
expand8_read_data
uint8_t expand8_read_data(expand8_t *ctx, uint8_t addr)
Generic read data function.
expand8_init
err_t expand8_init(expand8_t *ctx, expand8_cfg_t *cfg)
Expand 8 initialization function.
expand8_return_value_t
expand8_return_value_t
Expand 8 Click return value data.
Definition: expand8.h:180
expand8_cfg_setup
void expand8_cfg_setup(expand8_cfg_t *cfg)
Expand 8 configuration object setup function.
expand8_cfg_t::cs
pin_name_t cs
Definition: expand8.h:166
expand8_t::chip_select
pin_name_t chip_select
Definition: expand8.h:152
expand8_generic_write
err_t expand8_generic_write(expand8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 8 data writing function.
expand8_write_data
void expand8_write_data(expand8_t *ctx, uint8_t addr, uint8_t tx_data)
Generic write data function.
expand8_t::spi
spi_master_t spi
Definition: expand8.h:150
EXPAND8_ERROR
@ EXPAND8_ERROR
Definition: expand8.h:182