barcode  2.0.0.0
barcode.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 BARCODE_H
36 #define BARCODE_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define BARCODE_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_PWM )
57 
63 #define BARCODE_RETVAL uint8_t
64 
65 #define BARCODE_OK 0x00
66 #define BARCODE_INIT_ERROR 0xFF
67 
73 #define BARCODE_LOGIC_ON 0x00
74 #define BARCODE_LOGIC_OFF 0x01
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
86 typedef struct
87 {
88  // Output pins
89 
90  digital_out_t rst;
91  digital_out_t trg;
92 
93 
94  // Modules
95 
96  uart_t uart;
97 
98  char uart_rx_buffer[ 500 ];
99  char uart_tx_buffer[ 500 ];
100 
101 } barcode_t;
102 
106 typedef struct
107 {
108  // Communication gpio pins
109 
110  pin_name_t rx_pin;
111  pin_name_t tx_pin;
112 
113  // Additional gpio pins
114 
115  pin_name_t rst;
116  pin_name_t trg;
117 
118  // static variable
119 
120  uint32_t baud_rate; // Clock speed.
122  uart_data_bits_t data_bit; // Data bits.
123  uart_parity_t parity_bit; // Parity bit.
124  uart_stop_bits_t stop_bit; // Stop bits.
125 
126 } barcode_cfg_t;
127 
131 typedef uint8_t barcode_error_t;
132  // End types group
134 
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
154 void barcode_cfg_setup ( barcode_cfg_t *cfg );
155 
164 
170 void barcode_enable_scaning ( barcode_t *ctx, uint8_t state );
171 
178 void barcode_generic_write ( barcode_t *ctx, char *data_buf, uint16_t len );
179 
187 uint16_t barcode_generic_read ( barcode_t *ctx, char *data_buf, uint16_t max_len );
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif // _BARCODE_H_
193  // End public_function group
196 
197 // ------------------------------------------------------------------------- END
void barcode_cfg_setup(barcode_cfg_t *cfg)
Config Object Initialization function.
uart_t uart
Definition: barcode.h:96
uart_stop_bits_t stop_bit
Definition: barcode.h:124
uart_data_bits_t data_bit
Definition: barcode.h:122
Click ctx object definition.
Definition: barcode.h:86
digital_out_t rst
Definition: barcode.h:90
digital_out_t trg
Definition: barcode.h:91
BARCODE_RETVAL barcode_init(barcode_t *ctx, barcode_cfg_t *cfg)
Initialization function.
pin_name_t trg
Definition: barcode.h:116
pin_name_t rx_pin
Definition: barcode.h:110
uint16_t barcode_generic_read(barcode_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
pin_name_t rst
Definition: barcode.h:115
uart_parity_t parity_bit
Definition: barcode.h:123
#define BARCODE_RETVAL
Definition: barcode.h:63
pin_name_t tx_pin
Definition: barcode.h:111
void barcode_enable_scaning(barcode_t *ctx, uint8_t state)
Set WKP ( wake-up ) pin state.
void barcode_generic_write(barcode_t *ctx, char *data_buf, uint16_t len)
Generic write function.
bool uart_blocking
Definition: barcode.h:121
uint32_t baud_rate
Definition: barcode.h:120
uint8_t barcode_error_t
Error type.
Definition: barcode.h:131
Click configuration structure definition.
Definition: barcode.h:106