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 
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 #include "spi_specifics.h"
49 
70 #define EXPAND8_ADDR_OUT_LVL_PORT_P0 0x00
71 #define EXPAND8_ADDR_OUT_LVL_PORT_P1 0x01
72 #define EXPAND8_ADDR_OUT_LVL_PORT_P2 0x02
73 #define EXPAND8_ADDR_OUT_LVL_PORT_P3 0x03
74 #define EXPAND8_ADDR_OUT_LVL_PORT_P4 0x04
75 #define EXPAND8_ADDR_OUT_LVL_PORT_P5 0x05
76 #define EXPAND8_ADDR_OUT_LVL_PORT_P6 0x06
77 #define EXPAND8_ADDR_OUT_LVL_PORT_P7 0x07
78 #define EXPAND8_ADDR_OUT_LVL_PORT_P8 0x08
79 #define EXPAND8_ADDR_OUT_LVL_PORT_P9 0x09
80 #define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P9 0x0A
81 #define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P3 0x0B
82 #define EXPAND8_ADDR_OUT_LVL_PORT_P4_THROUGH_P7 0x0C
83 #define EXPAND8_ADDR_OUT_LVL_PORT_P8_THROUGH_P9 0x0D
84 #define EXPAND8_ADDR_OUT_LVL_PORT_P7_THROUGH_P0 0x0E
85 #define EXPAND8_ADDR_OUT_LVL_PORT_P9_THROUGH_P8 0x0F
86 #define EXPAND8_ADDR_RAM 0x13
87 #define EXPAND8_ADDR_NOP 0x20
88 
93 #define EXPAND8_SET_LOW_IMPEDANCE 0x00
94 #define EXPAND8_SET_HIGH_IMPEDANCE 0xFF
95 
100 #define EXPAND8_CMD_WRITE 0x00
101 #define EXPAND8_CMD_READ 0x80
102 
111 #define EXPAND8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
112 #define EXPAND8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
113  // expand8_set
115 
130 #define EXPAND8_MAP_MIKROBUS( cfg, mikrobus ) \
131  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
132  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
133  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
134  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
135  // expand8_map // expand8
138 
143 typedef struct
144 {
145  // Modules
146  spi_master_t spi;
148  pin_name_t chip_select;
150 } expand8_t;
151 
156 typedef struct
157 {
158  // Communication gpio pins
159  pin_name_t miso;
160  pin_name_t mosi;
161  pin_name_t sck;
162  pin_name_t cs;
164  // static variable
165  uint32_t spi_speed;
166  spi_master_mode_t spi_mode;
167  spi_master_chip_select_polarity_t cs_polarity;
169 } expand8_cfg_t;
170 
175 typedef enum
176 {
178  EXPAND8_ERROR = -1
179 
181 
198 
212 err_t expand8_init ( expand8_t *ctx, expand8_cfg_t *cfg );
213 
228 err_t expand8_generic_write ( expand8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
229 
244 err_t expand8_generic_read ( expand8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
245 
246 
259 void expand8_write_data ( expand8_t *ctx, uint8_t addr, uint8_t tx_data );
260 
272 uint8_t expand8_read_data ( expand8_t *ctx, uint8_t addr );
273 
288 err_t expand8_set_port ( expand8_t *ctx, uint8_t sel_port, uint8_t sel_imped );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif // EXPAND8_H
294  // expand8
296 
297 // ------------------------------------------------------------------------ END
expand8_cfg_t::spi_speed
uint32_t spi_speed
Definition: expand8.h:165
expand8_cfg_t
Expand 8 Click configuration object.
Definition: expand8.h:157
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:160
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:144
expand8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: expand8.h:167
expand8_cfg_t::sck
pin_name_t sck
Definition: expand8.h:161
expand8_cfg_t::miso
pin_name_t miso
Definition: expand8.h:159
expand8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: expand8.h:166
EXPAND8_OK
@ EXPAND8_OK
Definition: expand8.h:177
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:176
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:162
expand8_t::chip_select
pin_name_t chip_select
Definition: expand8.h:148
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:146
EXPAND8_ERROR
@ EXPAND8_ERROR
Definition: expand8.h:178