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_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define GRIDEYE_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define GRIDEYE_RETVAL uint8_t
64 
65 #define GRIDEYE_OK 0x00
66 #define GRIDEYE_INIT_ERROR 0xFF
67 
73 #define GRIDEYE_I2C_ADDR 0x68
74 
80 #define GRIDEYE_PCLT 0x00
81 #define GRIDEYE_RST 0x01
82 #define GRIDEYE_FPSC 0x02
83 #define GRIDEYE_INTC 0x03
84 #define GRIDEYE_STAT 0x04
85 #define GRIDEYE_SCLR 0x05
86 #define GRIDEYE_AVE 0x07
87 
88 #define GRIDEYE_INTHL 0x08
89 #define GRIDEYE_INTHH 0x09
90 #define GRIDEYE_INTLL 0x0A
91 #define GRIDEYE_INTLH 0x0B
92 #define GRIDEYE_IHYSL 0x0C
93 #define GRIDEYE_IHYSH 0x0D
94 #define GRIDEYE_TTHL 0x0E
95 #define GRIDEYE_TTHH 0x0F
96 
102 #define GRIDEYE_INT0 0x10
103 #define GRIDEYE_INT1 0x11
104 #define GRIDEYE_INT2 0x12
105 #define GRIDEYE_INT3 0x13
106 #define GRIDEYE_INT4 0x14
107 #define GRIDEYE_INT5 0x15
108 #define GRIDEYE_INT6 0x16
109 #define GRIDEYE_INT7 0x17
110 
116 #define GRIDEYE_PCLT_NORMAL 0x00
117 #define GRIDEYE_PCLT_SLEEP 0x10
118 #define GRIDEYE_PCLT_STANDBY_60 0x20
119 #define GRIDEYE_PCLT_STANDBY_10 0x21
120 
126 #define GRIDEYE_RST_FLAG 0x30
127 #define GRIDEYE_RST_INIT 0x3F
128 
134 #define GRIDEYE_FPSC_1FPS 0x01
135 #define GRIDEYE_FPSC_10FPS 0x00
136 
142 #define GRIDEYE_INTC_INTEN_ACTIVE 0x01
143 #define GRIDEYE_INTC_INTEN_INACTIVE 0x00
144 #define GRIDEYE_INTC_INTMOD_ABSO 0x10
145 #define GRIDEYE_INTC_INTMOD_DIFE 0x00
146 
152 #define GRIDEYE_SCLR_INTCLR 0x02
153 #define GRIDEYE_SCLR_OVS_CLR 0x04
154 #define GRIDEYE_SCLR_OVT_CLR 0x08
155 
161 #define GRIDEYE_AVE_MAMOD_ACTIVE 0x20
162 #define GRIDEYE_AVE_MAMOD_INACTIVE 0x00
163 
169 #define GRIDEYE_PIXELS 0x80
170  // End group macro
173 // --------------------------------------------------------------- PUBLIC TYPES
182 typedef struct
183 {
184  // Input pins
185 
186  digital_in_t int_pin;
187 
188  // Modules
189 
190  i2c_master_t i2c;
191 
192  // ctx variable
193 
194  uint8_t slave_address;
195 
196 } grideye_t;
197 
201 typedef struct
202 {
203  // Communication gpio pins
204 
205  pin_name_t scl;
206  pin_name_t sda;
207 
208  // Additional gpio pins
209 
210  pin_name_t int_pin;
211 
212  // static variable
213 
214  uint32_t i2c_speed;
215  uint8_t i2c_address;
216 
217 } grideye_cfg_t;
218  // End types group
220 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
221 
227 #ifdef __cplusplus
228 extern "C"{
229 #endif
230 
239 void grideye_cfg_setup ( grideye_cfg_t *cfg );
240 
249 
257 void grideye_default_cfg ( grideye_t *ctx );
258 
268 void grideye_generic_write ( grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
269 
281 void grideye_generic_read ( grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
282 
294 void grideye_write_data ( grideye_t *ctx, uint8_t wr_addr, uint16_t wr_data );
295 
306 uint16_t grideye_read_data ( grideye_t *ctx, uint8_t rd_addr );
307 
316 void grideye_read_grid ( grideye_t *ctx, uint16_t *buffer );
317 
329 uint8_t grideye_check_interrupt ( grideye_t *ctx );
330 
340 void grideye_set_power_control ( grideye_t *ctx, uint8_t pow_cnt );
341 
352 uint8_t grideye_read_power_control ( grideye_t *ctx );
353 
362 void grideye_flag_reset ( grideye_t *ctx );
363 
372 void grideye_initial_reset ( grideye_t *ctx );
373 
381 void grideye_set_fps1 ( grideye_t *ctx );
382 
390 void grideye_set_fps10 ( grideye_t *ctx );
391 
403 uint8_t grideye_check_fps ( grideye_t *ctx );
404 
414 void grideye_set_int_ctl_reg ( grideye_t *ctx, uint8_t int_cnt );
415 
426 uint8_t grideye_read_int_ctl_reg ( grideye_t *ctx );
427 
438 uint8_t grideye_read_stat_reg ( grideye_t *ctx );
439 
449 void grideye_set_stat_clr_reg ( grideye_t *ctx, uint8_t int_cnt );
450 
461 void grideye_set_ave_reg ( grideye_t *ctx, uint8_t mamod );
462 
473 uint8_t grideye_read_ave_reg ( grideye_t *ctx );
474 
483 void grideye_write_int_lvl_high ( grideye_t *ctx, uint16_t wr_data );
484 
492 void grideye_write_int_lvl_low( grideye_t *ctx, uint16_t wr_data );
493 
503 uint16_t grideye_read_int_lvl_high ( grideye_t *ctx );
504 
514 uint16_t grideye_read_int_lvl_low ( grideye_t *ctx );
515 
524 void grideye_write_int_hyst_lvl ( grideye_t *ctx, uint16_t wr_data );
525 
535 uint16_t grideye_read_int_hyst_lvl ( grideye_t *ctx );
536 
547 
557 uint8_t grideye_read_int0 ( grideye_t *ctx );
558 
568 uint8_t grideye_read_int1 ( grideye_t *ctx );
578 uint8_t grideye_read_int2 ( grideye_t *ctx );
579 
589 uint8_t grideye_read_int3 ( grideye_t *ctx );
590 
600 uint8_t grideye_read_int4 ( grideye_t *ctx );
601 
611 uint8_t grideye_read_int5 ( grideye_t *ctx );
612 
622 uint8_t grideye_read_int6 ( grideye_t *ctx );
623 
633 uint8_t grideye_read_int7 ( grideye_t *ctx );
634 
635 #ifdef __cplusplus
636 }
637 #endif
638 #endif // _GRIDEYE_H_
639  // End public_function group
642 
643 // ------------------------------------------------------------------------- END
void grideye_set_int_ctl_reg(grideye_t *ctx, uint8_t int_cnt)
Set Interrupt Control Register function.
void grideye_set_fps10(grideye_t *ctx)
Set FPS 10 function.
uint16_t grideye_read_int_lvl_high(grideye_t *ctx)
Read interrupt level high function.
void grideye_write_int_lvl_high(grideye_t *ctx, uint16_t wr_data)
Set interrupt level high function.
uint8_t grideye_read_int5(grideye_t *ctx)
Read Interrupt Table Register 5 function.
void grideye_default_cfg(grideye_t *ctx)
Click Default Configuration function.
uint8_t grideye_read_int6(grideye_t *ctx)
Read Interrupt Table Register 6 function.
#define GRIDEYE_RETVAL
Definition: grideye.h:63
uint8_t grideye_read_int0(grideye_t *ctx)
Read Interrupt Table Register 0 function.
void grideye_set_ave_reg(grideye_t *ctx, uint8_t mamod)
Set Average Register function.
void grideye_set_fps1(grideye_t *ctx)
Set FPS 1 function.
uint16_t grideye_read_int_lvl_low(grideye_t *ctx)
Read interrupt level low function.
Click ctx object definition.
Definition: grideye.h:182
uint8_t grideye_read_int2(grideye_t *ctx)
Read Interrupt Table Register 2 function.
uint8_t grideye_read_int_ctl_reg(grideye_t *ctx)
Read Interrupt Control Register function.
uint8_t grideye_read_stat_reg(grideye_t *ctx)
Read Status Register function.
void grideye_cfg_setup(grideye_cfg_t *cfg)
Config Object Initialization function.
uint8_t i2c_address
Definition: grideye.h:215
pin_name_t scl
Definition: grideye.h:205
uint8_t slave_address
Definition: grideye.h:194
uint8_t grideye_check_interrupt(grideye_t *ctx)
Get Interrupt state function.
uint8_t grideye_check_fps(grideye_t *ctx)
Check FPS function.
void grideye_write_data(grideye_t *ctx, uint8_t wr_addr, uint16_t wr_data)
Write data function.
uint16_t grideye_read_data(grideye_t *ctx, uint8_t rd_addr)
Data read function.
uint32_t i2c_speed
Definition: grideye.h:214
uint8_t grideye_read_int3(grideye_t *ctx)
Read Interrupt Table Register 3 function.
uint8_t grideye_read_power_control(grideye_t *ctx)
Read Power Control function.
Click configuration structure definition.
Definition: grideye.h:201
void grideye_generic_read(grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float grideye_read_therm_temp_reg(grideye_t *ctx)
Read Thermistor Temperature Register function.
void grideye_write_int_lvl_low(grideye_t *ctx, uint16_t wr_data)
Set interrupt level low function.
void grideye_flag_reset(grideye_t *ctx)
Flag reset function.
uint8_t grideye_read_int7(grideye_t *ctx)
Read Interrupt Table Register 7 function.
void grideye_set_stat_clr_reg(grideye_t *ctx, uint8_t int_cnt)
Set Status Clear Register function.
uint8_t grideye_read_int4(grideye_t *ctx)
Read Interrupt Table Register 4 function.
void grideye_read_grid(grideye_t *ctx, uint16_t *buffer)
Read whole grid function.
void grideye_initial_reset(grideye_t *ctx)
Initial reset function.
i2c_master_t i2c
Definition: grideye.h:190
uint16_t grideye_read_int_hyst_lvl(grideye_t *ctx)
Read interrupt hysteresis level function.
pin_name_t sda
Definition: grideye.h:206
uint8_t grideye_read_int1(grideye_t *ctx)
Read Interrupt Table Register 1 function.
pin_name_t int_pin
Definition: grideye.h:210
uint8_t grideye_read_ave_reg(grideye_t *ctx)
Read Average Register function.
void grideye_set_power_control(grideye_t *ctx, uint8_t pow_cnt)
Set Power Control function.
void grideye_generic_write(grideye_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
digital_in_t int_pin
Definition: grideye.h:186
void grideye_write_int_hyst_lvl(grideye_t *ctx, uint16_t wr_data)
Set interrupt hysteresis level function.
GRIDEYE_RETVAL grideye_init(grideye_t *ctx, grideye_cfg_t *cfg)
Initialization function.