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 
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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define FIBEROPT_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
70 
76 #define FIBEROPT_OK 0
77 #define FIBEROPT_ERROR -1
78 
84 #define FIBEROPT_DRV_TX_BUFFER_SIZE 100
85 #define FIBEROPT_DRV_RX_BUFFER_SIZE 300
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  // Modules
102  uart_t uart;
103 
104  uint8_t uart_rx_buffer[ FIBEROPT_DRV_RX_BUFFER_SIZE ];
105  uint8_t uart_tx_buffer[ FIBEROPT_DRV_TX_BUFFER_SIZE ];
106 
107 } fiberopt_t;
108 
112 typedef struct
113 {
114  // Communication gpio pins
115  pin_name_t rx_pin;
116  pin_name_t tx_pin;
117 
118  // static variable
119  uint32_t baud_rate; // Clock speed.
121  uart_data_bits_t data_bit; // Data bits.
122  uart_parity_t parity_bit; // Parity bit.
123  uart_stop_bits_t stop_bit; // Stop bits.
124 
126  // End types group
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
157 
169 err_t fiberopt_generic_write ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
170 
182 err_t fiberopt_generic_read ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 #endif // _FIBEROPT_H_
188  // End public_function group
191 
192 // ------------------------------------------------------------------------- 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:100
FIBEROPT_DRV_TX_BUFFER_SIZE
#define FIBEROPT_DRV_TX_BUFFER_SIZE
Definition: fiberopt.h:84
fiberopt_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: fiberopt.h:122
fiberopt_cfg_t
Click configuration structure definition.
Definition: fiberopt.h:113
fiberopt_cfg_t::uart_blocking
bool uart_blocking
Definition: fiberopt.h:120
fiberopt_cfg_t::tx_pin
pin_name_t tx_pin
Definition: fiberopt.h:116
fiberopt_cfg_t::rx_pin
pin_name_t rx_pin
Definition: fiberopt.h:115
fiberopt_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: fiberopt.h:121
fiberopt_cfg_t::baud_rate
uint32_t baud_rate
Definition: fiberopt.h:119
FIBEROPT_DRV_RX_BUFFER_SIZE
#define FIBEROPT_DRV_RX_BUFFER_SIZE
Definition: fiberopt.h:85
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:123
fiberopt_t::uart
uart_t uart
Definition: fiberopt.h:102
fiberopt_init
err_t fiberopt_init(fiberopt_t *ctx, fiberopt_cfg_t *cfg)
Initialization function.