ir2 2.0.0.0
ir2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef IR2_H
29#define IR2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_pwm.h"
52
73#define IR2_STATE_HIGH 0x01
74#define IR2_STATE_LOW 0x00
75
80#define IR2_DEF_FREQ 38000
81#define IR2_DEF_DUTY_CYCLE 0.25
82
83 // ir2_cfg
84
99#define IR2_MAP_MIKROBUS( cfg, mikrobus ) \
100 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
101 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
102 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
103 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
104
105 // ir2_map
106 // ir2
107
122typedef struct
123{
124 // Input pins
125 digital_in_t out_pin;
127 // Modules
128 pwm_t pwm;
130 // ctx variable
131 uint32_t pwm_freq;
135} ir2_t;
136
141typedef struct
142{
143 // Communication gpio pins
144 pin_name_t pwm;
145 pin_name_t int_pin;
146 pin_name_t rx_pin;
147 pin_name_t tx_pin;
149 uint32_t dev_pwm_freq;
153} ir2_cfg_t;
154
159typedef enum
160{
162 IR2_ERROR = -1
163
165
182
198
212err_t ir2_init ( ir2_t *ctx, ir2_cfg_t *cfg );
213
222uint8_t ir2_get_out_pin ( ir2_t *ctx );
223
234void ir2_nec_send_data ( ir2_t *ctx, uint8_t address, uint8_t data_in );
235
248err_t ir2_nec_read_data ( ir2_t *ctx, uint8_t *address, uint8_t *data_out );
249
250#ifdef __cplusplus
251}
252#endif
253#endif // IR2_H
254
255 // ir2
256
257// ------------------------------------------------------------------------ END
err_t ir2_nec_read_data(ir2_t *ctx, uint8_t *address, uint8_t *data_out)
IR 2 NEC read data function.
void ir2_drv_interface_selection(ir2_cfg_t *cfg, ir2_drv_t drv_sel)
IR 2 driver interface setup function.
void ir2_nec_send_data(ir2_t *ctx, uint8_t address, uint8_t data_in)
IR 2 NEC send data function.
uint8_t ir2_get_out_pin(ir2_t *ctx)
IR 2 get OUT pin function.
void ir2_cfg_setup(ir2_cfg_t *cfg)
IR 2 configuration object setup function.
err_t ir2_init(ir2_t *ctx, ir2_cfg_t *cfg)
IR 2 initialization function.
ir2_return_value_t
IR 2 Click return value data.
Definition ir2.h:160
@ IR2_OK
Definition ir2.h:161
@ IR2_ERROR
Definition ir2.h:162
ir2_drv_t
IR 2 Click driver selector.
Definition ir2.h:113
@ IR2_DRV_SEL_GPIO
Definition ir2.h:114
@ IR2_DRV_SEL_UART
Definition ir2.h:115
IR 2 Click configuration object.
Definition ir2.h:142
ir2_drv_t drv_sel
Definition ir2.h:151
pin_name_t tx_pin
Definition ir2.h:147
uint32_t dev_pwm_freq
Definition ir2.h:149
pin_name_t rx_pin
Definition ir2.h:146
pin_name_t int_pin
Definition ir2.h:145
pin_name_t pwm
Definition ir2.h:144
IR 2 Click context object.
Definition ir2.h:123
ir2_drv_t drv_sel
Definition ir2.h:133
uint32_t pwm_freq
Definition ir2.h:131
digital_in_t out_pin
Definition ir2.h:125
pwm_t pwm
Definition ir2.h:128