iqrf  2.0.0.0
iqrf.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  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef IQRF_H
35 #define IQRF_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_uart.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define IQRF_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.adc = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.io = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define IQRF_RETVAL uint8_t
77 
78 #define IQRF_OK 0x00
79 #define IQRF_INIT_ERROR 0xFF
80 
86 #define DRV_RX_BUFFER_SIZE 500
87  // End group macro
90 
91 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Output pins
104 
105  digital_out_t io;
106  digital_out_t cs;
107  digital_out_t pwm;
108 
109  // Input pins
110 
111  digital_in_t adc;
112  digital_in_t int_pin;
113 
114  // Modules
115 
116  uart_t uart;
117 
118  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
119  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
120 
121 } iqrf_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129 
130  pin_name_t rx_pin;
131  pin_name_t tx_pin;
132 
133  // Additional gpio pins
134 
135  pin_name_t adc;
136  pin_name_t io;
137  pin_name_t cs;
138  pin_name_t pwm;
139  pin_name_t int_pin;
140 
141  // Static variable
142 
143  uint32_t baud_rate; // Clock speed.
145  uart_data_bits_t data_bit; // Data bits.
146  uart_parity_t parity_bit; // Parity bit.
147  uart_stop_bits_t stop_bit; // Stop bits.
148 
149 } iqrf_cfg_t;
150  // End types group
152 
153 // ------------------------------------------------------------------ CONSTANTS // End constants group
161 
162 // ------------------------------------------------------------------ VARIABLES // End variable group
170 
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172 
178 #ifdef __cplusplus
179 extern "C"{
180 #endif
181 
191 
200 
214 void iqrf_default_cfg ( iqrf_t *ctx );
215 
225 void iqrf_generic_multi_write ( iqrf_t *ctx, char *data_buf, uint8_t len );
226 
236 void iqrf_generic_multi_read ( iqrf_t *ctx, char *data_buf, uint8_t len );
237 
247 
256 void iqrf_generic_single_write ( iqrf_t *ctx, char tx_data );
257 
274 uint8_t iqrf_get_interrupt ( iqrf_t *ctx );
275 
283 void iqrf_hw_reset ( iqrf_t *ctx );
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // _IQRF_H_
289  // End public_function group
292 
293 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: iqrf.h:86
iqrf_cfg_t::tx_pin
pin_name_t tx_pin
Definition: iqrf.h:131
iqrf_t::adc
digital_in_t adc
Definition: iqrf.h:111
iqrf_default_cfg
void iqrf_default_cfg(iqrf_t *ctx)
Click Default Configuration function.
iqrf_cfg_t::rx_pin
pin_name_t rx_pin
Definition: iqrf.h:130
iqrf_t::io
digital_out_t io
Definition: iqrf.h:105
iqrf_t
Click ctx object definition.
Definition: iqrf.h:102
iqrf_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: iqrf.h:146
iqrf_t::pwm
digital_out_t pwm
Definition: iqrf.h:107
iqrf_get_interrupt
uint8_t iqrf_get_interrupt(iqrf_t *ctx)
Interrupt function.
iqrf_init
IQRF_RETVAL iqrf_init(iqrf_t *ctx, iqrf_cfg_t *cfg)
Initialization function.
iqrf_cfg_t
Click configuration structure definition.
Definition: iqrf.h:127
iqrf_generic_single_read
char iqrf_generic_single_read(iqrf_t *ctx)
Generic single read function.
iqrf_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: iqrf.h:145
IQRF_RETVAL
#define IQRF_RETVAL
Definition: iqrf.h:76
iqrf_hw_reset
void iqrf_hw_reset(iqrf_t *ctx)
Hardware reset function.
iqrf_t::int_pin
digital_in_t int_pin
Definition: iqrf.h:112
iqrf_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: iqrf.h:147
iqrf_cfg_t::int_pin
pin_name_t int_pin
Definition: iqrf.h:139
iqrf_cfg_t::baud_rate
uint32_t baud_rate
Definition: iqrf.h:143
iqrf_cfg_t::uart_blocking
bool uart_blocking
Definition: iqrf.h:144
iqrf_t::uart
uart_t uart
Definition: iqrf.h:116
iqrf_generic_multi_write
void iqrf_generic_multi_write(iqrf_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
iqrf_t::cs
digital_out_t cs
Definition: iqrf.h:106
iqrf_cfg_t::cs
pin_name_t cs
Definition: iqrf.h:137
iqrf_generic_single_write
void iqrf_generic_single_write(iqrf_t *ctx, char tx_data)
Generic single write function.
iqrf_cfg_setup
void iqrf_cfg_setup(iqrf_cfg_t *cfg)
Config Object Initialization function.
iqrf_cfg_t::adc
pin_name_t adc
Definition: iqrf.h:135
iqrf_generic_multi_read
void iqrf_generic_multi_read(iqrf_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
iqrf_cfg_t::pwm
pin_name_t pwm
Definition: iqrf.h:138
iqrf_cfg_t::io
pin_name_t io
Definition: iqrf.h:136