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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define BARGRAPH_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
61 
62 
69 #define BARGRAPH_RETVAL uint8_t
70 
71 #define BARGRAPH_OK 0x00
72 #define BARGRAPH_INIT_ERROR 0xFF
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  digital_out_t cs;
88 
89  // Output pins
90 
91  digital_out_t mr;
92  digital_out_t pwm;
93 
94  // Modules
95 
96  spi_master_t spi;
97  pin_name_t chip_select;
98 
99 } bargraph_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t miso;
109  pin_name_t mosi;
110  pin_name_t sck;
111  pin_name_t cs;
112 
113  // Additional gpio pins
114 
115  pin_name_t mr;
116  pin_name_t pwm;
117 
118  // static variable
119 
120  uint32_t spi_speed;
121  spi_master_mode_t spi_mode;
122  spi_master_chip_select_polarity_t cs_polarity;
123 
125  // End types group
127 
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
134 #ifdef __cplusplus
135 extern "C"{
136 #endif
137 
146 void bargraph_cfg_setup ( bargraph_cfg_t *cfg );
147 
157 
169 void bargraph_generic_transfer ( bargraph_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
170 
178 void bargraph_driver_init ( bargraph_t *ctx );
179 
187 void bargraph_reset ( bargraph_t *ctx );
188 
197 void bargraph_display( bargraph_t *ctx, uint8_t input );
198 
207 void bargraph_enable ( bargraph_t *ctx, uint8_t input );
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 #endif // _BARGRAPH_H_
213  // End public_function group
216 
217 // ------------------------------------------------------------------------- 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:104
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:96
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:92
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:97
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:120
bargraph_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: bargraph.h:121
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:122
bargraph_cfg_t::mr
pin_name_t mr
Definition: bargraph.h:115
bargraph_t
Click ctx object definition.
Definition: bargraph.h:85
bargraph_t::cs
digital_out_t cs
Definition: bargraph.h:87
bargraph_cfg_t::mosi
pin_name_t mosi
Definition: bargraph.h:109
bargraph_cfg_t::pwm
pin_name_t pwm
Definition: bargraph.h:116
bargraph_reset
void bargraph_reset(bargraph_t *ctx)
Functions for reset the chip.
bargraph_t::mr
digital_out_t mr
Definition: bargraph.h:91
bargraph_cfg_t::miso
pin_name_t miso
Definition: bargraph.h:108
BARGRAPH_RETVAL
#define BARGRAPH_RETVAL
Definition: bargraph.h:69
bargraph_cfg_t::sck
pin_name_t sck
Definition: bargraph.h:110
bargraph_cfg_t::cs
pin_name_t cs
Definition: bargraph.h:111