utl7segb 2.1.0.0
utl7segb.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef UTL7SEGB_H
29#define UTL7SEGB_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
75#define UTL7SEGB_BASE_NUM_SYS_BINARY 2
76#define UTL7SEGB_BASE_NUM_SYS_TERNARY 3
77#define UTL7SEGB_BASE_NUM_SYS_QUATERNARY 4
78#define UTL7SEGB_BASE_NUM_SYS_QUINARY 5
79#define UTL7SEGB_BASE_NUM_SYS_SENARY 6
80#define UTL7SEGB_BASE_NUM_SYS_SEPTENARY 7
81#define UTL7SEGB_BASE_NUM_SYS_OCTAL 8
82#define UTL7SEGB_BASE_NUM_SYS_NONARY 9
83#define UTL7SEGB_BASE_NUM_SYS_DECIMAL 10
84#define UTL7SEGB_BASE_NUM_SYS_UNDECIMAL 11
85#define UTL7SEGB_BASE_NUM_SYS_DUODECIMAL 12
86#define UTL7SEGB_BASE_NUM_SYS_HEXADECIMAL 16
87
88 // utl7segb_base
89
104#define UTL7SEGB_NO_DOT 0
105#define UTL7SEGB_DOT_RIGHT 1
106#define UTL7SEGB_DOT_LEFT 2
107#define UTL7SEGB_DOT_LEFT_RIGHT 3
108
117#define UTL7SEGB_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
118#define UTL7SEGB_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
119
120 // utl7segb_set
121
136#define UTL7SEGB_MAP_MIKROBUS( cfg, mikrobus ) \
137 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141 cfg.oe = MIKROBUS( mikrobus, MIKROBUS_PWM )
142
143 // utl7segb_map
144 // utl7segb
145
150typedef struct
151{
152 // Output pins
153 digital_out_t oe;
155 // Modules
156 spi_master_t spi;
158 pin_name_t chip_select;
160} utl7segb_t;
161
166typedef struct
167{
168 // Communication gpio pins
169 pin_name_t miso;
170 pin_name_t mosi;
171 pin_name_t sck;
172 pin_name_t cs;
174 // Additional gpio pins
175 pin_name_t oe;
177 // static variable
178 uint32_t spi_speed;
179 spi_master_mode_t spi_mode;
180 spi_master_chip_select_polarity_t cs_polarity;
183
188typedef enum
189{
191 UTL7SEGB_ERROR = -1
192
194
211
226
240
253err_t utl7segb_generic_write ( utl7segb_t *ctx, uint8_t *data_in, uint8_t len );
254
267err_t utl7segb_generic_read ( utl7segb_t *ctx, uint8_t *data_out, uint8_t len );
268
280
292
308err_t utl7segb_display_number ( utl7segb_t *ctx, uint8_t base, uint8_t num, uint8_t dot_pos );
309
325err_t utl7segb_get_number ( utl7segb_t *ctx, uint8_t base, uint8_t *num, uint8_t *dot_pos );
326
327#ifdef __cplusplus
328}
329#endif
330#endif // UTL7SEGB_H
331
332 // utl7segb
333
334// ------------------------------------------------------------------------ END
err_t utl7segb_generic_write(utl7segb_t *ctx, uint8_t *data_in, uint8_t len)
UT-L 7-SEG B data writing function.
void utl7segb_disable(utl7segb_t *ctx)
UT-L 7-SEG B disable function.
err_t utl7segb_default_cfg(utl7segb_t *ctx)
UT-L 7-SEG B default configuration function.
err_t utl7segb_init(utl7segb_t *ctx, utl7segb_cfg_t *cfg)
UT-L 7-SEG B initialization function.
err_t utl7segb_get_number(utl7segb_t *ctx, uint8_t base, uint8_t *num, uint8_t *dot_pos)
UT-L 7-SEG B get number function.
void utl7segb_enable(utl7segb_t *ctx)
UT-L 7-SEG B enable function.
err_t utl7segb_generic_read(utl7segb_t *ctx, uint8_t *data_out, uint8_t len)
UT-L 7-SEG B data reading function.
void utl7segb_cfg_setup(utl7segb_cfg_t *cfg)
UT-L 7-SEG B configuration object setup function.
err_t utl7segb_display_number(utl7segb_t *ctx, uint8_t base, uint8_t num, uint8_t dot_pos)
UT-L 7-SEG B display number function.
This file contains SPI specific macros, functions, etc.
UT-L 7-SEG B Click configuration object.
Definition utl7segb.h:167
spi_master_chip_select_polarity_t cs_polarity
Definition utl7segb.h:180
pin_name_t sck
Definition utl7segb.h:171
pin_name_t oe
Definition utl7segb.h:175
spi_master_mode_t spi_mode
Definition utl7segb.h:179
pin_name_t mosi
Definition utl7segb.h:170
uint32_t spi_speed
Definition utl7segb.h:178
pin_name_t miso
Definition utl7segb.h:169
pin_name_t cs
Definition utl7segb.h:172
UT-L 7-SEG B Click context object.
Definition utl7segb.h:151
spi_master_t spi
Definition utl7segb.h:156
digital_out_t oe
Definition utl7segb.h:153
pin_name_t chip_select
Definition utl7segb.h:158
utl7segb_return_value_t
UT-L 7-SEG B Click return value data.
Definition utl7segb.h:189
@ UTL7SEGB_ERROR
Definition utl7segb.h:191
@ UTL7SEGB_OK
Definition utl7segb.h:190