irgrid  2.0.0.0
irgrid.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 IRGRID_H
36 #define IRGRID_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define IRGRID_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define IRGRID_RETVAL uint8_t
62 
63 #define IRGRID_OK 0x00
64 #define IRGRID_INIT_ERROR 0xFF
65 
71 #define IRGRID_CAL_ACOMMON_L 0xD0
72 #define IRGRID_CAL_ACOMMON_H 0xD1
73 #define IRGRID_CAL_ACP_L 0xD3
74 #define IRGRID_CAL_ACP_H 0xD4
75 #define IRGRID_CAL_BCP 0xD5
76 #define IRGRID_CAL_ALPHA_CP_L 0xD6
77 #define IRGRID_CAL_ALPHA_CP_H 0xD7
78 #define IRGRID_CAL_TGC 0xD8
79 #define IRGRID_CAL_AI_SCALE 0xD9
80 #define IRGRID_CAL_BI_SCALE 0xD9
81 #define IRGRID_VTH_L 0xDA
82 #define IRGRID_VTH_H 0xDB
83 #define IRGRID_KT1_L 0xDC
84 #define IRGRID_KT1_H 0xDD
85 #define IRGRID_KT2_L 0xDE
86 #define IRGRID_KT2_H 0xDF
87 #define IRGRID_KT_SCALE 0xD2
88 #define IRGRID_CAL_A0_L 0xE0
89 #define IRGRID_CAL_A0_H 0xE1
90 #define IRGRID_CAL_A0_SCALE 0xE2
91 #define IRGRID_CAL_DELTA_A_SCALE 0xE3
92 #define IRGRID_CAL_EMIS_L 0xE4
93 #define IRGRID_CAL_EMIS_H 0xE5
94 #define IRGRID_OSC_TRIM_VALUE 0xF7
95  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
106 typedef struct
107 {
108  // Modules
109 
110  i2c_master_t i2c;
111 
112  // ctx variable
113 
116 
117  // static variable
118  uint8_t refresh_rate;
120  int16_t resolution;
121  int16_t cpix;
122  int16_t ptat;
123 
124 } irgrid_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t scl;
134  pin_name_t sda;
135 
136  // static variable
137 
138  uint32_t i2c_speed;
141 
142 } irgrid_cfg_t;
143 
147 typedef struct
148 {
149  // Static variable
150 
151  uint8_t eeprom_data[ 256 ];
152  int16_t ir_data[ 64 ];
153  float temperature_data[ 64 ];
154  float a_data[ 64 ];
155  float b_data[ 64 ];
156  float alpha_a_data[ 64 ];
157 
158 } irgrid_data_t;
159  // End types group
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
180 void irgrid_cfg_setup ( irgrid_cfg_t *cfg );
181 
191 
203 uint8_t irgrid_device_init ( irgrid_t *ctx, irgrid_data_t *data_str, uint8_t refrate );
204 
214 void irgrid_write_ram( irgrid_t *ctx, uint8_t *data_buf, uint8_t len );
215 
226 void irgrid_read_ram ( irgrid_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len );
227 
238 void irgrid_write_eeprom ( irgrid_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
250 void irgrid_read_eeprom ( irgrid_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
251 
262 uint8_t irgrid_measure ( irgrid_t *ctx, irgrid_data_t *data_str );
263 
272 void irgrid_get_ir_raw ( irgrid_data_t *data_str, int16_t *buffer );
273 
282 void irgrid_get_temperature ( irgrid_data_t *data_str, float *buffer );
283 
293 float irgrid_get_amb_temperature ( irgrid_t *ctx );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // _IRGRID_H_
299  // End public_function group
302 
303 // ------------------------------------------------------------------------- END
void irgrid_write_eeprom(irgrid_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Write function using EEPROM slave adress.
uint8_t slave_eeprom_address
Definition: irgrid.h:115
int16_t resolution
Definition: irgrid.h:120
void irgrid_write_ram(irgrid_t *ctx, uint8_t *data_buf, uint8_t len)
Write function using RAM slave adress.
void irgrid_read_ram(irgrid_t *ctx, uint8_t *reg, uint8_t *data_buf, uint8_t len)
Read function using RAM slave adress.
uint8_t irgrid_device_init(irgrid_t *ctx, irgrid_data_t *data_str, uint8_t refrate)
Device Initialization.
uint8_t irgrid_measure(irgrid_t *ctx, irgrid_data_t *data_str)
Measurement.
pin_name_t scl
Definition: irgrid.h:133
i2c_master_t i2c
Definition: irgrid.h:110
float irgrid_get_amb_temperature(irgrid_t *ctx)
Read Ambient Temperature.
int16_t ptat
Definition: irgrid.h:122
float temperature_amb
Definition: irgrid.h:119
uint8_t refresh_rate
Definition: irgrid.h:118
uint8_t slave_ram_address
Definition: irgrid.h:114
Click configuration structure definition.
Definition: irgrid.h:129
void irgrid_get_ir_raw(irgrid_data_t *data_str, int16_t *buffer)
Read Raw Temperature buffer.
uint32_t i2c_speed
Definition: irgrid.h:138
void irgrid_cfg_setup(irgrid_cfg_t *cfg)
Config Object Initialization function.
Click data object definition.
Definition: irgrid.h:147
int16_t cpix
Definition: irgrid.h:121
pin_name_t sda
Definition: irgrid.h:134
uint8_t i2c_ram_address
Definition: irgrid.h:139
#define IRGRID_RETVAL
Definition: irgrid.h:61
void irgrid_read_eeprom(irgrid_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Read function using EEPROM slave adress.
uint8_t i2c_eeprom_address
Definition: irgrid.h:140
IRGRID_RETVAL irgrid_init(irgrid_t *ctx, irgrid_cfg_t *cfg)
Initialization function.
void irgrid_get_temperature(irgrid_data_t *data_str, float *buffer)
Read Calculated Temperature buffer.
Click ctx object definition.
Definition: irgrid.h:106