touchkey2  2.0.0.0
touchkey2.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 TOUCHKEY2_H
36 #define TOUCHKEY2_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 TOUCHKEY2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.pc5_target_reset = MIKROBUS( mikrobus, MIKROBUS_RST );
67 
73 #define TOUCHKEY2_RETVAL uint8_t
74 
75 #define TOUCHKEY2_OK 0x00
76 #define TOUCHKEY2_INIT_ERROR 0xFF
77 
83 #define DRV_RX_BUFFER_SIZE 500
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Output pins
100 
101  digital_out_t pc5_target_reset;
102 
103  // Modules
104 
105  uart_t uart;
106 
107  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
108  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
109 
110 } touchkey2_t;
111 
115 typedef struct
116 {
117  // Communication gpio pins
118 
119  pin_name_t rx_pin;
120  pin_name_t tx_pin;
121  pin_name_t pc5_target_reset;
122 
123  // static variable
124 
125  uint32_t baud_rate; // Clock speed.
127  uart_data_bits_t data_bit; // Data bits.
128  uart_parity_t parity_bit; // Parity bit.
129  uart_stop_bits_t stop_bit; // Stop bits.
130 
132  // End types group
134 
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
155 
164 
174 void touchkey2_generic_multi_write ( touchkey2_t *ctx, char *data_buf, uint8_t len );
175 
185 void touchkey2_generic_multi_read ( touchkey2_t *ctx, char *data_buf, uint8_t len );
186 
196 
205 void touchkey2_generic_single_write ( touchkey2_t *ctx, char tx_data );
206 
215 
224 
233 
234 #ifdef __cplusplus
235 }
236 #endif
237 #endif // _TOUCHKEY2_H_
238  // End public_function group
241 
242 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: touchkey2.h:83
touchkey2_cfg_t::baud_rate
uint32_t baud_rate
Definition: touchkey2.h:125
touchkey2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: touchkey2.h:127
touchkey2_clear_reset_pin
void touchkey2_clear_reset_pin(touchkey2_t *ctx)
Clear reset pin function.
touchkey2_target_reset
void touchkey2_target_reset(touchkey2_t *ctx)
Reset function.
touchkey2_init
TOUCHKEY2_RETVAL touchkey2_init(touchkey2_t *ctx, touchkey2_cfg_t *cfg)
Initialization function.
touchkey2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: touchkey2.h:129
touchkey2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: touchkey2.h:128
touchkey2_t::pc5_target_reset
digital_out_t pc5_target_reset
Definition: touchkey2.h:101
touchkey2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: touchkey2.h:119
touchkey2_t::uart
uart_t uart
Definition: touchkey2.h:105
touchkey2_generic_multi_read
void touchkey2_generic_multi_read(touchkey2_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
touchkey2_generic_multi_write
void touchkey2_generic_multi_write(touchkey2_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
touchkey2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: touchkey2.h:120
touchkey2_t
Click ctx object definition.
Definition: touchkey2.h:98
TOUCHKEY2_RETVAL
#define TOUCHKEY2_RETVAL
Definition: touchkey2.h:73
touchkey2_set_reset_pin
void touchkey2_set_reset_pin(touchkey2_t *ctx)
Set reset pin function.
touchkey2_cfg_t
Click configuration structure definition.
Definition: touchkey2.h:116
touchkey2_cfg_setup
void touchkey2_cfg_setup(touchkey2_cfg_t *cfg)
Config Object Initialization function.
touchkey2_cfg_t::uart_blocking
bool uart_blocking
Definition: touchkey2.h:126
touchkey2_generic_single_write
void touchkey2_generic_single_write(touchkey2_t *ctx, char tx_data)
Generic single write function.
touchkey2_generic_single_read
char touchkey2_generic_single_read(touchkey2_t *ctx)
Generic single read function.
touchkey2_cfg_t::pc5_target_reset
pin_name_t pc5_target_reset
Definition: touchkey2.h:121