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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
47 #define SAMLTOUCH_START_FRAME 0x55
48 #define SAMLTOUCH_END_FRAME 0xAA
49 
53 #define SAMLTOUCH_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
56 
62 #define SAMLTOUCH_RETVAL uint8_t
63 
64 #define SAMLTOUCH_OK 0x00
65 #define SAMLTOUCH_INIT_ERROR 0xFF
66 
72 #define DRV_RX_BUFFER_SIZE 1000
73 #define DRV_TX_BUFFER_SIZE 80
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
83 typedef struct
84 {
85  uint8_t button1;
86  uint8_t button2;
87  uint8_t sw_state;
88  uint8_t sw_pos;
89 
91 
95 typedef struct
96 {
97  // Modules
98 
99  uart_t uart;
100 
101  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
102  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
103 
104 } samltouch_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t rx_pin;
114  pin_name_t tx_pin;
115 
116  // static variable
117 
118  uint32_t baud_rate; // Clock speed.
120  uart_data_bits_t data_bit; // Data bits.
121  uart_parity_t parity_bit; // Parity bit.
122  uart_stop_bits_t stop_bit; // Stop bits.
123 
125 
129 typedef uint8_t samltouch_error_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
152 
162 
170 void samltouch_generic_write ( samltouch_t *ctx, char *data_buf, uint16_t len );
171 
181 int32_t samltouch_generic_read ( samltouch_t *ctx, char *data_buf, uint16_t max_len );
182 
192 void samltouch_parser ( char *data_in, samltouch_state_t *state );
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif // _SAMLTOUCH_H_
198  // End public_function group
201 
202 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: samltouch.h:72
samltouch_init
SAMLTOUCH_RETVAL samltouch_init(samltouch_t *ctx, samltouch_cfg_t *cfg)
Initialization function.
samltouch_state_t
Definition: samltouch.h:84
samltouch_t::uart
uart_t uart
Definition: samltouch.h:99
samltouch_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: samltouch.h:121
samltouch_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: samltouch.h:120
samltouch_cfg_t::rx_pin
pin_name_t rx_pin
Definition: samltouch.h:113
samltouch_state_t::button2
uint8_t button2
Definition: samltouch.h:86
SAMLTOUCH_RETVAL
#define SAMLTOUCH_RETVAL
Definition: samltouch.h:62
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:118
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:87
samltouch_state_t::button1
uint8_t button1
Definition: samltouch.h:85
samltouch_error_t
uint8_t samltouch_error_t
Error type.
Definition: samltouch.h:129
samltouch_cfg_t::uart_blocking
bool uart_blocking
Definition: samltouch.h:119
samltouch_cfg_t::tx_pin
pin_name_t tx_pin
Definition: samltouch.h:114
samltouch_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: samltouch.h:122
samltouch_t
Click ctx object definition.
Definition: samltouch.h:96
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: samltouch.h:73
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:88
samltouch_cfg_t
Click configuration structure definition.
Definition: samltouch.h:110