samltouch  2.0.0.0
samltouch.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 SAMLTOUCH_H
36 #define SAMLTOUCH_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 // -------------------------------------------------------------- PUBLIC MACROS
61 #define SAMLTOUCH_START_FRAME 0x55
62 #define SAMLTOUCH_END_FRAME 0xAA
63 
67 #define SAMLTOUCH_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
70 
76 #define SAMLTOUCH_RETVAL uint8_t
77 
78 #define SAMLTOUCH_OK 0x00
79 #define SAMLTOUCH_INIT_ERROR 0xFF
80 
86 #define DRV_RX_BUFFER_SIZE 1000
87 #define DRV_TX_BUFFER_SIZE 80
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  uint8_t button1;
100  uint8_t button2;
101  uint8_t sw_state;
102  uint8_t sw_pos;
103 
105 
109 typedef struct
110 {
111  // Modules
112 
113  uart_t uart;
114 
115  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
116  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
117 
118 } samltouch_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  // static variable
131 
132  uint32_t baud_rate; // Clock speed.
134  uart_data_bits_t data_bit; // Data bits.
135  uart_parity_t parity_bit; // Parity bit.
136  uart_stop_bits_t stop_bit; // Stop bits.
137 
139 
143 typedef uint8_t samltouch_error_t;
144  // End types group
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
166 
176 
184 void samltouch_generic_write ( samltouch_t *ctx, char *data_buf, uint16_t len );
185 
195 int32_t samltouch_generic_read ( samltouch_t *ctx, char *data_buf, uint16_t max_len );
196 
206 void samltouch_parser ( char *data_in, samltouch_state_t *state );
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 #endif // _SAMLTOUCH_H_
212  // End public_function group
215 
216 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: samltouch.h:86
samltouch_init
SAMLTOUCH_RETVAL samltouch_init(samltouch_t *ctx, samltouch_cfg_t *cfg)
Initialization function.
samltouch_state_t
Definition: samltouch.h:98
samltouch_t::uart
uart_t uart
Definition: samltouch.h:113
samltouch_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: samltouch.h:135
samltouch_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: samltouch.h:134
samltouch_cfg_t::rx_pin
pin_name_t rx_pin
Definition: samltouch.h:127
samltouch_state_t::button2
uint8_t button2
Definition: samltouch.h:100
SAMLTOUCH_RETVAL
#define SAMLTOUCH_RETVAL
Definition: samltouch.h:76
samltouch_cfg_setup
void samltouch_cfg_setup(samltouch_cfg_t *cfg)
Config Object Initialization function.
samltouch_cfg_t::baud_rate
uint32_t baud_rate
Definition: samltouch.h:132
samltouch_generic_read
int32_t samltouch_generic_read(samltouch_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
samltouch_generic_write
void samltouch_generic_write(samltouch_t *ctx, char *data_buf, uint16_t len)
Generic write function.
samltouch_state_t::sw_state
uint8_t sw_state
Definition: samltouch.h:101
samltouch_state_t::button1
uint8_t button1
Definition: samltouch.h:99
samltouch_error_t
uint8_t samltouch_error_t
Error type.
Definition: samltouch.h:143
samltouch_cfg_t::uart_blocking
bool uart_blocking
Definition: samltouch.h:133
samltouch_cfg_t::tx_pin
pin_name_t tx_pin
Definition: samltouch.h:128
samltouch_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: samltouch.h:136
samltouch_t
Click ctx object definition.
Definition: samltouch.h:110
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: samltouch.h:87
samltouch_parser
void samltouch_parser(char *data_in, samltouch_state_t *state)
Generic parser function.
samltouch_state_t::sw_pos
uint8_t sw_pos
Definition: samltouch.h:102
samltouch_cfg_t
Click configuration structure definition.
Definition: samltouch.h:124