fiberopt  2.0.0.0
fiberopt.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 FIBEROPT_H
36 #define FIBEROPT_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define FIBEROPT_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
56 
62 #define FIBEROPT_OK 0
63 #define FIBEROPT_ERROR -1
64 
70 #define FIBEROPT_DRV_TX_BUFFER_SIZE 100
71 #define FIBEROPT_DRV_RX_BUFFER_SIZE 300
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Modules
88  uart_t uart;
89 
90  uint8_t uart_rx_buffer[ FIBEROPT_DRV_RX_BUFFER_SIZE ];
91  uint8_t uart_tx_buffer[ FIBEROPT_DRV_TX_BUFFER_SIZE ];
92 
93 } fiberopt_t;
94 
98 typedef struct
99 {
100  // Communication gpio pins
101  pin_name_t rx_pin;
102  pin_name_t tx_pin;
103 
104  // static variable
105  uint32_t baud_rate; // Clock speed.
107  uart_data_bits_t data_bit; // Data bits.
108  uart_parity_t parity_bit; // Parity bit.
109  uart_stop_bits_t stop_bit; // Stop bits.
110 
112  // End types group
114 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
115 
121 #ifdef __cplusplus
122 extern "C"{
123 #endif
124 
134 
143 
155 err_t fiberopt_generic_write ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
156 
168 err_t fiberopt_generic_read ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 #endif // _FIBEROPT_H_
174  // End public_function group
177 
178 // ------------------------------------------------------------------------- END
fiberopt_generic_write
err_t fiberopt_generic_write(fiberopt_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
fiberopt_t
Click ctx object definition.
Definition: fiberopt.h:86
FIBEROPT_DRV_TX_BUFFER_SIZE
#define FIBEROPT_DRV_TX_BUFFER_SIZE
Definition: fiberopt.h:70
fiberopt_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: fiberopt.h:108
fiberopt_cfg_t
Click configuration structure definition.
Definition: fiberopt.h:99
fiberopt_cfg_t::uart_blocking
bool uart_blocking
Definition: fiberopt.h:106
fiberopt_cfg_t::tx_pin
pin_name_t tx_pin
Definition: fiberopt.h:102
fiberopt_cfg_t::rx_pin
pin_name_t rx_pin
Definition: fiberopt.h:101
fiberopt_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: fiberopt.h:107
fiberopt_cfg_t::baud_rate
uint32_t baud_rate
Definition: fiberopt.h:105
FIBEROPT_DRV_RX_BUFFER_SIZE
#define FIBEROPT_DRV_RX_BUFFER_SIZE
Definition: fiberopt.h:71
fiberopt_cfg_setup
void fiberopt_cfg_setup(fiberopt_cfg_t *cfg)
Config Object Initialization function.
fiberopt_generic_read
err_t fiberopt_generic_read(fiberopt_t *ctx, uint8_t *data_buf, uint16_t len)
Generic read function.
fiberopt_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: fiberopt.h:109
fiberopt_t::uart
uart_t uart
Definition: fiberopt.h:88
fiberopt_init
err_t fiberopt_init(fiberopt_t *ctx, fiberopt_cfg_t *cfg)
Initialization function.