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
67#define SAMLTOUCH_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
76#define SAMLTOUCH_RETVAL uint8_t
77
78#define SAMLTOUCH_OK 0x00
79#define SAMLTOUCH_INIT_ERROR 0xFF
86#define DRV_RX_BUFFER_SIZE 1000
87#define DRV_TX_BUFFER_SIZE 80
90 // End group macro
91// --------------------------------------------------------------- PUBLIC TYPES
97typedef struct
98{
99 uint8_t button1;
100 uint8_t button2;
101 uint8_t sw_state;
102 uint8_t sw_pos;
103
105
109typedef 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
119
123typedef 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
143typedef uint8_t samltouch_error_t;
144
145 // End types group
146// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147
153#ifdef __cplusplus
154extern "C"{
155#endif
156
166
176
184void samltouch_generic_write ( samltouch_t *ctx, char *data_buf, uint16_t len );
185
195int32_t samltouch_generic_read ( samltouch_t *ctx, char *data_buf, uint16_t max_len );
196
206void samltouch_parser ( char *data_in, samltouch_state_t *state );
207
208#ifdef __cplusplus
209}
210#endif
211#endif // _SAMLTOUCH_H_
212
213 // End public_function group
215
216// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition samltouch.h:86
#define DRV_TX_BUFFER_SIZE
Definition samltouch.h:87
#define SAMLTOUCH_RETVAL
Definition samltouch.h:76
SAMLTOUCH_RETVAL samltouch_init(samltouch_t *ctx, samltouch_cfg_t *cfg)
Initialization function.
void samltouch_generic_write(samltouch_t *ctx, char *data_buf, uint16_t len)
Generic write function.
int32_t samltouch_generic_read(samltouch_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void samltouch_cfg_setup(samltouch_cfg_t *cfg)
Config Object Initialization function.
void samltouch_parser(char *data_in, samltouch_state_t *state)
Generic parser function.
uint8_t samltouch_error_t
Error type.
Definition samltouch.h:143
Click configuration structure definition.
Definition samltouch.h:124
uint32_t baud_rate
Definition samltouch.h:132
bool uart_blocking
Definition samltouch.h:133
uart_data_bits_t data_bit
Definition samltouch.h:134
pin_name_t tx_pin
Definition samltouch.h:128
pin_name_t rx_pin
Definition samltouch.h:127
uart_stop_bits_t stop_bit
Definition samltouch.h:136
uart_parity_t parity_bit
Definition samltouch.h:135
Definition samltouch.h:98
uint8_t sw_pos
Definition samltouch.h:102
uint8_t button2
Definition samltouch.h:100
uint8_t button1
Definition samltouch.h:99
uint8_t sw_state
Definition samltouch.h:101
Click ctx object definition.
Definition samltouch.h:110
uart_t uart
Definition samltouch.h:113