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
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38#include "spi_specifics.h"
39
60#define EXPAND8_ADDR_OUT_LVL_PORT_P0 0x00
61#define EXPAND8_ADDR_OUT_LVL_PORT_P1 0x01
62#define EXPAND8_ADDR_OUT_LVL_PORT_P2 0x02
63#define EXPAND8_ADDR_OUT_LVL_PORT_P3 0x03
64#define EXPAND8_ADDR_OUT_LVL_PORT_P4 0x04
65#define EXPAND8_ADDR_OUT_LVL_PORT_P5 0x05
66#define EXPAND8_ADDR_OUT_LVL_PORT_P6 0x06
67#define EXPAND8_ADDR_OUT_LVL_PORT_P7 0x07
68#define EXPAND8_ADDR_OUT_LVL_PORT_P8 0x08
69#define EXPAND8_ADDR_OUT_LVL_PORT_P9 0x09
70#define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P9 0x0A
71#define EXPAND8_ADDR_OUT_LVL_PORT_P0_THROUGH_P3 0x0B
72#define EXPAND8_ADDR_OUT_LVL_PORT_P4_THROUGH_P7 0x0C
73#define EXPAND8_ADDR_OUT_LVL_PORT_P8_THROUGH_P9 0x0D
74#define EXPAND8_ADDR_OUT_LVL_PORT_P7_THROUGH_P0 0x0E
75#define EXPAND8_ADDR_OUT_LVL_PORT_P9_THROUGH_P8 0x0F
76#define EXPAND8_ADDR_RAM 0x13
77#define EXPAND8_ADDR_NOP 0x20
78
83#define EXPAND8_SET_LOW_IMPEDANCE 0x00
84#define EXPAND8_SET_HIGH_IMPEDANCE 0xFF
85
90#define EXPAND8_CMD_WRITE 0x00
91#define EXPAND8_CMD_READ 0x80
92
101#define EXPAND8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
102#define EXPAND8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
103 // expand8_set
105
120#define EXPAND8_MAP_MIKROBUS( cfg, mikrobus ) \
121 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
122 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
123 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
124 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
125 // expand8_map // expand8
128
133typedef struct
134{
135 // Modules
136 spi_master_t spi;
138 pin_name_t chip_select;
140} expand8_t;
141
146typedef struct
147{
148 // Communication gpio pins
149 pin_name_t miso;
150 pin_name_t mosi;
151 pin_name_t sck;
152 pin_name_t cs;
154 // static variable
155 uint32_t spi_speed;
156 spi_master_mode_t spi_mode;
157 spi_master_chip_select_polarity_t cs_polarity;
160
165typedef enum
166{
168 EXPAND8_ERROR = -1
169
171
188
203
218err_t expand8_generic_write ( expand8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
219
234err_t expand8_generic_read ( expand8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
235
236
249void expand8_write_data ( expand8_t *ctx, uint8_t addr, uint8_t tx_data );
250
262uint8_t expand8_read_data ( expand8_t *ctx, uint8_t addr );
263
278err_t expand8_set_port ( expand8_t *ctx, uint8_t sel_port, uint8_t sel_imped );
279
280#ifdef __cplusplus
281}
282#endif
283#endif // EXPAND8_H
284 // expand8
286
287// ------------------------------------------------------------------------ END
expand8_return_value_t
Expand 8 Click return value data.
Definition: expand8.h:166
@ EXPAND8_ERROR
Definition: expand8.h:168
@ EXPAND8_OK
Definition: expand8.h:167
void expand8_write_data(expand8_t *ctx, uint8_t addr, uint8_t tx_data)
Generic write data function.
err_t expand8_generic_read(expand8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 8 data reading function.
uint8_t expand8_read_data(expand8_t *ctx, uint8_t addr)
Generic read data function.
void expand8_cfg_setup(expand8_cfg_t *cfg)
Expand 8 configuration object setup function.
err_t expand8_set_port(expand8_t *ctx, uint8_t sel_port, uint8_t sel_imped)
Set port function.
err_t expand8_generic_write(expand8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 8 data writing function.
err_t expand8_init(expand8_t *ctx, expand8_cfg_t *cfg)
Expand 8 initialization function.
This file contains SPI specific macros, functions, etc.
Expand 8 Click configuration object.
Definition: expand8.h:147
spi_master_chip_select_polarity_t cs_polarity
Definition: expand8.h:157
pin_name_t sck
Definition: expand8.h:151
spi_master_mode_t spi_mode
Definition: expand8.h:156
pin_name_t mosi
Definition: expand8.h:150
uint32_t spi_speed
Definition: expand8.h:155
pin_name_t miso
Definition: expand8.h:149
pin_name_t cs
Definition: expand8.h:152
Expand 8 Click context object.
Definition: expand8.h:134
spi_master_t spi
Definition: expand8.h:136
pin_name_t chip_select
Definition: expand8.h:138