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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define MCP2542_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_AN )
67 
73 #define MCP2542_DRV_RX_BUFFER_SIZE 500
74 #define MCP2542_DRV_TX_BUFFER_SIZE 500
75 
81 #define MCP2542_RETVAL uint8_t
82 
83 #define MCP2542_OK 0x00
84 #define MCP2542_INIT_ERROR 0xFF
85 
91 #define MCP2542_STANDBY_MODE_ON 1
92 #define MCP2542_STANDBY_MODE_OFF 0
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
102 //typedef uart_data_t char;
103 
107 typedef struct
108 {
109  // Output pins
110 
111  digital_out_t stb;
112 
113  uart_t uart;
114 
115  uint8_t uart_rx_buffer[ MCP2542_DRV_RX_BUFFER_SIZE ];
116  uint8_t uart_tx_buffer[ MCP2542_DRV_TX_BUFFER_SIZE ];
117 
118 } mcp2542_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t rx_pin;
128  pin_name_t tx_pin;
129 
130  // Additional gpio pins
131 
132  pin_name_t stb;
133 
134 
135  // static variable
136 
137  uint32_t baud_rate; // Clock speed.
139  uart_data_bits_t data_bit; // Data bits.
140  uart_parity_t parity_bit; // Parity bit.
141  uart_stop_bits_t stop_bit; // Stop bits.
142 
143 } mcp2542_cfg_t;
144  // End types group
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
166 
175 
184 
194 void mcp2542_generic_multi_write ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
195 
205 void mcp2542_generic_multi_read ( mcp2542_t *ctx, uint8_t *data_buf, uint8_t len );
206 
207 
217 
226 void mcp2542_generic_single_write ( mcp2542_t *ctx, uint8_t tx_data );
227 
236 void mcp2542_set_mode ( mcp2542_t *ctx, uint8_t mode );
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 #endif // _MCP2542_H_
242  // End public_function group
245 
246 // ------------------------------------------------------------------------- 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:108
mcp2542_t::stb
digital_out_t stb
Definition: mcp2542.h:111
mcp2542_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: mcp2542.h:139
MCP2542_RETVAL
#define MCP2542_RETVAL
Definition: mcp2542.h:81
mcp2542_cfg_t::rx_pin
pin_name_t rx_pin
Definition: mcp2542.h:127
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:132
mcp2542_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: mcp2542.h:140
mcp2542_cfg_t::uart_blocking
bool uart_blocking
Definition: mcp2542.h:138
mcp2542_t::uart
uart_t uart
Definition: mcp2542.h:113
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:124
MCP2542_DRV_TX_BUFFER_SIZE
#define MCP2542_DRV_TX_BUFFER_SIZE
Definition: mcp2542.h:74
mcp2542_cfg_t::baud_rate
uint32_t baud_rate
Definition: mcp2542.h:137
mcp2542_cfg_t::tx_pin
pin_name_t tx_pin
Definition: mcp2542.h:128
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:141
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:73
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.