matrixg  2.0.0.0
matrixg.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 
34 // ----------------------------------------------------------------------------
35 
36 #ifndef MATRIXG_H
37 #define MATRIXG_H
38 
39 #include "mikrosdk_version.h"
40 
41 #ifdef __GNUC__
42 #if mikroSDK_GET_VERSION < 20800ul
43 #include "rcu_delays.h"
44 #else
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 
53 
54 // -------------------------------------------------------------- PUBLIC MACROS
55 
66 #define MATRIXG_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.csn = MIKROBUS( mikrobus, MIKROBUS_AN );
72 
78 #define MATRIXG_RETVAL uint8_t
79 
80 #define MATRIXG_OK 0x00
81 #define MATRIXG_INIT_ERROR 0xFF
82 
88 #define MATRIXG_DECODE_MODE_REG 0x09
89 #define MATRIXG_INTENSITY_REG 0x0A
90 #define MATRIXG_SCAN_LIMIT_REG 0x0B
91 #define MATRIXG_SHUTDOWN_REG 0x0C
92 #define MATRIXG_DISPLAY_TEST_REG 0x0F
93 
99 #define MATRIXG_NO_DECODE 0x00
100 #define MATRIXG_DECODE_DIGIT_0 0x01
101 #define MATRIXG_DECODE_DIGIT_3_0 0x0F
102 #define MATRIXG_DECODE_DIGIT_7 0xFF
103 
109 #define MATRIXG_INTEN_LVL_0 0x00
110 #define MATRIXG_INTEN_LVL_1 0x03
111 #define MATRIXG_INTEN_LVL_2 0x06
112 #define MATRIXG_INTEN_LVL_3 0x09
113 #define MATRIXG_INTEN_LVL_4 0x0C
114 #define MATRIXG_INTEN_LVL_5 0x0F
115 
121 #define MATRIXG_DISPLAY_DIGIT_0 0x00
122 #define MATRIXG_DISPLAY_DIGIT_0_1 0x01
123 #define MATRIXG_DISPLAY_DIGIT_0_2 0x02
124 #define MATRIXG_DISPLAY_DIGIT_0_3 0x03
125 #define MATRIXG_DISPLAY_DIGIT_0_4 0x04
126 #define MATRIXG_DISPLAY_DIGIT_0_5 0x05
127 #define MATRIXG_DISPLAY_DIGIT_0_6 0x06
128 #define MATRIXG_DISPLAY_DIGIT_0_7 0x07
129 
135 #define MATRIXG_SHUTDOWN_MODE 0x00
136 #define MATRIXG_NORMAL_OPERATION 0x01
137 
142 #define MATRIXG_DISPLAY_NORMAL_OPERATION 0x00
143 #define MATRIXG_DISPLAY_TEST_MODE 0X01
144  // End group macro
147 
148 // --------------------------------------------------------------- PUBLIC TYPES
149 
158 typedef struct
159 {
160  // Output pins
161 
162  digital_out_t csn;
163  digital_out_t cs;
164 
165  // Modules
166 
167  spi_master_t spi;
168  pin_name_t chip_select;
169 
170 } matrixg_t;
171 
175 typedef struct
176 {
177  // Communication gpio pins
178 
179  pin_name_t miso;
180  pin_name_t mosi;
181  pin_name_t sck;
182  pin_name_t cs;
183 
184  // Additional gpio pins
185 
186  pin_name_t csn;
187 
188  // static variable
189 
190  uint32_t spi_speed;
191  spi_master_mode_t spi_mode;
192  spi_master_chip_select_polarity_t cs_polarity;
193 
194 
195 } matrixg_cfg_t;
196  // End types group
198 
199 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200 
201 
206 #ifdef __cplusplus
207 extern "C"{
208 #endif
209 
219 
228 
237 
247 void matrixg_display_characters ( matrixg_t *ctx, uint8_t left_char, uint8_t right_char );
248 
258 void matrixg_write_reg ( matrixg_t *ctx, uint8_t address, uint8_t input_data );
259 
268 
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // _MATRIXG_H_
282  // End public_function group
285 
286 // ------------------------------------------------------------------------- END
matrixg_cfg_setup
void matrixg_cfg_setup(matrixg_cfg_t *cfg)
Config Object Initialization function.
matrixg_cfg_t::mosi
pin_name_t mosi
Definition: matrixg.h:180
matrixg_write_reg
void matrixg_write_reg(matrixg_t *ctx, uint8_t address, uint8_t input_data)
Register write function.
matrixg_cfg_t
Click configuration structure definition.
Definition: matrixg.h:176
MATRIXG_RETVAL
#define MATRIXG_RETVAL
Definition: matrixg.h:78
matrixg_t
Click ctx object definition.
Definition: matrixg.h:159
matrixg_init
MATRIXG_RETVAL matrixg_init(matrixg_t *ctx, matrixg_cfg_t *cfg)
Initialization function.
matrixg_cfg_t::spi_speed
uint32_t spi_speed
Definition: matrixg.h:190
matrixg_t::chip_select
pin_name_t chip_select
Definition: matrixg.h:168
matrixg_default_cfg
void matrixg_default_cfg(matrixg_t *ctx)
Click Default Configuration function.
matrixg_display_characters
void matrixg_display_characters(matrixg_t *ctx, uint8_t left_char, uint8_t right_char)
Display characters function.
matrixg_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: matrixg.h:191
matrixg_cfg_t::cs
pin_name_t cs
Definition: matrixg.h:182
matrixg_t::csn
digital_out_t csn
Definition: matrixg.h:162
matrixg_t::cs
digital_out_t cs
Definition: matrixg.h:163
matrixg_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: matrixg.h:192
matrixg_t::spi
spi_master_t spi
Definition: matrixg.h:167
matrixg_set_csn_low
void matrixg_set_csn_low(matrixg_t *ctx)
Set CSN pin to low function.
matrixg_cfg_t::miso
pin_name_t miso
Definition: matrixg.h:179
matrixg_set_csn_high
void matrixg_set_csn_high(matrixg_t *ctx)
Set CSN pin to high function.
matrixg_cfg_t::csn
pin_name_t csn
Definition: matrixg.h:186
matrixg_cfg_t::sck
pin_name_t sck
Definition: matrixg.h:181