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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define LIGHT_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
59 
65 #define LIGHT_RETVAL uint8_t
66 
67 #define LIGHT_OK 0x00
68 #define LIGHT_INIT_ERROR 0xFF
69 
75 #define LIGHT_COMMAND_REG 0x80
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  // Output pins
91 
92  digital_out_t cs;
93 
94  // Input pins
95 
96  // Modules
97 
98  spi_master_t spi;
99  pin_name_t chip_select;
100 
101 } light_t;
102 
106 typedef struct
107 {
108  // Communication gpio pins
109 
110  pin_name_t miso;
111  pin_name_t mosi;
112  pin_name_t sck;
113  pin_name_t cs;
114 
115  // Additional gpio pins
116 
117 
118  // static variable
119 
120  uint32_t spi_speed;
121  uint8_t spi_mode;
122  spi_master_chip_select_polarity_t cs_polarity;
123 
124 } light_cfg_t;
125  // End types group
127 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
128 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
145 void light_cfg_setup ( light_cfg_t *cfg );
146 
155 
168 (
169  light_t *ctx,
170  uint8_t *wr_buf,
171  uint16_t wr_len,
172  uint8_t *rd_buf,
173  uint16_t rd_len
174 );
175 
185 void light_write_data ( light_t *ctx, uint8_t address, uint8_t write_command );
186 
194 uint16_t light_read_data ( light_t *ctx );
195 
204 uint8_t light_calculate_percent ( light_t *ctx, uint16_t light_value );
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 #endif // _LIGHT_H_
210  // End public_function group
213 
214 // ------------------------------------------------------------------------- END
void light_generic_transfer(light_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
#define LIGHT_RETVAL
Definition: light.h:65
Click ctx object definition.
Definition: light.h:88
pin_name_t miso
Definition: light.h:110
LIGHT_RETVAL light_init(light_t *ctx, light_cfg_t *cfg)
Initialization function.
pin_name_t cs
Definition: light.h:113
uint8_t light_calculate_percent(light_t *ctx, uint16_t light_value)
Function calculate percent.
uint32_t spi_speed
Definition: light.h:120
uint16_t light_read_data(light_t *ctx)
Generic read data function.
Click configuration structure definition.
Definition: light.h:106
void light_write_data(light_t *ctx, uint8_t address, uint8_t write_command)
Generic write data function.
digital_out_t cs
Definition: light.h:92
uint8_t spi_mode
Definition: light.h:121
spi_master_chip_select_polarity_t cs_polarity
Definition: light.h:122
pin_name_t chip_select
Definition: light.h:99
void light_cfg_setup(light_cfg_t *cfg)
Config Object Initialization function.
pin_name_t mosi
Definition: light.h:111
pin_name_t sck
Definition: light.h:112
spi_master_t spi
Definition: light.h:98