bargraph3  2.0.0.0
bargraph3.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 BARGRAPH3_H
36 #define BARGRAPH3_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 BARGRAPH3_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.oe = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
71 
77 #define BARGRAPH3_RETVAL uint8_t
78 
79 #define BARGRAPH3_OK 0x00
80 #define BARGRAPH3_INIT_ERROR 0xFF
81 
87 #define BARGRAPH3_LED_0 0
88 #define BARGRAPH3_LED_1 1
89 #define BARGRAPH3_LED_2 2
90 #define BARGRAPH3_LED_3 3
91 #define BARGRAPH3_LED_4 4
92 #define BARGRAPH3_LED_5 5
93 
99 #define BARGRAPH3_INCREASE_LED 1
100 #define BARGRAPH3_CONTROL_ONE_LED 0
101 
107 #define BARGRAPH3_DIRECTION_TOP_TO_BOTTOM 1
108 #define BARGRAPH3_DIRECTION_BOTTOM_TO_TOP 0
109 
115 #define BARGRAPH3_DEVICE_ENABLE 0
116 #define BARGRAPH3_DEVICE_DISABLE 1
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  digital_out_t cs;
132 
133  // Output pins
134 
135  digital_out_t oe;
136  digital_out_t rst;
137  digital_out_t pwm;
138 
139  // Modules
140 
141  spi_master_t spi;
142  pin_name_t chip_select;
143 
144 } bargraph3_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
157 
158  // Additional gpio pins
159 
160  pin_name_t oe;
161  pin_name_t rst;
162  pin_name_t pwm;
163 
164  // static variable
165 
166  uint32_t spi_speed;
167  spi_master_mode_t spi_mode;
168  spi_master_chip_select_polarity_t cs_polarity;
169 
171  // End types groupS
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
179 #ifdef __cplusplus
180 extern "C"{
181 #endif
182 
192 
202 
211 
223 void bargraph3_generic_transfer ( bargraph3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
224 void bargraph3_enable ( bargraph3_t *ctx, uint8_t state );
233 void bargraph3_reset ( bargraph3_t *ctx );
241 void bargraph3_set_pwm ( bargraph3_t *ctx, uint8_t state );
250 void bargraph3_display ( bargraph3_t *ctx, uint8_t ctrl, uint8_t dir, uint8_t counter);
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _BARGRAPH3_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- END
bargraph3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: bargraph3.h:168
bargraph3_cfg_t::spi_speed
uint32_t spi_speed
Definition: bargraph3.h:166
bargraph3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: bargraph3.h:167
bargraph3_t::chip_select
pin_name_t chip_select
Definition: bargraph3.h:142
bargraph3_t::spi
spi_master_t spi
Definition: bargraph3.h:141
bargraph3_cfg_setup
void bargraph3_cfg_setup(bargraph3_cfg_t *cfg)
Config Object Initialization function.
BARGRAPH3_RETVAL
#define BARGRAPH3_RETVAL
Definition: bargraph3.h:77
bargraph3_cfg_t::miso
pin_name_t miso
Definition: bargraph3.h:153
bargraph3_reset
void bargraph3_reset(bargraph3_t *ctx)
Functions for reset the chip.
bargraph3_enable
void bargraph3_enable(bargraph3_t *ctx, uint8_t state)
Functions for enable the chip.
bargraph3_set_pwm
void bargraph3_set_pwm(bargraph3_t *ctx, uint8_t state)
Functions for set PWM.
bargraph3_t::rst
digital_out_t rst
Definition: bargraph3.h:136
bargraph3_generic_transfer
void bargraph3_generic_transfer(bargraph3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
bargraph3_cfg_t::mosi
pin_name_t mosi
Definition: bargraph3.h:154
bargraph3_t
Click ctx object definition.
Definition: bargraph3.h:130
bargraph3_cfg_t::cs
pin_name_t cs
Definition: bargraph3.h:156
bargraph3_t::cs
digital_out_t cs
Definition: bargraph3.h:131
bargraph3_cfg_t::sck
pin_name_t sck
Definition: bargraph3.h:155
bargraph3_cfg_t
Click configuration structure definition.
Definition: bargraph3.h:150
bargraph3_t::pwm
digital_out_t pwm
Definition: bargraph3.h:137
bargraph3_default_cfg
void bargraph3_default_cfg(bargraph3_t *ctx)
Click Default Configuration function.
bargraph3_cfg_t::rst
pin_name_t rst
Definition: bargraph3.h:161
bargraph3_display
void bargraph3_display(bargraph3_t *ctx, uint8_t ctrl, uint8_t dir, uint8_t counter)
Displays function.
bargraph3_init
BARGRAPH3_RETVAL bargraph3_init(bargraph3_t *ctx, bargraph3_cfg_t *cfg)
Initialization function.
bargraph3_cfg_t::oe
pin_name_t oe
Definition: bargraph3.h:160
bargraph3_cfg_t::pwm
pin_name_t pwm
Definition: bargraph3.h:162
bargraph3_t::oe
digital_out_t oe
Definition: bargraph3.h:135