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 MCP2542_DRV_RX_BUFFER_SIZE 500
64 #define MCP2542_DRV_TX_BUFFER_SIZE 500
65 
71 #define MCP2542_RETVAL uint8_t
72 
73 #define MCP2542_OK 0x00
74 #define MCP2542_INIT_ERROR 0xFF
75 
81 #define MCP2542_STANDBY_MODE_ON 1
82 #define MCP2542_STANDBY_MODE_OFF 0
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
92 //typedef uart_data_t char;
93 
97 typedef struct
98 {
99  // Output pins
100 
101  digital_out_t stb;
102 
103  uart_t uart;
104 
105  uint8_t uart_rx_buffer[ MCP2542_DRV_RX_BUFFER_SIZE ];
106  uint8_t uart_tx_buffer[ MCP2542_DRV_TX_BUFFER_SIZE ];
107 
108 } mcp2542_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116 
117  pin_name_t rx_pin;
118  pin_name_t tx_pin;
119 
120  // Additional gpio pins
121 
122  pin_name_t stb;
123 
124 
125  // static variable
126 
127  uint32_t baud_rate; // Clock speed.
129  uart_data_bits_t data_bit; // Data bits.
130  uart_parity_t parity_bit; // Parity bit.
131  uart_stop_bits_t stop_bit; // Stop bits.
132 
133 } mcp2542_cfg_t;
134  // End types group
136 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
137 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
165 
174 
184 void mcp2542_generic_multi_write ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
185 
195 void mcp2542_generic_multi_read ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
196 
197 
207 
216 void mcp2542_generic_single_write ( mcp2542_t *ctx, uint8_t tx_data );
217 
226 void mcp2542_set_mode ( mcp2542_t *ctx, uint8_t mode );
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif // _MCP2542_H_
232  // End public_function group
235 
236 // ------------------------------------------------------------------------- END
mcp2542_generic_single_read
uint8_t mcp2542_generic_single_read(mcp2542_t *ctx)
Generic single read function.
mcp2542_t
Click ctx object definition.
Definition: mcp2542.h:98
mcp2542_t::stb
digital_out_t stb
Definition: mcp2542.h:101
mcp2542_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mcp2542.h:129
MCP2542_RETVAL
#define MCP2542_RETVAL
Definition: mcp2542.h:71
mcp2542_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mcp2542.h:117
mcp2542_init
MCP2542_RETVAL mcp2542_init(mcp2542_t *ctx, mcp2542_cfg_t *cfg)
Initialization function.
mcp2542_generic_multi_read
void mcp2542_generic_multi_read(mcp2542_t *ctx, uint8_t *data_buf, uint8_t len)
Generic multi read function.
mcp2542_cfg_t::stb
pin_name_t stb
Definition: mcp2542.h:122
mcp2542_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mcp2542.h:130
mcp2542_cfg_t::uart_blocking
bool uart_blocking
Definition: mcp2542.h:128
mcp2542_t::uart
uart_t uart
Definition: mcp2542.h:103
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:114
MCP2542_DRV_TX_BUFFER_SIZE
#define MCP2542_DRV_TX_BUFFER_SIZE
Definition: mcp2542.h:64
mcp2542_cfg_t::baud_rate
uint32_t baud_rate
Definition: mcp2542.h:127
mcp2542_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mcp2542.h:118
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:131
mcp2542_generic_single_write
void mcp2542_generic_single_write(mcp2542_t *ctx, uint8_t tx_data)
Generic single write function.
MCP2542_DRV_RX_BUFFER_SIZE
#define MCP2542_DRV_RX_BUFFER_SIZE
Definition: mcp2542.h:63
mcp2542_generic_multi_write
void mcp2542_generic_multi_write(mcp2542_t *ctx, uint8_t *data_buf, uint8_t len)
Generic multi write function.
mcp2542_default_cfg
void mcp2542_default_cfg(mcp2542_t *ctx)
Click Default Configuration function.