mcp2542  2.0.0.0
mcp2542.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 MCP2542_H
36 #define MCP2542_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define MCP2542_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_AN )
57 
63 #define DRV_RX_BUFFER_SIZE 500
64 
70 #define MCP2542_RETVAL uint8_t
71 
72 #define MCP2542_OK 0x00
73 #define MCP2542_INIT_ERROR 0xFF
74 
80 #define MCP2542_STANDBY_MODE_ON 1
81 #define MCP2542_STANDBY_MODE_OFF 0
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
91 //typedef uart_data_t char;
92 
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t stb;
101 
102  uart_t uart;
103 
104  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
105  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
106 
107 } mcp2542_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t rx_pin;
117  pin_name_t tx_pin;
118 
119  // Additional gpio pins
120 
121  pin_name_t stb;
122 
123 
124  // static variable
125 
126  uint32_t baud_rate; // Clock speed.
128  uart_data_bits_t data_bit; // Data bits.
129  uart_parity_t parity_bit; // Parity bit.
130  uart_stop_bits_t stop_bit; // Stop bits.
131 
132 } mcp2542_cfg_t;
133  // End types group
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
154 void mcp2542_cfg_setup ( mcp2542_cfg_t *cfg );
155 
164 
172 void mcp2542_default_cfg( mcp2542_t *ctx );
173 
183 void mcp2542_generic_multi_write ( mcp2542_t *ctx, char *data_buf, char len );
184 
194 void mcp2542_generic_multi_read ( mcp2542_t *ctx, char *data_buf, char len );
195 
196 
206 
215 void mcp2542_generic_single_write ( mcp2542_t *ctx, char tx_data );
216 
225 void mcp2542_set_mode ( mcp2542_t *ctx, uint8_t mode );
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 #endif // _MCP2542_H_
231  // End public_function group
234 
235 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: mcp2542.h:63
mcp2542_t
Click ctx object definition.
Definition: mcp2542.h:96
mcp2542_t::stb
digital_out_t stb
Definition: mcp2542.h:100
mcp2542_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mcp2542.h:128
mcp2542_generic_single_read
char mcp2542_generic_single_read(mcp2542_t *ctx)
Generic single read function.
MCP2542_RETVAL
#define MCP2542_RETVAL
Definition: mcp2542.h:70
mcp2542_generic_multi_read
void mcp2542_generic_multi_read(mcp2542_t *ctx, char *data_buf, char len)
Generic multi read function.
mcp2542_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mcp2542.h:116
mcp2542_init
MCP2542_RETVAL mcp2542_init(mcp2542_t *ctx, mcp2542_cfg_t *cfg)
Initialization function.
mcp2542_cfg_t::stb
pin_name_t stb
Definition: mcp2542.h:121
mcp2542_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mcp2542.h:129
mcp2542_cfg_t::uart_blocking
bool uart_blocking
Definition: mcp2542.h:127
mcp2542_t::uart
uart_t uart
Definition: mcp2542.h:102
mcp2542_set_mode
void mcp2542_set_mode(mcp2542_t *ctx, uint8_t mode)
Set device mode.
mcp2542_cfg_t
Click configuration structure definition.
Definition: mcp2542.h:112
mcp2542_cfg_t::baud_rate
uint32_t baud_rate
Definition: mcp2542.h:126
mcp2542_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mcp2542.h:117
mcp2542_cfg_setup
void mcp2542_cfg_setup(mcp2542_cfg_t *cfg)
Config Object Initialization function.
mcp2542_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: mcp2542.h:130
mcp2542_generic_multi_write
void mcp2542_generic_multi_write(mcp2542_t *ctx, char *data_buf, char len)
Generic multi write function.
mcp2542_generic_single_write
void mcp2542_generic_single_write(mcp2542_t *ctx, char tx_data)
Generic single write function.
mcp2542_default_cfg
void mcp2542_default_cfg(mcp2542_t *ctx)
Click Default Configuration function.