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 
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 // -------------------------------------------------------------- PUBLIC MACROS
57 #define SAMLTOUCH_START_FRAME 0x55
58 #define SAMLTOUCH_END_FRAME 0xAA
59 
63 #define SAMLTOUCH_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
66 
72 #define SAMLTOUCH_RETVAL uint8_t
73 
74 #define SAMLTOUCH_OK 0x00
75 #define SAMLTOUCH_INIT_ERROR 0xFF
76 
82 #define DRV_RX_BUFFER_SIZE 1000
83 #define DRV_TX_BUFFER_SIZE 80
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef struct
94 {
95  uint8_t button1;
96  uint8_t button2;
97  uint8_t sw_state;
98  uint8_t sw_pos;
99 
101 
105 typedef struct
106 {
107  // Modules
108 
109  uart_t uart;
110 
111  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
112  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
113 
114 } samltouch_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t rx_pin;
124  pin_name_t tx_pin;
125 
126  // static variable
127 
128  uint32_t baud_rate; // Clock speed.
130  uart_data_bits_t data_bit; // Data bits.
131  uart_parity_t parity_bit; // Parity bit.
132  uart_stop_bits_t stop_bit; // Stop bits.
133 
135 
139 typedef uint8_t samltouch_error_t;
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
162 
172 
180 void samltouch_generic_write ( samltouch_t *ctx, char *data_buf, uint16_t len );
181 
191 int32_t samltouch_generic_read ( samltouch_t *ctx, char *data_buf, uint16_t max_len );
192 
202 void samltouch_parser ( char *data_in, samltouch_state_t *state );
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 #endif // _SAMLTOUCH_H_
208  // End public_function group
211 
212 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: samltouch.h:82
samltouch_init
SAMLTOUCH_RETVAL samltouch_init(samltouch_t *ctx, samltouch_cfg_t *cfg)
Initialization function.
samltouch_state_t
Definition: samltouch.h:94
samltouch_t::uart
uart_t uart
Definition: samltouch.h:109
samltouch_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: samltouch.h:131
samltouch_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: samltouch.h:130
samltouch_cfg_t::rx_pin
pin_name_t rx_pin
Definition: samltouch.h:123
samltouch_state_t::button2
uint8_t button2
Definition: samltouch.h:96
SAMLTOUCH_RETVAL
#define SAMLTOUCH_RETVAL
Definition: samltouch.h:72
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:128
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:97
samltouch_state_t::button1
uint8_t button1
Definition: samltouch.h:95
samltouch_error_t
uint8_t samltouch_error_t
Error type.
Definition: samltouch.h:139
samltouch_cfg_t::uart_blocking
bool uart_blocking
Definition: samltouch.h:129
samltouch_cfg_t::tx_pin
pin_name_t tx_pin
Definition: samltouch.h:124
samltouch_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: samltouch.h:132
samltouch_t
Click ctx object definition.
Definition: samltouch.h:106
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: samltouch.h:83
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:98
samltouch_cfg_t
Click configuration structure definition.
Definition: samltouch.h:120