dotmatrixr 2.0.0.0
dotmatrixr.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 DOTMATRIXR_H
36#define DOTMATRIXR_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_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define DOTMATRIXR_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.rs = MIKROBUS( mikrobus, MIKROBUS_AN ); \
73 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.bl = MIKROBUS( mikrobus, MIKROBUS_PWM )
81#define DOTMATRIXR_RETVAL uint8_t
82
83#define DOTMATRIXR_OK 0x00
84#define DOTMATRIXR_INIT_ERROR 0xFF
91#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_0 0x00
92#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_1p7 0x01
93#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_3p3 0x02
94#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_5 0x03
95#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_6p7 0x04
96#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_8p3 0x05
97#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_11p7 0x06
98#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_15 0x07
99#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_18 0x08
100#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_23 0x09
101#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_30 0x0A
102#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_37 0x0B
103#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_47 0x0C
104#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_60 0x0D
105#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_80 0x0E
106#define DOTMATRIXR_CTRL_BYTE_0_BRIGHTNESS_100 0x0F
107#define DOTMATRIXR_CTRL_BYTE_0_PIXEL_PEAK_CURRENT_4mA 0x20
108#define DOTMATRIXR_CTRL_BYTE_0_PIXEL_PEAK_CURRENT_6p4mA 0x10
109#define DOTMATRIXR_CTRL_BYTE_0_PIXEL_PEAK_CURRENT_9p3mA 0x00
110#define DOTMATRIXR_CTRL_BYTE_0_PIXEL_PEAK_CURRENT_12p8mA 0x30
111#define DOTMATRIXR_CTRL_BYTE_0_MODE_SLEEP 0x00
112#define DOTMATRIXR_CTRL_BYTE_0_MODE_NORMAL 0x40
119#define DOTMATRIXR_CTRL_BYTE_1_OSC_PRESCALER_1 0x80
120#define DOTMATRIXR_CTRL_BYTE_1_OSC_PRESCALER_8 0x82
121#define DOTMATRIXR_CTRL_BYTE_1_DOUT_D7 0x80
122#define DOTMATRIXR_CTRL_BYTE_1_DOUT_DIN 0x81
125 // End group macro
126// --------------------------------------------------------------- PUBLIC TYPES
135typedef struct
136{
137 // Output pins
138
139 digital_out_t cs;
140 digital_out_t rs;
141 digital_out_t rst;
142 digital_out_t bl;
143
144 // Modules
145
146 spi_master_t spi;
147 pin_name_t chip_select;
148
150
154typedef struct
155{
156 // Communication gpio pins
157
158 pin_name_t miso;
159 pin_name_t mosi;
160 pin_name_t sck;
161 pin_name_t cs;
162
163 // Additional gpio pins
164
165 pin_name_t rs;
166 pin_name_t rst;
167 pin_name_t bl;
168
169 // static variable
170
171 uint32_t spi_speed;
172 spi_master_mode_t spi_mode;
173 spi_master_chip_select_polarity_t cs_polarity;
174
176
177 // End types group
178// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179
184#ifdef __cplusplus
185extern "C"{
186#endif
187
197
207
219void dotmatrixr_generic_transfer ( dotmatrixr_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
220
227void dotmatrixr_set_bl_pin_state ( dotmatrixr_t *ctx, uint8_t state );
228
235void dotmatrixr_set_rs_pin_state ( dotmatrixr_t *ctx, uint8_t state );
236
243void dotmatrixr_set_rst_pin_state ( dotmatrixr_t *ctx, uint8_t state );
244
251
258void dotmatrixr_ctrl_0 ( dotmatrixr_t *ctx, uint8_t ctrl_byte );
259
266void dotmatrixr_ctrl_1 ( dotmatrixr_t *ctx, uint8_t ctrl_byte );
267
274void dotmatrixr_write_ascii ( dotmatrixr_t *ctx, char *ascii_data );
275
276#ifdef __cplusplus
277}
278#endif
279#endif // _DOTMATRIXR_H_
280
281 // End public_function group
283
284// ------------------------------------------------------------------------- END
#define DOTMATRIXR_RETVAL
Definition dotmatrixr.h:81
void dotmatrixr_generic_transfer(dotmatrixr_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
DOTMATRIXR_RETVAL dotmatrixr_init(dotmatrixr_t *ctx, dotmatrixr_cfg_t *cfg)
Initialization function.
void dotmatrixr_ctrl_1(dotmatrixr_t *ctx, uint8_t ctrl_byte)
Function for writing control word 1.
void dotmatrixr_ctrl_0(dotmatrixr_t *ctx, uint8_t ctrl_byte)
Function for writing control word 0.
void dotmatrixr_set_rs_pin_state(dotmatrixr_t *ctx, uint8_t state)
Sets RS pin to high or low state.
void dotmatrixr_write_ascii(dotmatrixr_t *ctx, char *ascii_data)
Sets display to written value.
void dotmatrixr_cfg_setup(dotmatrixr_cfg_t *cfg)
Config Object Initialization function.
void dotmatrixr_set_rst_pin_state(dotmatrixr_t *ctx, uint8_t state)
Sets RST pin to high or low state.
void dotmatrixr_restart(dotmatrixr_t *ctx)
Restart device.
void dotmatrixr_set_bl_pin_state(dotmatrixr_t *ctx, uint8_t state)
Sets BL pin to high or low state.
Click configuration structure definition.
Definition dotmatrixr.h:155
pin_name_t rs
Definition dotmatrixr.h:165
spi_master_chip_select_polarity_t cs_polarity
Definition dotmatrixr.h:173
pin_name_t sck
Definition dotmatrixr.h:160
pin_name_t bl
Definition dotmatrixr.h:167
spi_master_mode_t spi_mode
Definition dotmatrixr.h:172
pin_name_t mosi
Definition dotmatrixr.h:159
uint32_t spi_speed
Definition dotmatrixr.h:171
pin_name_t miso
Definition dotmatrixr.h:158
pin_name_t rst
Definition dotmatrixr.h:166
pin_name_t cs
Definition dotmatrixr.h:161
Click ctx object definition.
Definition dotmatrixr.h:136
digital_out_t cs
Definition dotmatrixr.h:139
spi_master_t spi
Definition dotmatrixr.h:146
digital_out_t bl
Definition dotmatrixr.h:142
digital_out_t rst
Definition dotmatrixr.h:141
pin_name_t chip_select
Definition dotmatrixr.h:147
digital_out_t rs
Definition dotmatrixr.h:140