uts7segb2 2.1.0.0
uts7segb2.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 UTS7SEGB2_H
29#define UTS7SEGB2_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
74#define UTS7SEGB2_SEG_DIS14_SEG0 0x00000001l
75#define UTS7SEGB2_SEG_DIS14_SEG1 0x00000002l
76#define UTS7SEGB2_SEG_DIS14_SEG2 0x00000004l
77#define UTS7SEGB2_SEG_DIS14_SEG3 0x00000008l
78#define UTS7SEGB2_SEG_DIS14_SEG4 0x00000010l
79#define UTS7SEGB2_SEG_DIS14_SEG5 0x00000020l
80#define UTS7SEGB2_SEG_DIS14_SEG6 0x00000040l
81#define UTS7SEGB2_SEG_DIS14_SEG7 0x00000080l
82#define UTS7SEGB2_SEG_DIS25_SEG0 0x00000100l
83#define UTS7SEGB2_SEG_DIS25_SEG1 0x00000200l
84#define UTS7SEGB2_SEG_DIS25_SEG2 0x00000400l
85#define UTS7SEGB2_SEG_DIS25_SEG3 0x00000800l
86#define UTS7SEGB2_SEG_DIS25_SEG4 0x00001000l
87#define UTS7SEGB2_SEG_DIS25_SEG5 0x00002000l
88#define UTS7SEGB2_SEG_DIS25_SEG6 0x00004000l
89#define UTS7SEGB2_SEG_DIS25_SEG7 0x00008000l
90#define UTS7SEGB2_SEG_DIS36_SEG0 0x00010000l
91#define UTS7SEGB2_SEG_DIS36_SEG1 0x00020000l
92#define UTS7SEGB2_SEG_DIS36_SEG2 0x00040000l
93#define UTS7SEGB2_SEG_DIS36_SEG3 0x00080000l
94#define UTS7SEGB2_SEG_DIS36_SEG4 0x00100000l
95#define UTS7SEGB2_SEG_DIS36_SEG5 0x00200000l
96#define UTS7SEGB2_SEG_DIS36_SEG6 0x00400000l
97#define UTS7SEGB2_SEG_DIS36_SEG7 0x00800000l
98#define UTS7SEGB2_SEG_ALL 0x01FFFFFFl
99#define UTS7SEGB2_SEG_BIT_MASK 0x01FFFFFFl
100
105#define UTS7SEGB2_NIBBLE_LOW 0x000Fu
106#define UTS7SEGB2_NIBBLE_HIGH 0x00F0u
107#define UTS7SEGB2_BYTE_LOW 0x00FFu
108#define UTS7SEGB2_WORD_BIT_POS_0 0x0001u
109#define UTS7SEGB2_WORD_BIT_POS_14 0x4000u
110#define UTS7SEGB2_WORD_BIT_POS_15 0x8000u
111
116#define UTS7SEGB2_SEG_NUM_START 0
117#define UTS7SEGB2_SEG_NUM_END 23
118#define UTS7SEGB2_SEG_NUM_POS 24
119
124#define UTS7SEGB2_BRIGHTNESS_MIN 0x0000u
125#define UTS7SEGB2_BRIGHTNESS_DEFAULT 0x07FFu
126#define UTS7SEGB2_BRIGHTNESS_MAX 0x0FFFu
127
133#define UTS7SEGB2_BASE_NUM_SYS_BINARY 2
134#define UTS7SEGB2_BINARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_BINARY * \
135 UTS7SEGB2_BASE_NUM_SYS_BINARY * \
136 UTS7SEGB2_BASE_NUM_SYS_BINARY - 1
137#define UTS7SEGB2_BASE_NUM_SYS_TERNARY 3
138#define UTS7SEGB2_TERNARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_TERNARY * \
139 UTS7SEGB2_BASE_NUM_SYS_TERNARY * \
140 UTS7SEGB2_BASE_NUM_SYS_TERNARY - 1
141#define UTS7SEGB2_BASE_NUM_SYS_QUATERNARY 4
142#define UTS7SEGB2_QUATERNARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_QUATERNARY * \
143 UTS7SEGB2_BASE_NUM_SYS_QUATERNARY * \
144 UTS7SEGB2_BASE_NUM_SYS_QUATERNARY - 1
145#define UTS7SEGB2_BASE_NUM_SYS_QUINARY 5
146#define UTS7SEGB2_QUINARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_QUINARY * \
147 UTS7SEGB2_BASE_NUM_SYS_QUINARY * \
148 UTS7SEGB2_BASE_NUM_SYS_QUINARY - 1
149#define UTS7SEGB2_BASE_NUM_SYS_SENARY 6
150#define UTS7SEGB2_SENARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_SENARY * \
151 UTS7SEGB2_BASE_NUM_SYS_SENARY * \
152 UTS7SEGB2_BASE_NUM_SYS_SENARY - 1
153#define UTS7SEGB2_BASE_NUM_SYS_SEPTENARY 7
154#define UTS7SEGB2_SEPTENARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_SEPTENARY * \
155 UTS7SEGB2_BASE_NUM_SYS_SEPTENARY * \
156 UTS7SEGB2_BASE_NUM_SYS_SEPTENARY - 1
157#define UTS7SEGB2_BASE_NUM_SYS_OCTAL 8
158#define UTS7SEGB2_OCTAL_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_OCTAL * \
159 UTS7SEGB2_BASE_NUM_SYS_OCTAL * \
160 UTS7SEGB2_BASE_NUM_SYS_OCTAL - 1
161#define UTS7SEGB2_BASE_NUM_SYS_NONARY 9
162#define UTS7SEGB2_NONARY_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_NONARY * \
163 UTS7SEGB2_BASE_NUM_SYS_NONARY * \
164 UTS7SEGB2_BASE_NUM_SYS_NONARY - 1
165#define UTS7SEGB2_BASE_NUM_SYS_DECIMAL 10
166#define UTS7SEGB2_DECIMAL_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_DECIMAL * \
167 UTS7SEGB2_BASE_NUM_SYS_DECIMAL * \
168 UTS7SEGB2_BASE_NUM_SYS_DECIMAL - 1
169#define UTS7SEGB2_BASE_NUM_SYS_UNDECIMAL 11
170#define UTS7SEGB2_UNDECIMAL_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_UNDECIMAL * \
171 UTS7SEGB2_BASE_NUM_SYS_UNDECIMAL * \
172 UTS7SEGB2_BASE_NUM_SYS_UNDECIMAL - 1
173#define UTS7SEGB2_BASE_NUM_SYS_DUODECIMAL 12
174#define UTS7SEGB2_DUODECIMAL_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_DUODECIMAL * \
175 UTS7SEGB2_BASE_NUM_SYS_DUODECIMAL * \
176 UTS7SEGB2_BASE_NUM_SYS_DUODECIMAL - 1
177#define UTS7SEGB2_BASE_NUM_SYS_HEXADECIMAL 16
178#define UTS7SEGB2_HEXADECIMAL_NUM_MAX UTS7SEGB2_BASE_NUM_SYS_HEXADECIMAL * \
179 UTS7SEGB2_BASE_NUM_SYS_HEXADECIMAL * \
180 UTS7SEGB2_BASE_NUM_SYS_HEXADECIMAL - 1
181
186#define UTS7SEGB2_TOP_SEG_NO_DOT 0x00
187#define UTS7SEGB2_TOP_SEG_DOT_RIGHT 0x01
188#define UTS7SEGB2_TOP_SEG_DOT_MIDDLE 0x02
189#define UTS7SEGB2_TOP_SEG_DOT_LEFT 0x04
190#define UTS7SEGB2_BOTTOM_SEG_NO_DOT 0x00
191#define UTS7SEGB2_BOTTOM_SEG_DOT_RIGHT 0x20
192#define UTS7SEGB2_BOTTOM_SEG_DOT_LEFT 0x08
193#define UTS7SEGB2_BOTTOM_SEG_DOT_MIDDLE 0x10
194
203#define UTS7SEGB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
204#define UTS7SEGB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
205
206 // uts7segb2_set
207
222#define UTS7SEGB2_MAP_MIKROBUS( cfg, mikrobus ) \
223 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
224 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
225 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
226 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
227 cfg.cs2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
228 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
229
230 // uts7segb2_map
231 // uts7segb2
232
237typedef struct
238{
239 // Output pins
240 digital_out_t cs2;
241 digital_out_t pwm;
243 // Modules
244 spi_master_t spi;
246 pin_name_t chip_select;
249
254typedef struct
255{
256 // Communication gpio pins
257 pin_name_t miso;
258 pin_name_t mosi;
259 pin_name_t sck;
260 pin_name_t cs;
262 // Additional gpio pins
263 pin_name_t cs2;
264 pin_name_t pwm;
266 // static variable
267 uint32_t spi_speed;
268 spi_master_mode_t spi_mode;
269 spi_master_chip_select_polarity_t cs_polarity;
272
288
293typedef struct
294{
295 uint16_t num_top;
296 uint16_t brightness_top;
297 uint16_t num_bottom;
299 uint8_t base;
300 uint8_t dot_bit_mask;
303
314
325
342
357
371
386err_t uts7segb2_top_seg_write ( uts7segb2_t *ctx, uint8_t *data_in, uint8_t len );
387
402err_t uts7segb2_top_seg_read ( uts7segb2_t *ctx, uint8_t *data_out, uint8_t len );
403
418err_t uts7segb2_bottom_seg_write ( uts7segb2_t *ctx, uint8_t *data_in, uint8_t len );
419
434err_t uts7segb2_bottom_seg_read ( uts7segb2_t *ctx, uint8_t *data_out, uint8_t len );
435
448
460
477 uint8_t seg_num, uint16_t brightness );
478
495 uint32_t seg_bit_mask, uint16_t brightness );
496
513
530
531#ifdef __cplusplus
532}
533#endif
534#endif // UTS7SEGB2_H
535
536 // uts7segb2
537
538// ------------------------------------------------------------------------ END
err_t uts7segb2_display_number(uts7segb2_t *ctx, uts7segb2_number_cfg_t number)
UT-S 7-SEG B 2 display number function.
void uts7segb2_set_outputs_on(uts7segb2_t *ctx)
UT-S 7-SEG B 2 set outputs ON function.
err_t uts7segb2_set_seg_pos(uts7segb2_t *ctx, uts7segb2_seg_sel_t seg_sel, uint8_t seg_num, uint16_t brightness)
UT-S 7-SEG B 2 set segment position function.
err_t uts7segb2_bottom_seg_write(uts7segb2_t *ctx, uint8_t *data_in, uint8_t len)
UT-S 7-SEG B 2 bottom segment data writing function.
err_t uts7segb2_bottom_seg_read(uts7segb2_t *ctx, uint8_t *data_out, uint8_t len)
UT-S 7-SEG B 2 bottom segment data reading function.
void uts7segb2_cfg_setup(uts7segb2_cfg_t *cfg)
UT-S 7-SEG B 2 configuration object setup function.
err_t uts7segb2_top_seg_write(uts7segb2_t *ctx, uint8_t *data_in, uint8_t len)
UT-S 7-SEG B 2 top segment data writing function.
err_t uts7segb2_display_character(uts7segb2_t *ctx, uts7segb2_character_cfg_t ascii_char)
UT-S 7-SEG B 2 display character function.
void uts7segb2_set_outputs_off(uts7segb2_t *ctx)
UT-S 7-SEG B 2 set outputs OFF function.
err_t uts7segb2_init(uts7segb2_t *ctx, uts7segb2_cfg_t *cfg)
UT-S 7-SEG B 2 initialization function.
err_t uts7segb2_default_cfg(uts7segb2_t *ctx)
UT-S 7-SEG B 2 default configuration function.
err_t uts7segb2_set_led_output(uts7segb2_t *ctx, uts7segb2_seg_sel_t seg_sel, uint32_t seg_bit_mask, uint16_t brightness)
UT-S 7-SEG B 2 set LED output function.
err_t uts7segb2_top_seg_read(uts7segb2_t *ctx, uint8_t *data_out, uint8_t len)
UT-S 7-SEG B 2 top segment data reading function.
This file contains SPI specific macros, functions, etc.
UT-S 7-SEG B 2 Click configuration object.
Definition uts7segb2.h:255
pin_name_t cs2
Definition uts7segb2.h:263
spi_master_chip_select_polarity_t cs_polarity
Definition uts7segb2.h:269
pin_name_t sck
Definition uts7segb2.h:259
spi_master_mode_t spi_mode
Definition uts7segb2.h:268
pin_name_t mosi
Definition uts7segb2.h:258
uint32_t spi_speed
Definition uts7segb2.h:267
pin_name_t pwm
Definition uts7segb2.h:264
pin_name_t miso
Definition uts7segb2.h:257
pin_name_t cs
Definition uts7segb2.h:260
UT-S 7-SEG B 2 character configuration object.
Definition uts7segb2.h:278
uint8_t char_top_left
Definition uts7segb2.h:279
uint16_t brightness
Definition uts7segb2.h:285
uint8_t char_bottom_mid
Definition uts7segb2.h:283
uint8_t char_bottom_right
Definition uts7segb2.h:284
uint8_t char_bottom_left
Definition uts7segb2.h:282
uint8_t char_top_right
Definition uts7segb2.h:281
uint8_t char_top_mid
Definition uts7segb2.h:280
UT-S 7-SEG B 2 number configuration object.
Definition uts7segb2.h:294
uint8_t dot_bit_mask
Definition uts7segb2.h:300
uint16_t brightness_top
Definition uts7segb2.h:296
uint16_t num_top
Definition uts7segb2.h:295
uint8_t base
Definition uts7segb2.h:299
uint16_t brightness_bottom
Definition uts7segb2.h:298
uint16_t num_bottom
Definition uts7segb2.h:297
UT-S 7-SEG B 2 Click context object.
Definition uts7segb2.h:238
spi_master_t spi
Definition uts7segb2.h:244
digital_out_t pwm
Definition uts7segb2.h:241
digital_out_t cs2
Definition uts7segb2.h:240
pin_name_t chip_select
Definition uts7segb2.h:246
uts7segb2_seg_sel_t
UT-S 7-SEG B 2 segment group selection value data.
Definition uts7segb2.h:320
@ UTS7SEGB2_SEG_TOP
Definition uts7segb2.h:321
@ UTS7SEGB2_SEG_BOTTOM
Definition uts7segb2.h:322
uts7segb2_return_value_t
UT-S 7-SEG B 2 Click return value data.
Definition uts7segb2.h:309
@ UTS7SEGB2_ERROR
Definition uts7segb2.h:311
@ UTS7SEGB2_OK
Definition uts7segb2.h:310