bargraph  2.0.0.0
bargraph.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 BARGRAPH_H
36 #define BARGRAPH_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 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define BARGRAPH_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
75 
76 
83 #define BARGRAPH_RETVAL uint8_t
84 
85 #define BARGRAPH_OK 0x00
86 #define BARGRAPH_INIT_ERROR 0xFF
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  digital_out_t cs;
102 
103  // Output pins
104 
105  digital_out_t mr;
106  digital_out_t pwm;
107 
108  // Modules
109 
110  spi_master_t spi;
111  pin_name_t chip_select;
112 
113 } bargraph_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t miso;
123  pin_name_t mosi;
124  pin_name_t sck;
125  pin_name_t cs;
126 
127  // Additional gpio pins
128 
129  pin_name_t mr;
130  pin_name_t pwm;
131 
132  // static variable
133 
134  uint32_t spi_speed;
135  spi_master_mode_t spi_mode;
136  spi_master_chip_select_polarity_t cs_polarity;
137 
139  // End types group
141 
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
171 
183 void bargraph_generic_transfer ( bargraph_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
184 
193 
202 
211 void bargraph_display( bargraph_t *ctx, uint8_t input );
212 
221 void bargraph_enable ( bargraph_t *ctx, uint8_t input );
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 #endif // _BARGRAPH_H_
227  // End public_function group
230 
231 // ------------------------------------------------------------------------- END
bargraph_init
BARGRAPH_RETVAL bargraph_init(bargraph_t *ctx, bargraph_cfg_t *cfg)
Initialization function.
bargraph_cfg_t
Click configuration structure definition.
Definition: bargraph.h:119
bargraph_driver_init
void bargraph_driver_init(bargraph_t *ctx)
Functions for initializes the chip.
bargraph_t::spi
spi_master_t spi
Definition: bargraph.h:110
bargraph_cfg_setup
void bargraph_cfg_setup(bargraph_cfg_t *cfg)
Config Object Initialization function.
bargraph_t::pwm
digital_out_t pwm
Definition: bargraph.h:106
bargraph_generic_transfer
void bargraph_generic_transfer(bargraph_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
bargraph_t::chip_select
pin_name_t chip_select
Definition: bargraph.h:111
bargraph_enable
void bargraph_enable(bargraph_t *ctx, uint8_t input)
Functions for enable the chip.
bargraph_cfg_t::spi_speed
uint32_t spi_speed
Definition: bargraph.h:134
bargraph_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: bargraph.h:135
bargraph_display
void bargraph_display(bargraph_t *ctx, uint8_t input)
Displays function.
bargraph_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: bargraph.h:136
bargraph_cfg_t::mr
pin_name_t mr
Definition: bargraph.h:129
bargraph_t
Click ctx object definition.
Definition: bargraph.h:100
bargraph_t::cs
digital_out_t cs
Definition: bargraph.h:101
bargraph_cfg_t::mosi
pin_name_t mosi
Definition: bargraph.h:123
bargraph_cfg_t::pwm
pin_name_t pwm
Definition: bargraph.h:130
bargraph_reset
void bargraph_reset(bargraph_t *ctx)
Functions for reset the chip.
bargraph_t::mr
digital_out_t mr
Definition: bargraph.h:105
bargraph_cfg_t::miso
pin_name_t miso
Definition: bargraph.h:122
BARGRAPH_RETVAL
#define BARGRAPH_RETVAL
Definition: bargraph.h:83
bargraph_cfg_t::sck
pin_name_t sck
Definition: bargraph.h:124
bargraph_cfg_t::cs
pin_name_t cs
Definition: bargraph.h:125