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 );
76#define FIBEROPT_OK 0
77#define FIBEROPT_ERROR -1
84#define FIBEROPT_DRV_TX_BUFFER_SIZE 100
85#define FIBEROPT_DRV_RX_BUFFER_SIZE 300
88 // End group macro
89// --------------------------------------------------------------- PUBLIC TYPES
99typedef 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
112typedef 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
127 // End types group
128// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129
135#ifdef __cplusplus
136extern "C"{
137#endif
138
148
157
169err_t fiberopt_generic_write ( fiberopt_t *ctx, uint8_t *data_buf, uint16_t len );
170
182err_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
189 // End public_function group
191
192// ------------------------------------------------------------------------- END
#define FIBEROPT_DRV_RX_BUFFER_SIZE
Definition fiberopt.h:85
#define FIBEROPT_DRV_TX_BUFFER_SIZE
Definition fiberopt.h:84
err_t fiberopt_init(fiberopt_t *ctx, fiberopt_cfg_t *cfg)
Initialization function.
void fiberopt_cfg_setup(fiberopt_cfg_t *cfg)
Config Object Initialization function.
err_t fiberopt_generic_write(fiberopt_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
err_t fiberopt_generic_read(fiberopt_t *ctx, uint8_t *data_buf, uint16_t len)
Generic read function.
Click configuration structure definition.
Definition fiberopt.h:113
uint32_t baud_rate
Definition fiberopt.h:119
bool uart_blocking
Definition fiberopt.h:120
uart_data_bits_t data_bit
Definition fiberopt.h:121
pin_name_t tx_pin
Definition fiberopt.h:116
pin_name_t rx_pin
Definition fiberopt.h:115
uart_stop_bits_t stop_bit
Definition fiberopt.h:123
uart_parity_t parity_bit
Definition fiberopt.h:122
Click ctx object definition.
Definition fiberopt.h:100
uart_t uart
Definition fiberopt.h:102