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  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
57 
63 #define FIBEROPT_RETVAL uint8_t
64 
65 #define FIBEROPT_OK 0x00
66 #define FIBEROPT_INIT_ERROR 0xFF
67 
73 #define DRV_RX_BUFFER_SIZE 500
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t pwm;
92 
93  // Modules
94 
95  uart_t uart;
96  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
97  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
98 } fiberopt_t;
99 
103 typedef struct
104 {
105  // Communication gpio pins
106 
107  pin_name_t rx_pin;
108  pin_name_t tx_pin;
109 
110  // Additional gpio pins
111 
112  pin_name_t pwm;
113 
114  // static variable
115 
116  uint32_t baud_rate; // Clock speed.
118  uart_data_bits_t data_bit; // Data bits.
119  uart_parity_t parity_bit; // Parity bit.
120  uart_stop_bits_t stop_bit; // Stop bits.
121 
123  // End types group
125 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126 
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
144 void fiberopt_cfg_setup ( fiberopt_cfg_t *cfg );
145 
154 
164 void fiberopt_generic_multi_write ( fiberopt_t *ctx, char *data_buf, uint8_t len );
165 
175 void fiberopt_generic_multi_read ( fiberopt_t *ctx, char *data_buf, uint8_t len );
176 
186 
195 void fiberopt_generic_single_write ( fiberopt_t *ctx, char tx_data );
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif // _FIBEROPT_H_
201  // End public_function group
204 
205 // ------------------------------------------------------------------------- END
char fiberopt_generic_single_read(fiberopt_t *ctx)
Generic single read function.
#define FIBEROPT_RETVAL
Definition: fiberopt.h:63
Click configuration structure definition.
Definition: fiberopt.h:103
pin_name_t pwm
Definition: fiberopt.h:112
FIBEROPT_RETVAL fiberopt_init(fiberopt_t *ctx, fiberopt_cfg_t *cfg)
Initialization function.
uart_parity_t parity_bit
Definition: fiberopt.h:119
pin_name_t tx_pin
Definition: fiberopt.h:108
uart_data_bits_t data_bit
Definition: fiberopt.h:118
pin_name_t rx_pin
Definition: fiberopt.h:107
uint32_t baud_rate
Definition: fiberopt.h:116
void fiberopt_generic_single_write(fiberopt_t *ctx, char tx_data)
Generic single write function.
bool uart_blocking
Definition: fiberopt.h:117
#define DRV_RX_BUFFER_SIZE
Definition: fiberopt.h:73
void fiberopt_generic_multi_write(fiberopt_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
uart_t uart
Definition: fiberopt.h:95
Click ctx object definition.
Definition: fiberopt.h:87
void fiberopt_cfg_setup(fiberopt_cfg_t *cfg)
Config Object Initialization function.
void fiberopt_generic_multi_read(fiberopt_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
digital_out_t pwm
Definition: fiberopt.h:91
uart_stop_bits_t stop_bit
Definition: fiberopt.h:120