c4dotmatrixr  2.0.0.0
c4dotmatrixr.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 C4DOTMATRIXR_H
36 #define C4DOTMATRIXR_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_i2c_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define C4DOTMATRIXR_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
73 
80 #define C4DOTMATRIXR_RETVAL uint8_t
81 
82 #define C4DOTMATRIXR_OK 0x00
83 #define C4DOTMATRIXR_INIT_ERROR 0xFF
84 
86 #define C4DOT_IODIRA 0x00
87 #define C4DOT_IODIRB 0x01
88 #define C4DOT_IPOLA 0x02
89 #define C4DOT_IPOLB 0x03
90 #define C4DOT_GPINTENA 0x04
91 #define C4DOT_GPINTENB 0x05
92 #define C4DOT_DEFVALA 0x06
93 #define C4DOT_DEFVALB 0x07
94 #define C4DOT_INTCONA 0x08
95 #define C4DOT_INTCONB 0x09
96 #define C4DOT_IOCON 0x0A
97 #define C4DOT_GPPUA 0x0C
98 #define C4DOT_GPPUB 0x0D
99 #define C4DOT_INTFA 0x0E
100 #define C4DOT_INTFB 0x0F
101 #define C4DOT_INTCAPA 0x10
102 #define C4DOT_INTCAPB 0x11
103 #define C4DOT_GPIOA 0x12
104 #define C4DOT_GPIOB 0x13
105 #define C4DOT_OLATA 0x14
106 #define C4DOT_OLATB 0x15
107  // End group macro
109 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  // Output pins
121 
122  digital_out_t rst;
123  digital_out_t cs;
124  digital_out_t pwm;
125 
126  // Modules
127 
128  i2c_master_t i2c;
129 
130  // ctx variable
131 
132  uint8_t slave_address;
133 
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t scl;
144  pin_name_t sda;
145 
146  // Additional gpio pins
147 
148  pin_name_t rst;
149  pin_name_t cs;
150  pin_name_t pwm;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156 
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
180 
189 
198 
209 void c4dotmatrixr_generic_write ( c4dotmatrixr_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
210 
222 void c4dotmatrixr_generic_read ( c4dotmatrixr_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
223 
240 void c4dot_write_char ( c4dotmatrixr_t *ctx, uint8_t char_num, uint8_t char_value );
241 
256 void c4dot_write_char0 ( c4dotmatrixr_t *ctx, uint8_t char_value );
257 
272 void c4dot_write_char1 ( c4dotmatrixr_t *ctx, uint8_t char_value );
273 
288 void c4dot_write_char2 ( c4dotmatrixr_t *ctx, uint8_t char_value );
289 
304 void c4dot_write_char3 ( c4dotmatrixr_t *ctx, uint8_t char_value);
305 
316 void c4dot_write_text ( c4dotmatrixr_t *ctx, uint8_t *text_to_write );
317 
328 void c4dot_write_int ( c4dotmatrixr_t *ctx, int16_t int_to_write, uint8_t int_base );
329 
341 void c4dot_write_int_bin ( c4dotmatrixr_t *ctx, int16_t int_to_write );
342 
354 void c4dot_write_int_oct ( c4dotmatrixr_t *ctx, int16_t int_to_write );
355 
367 void c4dot_write_int_dec ( c4dotmatrixr_t *ctx, int16_t int_to_write);
368 
380 void c4dot_write_int_hex ( c4dotmatrixr_t *ctx, int16_t int_to_write );
381 
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 #endif // _C4DOTMATRIXR_H_
396  // End public_function group
399 
400 // ------------------------------------------------------------------------- END
c4dotmatrixr_cfg_t
Click configuration structure definition.
Definition: c4dotmatrixr.h:140
c4dot_write_int
void c4dot_write_int(c4dotmatrixr_t *ctx, int16_t int_to_write, uint8_t int_base)
4DotMatrix Int Write.
c4dotmatrixr_t::i2c
i2c_master_t i2c
Definition: c4dotmatrixr.h:128
c4dot_write_int_oct
void c4dot_write_int_oct(c4dotmatrixr_t *ctx, int16_t int_to_write)
4DotMatrix Octal Int Write.
c4dotmatrixr_t
Click ctx object definition.
Definition: c4dotmatrixr.h:119
c4dot_write_char0
void c4dot_write_char0(c4dotmatrixr_t *ctx, uint8_t char_value)
4DotMatrix Char 0 Write.
c4dotmatrixr_t::cs
digital_out_t cs
Definition: c4dotmatrixr.h:123
c4dotmatrixr_generic_write
void c4dotmatrixr_generic_write(c4dotmatrixr_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c4dotmatrixr_generic_read
void c4dotmatrixr_generic_read(c4dotmatrixr_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c4dotmatrixr_init
C4DOTMATRIXR_RETVAL c4dotmatrixr_init(c4dotmatrixr_t *ctx, c4dotmatrixr_cfg_t *cfg)
Initialization function.
c4dotmatrixr_t::pwm
digital_out_t pwm
Definition: c4dotmatrixr.h:124
c4dot_write_char
void c4dot_write_char(c4dotmatrixr_t *ctx, uint8_t char_num, uint8_t char_value)
4DotMatrix Char Write.
c4dotmatrixr_default_cfg
void c4dotmatrixr_default_cfg(c4dotmatrixr_t *ctx)
Click Default Configuration function.
c4dot_write_int_bin
void c4dot_write_int_bin(c4dotmatrixr_t *ctx, int16_t int_to_write)
4DotMatrix Binary Int Write.
c4dotmatrixr_cfg_t::scl
pin_name_t scl
Definition: c4dotmatrixr.h:143
c4dot_write_char3
void c4dot_write_char3(c4dotmatrixr_t *ctx, uint8_t char_value)
4DotMatrix Char 3 Write.
c4dotmatrixr_cfg_t::i2c_address
uint8_t i2c_address
Definition: c4dotmatrixr.h:155
c4dotmatrixr_cfg_setup
void c4dotmatrixr_cfg_setup(c4dotmatrixr_cfg_t *cfg)
Config Object Initialization function.
c4dotmatrixr_cfg_t::pwm
pin_name_t pwm
Definition: c4dotmatrixr.h:150
c4dotmatrixr_cfg_t::sda
pin_name_t sda
Definition: c4dotmatrixr.h:144
c4dotmatrixr_t::rst
digital_out_t rst
Definition: c4dotmatrixr.h:122
c4dotmatrixr_t::slave_address
uint8_t slave_address
Definition: c4dotmatrixr.h:132
c4dotmatrixr_cfg_t::cs
pin_name_t cs
Definition: c4dotmatrixr.h:149
c4dot_write_char2
void c4dot_write_char2(c4dotmatrixr_t *ctx, uint8_t char_value)
4DotMatrix Char 2 Write.
c4dot_write_text
void c4dot_write_text(c4dotmatrixr_t *ctx, uint8_t *text_to_write)
4DotMatrix Text Write.
c4dot_clear_display
void c4dot_clear_display(c4dotmatrixr_t *ctx)
4DotMatrix Display Clear.
c4dot_write_int_dec
void c4dot_write_int_dec(c4dotmatrixr_t *ctx, int16_t int_to_write)
4DotMatrix Decimal Int Write.
c4dotmatrixr_cfg_t::rst
pin_name_t rst
Definition: c4dotmatrixr.h:148
c4dot_write_char1
void c4dot_write_char1(c4dotmatrixr_t *ctx, uint8_t char_value)
4DotMatrix Char 1 Write.
c4dot_write_int_hex
void c4dot_write_int_hex(c4dotmatrixr_t *ctx, int16_t int_to_write)
4DotMatrix Hexadecimal Int Write.
c4dotmatrixr_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c4dotmatrixr.h:154
C4DOTMATRIXR_RETVAL
#define C4DOTMATRIXR_RETVAL
Definition: c4dotmatrixr.h:80