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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define BARGRAPH3_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.oe = MIKROBUS( mikrobus, MIKROBUS_AN ); \
73  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
75 
81 #define BARGRAPH3_RETVAL uint8_t
82 
83 #define BARGRAPH3_OK 0x00
84 #define BARGRAPH3_INIT_ERROR 0xFF
85 
91 #define BARGRAPH3_LED_0 0
92 #define BARGRAPH3_LED_1 1
93 #define BARGRAPH3_LED_2 2
94 #define BARGRAPH3_LED_3 3
95 #define BARGRAPH3_LED_4 4
96 #define BARGRAPH3_LED_5 5
97 
103 #define BARGRAPH3_INCREASE_LED 1
104 #define BARGRAPH3_CONTROL_ONE_LED 0
105 
111 #define BARGRAPH3_DIRECTION_TOP_TO_BOTTOM 1
112 #define BARGRAPH3_DIRECTION_BOTTOM_TO_TOP 0
113 
119 #define BARGRAPH3_DEVICE_ENABLE 0
120 #define BARGRAPH3_DEVICE_DISABLE 1
121  // End group macro
124 // --------------------------------------------------------------- PUBLIC TYPES
133 typedef struct
134 {
135  digital_out_t cs;
136 
137  // Output pins
138 
139  digital_out_t oe;
140  digital_out_t rst;
141  digital_out_t pwm;
142 
143  // Modules
144 
145  spi_master_t spi;
146  pin_name_t chip_select;
147 
148 } bargraph3_t;
149 
153 typedef struct
154 {
155  // Communication gpio pins
156 
157  pin_name_t miso;
158  pin_name_t mosi;
159  pin_name_t sck;
160  pin_name_t cs;
161 
162  // Additional gpio pins
163 
164  pin_name_t oe;
165  pin_name_t rst;
166  pin_name_t pwm;
167 
168  // static variable
169 
170  uint32_t spi_speed;
171  spi_master_mode_t spi_mode;
172  spi_master_chip_select_polarity_t cs_polarity;
173 
175  // End types groupS
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178 
183 #ifdef __cplusplus
184 extern "C"{
185 #endif
186 
196 
206 
215 
227 void bargraph3_generic_transfer ( bargraph3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
228 void bargraph3_enable ( bargraph3_t *ctx, uint8_t state );
237 void bargraph3_reset ( bargraph3_t *ctx );
245 void bargraph3_set_pwm ( bargraph3_t *ctx, uint8_t state );
254 void bargraph3_display ( bargraph3_t *ctx, uint8_t ctrl, uint8_t dir, uint8_t counter);
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 #endif // _BARGRAPH3_H_
270  // End public_function group
273 
274 // ------------------------------------------------------------------------- END
bargraph3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: bargraph3.h:172
bargraph3_cfg_t::spi_speed
uint32_t spi_speed
Definition: bargraph3.h:170
bargraph3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: bargraph3.h:171
bargraph3_t::chip_select
pin_name_t chip_select
Definition: bargraph3.h:146
bargraph3_t::spi
spi_master_t spi
Definition: bargraph3.h:145
bargraph3_cfg_setup
void bargraph3_cfg_setup(bargraph3_cfg_t *cfg)
Config Object Initialization function.
BARGRAPH3_RETVAL
#define BARGRAPH3_RETVAL
Definition: bargraph3.h:81
bargraph3_cfg_t::miso
pin_name_t miso
Definition: bargraph3.h:157
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:140
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:158
bargraph3_t
Click ctx object definition.
Definition: bargraph3.h:134
bargraph3_cfg_t::cs
pin_name_t cs
Definition: bargraph3.h:160
bargraph3_t::cs
digital_out_t cs
Definition: bargraph3.h:135
bargraph3_cfg_t::sck
pin_name_t sck
Definition: bargraph3.h:159
bargraph3_cfg_t
Click configuration structure definition.
Definition: bargraph3.h:154
bargraph3_t::pwm
digital_out_t pwm
Definition: bargraph3.h:141
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:165
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:164
bargraph3_cfg_t::pwm
pin_name_t pwm
Definition: bargraph3.h:166
bargraph3_t::oe
digital_out_t oe
Definition: bargraph3.h:139