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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define LIGHT_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
69 
75 #define LIGHT_RETVAL uint8_t
76 
77 #define LIGHT_OK 0x00
78 #define LIGHT_INIT_ERROR 0xFF
79 
85 #define LIGHT_COMMAND_REG 0x80
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100  // Output pins
101 
102  digital_out_t cs;
103 
104  // Input pins
105 
106  // Modules
107 
108  spi_master_t spi;
109  pin_name_t chip_select;
110 
111 } light_t;
112 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t miso;
121  pin_name_t mosi;
122  pin_name_t sck;
123  pin_name_t cs;
124 
125  // Additional gpio pins
126 
127 
128  // static variable
129 
130  uint32_t spi_speed;
131  uint8_t spi_mode;
132  spi_master_chip_select_polarity_t cs_polarity;
133 
134 } light_cfg_t;
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
165 
173 uint16_t light_read_data ( light_t *ctx );
174 
183 uint8_t light_calculate_percent ( light_t *ctx, uint16_t light_value );
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 #endif // _LIGHT_H_
189  // End public_function group
192 
193 // ------------------------------------------------------------------------- END
LIGHT_RETVAL
#define LIGHT_RETVAL
Definition: light.h:75
light_t::cs
digital_out_t cs
Definition: light.h:102
light_t
Click ctx object definition.
Definition: light.h:99
light_cfg_t::mosi
pin_name_t mosi
Definition: light.h:121
light_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: light.h:132
light_t::chip_select
pin_name_t chip_select
Definition: light.h:109
light_cfg_t::spi_speed
uint32_t spi_speed
Definition: light.h:130
light_cfg_t::cs
pin_name_t cs
Definition: light.h:123
light_cfg_t::spi_mode
uint8_t spi_mode
Definition: light.h:131
light_cfg_t::sck
pin_name_t sck
Definition: light.h:122
light_t::spi
spi_master_t spi
Definition: light.h:108
light_cfg_setup
void light_cfg_setup(light_cfg_t *cfg)
Config Object Initialization function.
light_calculate_percent
uint8_t light_calculate_percent(light_t *ctx, uint16_t light_value)
Function calculate percent.
light_read_data
uint16_t light_read_data(light_t *ctx)
Generic read data function.
light_init
LIGHT_RETVAL light_init(light_t *ctx, light_cfg_t *cfg)
Initialization function.
light_cfg_t::miso
pin_name_t miso
Definition: light.h:120
light_cfg_t
Click configuration structure definition.
Definition: light.h:117