lcdmini 2.0.0.0
lcdmini.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 LCDMINI_H
29#define LCDMINI_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#include "drv_pwm.h"
54
75#define LCDMINI_IODIRB_BANK0 0x01
76#define LCDMINI_OLATB_BANK0 0x15
77#define LCDMINI_IOCON_BANK0 0x0A
78#define LCDMINI_ADDRESS_CODE 0x40
79#define LCDMINI_GPIO_REGISTER 0x09
80
81 // lcdmini_reg
82
97#define LCDMINI_ENABLE 0x08
98#define LCDMINI_RESET 0x04
99
100#define LCDMINI_OP_CODE_READ 0x01
101#define LCDMINI_OP_CODE_WRITE 0xFE
102
107#define LCDMINI_CLEAR 0x01
108#define LCDMINI_RETURN_HOME 0x02
109#define LCDMINI_DISPLAY_OFF_CURSOR_OFF 0x08
110#define LCDMINI_CURSOR_OFF 0x0C
111#define LCDMINI_UNDERLINE_ON 0x0E
112#define LCDMINI_BLINK_CURSOR_ON 0x0F
113#define LCDMINI_MOVE_CURSOR_LEFT 0x10
114#define LCDMINI_MOVE_CURSOR_RIGHT 0x14
115#define LCDMINI_TURN_ON 0x0A
116#define LCDMINI_TURN_OFF 0x0C
117#define LCDMINI_SHIFT_LEFT 0x18
118#define LCDMINI_SHIFT_RIGHT 0x1C
119#define LCDMINI_2_LINE_5X7 0x28
120
121#define LCDMINI_FIRST_ROW 0x80
122#define LCDMINI_SECOND_ROW 0xC0
123#define LCDMINI_THIRD_ROW 0x94
124#define LCDMINI_FOURTH_ROW 0xD4
125
126
131#define LCDMINI_DEF_FREQ 500
132
141#define LCDMINI_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
142#define LCDMINI_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
143
144 // lcdmini_set
145
160#define LCDMINI_MAP_MIKROBUS( cfg, mikrobus ) \
161 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
162 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
163 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
164 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
165 cfg.cs2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
166 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
167 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
168 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
169
170 // lcdmini_map
171 // lcdmini
172
177typedef struct
178{
179 // Output pins
180 digital_out_t cs2;
181 digital_out_t rst;
183 // Input pins
184 digital_in_t int_pin;
186 // Modules
187 pwm_t pwm;
189 spi_master_t spi;
191 pin_name_t chip_select;
192 uint32_t pwm_freq;
194} lcdmini_t;
195
200typedef struct
201{
202 // Communication gpio pins
203 pin_name_t miso;
204 pin_name_t mosi;
205 pin_name_t sck;
206 pin_name_t cs;
208 // Additional gpio pins
209 pin_name_t cs2;
210 pin_name_t rst;
211 pin_name_t pwm;
212 pin_name_t int_pin;
214 // Static variables
215 uint32_t dev_pwm_freq;
217 uint32_t spi_speed;
218 spi_master_mode_t spi_mode;
219 spi_master_chip_select_polarity_t cs_polarity;
222
227typedef enum
228{
230 LCDMINI_ERROR = -1
231
233
250
265
280
295err_t lcdmini_generic_write ( lcdmini_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
296
311err_t lcdmini_generic_read ( lcdmini_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
312
324err_t lcdmini_set_duty_cycle ( lcdmini_t *ctx, float duty_cycle );
325
337
349
359void lcdmini_set_backlight ( lcdmini_t *ctx, float backlight_value );
360
370void lcdmini_set_contrast( lcdmini_t *ctx, uint8_t contrast_value );
371
380
389
403err_t lcdmini_read_register ( lcdmini_t *ctx, uint8_t reg , uint8_t *data_out );
404
418err_t lcdmini_write_register ( lcdmini_t *ctx, uint8_t reg , uint8_t data_in );
419
428void lcdmini_send_cmd ( lcdmini_t *ctx, uint8_t command );
429
438void lcdmini_send_char ( lcdmini_t *ctx, uint8_t character );
439
450void lcdmini_display_char ( lcdmini_t *ctx, uint8_t row, uint8_t column, char character );
451
464void lcdmini_display_text ( lcdmini_t *ctx, uint8_t row, uint8_t column, char *data_in );
465
466#ifdef __cplusplus
467}
468#endif
469#endif // LCDMINI_H
470
471 // lcdmini
472
473// ------------------------------------------------------------------------ END
void lcdmini_set_contrast(lcdmini_t *ctx, uint8_t contrast_value)
Set contrast function.
void lcdmini_display_text(lcdmini_t *ctx, uint8_t row, uint8_t column, char *data_in)
LCD mini display text.
void lcdmini_send_char(lcdmini_t *ctx, uint8_t character)
LCD mini send character.
err_t lcdmini_pwm_stop(lcdmini_t *ctx)
LCD mini stop PWM module.
void lcdmini_hw_reset(lcdmini_t *ctx)
Hardware reset function.
err_t lcdmini_read_register(lcdmini_t *ctx, uint8_t reg, uint8_t *data_out)
LCD mini register data reading function.
err_t lcdmini_generic_write(lcdmini_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LCD mini data writing function.
void lcdmini_cfg_setup(lcdmini_cfg_t *cfg)
LCD mini configuration object setup function.
err_t lcdmini_write_register(lcdmini_t *ctx, uint8_t reg, uint8_t data_in)
LCD mini register data writing function.
void lcdmini_send_cmd(lcdmini_t *ctx, uint8_t command)
LCD mini send command.
err_t lcdmini_default_cfg(lcdmini_t *ctx)
LCD mini default configuration function.
err_t lcdmini_set_duty_cycle(lcdmini_t *ctx, float duty_cycle)
LCD mini sets PWM duty cycle.
err_t lcdmini_generic_read(lcdmini_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LCD mini data reading function.
void lcdmini_set_backlight(lcdmini_t *ctx, float backlight_value)
Set backlight function.
err_t lcdmini_init(lcdmini_t *ctx, lcdmini_cfg_t *cfg)
LCD mini initialization function.
uint8_t lcdmini_get_interrupt(lcdmini_t *ctx)
Get interrupt.
void lcdmini_display_char(lcdmini_t *ctx, uint8_t row, uint8_t column, char character)
LCD mini display character.
err_t lcdmini_pwm_start(lcdmini_t *ctx)
LCD mini start PWM module.
lcdmini_return_value_t
LCD mini Click return value data.
Definition lcdmini.h:228
@ LCDMINI_ERROR
Definition lcdmini.h:230
@ LCDMINI_OK
Definition lcdmini.h:229
This file contains SPI specific macros, functions, etc.
LCD mini Click configuration object.
Definition lcdmini.h:201
pin_name_t cs2
Definition lcdmini.h:209
spi_master_chip_select_polarity_t cs_polarity
Definition lcdmini.h:219
pin_name_t sck
Definition lcdmini.h:205
spi_master_mode_t spi_mode
Definition lcdmini.h:218
pin_name_t mosi
Definition lcdmini.h:204
uint32_t spi_speed
Definition lcdmini.h:217
uint32_t dev_pwm_freq
Definition lcdmini.h:215
pin_name_t int_pin
Definition lcdmini.h:212
pin_name_t pwm
Definition lcdmini.h:211
pin_name_t miso
Definition lcdmini.h:203
pin_name_t rst
Definition lcdmini.h:210
pin_name_t cs
Definition lcdmini.h:206
LCD mini Click context object.
Definition lcdmini.h:178
spi_master_t spi
Definition lcdmini.h:189
uint32_t pwm_freq
Definition lcdmini.h:192
digital_in_t int_pin
Definition lcdmini.h:184
digital_out_t rst
Definition lcdmini.h:181
digital_out_t cs2
Definition lcdmini.h:180
pin_name_t chip_select
Definition lcdmini.h:191
pwm_t pwm
Definition lcdmini.h:187