mcp2003b  2.1.0.0
mcp2003b.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 MCP2003B_H
29 #define MCP2003B_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_uart.h"
48 
70 #define MCP2003B_TX_DRV_BUFFER_SIZE 100
71 #define MCP2003B_RX_DRV_BUFFER_SIZE 300
72  // mcp2003b_cmd
74 
89 #define MCP2003B_MAP_MIKROBUS( cfg, mikrobus ) \
90  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
91  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
92  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
93  // mcp2003b_map // mcp2003b
96 
101 typedef struct
102 {
103  // Output pins
104  digital_out_t cs;
106  // Modules
107  uart_t uart;
109  // Buffers
110  uint8_t uart_rx_buffer[ MCP2003B_RX_DRV_BUFFER_SIZE ];
111  uint8_t uart_tx_buffer[ MCP2003B_TX_DRV_BUFFER_SIZE ];
113 } mcp2003b_t;
114 
119 typedef struct
120 {
121  // Communication gpio pins
122  pin_name_t rx_pin;
123  pin_name_t tx_pin;
125  // Additional gpio pins
126  pin_name_t cs;
128  // Static variable
129  uint32_t baud_rate;
131  uart_data_bits_t data_bit;
132  uart_parity_t parity_bit;
133  uart_stop_bits_t stop_bit;
136 
141 typedef enum
142 {
144  MCP2003B_ERROR = -1
145 
147 
164 
179 
192 err_t mcp2003b_generic_write ( mcp2003b_t *ctx, uint8_t *data_in, uint16_t len );
193 
206 err_t mcp2003b_generic_read ( mcp2003b_t *ctx, uint8_t *data_out, uint16_t len );
207 
217 void mcp2003b_set_cs_pin ( mcp2003b_t *ctx, uint8_t state );
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 #endif // MCP2003B_H
223  // mcp2003b
225 
226 // ------------------------------------------------------------------------ END
MCP2003B_OK
@ MCP2003B_OK
Definition: mcp2003b.h:143
mcp2003b_set_cs_pin
void mcp2003b_set_cs_pin(mcp2003b_t *ctx, uint8_t state)
MCP2003B set cs pin function.
mcp2003b_t::uart
uart_t uart
Definition: mcp2003b.h:107
mcp2003b_return_value_t
mcp2003b_return_value_t
MCP2003B Click return value data.
Definition: mcp2003b.h:142
mcp2003b_t
MCP2003B Click context object.
Definition: mcp2003b.h:102
mcp2003b_generic_write
err_t mcp2003b_generic_write(mcp2003b_t *ctx, uint8_t *data_in, uint16_t len)
MCP2003B data writing function.
mcp2003b_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mcp2003b.h:122
mcp2003b_cfg_t::baud_rate
uint32_t baud_rate
Definition: mcp2003b.h:129
mcp2003b_cfg_t
MCP2003B Click configuration object.
Definition: mcp2003b.h:120
mcp2003b_init
err_t mcp2003b_init(mcp2003b_t *ctx, mcp2003b_cfg_t *cfg)
MCP2003B initialization function.
mcp2003b_generic_read
err_t mcp2003b_generic_read(mcp2003b_t *ctx, uint8_t *data_out, uint16_t len)
MCP2003B data reading function.
mcp2003b_cfg_t::cs
pin_name_t cs
Definition: mcp2003b.h:126
mcp2003b_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mcp2003b.h:132
MCP2003B_ERROR
@ MCP2003B_ERROR
Definition: mcp2003b.h:144
mcp2003b_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: mcp2003b.h:133
mcp2003b_cfg_t::uart_blocking
bool uart_blocking
Definition: mcp2003b.h:130
mcp2003b_cfg_setup
void mcp2003b_cfg_setup(mcp2003b_cfg_t *cfg)
MCP2003B configuration object setup function.
MCP2003B_RX_DRV_BUFFER_SIZE
#define MCP2003B_RX_DRV_BUFFER_SIZE
Definition: mcp2003b.h:71
MCP2003B_TX_DRV_BUFFER_SIZE
#define MCP2003B_TX_DRV_BUFFER_SIZE
MCP2003B driver buffer size.
Definition: mcp2003b.h:70
mcp2003b_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mcp2003b.h:131
mcp2003b_t::cs
digital_out_t cs
Definition: mcp2003b.h:104
mcp2003b_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mcp2003b.h:123