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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define MCP2542_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_AN )
71 
77 #define MCP2542_DRV_RX_BUFFER_SIZE 500
78 #define MCP2542_DRV_TX_BUFFER_SIZE 500
79 
85 #define MCP2542_RETVAL uint8_t
86 
87 #define MCP2542_OK 0x00
88 #define MCP2542_INIT_ERROR 0xFF
89 
95 #define MCP2542_STANDBY_MODE_ON 1
96 #define MCP2542_STANDBY_MODE_OFF 0
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
106 //typedef uart_data_t char;
107 
111 typedef struct
112 {
113  // Output pins
114 
115  digital_out_t stb;
116 
117  uart_t uart;
118 
119  uint8_t uart_rx_buffer[ MCP2542_DRV_RX_BUFFER_SIZE ];
120  uint8_t uart_tx_buffer[ MCP2542_DRV_TX_BUFFER_SIZE ];
121 
122 } mcp2542_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t rx_pin;
132  pin_name_t tx_pin;
133 
134  // Additional gpio pins
135 
136  pin_name_t stb;
137 
138 
139  // static variable
140 
141  uint32_t baud_rate; // Clock speed.
143  uart_data_bits_t data_bit; // Data bits.
144  uart_parity_t parity_bit; // Parity bit.
145  uart_stop_bits_t stop_bit; // Stop bits.
146 
147 } mcp2542_cfg_t;
148  // End types group
150 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
151 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
179 
188 
198 void mcp2542_generic_multi_write ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
199 
209 void mcp2542_generic_multi_read ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
210 
211 
221 
230 void mcp2542_generic_single_write ( mcp2542_t *ctx, uint8_t tx_data );
231 
240 void mcp2542_set_mode ( mcp2542_t *ctx, uint8_t mode );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _MCP2542_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- 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:112
mcp2542_t::stb
digital_out_t stb
Definition: mcp2542.h:115
mcp2542_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mcp2542.h:143
MCP2542_RETVAL
#define MCP2542_RETVAL
Definition: mcp2542.h:85
mcp2542_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mcp2542.h:131
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:136
mcp2542_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mcp2542.h:144
mcp2542_cfg_t::uart_blocking
bool uart_blocking
Definition: mcp2542.h:142
mcp2542_t::uart
uart_t uart
Definition: mcp2542.h:117
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:128
MCP2542_DRV_TX_BUFFER_SIZE
#define MCP2542_DRV_TX_BUFFER_SIZE
Definition: mcp2542.h:78
mcp2542_cfg_t::baud_rate
uint32_t baud_rate
Definition: mcp2542.h:141
mcp2542_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mcp2542.h:132
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:145
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:77
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.