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 
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 TOUCHKEY2_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.pc5_target_reset = MIKROBUS( mikrobus, MIKROBUS_RST );
71 
77 #define TOUCHKEY2_RETVAL uint8_t
78 
79 #define TOUCHKEY2_OK 0x00
80 #define TOUCHKEY2_INIT_ERROR 0xFF
81 
87 #define DRV_RX_BUFFER_SIZE 500
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Output pins
104 
105  digital_out_t pc5_target_reset;
106 
107  // Modules
108 
109  uart_t uart;
110 
111  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
112  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
113 
114 } touchkey2_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t rx_pin;
124  pin_name_t tx_pin;
125  pin_name_t pc5_target_reset;
126 
127  // static variable
128 
129  uint32_t baud_rate; // Clock speed.
131  uart_data_bits_t data_bit; // Data bits.
132  uart_parity_t parity_bit; // Parity bit.
133  uart_stop_bits_t stop_bit; // Stop bits.
134 
136  // End types group
138 
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
168 
178 void touchkey2_generic_multi_write ( touchkey2_t *ctx, char *data_buf, uint8_t len );
179 
189 void touchkey2_generic_multi_read ( touchkey2_t *ctx, char *data_buf, uint8_t len );
190 
200 
209 void touchkey2_generic_single_write ( touchkey2_t *ctx, char tx_data );
210 
219 
228 
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 #endif // _TOUCHKEY2_H_
242  // End public_function group
245 
246 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: touchkey2.h:87
touchkey2_cfg_t::baud_rate
uint32_t baud_rate
Definition: touchkey2.h:129
touchkey2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: touchkey2.h:131
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:133
touchkey2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: touchkey2.h:132
touchkey2_t::pc5_target_reset
digital_out_t pc5_target_reset
Definition: touchkey2.h:105
touchkey2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: touchkey2.h:123
touchkey2_t::uart
uart_t uart
Definition: touchkey2.h:109
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:124
touchkey2_t
Click ctx object definition.
Definition: touchkey2.h:102
TOUCHKEY2_RETVAL
#define TOUCHKEY2_RETVAL
Definition: touchkey2.h:77
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:120
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:130
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:125