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 "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 // -------------------------------------------------------------- PUBLIC MACROS
63 #define BARGRAPH2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
70 
76 #define BARGRAPH2_RETVAL uint8_t
77 
78 #define BARGRAPH2_OK 0x00
79 #define BARGRAPH2_INIT_ERROR 0xFF
80 
86 #define BARGRAPH2_POWER_ON 1
87 #define BARGRAPH2_POWER_OFF 0
88 
94 #define BARGRAPH2_LED_SEG_0 0x00
95 #define BARGRAPH2_LED_SEG_1 0x01
96 #define BARGRAPH2_LED_SEG_2 0x02
97 #define BARGRAPH2_LED_SEG_3 0x04
98 #define BARGRAPH2_LED_SEG_4 0x08
99 #define BARGRAPH2_LED_SEG_5 0x10
100 #define BARGRAPH2_LED_SEG_6 0x20
101 #define BARGRAPH2_LED_SEG_7 0x40
102 #define BARGRAPH2_LED_SEG_8 0x80
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  digital_out_t cs;
118 
119  // Output pins
120 
121  digital_out_t mr;
122  digital_out_t pwm;
123 
124  // Modules
125 
126  spi_master_t spi;
127  pin_name_t chip_select;
128 
129 } bargraph2_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t miso;
139  pin_name_t mosi;
140  pin_name_t sck;
141  pin_name_t cs;
142 
143  // Additional gpio pins
144 
145  pin_name_t mr;
146  pin_name_t pwm;
147 
148  // static variable
149 
150  uint32_t spi_speed;
151  spi_master_mode_t spi_mode;
152  spi_master_chip_select_polarity_t cs_polarity;
153 
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
176 
186 
195 
207 void bargraph2_generic_transfer ( bargraph2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
208 
217 
226 void bargraph2_write_byte ( bargraph2_t *ctx, uint8_t input_data );
227 
239 void bargraph2_led_green ( bargraph2_t *ctx, uint8_t index );
240 
252 void bargraph2_led_red ( bargraph2_t *ctx, uint8_t index );
253 
265 void bargraph2_led_yellow ( bargraph2_t *ctx, uint8_t index );
266 
277 void bargraph2_leds_green ( bargraph2_t *ctx, int start_index, int end_index );
278 
289 void bargraph2_leds_red ( bargraph2_t *ctx, int start_index, int end_index );
290 
301 void bargraph2_leds_yellow ( bargraph2_t *ctx, int start_index, int end_index );
302 
311 
320 void barpgraph2_power ( bargraph2_t *ctx, uint8_t power_on_off );
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // _BARGRAPH2_H_
326  // End public_function group
329 
330 // ------------------------------------------------------------------------- END
bargraph2_t
Click ctx object definition.
Definition: bargraph2.h:116
bargraph2_lights_out
void bargraph2_lights_out(bargraph2_t *ctx)
Lights out function.
bargraph2_default_cfg
void bargraph2_default_cfg(bargraph2_t *ctx)
Click Default Configuration function.
bargraph2_leds_red
void bargraph2_leds_red(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
bargraph2_cfg_t::spi_speed
uint32_t spi_speed
Definition: bargraph2.h:150
bargraph2_t::spi
spi_master_t spi
Definition: bargraph2.h:126
bargraph2_t::chip_select
pin_name_t chip_select
Definition: bargraph2.h:127
bargraph2_write_byte
void bargraph2_write_byte(bargraph2_t *ctx, uint8_t input_data)
Write byte function.
bargraph2_leds_yellow
void bargraph2_leds_yellow(bargraph2_t *ctx, int start_index, int end_index)
LEDs red function.
barpgraph2_power
void barpgraph2_power(bargraph2_t *ctx, uint8_t power_on_off)
Lights out function.
bargraph2_cfg_t::pwm
pin_name_t pwm
Definition: bargraph2.h:146
bargraph2_cfg_t::miso
pin_name_t miso
Definition: bargraph2.h:138
bargraph2_led_yellow
void bargraph2_led_yellow(bargraph2_t *ctx, uint8_t index)
LED yellow function.
bargraph2_t::pwm
digital_out_t pwm
Definition: bargraph2.h:122
bargraph2_cfg_t::sck
pin_name_t sck
Definition: bargraph2.h:140
bargraph2_generic_transfer
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.
bargraph2_led_green
void bargraph2_led_green(bargraph2_t *ctx, uint8_t index)
LED green function.
bargraph2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: bargraph2.h:151
bargraph2_cfg_t::mr
pin_name_t mr
Definition: bargraph2.h:145
bargraph2_reset
void bargraph2_reset(bargraph2_t *ctx)
Reset function.
bargraph2_t::cs
digital_out_t cs
Definition: bargraph2.h:117
bargraph2_cfg_t::mosi
pin_name_t mosi
Definition: bargraph2.h:139
bargraph2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: bargraph2.h:152
bargraph2_cfg_setup
void bargraph2_cfg_setup(bargraph2_cfg_t *cfg)
Config Object Initialization function.
bargraph2_cfg_t::cs
pin_name_t cs
Definition: bargraph2.h:141
bargraph2_led_red
void bargraph2_led_red(bargraph2_t *ctx, uint8_t index)
LED red function.
bargraph2_leds_green
void bargraph2_leds_green(bargraph2_t *ctx, int start_index, int end_index)
LEDs green function.
bargraph2_init
BARGRAPH2_RETVAL bargraph2_init(bargraph2_t *ctx, bargraph2_cfg_t *cfg)
Initialization function.
BARGRAPH2_RETVAL
#define BARGRAPH2_RETVAL
Definition: bargraph2.h:76
bargraph2_cfg_t
Click configuration structure definition.
Definition: bargraph2.h:135
bargraph2_t::mr
digital_out_t mr
Definition: bargraph2.h:121