scanner  2.0.0.0
scanner.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 SCANNER_H
36 #define SCANNER_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define SCANNER_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK )
69 
75 #define SCANNER_RETVAL uint8_t
76 
77 #define SCANNER_OK 0x00
78 #define SCANNER_INIT_ERROR 0xFF
79 
85 #define SCANNER_REG_OFFSET_LEFT 0x00
86 #define SCANNER_REG_GAIN_LEFT 0x01
87 #define SCANNER_REG_OFFSET_CENTER 0x02
88 #define SCANNER_REG_GAIN_CENTER 0x03
89 #define SCANNER_REG_OFFSET_RIGHT 0x04
90 #define SCANNER_REG_GAIN_RIGHT 0x05
91 #define SCANNER_REG_MODE 0x1F
92 
98 #define SCANNER_CMD_IRESET 0x00
99 #define SCANNER_CMD_RESET 0x1B
100 #define SCANNER_CMD_STARTINT 0x08
101 #define SCANNER_CMD_SAMPLEINT 0x10
102 #define SCANNER_CMD_READPIXEL 0x02
103 #define SCANNER_CMD_ABORTPIXEL 0x19
104 #define SCANNER_CMD_READHOLD 0x12
105 #define SCANNER_CMD_READHOLD_START 0x16
106 #define SCANNER_CMD_REGWRITE 0x40
107 #define SCANNER_CMD_REGREAD 0x60
108 
114 #define SCANNER_DATA_SLEEP_MODE 0x10
115 #define SCANNER_DATA_NORMAL_MODE 0x00
116  // End group macro
119 // --------------------------------------------------------------- PUBLIC TYPES
128 typedef struct
129 {
130  // Output pins
131 
132  digital_out_t mosi;
133  digital_out_t sck;
134 
135  // Input pins
136 
137  digital_in_t miso;
138 
139 } scanner_t;
140 
144 typedef struct
145 {
146  // Additional gpio pins
147 
148  pin_name_t mosi;
149  pin_name_t miso;
150  pin_name_t sck;
151 
152 } scanner_cfg_t;
153  // End types group
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
185 
196 void scanner_set_sdi ( scanner_t *ctx, uint8_t sdi_mode );
197 
209 uint8_t scanner_get_sdo ( scanner_t *ctx );
210 
218 void scanner_clock ( scanner_t *ctx );
219 
228 void scanner_serial_cmd ( scanner_t *ctx, uint8_t cmd );
229 
241 uint8_t scanner_serial_read_reg ( scanner_t *ctx, uint8_t reg_adr );
242 
252 void scanner_serial_write_reg ( scanner_t *ctx, uint8_t reg_adr, uint8_t write_data );
253 
263 
273 void scanner_read_pixel ( scanner_t *ctx, uint8_t *pixel_data );
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // _SCANNER_H_
279  // End public_function group
282 
283 // ------------------------------------------------------------------------- END
scanner_t::sck
digital_out_t sck
Definition: scanner.h:133
scanner_cfg_setup
void scanner_cfg_setup(scanner_cfg_t *cfg)
Config Object Initialization function.
scanner_init
SCANNER_RETVAL scanner_init(scanner_t *ctx, scanner_cfg_t *cfg)
Initialization function.
scanner_t::miso
digital_in_t miso
Definition: scanner.h:137
scanner_cfg_t::mosi
pin_name_t mosi
Definition: scanner.h:148
scanner_set_sdi
void scanner_set_sdi(scanner_t *ctx, uint8_t sdi_mode)
Set SDI Pin function.
scanner_read_pixel
void scanner_read_pixel(scanner_t *ctx, uint8_t *pixel_data)
Read pixels.
SCANNER_RETVAL
#define SCANNER_RETVAL
Definition: scanner.h:75
scanner_serial_cmd
void scanner_serial_cmd(scanner_t *ctx, uint8_t cmd)
Write function.
scanner_cfg_t
Click configuration structure definition.
Definition: scanner.h:145
scanner_cfg_t::sck
pin_name_t sck
Definition: scanner.h:150
scanner_startup
void scanner_startup(scanner_t *ctx)
Start function.
scanner_clock
void scanner_clock(scanner_t *ctx)
Pulse function.
scanner_cfg_t::miso
pin_name_t miso
Definition: scanner.h:149
scanner_get_sdo
uint8_t scanner_get_sdo(scanner_t *ctx)
Get SDO Pin state function.
scanner_t::mosi
digital_out_t mosi
Definition: scanner.h:132
scanner_t
Click ctx object definition.
Definition: scanner.h:129
scanner_serial_write_reg
void scanner_serial_write_reg(scanner_t *ctx, uint8_t reg_adr, uint8_t write_data)
Write function.
scanner_serial_read_reg
uint8_t scanner_serial_read_reg(scanner_t *ctx, uint8_t reg_adr)
Read function.