bargraph2  2.0.0.0
bargraph2.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 BARGRAPH2_H
36 #define BARGRAPH2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define BARGRAPH2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
60 
66 #define BARGRAPH2_RETVAL uint8_t
67 
68 #define BARGRAPH2_OK 0x00
69 #define BARGRAPH2_INIT_ERROR 0xFF
70 
76 #define BARGRAPH2_LED_SEG_0 0x00
77 #define BARGRAPH2_LED_SEG_1 0x01
78 #define BARGRAPH2_LED_SEG_2 0x02
79 #define BARGRAPH2_LED_SEG_3 0x04
80 #define BARGRAPH2_LED_SEG_4 0x08
81 #define BARGRAPH2_LED_SEG_5 0x10
82 #define BARGRAPH2_LED_SEG_6 0x20
83 #define BARGRAPH2_LED_SEG_7 0x40
84 #define BARGRAPH2_LED_SEG_8 0x80
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  digital_out_t cs;
100 
101  // Output pins
102 
103  digital_out_t mr;
104  digital_out_t pwm;
105 
106  // Modules
107 
108  spi_master_t spi;
109  pin_name_t chip_select;
110 
111 } bargraph2_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  pin_name_t mr;
128  pin_name_t pwm;
129 
130  // static variable
131 
132  uint32_t spi_speed;
133  spi_master_mode_t spi_mode;
134  spi_master_chip_select_polarity_t cs_polarity;
135 
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
168 
176 void bargraph2_default_cfg ( bargraph2_t *ctx );
177 
189 void bargraph2_generic_transfer ( bargraph2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
190 
198 void bargraph2_reset ( bargraph2_t *ctx );
199 
208 void bargraph2_write_byte ( bargraph2_t *ctx, uint8_t input_data );
209 
221 void bargraph2_led_green ( bargraph2_t *ctx, uint8_t index );
222 
234 void bargraph2_led_red ( bargraph2_t *ctx, uint8_t index );
235 
247 void bargraph2_led_yellow ( bargraph2_t *ctx, uint8_t index );
248 
259 void bargraph2_leds_green ( bargraph2_t *ctx, int start_index, int end_index );
260 
271 void bargraph2_leds_red ( bargraph2_t *ctx, int start_index, int end_index );
272 
283 void bargraph2_leds_yellow ( bargraph2_t *ctx, int start_index, int end_index );
284 
292 void bargraph2_lights_out ( bargraph2_t *ctx );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // _BARGRAPH2_H_
298  // End public_function group
301 
302 // ------------------------------------------------------------------------- END
pin_name_t mr
Definition: bargraph2.h:127
void bargraph2_generic_transfer(bargraph2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void bargraph2_cfg_setup(bargraph2_cfg_t *cfg)
Config Object Initialization function.
BARGRAPH2_RETVAL bargraph2_init(bargraph2_t *ctx, bargraph2_cfg_t *cfg)
Initialization function.
digital_out_t mr
Definition: bargraph2.h:103
pin_name_t pwm
Definition: bargraph2.h:128
pin_name_t miso
Definition: bargraph2.h:120
void bargraph2_leds_red(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
pin_name_t sck
Definition: bargraph2.h:122
Click ctx object definition.
Definition: bargraph2.h:97
Click configuration structure definition.
Definition: bargraph2.h:116
pin_name_t cs
Definition: bargraph2.h:123
spi_master_t spi
Definition: bargraph2.h:108
void bargraph2_leds_green(bargraph2_t *ctx, int start_index, int end_index)
LEDs green function.
uint32_t spi_speed
Definition: bargraph2.h:132
void bargraph2_led_red(bargraph2_t *ctx, uint8_t index)
LED red function.
void bargraph2_leds_yellow(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
#define BARGRAPH2_RETVAL
Definition: bargraph2.h:66
void bargraph2_led_yellow(bargraph2_t *ctx, uint8_t index)
LED yellow function.
pin_name_t mosi
Definition: bargraph2.h:121
void bargraph2_led_green(bargraph2_t *ctx, uint8_t index)
LED green function.
void bargraph2_default_cfg(bargraph2_t *ctx)
Click Default Configuration function.
digital_out_t pwm
Definition: bargraph2.h:104
spi_master_chip_select_polarity_t cs_polarity
Definition: bargraph2.h:134
spi_master_mode_t spi_mode
Definition: bargraph2.h:133
digital_out_t cs
Definition: bargraph2.h:99
void bargraph2_write_byte(bargraph2_t *ctx, uint8_t input_data)
Write byte function.
pin_name_t chip_select
Definition: bargraph2.h:109
void bargraph2_lights_out(bargraph2_t *ctx)
Lights out function.
void bargraph2_reset(bargraph2_t *ctx)
Reset function.