grideye  2.0.0.0
grideye.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 GRIDEYE_H
36 #define GRIDEYE_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define GRIDEYE_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
55 
61 #define GRIDEYE_RETVAL int8_t
62 
63 #define GRIDEYE_OK 0
64 #define GRIDEYE_INIT_ERROR (-1)
65 
71 #define GRIDEYE_I2C_ADDR 0x68
72 
78 #define GRIDEYE_PCLT 0x00
79 #define GRIDEYE_RST 0x01
80 #define GRIDEYE_FPSC 0x02
81 #define GRIDEYE_INTC 0x03
82 #define GRIDEYE_STAT 0x04
83 #define GRIDEYE_SCLR 0x05
84 #define GRIDEYE_AVE 0x07
85 
86 #define GRIDEYE_INTHL 0x08
87 #define GRIDEYE_INTHH 0x09
88 #define GRIDEYE_INTLL 0x0A
89 #define GRIDEYE_INTLH 0x0B
90 #define GRIDEYE_IHYSL 0x0C
91 #define GRIDEYE_IHYSH 0x0D
92 #define GRIDEYE_TTHL 0x0E
93 #define GRIDEYE_TTHH 0x0F
94 
100 #define GRIDEYE_INT0 0x10
101 #define GRIDEYE_INT1 0x11
102 #define GRIDEYE_INT2 0x12
103 #define GRIDEYE_INT3 0x13
104 #define GRIDEYE_INT4 0x14
105 #define GRIDEYE_INT5 0x15
106 #define GRIDEYE_INT6 0x16
107 #define GRIDEYE_INT7 0x17
108 
114 #define GRIDEYE_PCLT_NORMAL 0x00
115 #define GRIDEYE_PCLT_SLEEP 0x10
116 #define GRIDEYE_PCLT_STANDBY_60 0x20
117 #define GRIDEYE_PCLT_STANDBY_10 0x21
118 
124 #define GRIDEYE_RST_FLAG 0x30
125 #define GRIDEYE_RST_INIT 0x3F
126 
132 #define GRIDEYE_FPSC_1FPS 0x01
133 #define GRIDEYE_FPSC_10FPS 0x00
134 
140 #define GRIDEYE_INTC_INTEN_ACTIVE 0x01
141 #define GRIDEYE_INTC_INTEN_INACTIVE 0x00
142 #define GRIDEYE_INTC_INTMOD_ABSO 0x10
143 #define GRIDEYE_INTC_INTMOD_DIFE 0x00
144 
150 #define GRIDEYE_SCLR_INTCLR 0x02
151 #define GRIDEYE_SCLR_OVS_CLR 0x04
152 #define GRIDEYE_SCLR_OVT_CLR 0x08
153 
159 #define GRIDEYE_AVE_MAMOD_ACTIVE 0x20
160 #define GRIDEYE_AVE_MAMOD_INACTIVE 0x00
161 
167 #define GRIDEYE_PIXELS 0x80
168  // End group macro
171 // --------------------------------------------------------------- PUBLIC TYPES
180 typedef struct
181 {
182  // Input pins
183 
184  digital_in_t int_pin;
185 
186  // Modules
187 
188  i2c_master_t i2c;
189 
190  // ctx variable
191 
192  uint8_t slave_address;
193 
194 } grideye_t;
195 
199 typedef struct
200 {
201  // Communication gpio pins
202 
203  pin_name_t scl;
204  pin_name_t sda;
205 
206  // Additional gpio pins
207 
208  pin_name_t int_pin;
209 
210  // static variable
211 
212  uint32_t i2c_speed;
213  uint8_t i2c_address;
214 
215 } grideye_cfg_t;
216  // End types group
218 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
219 
225 #ifdef __cplusplus
226 extern "C"{
227 #endif
228 
237 void grideye_cfg_setup ( grideye_cfg_t *cfg );
238 
247 
255 void grideye_default_cfg ( grideye_t *ctx );
256 
266 void grideye_generic_write ( grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
267 
279 void grideye_generic_read ( grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
280 
292 void grideye_write_data ( grideye_t *ctx, uint8_t wr_addr, uint16_t wr_data );
293 
304 uint16_t grideye_read_data ( grideye_t *ctx, uint8_t rd_addr );
305 
314 void grideye_read_grid ( grideye_t *ctx, int16_t *buffer );
315 
327 uint8_t grideye_check_interrupt ( grideye_t *ctx );
328 
338 void grideye_set_power_control ( grideye_t *ctx, uint8_t pow_cnt );
339 
350 uint8_t grideye_read_power_control ( grideye_t *ctx );
351 
360 void grideye_flag_reset ( grideye_t *ctx );
361 
370 void grideye_initial_reset ( grideye_t *ctx );
371 
379 void grideye_set_fps1 ( grideye_t *ctx );
380 
388 void grideye_set_fps10 ( grideye_t *ctx );
389 
401 uint8_t grideye_check_fps ( grideye_t *ctx );
402 
412 void grideye_set_int_ctl_reg ( grideye_t *ctx, uint8_t int_cnt );
413 
424 uint8_t grideye_read_int_ctl_reg ( grideye_t *ctx );
425 
436 uint8_t grideye_read_stat_reg ( grideye_t *ctx );
437 
447 void grideye_set_stat_clr_reg ( grideye_t *ctx, uint8_t int_cnt );
448 
459 void grideye_set_ave_reg ( grideye_t *ctx, uint8_t mamod );
460 
471 uint8_t grideye_read_ave_reg ( grideye_t *ctx );
472 
481 void grideye_write_int_lvl_high ( grideye_t *ctx, uint16_t wr_data );
482 
490 void grideye_write_int_lvl_low( grideye_t *ctx, uint16_t wr_data );
491 
501 uint16_t grideye_read_int_lvl_high ( grideye_t *ctx );
502 
512 uint16_t grideye_read_int_lvl_low ( grideye_t *ctx );
513 
522 void grideye_write_int_hyst_lvl ( grideye_t *ctx, uint16_t wr_data );
523 
533 uint16_t grideye_read_int_hyst_lvl ( grideye_t *ctx );
534 
545 
555 uint8_t grideye_read_int0 ( grideye_t *ctx );
556 
566 uint8_t grideye_read_int1 ( grideye_t *ctx );
576 uint8_t grideye_read_int2 ( grideye_t *ctx );
577 
587 uint8_t grideye_read_int3 ( grideye_t *ctx );
588 
598 uint8_t grideye_read_int4 ( grideye_t *ctx );
599 
609 uint8_t grideye_read_int5 ( grideye_t *ctx );
610 
620 uint8_t grideye_read_int6 ( grideye_t *ctx );
621 
631 uint8_t grideye_read_int7 ( grideye_t *ctx );
632 
633 #ifdef __cplusplus
634 }
635 #endif
636 #endif // GRIDEYE_H
637  // End public_function group // End click Driver group
640 
641 // ------------------------------------------------------------------------ END
grideye_read_int5
uint8_t grideye_read_int5(grideye_t *ctx)
Read Interrupt Table Register 5 function.
grideye_cfg_t::scl
pin_name_t scl
Definition: grideye.h:203
grideye_write_data
void grideye_write_data(grideye_t *ctx, uint8_t wr_addr, uint16_t wr_data)
Write data function.
grideye_read_grid
void grideye_read_grid(grideye_t *ctx, int16_t *buffer)
Read whole grid function.
grideye_write_int_lvl_low
void grideye_write_int_lvl_low(grideye_t *ctx, uint16_t wr_data)
Set interrupt level low function.
grideye_write_int_hyst_lvl
void grideye_write_int_hyst_lvl(grideye_t *ctx, uint16_t wr_data)
Set interrupt hysteresis level function.
grideye_set_stat_clr_reg
void grideye_set_stat_clr_reg(grideye_t *ctx, uint8_t int_cnt)
Set Status Clear Register function.
grideye_read_therm_temp_reg
float grideye_read_therm_temp_reg(grideye_t *ctx)
Read Thermistor Temperature Register function.
grideye_cfg_t::int_pin
pin_name_t int_pin
Definition: grideye.h:208
grideye_generic_write
void grideye_generic_write(grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
grideye_read_ave_reg
uint8_t grideye_read_ave_reg(grideye_t *ctx)
Read Average Register function.
GRIDEYE_RETVAL
#define GRIDEYE_RETVAL
Definition: grideye.h:61
grideye_read_stat_reg
uint8_t grideye_read_stat_reg(grideye_t *ctx)
Read Status Register function.
grideye_set_fps1
void grideye_set_fps1(grideye_t *ctx)
Set FPS 1 function.
grideye_set_fps10
void grideye_set_fps10(grideye_t *ctx)
Set FPS 10 function.
grideye_read_int2
uint8_t grideye_read_int2(grideye_t *ctx)
Read Interrupt Table Register 2 function.
grideye_flag_reset
void grideye_flag_reset(grideye_t *ctx)
Flag reset function.
grideye_initial_reset
void grideye_initial_reset(grideye_t *ctx)
Initial reset function.
grideye_set_ave_reg
void grideye_set_ave_reg(grideye_t *ctx, uint8_t mamod)
Set Average Register function.
grideye_t::slave_address
uint8_t slave_address
Definition: grideye.h:192
grideye_check_interrupt
uint8_t grideye_check_interrupt(grideye_t *ctx)
Get Interrupt state function.
grideye_read_power_control
uint8_t grideye_read_power_control(grideye_t *ctx)
Read Power Control function.
grideye_read_int6
uint8_t grideye_read_int6(grideye_t *ctx)
Read Interrupt Table Register 6 function.
grideye_set_int_ctl_reg
void grideye_set_int_ctl_reg(grideye_t *ctx, uint8_t int_cnt)
Set Interrupt Control Register function.
grideye_cfg_t::sda
pin_name_t sda
Definition: grideye.h:204
grideye_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: grideye.h:212
grideye_default_cfg
void grideye_default_cfg(grideye_t *ctx)
Click Default Configuration function.
grideye_write_int_lvl_high
void grideye_write_int_lvl_high(grideye_t *ctx, uint16_t wr_data)
Set interrupt level high function.
grideye_read_data
uint16_t grideye_read_data(grideye_t *ctx, uint8_t rd_addr)
Data read function.
grideye_read_int_ctl_reg
uint8_t grideye_read_int_ctl_reg(grideye_t *ctx)
Read Interrupt Control Register function.
grideye_read_int7
uint8_t grideye_read_int7(grideye_t *ctx)
Read Interrupt Table Register 7 function.
grideye_cfg_setup
void grideye_cfg_setup(grideye_cfg_t *cfg)
Config Object Initialization function.
grideye_init
GRIDEYE_RETVAL grideye_init(grideye_t *ctx, grideye_cfg_t *cfg)
Initialization function.
grideye_t::int_pin
digital_in_t int_pin
Definition: grideye.h:184
grideye_t
Click ctx object definition.
Definition: grideye.h:180
grideye_set_power_control
void grideye_set_power_control(grideye_t *ctx, uint8_t pow_cnt)
Set Power Control function.
grideye_read_int_hyst_lvl
uint16_t grideye_read_int_hyst_lvl(grideye_t *ctx)
Read interrupt hysteresis level function.
grideye_read_int_lvl_low
uint16_t grideye_read_int_lvl_low(grideye_t *ctx)
Read interrupt level low function.
grideye_read_int0
uint8_t grideye_read_int0(grideye_t *ctx)
Read Interrupt Table Register 0 function.
grideye_check_fps
uint8_t grideye_check_fps(grideye_t *ctx)
Check FPS function.
grideye_read_int3
uint8_t grideye_read_int3(grideye_t *ctx)
Read Interrupt Table Register 3 function.
grideye_read_int_lvl_high
uint16_t grideye_read_int_lvl_high(grideye_t *ctx)
Read interrupt level high function.
grideye_t::i2c
i2c_master_t i2c
Definition: grideye.h:188
grideye_cfg_t::i2c_address
uint8_t i2c_address
Definition: grideye.h:213
grideye_generic_read
void grideye_generic_read(grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
grideye_cfg_t
Click configuration structure definition.
Definition: grideye.h:199
grideye_read_int4
uint8_t grideye_read_int4(grideye_t *ctx)
Read Interrupt Table Register 4 function.
grideye_read_int1
uint8_t grideye_read_int1(grideye_t *ctx)
Read Interrupt Table Register 1 function.