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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define FIBEROPT_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
66 
72 #define FIBEROPT_OK 0
73 #define FIBEROPT_ERROR -1
74 
80 #define FIBEROPT_DRV_TX_BUFFER_SIZE 100
81 #define FIBEROPT_DRV_RX_BUFFER_SIZE 300
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Modules
98  uart_t uart;
99 
100  uint8_t uart_rx_buffer[ FIBEROPT_DRV_RX_BUFFER_SIZE ];
101  uint8_t uart_tx_buffer[ FIBEROPT_DRV_TX_BUFFER_SIZE ];
102 
103 } fiberopt_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111  pin_name_t rx_pin;
112  pin_name_t tx_pin;
113 
114  // static variable
115  uint32_t baud_rate; // Clock speed.
117  uart_data_bits_t data_bit; // Data bits.
118  uart_parity_t parity_bit; // Parity bit.
119  uart_stop_bits_t stop_bit; // Stop bits.
120 
122  // End types group
124 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
125 
131 #ifdef __cplusplus
132 extern "C"{
133 #endif
134 
144 
153 
165 err_t fiberopt_generic_write ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
166 
178 err_t fiberopt_generic_read ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 #endif // _FIBEROPT_H_
184  // End public_function group
187 
188 // ------------------------------------------------------------------------- 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:96
FIBEROPT_DRV_TX_BUFFER_SIZE
#define FIBEROPT_DRV_TX_BUFFER_SIZE
Definition: fiberopt.h:80
fiberopt_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: fiberopt.h:118
fiberopt_cfg_t
Click configuration structure definition.
Definition: fiberopt.h:109
fiberopt_cfg_t::uart_blocking
bool uart_blocking
Definition: fiberopt.h:116
fiberopt_cfg_t::tx_pin
pin_name_t tx_pin
Definition: fiberopt.h:112
fiberopt_cfg_t::rx_pin
pin_name_t rx_pin
Definition: fiberopt.h:111
fiberopt_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: fiberopt.h:117
fiberopt_cfg_t::baud_rate
uint32_t baud_rate
Definition: fiberopt.h:115
FIBEROPT_DRV_RX_BUFFER_SIZE
#define FIBEROPT_DRV_RX_BUFFER_SIZE
Definition: fiberopt.h:81
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:119
fiberopt_t::uart
uart_t uart
Definition: fiberopt.h:98
fiberopt_init
err_t fiberopt_init(fiberopt_t *ctx, fiberopt_cfg_t *cfg)
Initialization function.