light 2.0.0.0
light.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 LIGHT_H
36#define LIGHT_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#include "drv_spi_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define LIGHT_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
79#define LIGHT_RETVAL uint8_t
80
81#define LIGHT_OK 0x00
82#define LIGHT_INIT_ERROR 0xFF
89#define LIGHT_COMMAND_REG 0x80
92 // End group macro
93// --------------------------------------------------------------- PUBLIC TYPES
102typedef struct
103{
104 // Output pins
105
106 digital_out_t cs;
107
108 // Input pins
109
110 // Modules
111
112 spi_master_t spi;
113 pin_name_t chip_select;
114
115} light_t;
116
120typedef struct
121{
122 // Communication gpio pins
123
124 pin_name_t miso;
125 pin_name_t mosi;
126 pin_name_t sck;
127 pin_name_t cs;
128
129 // Additional gpio pins
130
131
132 // static variable
133
134 uint32_t spi_speed;
135 uint8_t spi_mode;
136 spi_master_chip_select_polarity_t cs_polarity;
137
139
140 // End types group
141// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142
147#ifdef __cplusplus
148extern "C"{
149#endif
150
160
169
177uint16_t light_read_data ( light_t *ctx );
178
187uint8_t light_calculate_percent ( light_t *ctx, uint16_t light_value );
188
189#ifdef __cplusplus
190}
191#endif
192#endif // _LIGHT_H_
193
194 // End public_function group
196
197// ------------------------------------------------------------------------- END
#define LIGHT_RETVAL
Definition light.h:79
uint8_t light_calculate_percent(light_t *ctx, uint16_t light_value)
Function calculate percent.
LIGHT_RETVAL light_init(light_t *ctx, light_cfg_t *cfg)
Initialization function.
uint16_t light_read_data(light_t *ctx)
Generic read data function.
void light_cfg_setup(light_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition light.h:121
uint8_t spi_mode
Definition light.h:135
spi_master_chip_select_polarity_t cs_polarity
Definition light.h:136
pin_name_t sck
Definition light.h:126
pin_name_t mosi
Definition light.h:125
uint32_t spi_speed
Definition light.h:134
pin_name_t miso
Definition light.h:124
pin_name_t cs
Definition light.h:127
Click ctx object definition.
Definition light.h:103
digital_out_t cs
Definition light.h:106
spi_master_t spi
Definition light.h:112
pin_name_t chip_select
Definition light.h:113