c7seg  2.0.0.0
c7seg.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 C7SEG_H
36 #define C7SEG_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define C7SEG_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.mr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
60 
66 #define C7SEG_RETVAL uint8_t
67 
68 #define C7SEG_OK 0x00
69 #define C7SEG_INIT_ERROR 0xFF
70 
76 #define C7SEG_DISPLAY_OFF 0
77 #define C7SEG_DISPLAY_ON 1
78  // End group macro
81 
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef struct
92 {
93  digital_out_t cs;
94  // Output pins
95 
96  digital_out_t mr;
97  digital_out_t pwm;
98 
99  // Modules
100 
101  spi_master_t spi;
102  pin_name_t chip_select;
103 
104 } c7seg_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t miso;
114  pin_name_t mosi;
115  pin_name_t sck;
116  pin_name_t cs;
117 
118  // Additional gpio pins
119 
120  pin_name_t mr;
121  pin_name_t pwm;
122 
123  // static variable
124 
125  uint32_t spi_speed;
126  spi_master_mode_t spi_mode;
127  spi_master_chip_select_polarity_t cs_polarity;
128 
129 } c7seg_cfg_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
138 #ifdef __cplusplus
139 extern "C"{
140 #endif
141 
151 
161 
180 
192 void c7seg_generic_transfer ( c7seg_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
193 
203 void c7seg_write_data ( c7seg_t *ctx, uint8_t write_left, uint8_t write_right );
204 
212 void c7seg_reset ( c7seg_t *ctx );
213 
222 void c7seg_display_mode ( c7seg_t *ctx, uint8_t display_mode );
223 
233 void c7seg_write_data_number ( c7seg_t *ctx, uint8_t left_number, uint8_t right_number );
234 
244 void c7seg_write_data_character ( c7seg_t *ctx, char left_char, char right_char );
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // _C7SEG_H_
250  // End public_function group
253 
255 // ------------------------------------------------------------------------- END
c7seg_cfg_t::mosi
pin_name_t mosi
Definition: c7seg.h:114
c7seg_display_mode
void c7seg_display_mode(c7seg_t *ctx, uint8_t display_mode)
Display mode function.
c7seg_t::chip_select
pin_name_t chip_select
Definition: c7seg.h:102
c7seg_cfg_setup
void c7seg_cfg_setup(c7seg_cfg_t *cfg)
Config Object Initialization function.
c7seg_write_data
void c7seg_write_data(c7seg_t *ctx, uint8_t write_left, uint8_t write_right)
Generic write data function.
c7seg_t::spi
spi_master_t spi
Definition: c7seg.h:101
c7seg_write_data_character
void c7seg_write_data_character(c7seg_t *ctx, char left_char, char right_char)
c7seg_cfg_t::pwm
pin_name_t pwm
Definition: c7seg.h:121
c7seg_t::mr
digital_out_t mr
Definition: c7seg.h:96
c7seg_t::cs
digital_out_t cs
Definition: c7seg.h:93
c7seg_cfg_t::miso
pin_name_t miso
Definition: c7seg.h:113
c7seg_init
C7SEG_RETVAL c7seg_init(c7seg_t *ctx, c7seg_cfg_t *cfg)
Initialization function.
C7SEG_RETVAL
#define C7SEG_RETVAL
Definition: c7seg.h:66
c7seg_t::pwm
digital_out_t pwm
Definition: c7seg.h:97
c7seg_cfg_t::mr
pin_name_t mr
Definition: c7seg.h:120
c7seg_write_data_number
void c7seg_write_data_number(c7seg_t *ctx, uint8_t left_number, uint8_t right_number)
c7seg_cfg_t::cs
pin_name_t cs
Definition: c7seg.h:116
c7seg_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c7seg.h:126
c7seg_cfg_t::spi_speed
uint32_t spi_speed
Definition: c7seg.h:125
c7seg_cfg_t
Click configuration structure definition.
Definition: c7seg.h:110
c7seg_cfg_t::sck
pin_name_t sck
Definition: c7seg.h:115
c7seg_generic_transfer
void c7seg_generic_transfer(c7seg_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
c7seg_default_cfg
void c7seg_default_cfg(c7seg_t *ctx)
Click Default Configuration function.
c7seg_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c7seg.h:127
c7seg_reset
void c7seg_reset(c7seg_t *ctx)
Click Reset function.
c7seg_t
Click ctx object definition.
Definition: c7seg.h:92