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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40
41// -------------------------------------------------------------- PUBLIC MACROS
51#define SCANNER_MAP_MIKROBUS( cfg, mikrobus ) \
52 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
53 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
54 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK )
61#define SCANNER_RETVAL uint8_t
62
63#define SCANNER_OK 0x00
64#define SCANNER_INIT_ERROR 0xFF
71#define SCANNER_REG_OFFSET_LEFT 0x00
72#define SCANNER_REG_GAIN_LEFT 0x01
73#define SCANNER_REG_OFFSET_CENTER 0x02
74#define SCANNER_REG_GAIN_CENTER 0x03
75#define SCANNER_REG_OFFSET_RIGHT 0x04
76#define SCANNER_REG_GAIN_RIGHT 0x05
77#define SCANNER_REG_MODE 0x1F
84#define SCANNER_CMD_IRESET 0x00
85#define SCANNER_CMD_RESET 0x1B
86#define SCANNER_CMD_STARTINT 0x08
87#define SCANNER_CMD_SAMPLEINT 0x10
88#define SCANNER_CMD_READPIXEL 0x02
89#define SCANNER_CMD_ABORTPIXEL 0x19
90#define SCANNER_CMD_READHOLD 0x12
91#define SCANNER_CMD_READHOLD_START 0x16
92#define SCANNER_CMD_REGWRITE 0x40
93#define SCANNER_CMD_REGREAD 0x60
100#define SCANNER_DATA_SLEEP_MODE 0x10
101#define SCANNER_DATA_NORMAL_MODE 0x00 // End group macro
105// --------------------------------------------------------------- PUBLIC TYPES
114typedef struct
115{
116 // Output pins
117
118 digital_out_t mosi;
119 digital_out_t sck;
120
121 // Input pins
122
123 digital_in_t miso;
124
125} scanner_t;
126
130typedef struct
131{
132 // Additional gpio pins
133
134 pin_name_t mosi;
135 pin_name_t miso;
136 pin_name_t sck;
137
139 // End types group
141// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142
148#ifdef __cplusplus
149extern "C"{
150#endif
151
161
171
182void scanner_set_sdi ( scanner_t *ctx, uint8_t sdi_mode );
183
195uint8_t scanner_get_sdo ( scanner_t *ctx );
196
205
214void scanner_serial_cmd ( scanner_t *ctx, uint8_t cmd );
215
227uint8_t scanner_serial_read_reg ( scanner_t *ctx, uint8_t reg_adr );
228
238void scanner_serial_write_reg ( scanner_t *ctx, uint8_t reg_adr, uint8_t write_data );
239
249
259void scanner_read_pixel ( scanner_t *ctx, uint8_t *pixel_data );
260
261#ifdef __cplusplus
262}
263#endif
264#endif // _SCANNER_H_
265 // End public_function group
268
269// ------------------------------------------------------------------------- END
#define SCANNER_RETVAL
Definition: scanner.h:61
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:131
pin_name_t sck
Definition: scanner.h:136
pin_name_t mosi
Definition: scanner.h:134
pin_name_t miso
Definition: scanner.h:135
Click ctx object definition.
Definition: scanner.h:115
digital_out_t sck
Definition: scanner.h:119
digital_out_t mosi
Definition: scanner.h:118
digital_in_t miso
Definition: scanner.h:123