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 )
75#define SCANNER_RETVAL uint8_t
76
77#define SCANNER_OK 0x00
78#define SCANNER_INIT_ERROR 0xFF
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
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
114#define SCANNER_DATA_SLEEP_MODE 0x10
115#define SCANNER_DATA_NORMAL_MODE 0x00
118 // End group macro
119// --------------------------------------------------------------- PUBLIC TYPES
128typedef 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
144typedef struct
145{
146 // Additional gpio pins
147
148 pin_name_t mosi;
149 pin_name_t miso;
150 pin_name_t sck;
151
153
154 // End types group
155// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156
162#ifdef __cplusplus
163extern "C"{
164#endif
165
175
185
196void scanner_set_sdi ( scanner_t *ctx, uint8_t sdi_mode );
197
209uint8_t scanner_get_sdo ( scanner_t *ctx );
210
219
228void scanner_serial_cmd ( scanner_t *ctx, uint8_t cmd );
229
241uint8_t scanner_serial_read_reg ( scanner_t *ctx, uint8_t reg_adr );
242
252void scanner_serial_write_reg ( scanner_t *ctx, uint8_t reg_adr, uint8_t write_data );
253
263
273void scanner_read_pixel ( scanner_t *ctx, uint8_t *pixel_data );
274
275#ifdef __cplusplus
276}
277#endif
278#endif // _SCANNER_H_
279
280 // End public_function group
282
283// ------------------------------------------------------------------------- END
#define SCANNER_RETVAL
Definition scanner.h:75
void scanner_serial_write_reg(scanner_t *ctx, uint8_t reg_adr, uint8_t write_data)
Write function.
void scanner_set_sdi(scanner_t *ctx, uint8_t sdi_mode)
Set SDI Pin function.
void scanner_startup(scanner_t *ctx)
Start function.
uint8_t scanner_serial_read_reg(scanner_t *ctx, uint8_t reg_adr)
Read function.
void scanner_read_pixel(scanner_t *ctx, uint8_t *pixel_data)
Read pixels.
void scanner_clock(scanner_t *ctx)
Pulse function.
void scanner_cfg_setup(scanner_cfg_t *cfg)
Config Object Initialization function.
void scanner_serial_cmd(scanner_t *ctx, uint8_t cmd)
Write function.
uint8_t scanner_get_sdo(scanner_t *ctx)
Get SDO Pin state function.
SCANNER_RETVAL scanner_init(scanner_t *ctx, scanner_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition scanner.h:145
pin_name_t sck
Definition scanner.h:150
pin_name_t mosi
Definition scanner.h:148
pin_name_t miso
Definition scanner.h:149
Click ctx object definition.
Definition scanner.h:129
digital_out_t sck
Definition scanner.h:133
digital_out_t mosi
Definition scanner.h:132
digital_in_t miso
Definition scanner.h:137