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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TOUCHKEY2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.pc5_target_reset = MIKROBUS( mikrobus, MIKROBUS_RST );
57 
63 #define TOUCHKEY2_RETVAL uint8_t
64 
65 #define TOUCHKEY2_OK 0x00
66 #define TOUCHKEY2_INIT_ERROR 0xFF
67 
73 #define DRV_RX_BUFFER_SIZE 500
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t pc5_target_reset;
92 
93  // Modules
94 
95  uart_t uart;
96 
97  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
98  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
99 
100 } touchkey2_t;
101 
105 typedef struct
106 {
107  // Communication gpio pins
108 
109  pin_name_t rx_pin;
110  pin_name_t tx_pin;
111  pin_name_t pc5_target_reset;
112 
113  // static variable
114 
115  uint32_t baud_rate; // Clock speed.
117  uart_data_bits_t data_bit; // Data bits.
118  uart_parity_t parity_bit; // Parity bit.
119  uart_stop_bits_t stop_bit; // Stop bits.
120 
122  // End types group
124 
125 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126 
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
145 
154 
164 void touchkey2_generic_multi_write ( touchkey2_t *ctx, char *data_buf, uint8_t len );
165 
175 void touchkey2_generic_multi_read ( touchkey2_t *ctx, char *data_buf, uint8_t len );
176 
186 
195 void touchkey2_generic_single_write ( touchkey2_t *ctx, char tx_data );
196 
205 
214 
222 void touchkey2_target_reset ( touchkey2_t *ctx );
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 #endif // _TOUCHKEY2_H_
228  // End public_function group
231 
232 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: touchkey2.h:73
touchkey2_cfg_t::baud_rate
uint32_t baud_rate
Definition: touchkey2.h:115
touchkey2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: touchkey2.h:117
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:119
touchkey2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: touchkey2.h:118
touchkey2_t::pc5_target_reset
digital_out_t pc5_target_reset
Definition: touchkey2.h:91
touchkey2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: touchkey2.h:109
touchkey2_t::uart
uart_t uart
Definition: touchkey2.h:95
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:110
touchkey2_t
Click ctx object definition.
Definition: touchkey2.h:87
TOUCHKEY2_RETVAL
#define TOUCHKEY2_RETVAL
Definition: touchkey2.h:63
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:105
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:116
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:111