aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
blob: 1ba28f022d87c213028b265e4582e80649e6c737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* 
 * This source code form is a part of the ChibiOS/GFX project and stands
 * under the terms of the GFX License v1.0. If a copy of the license
 * was not distributed with this file, You can obtain one at: 
 * 
 * http://chibios-gfx.com/license.html
 *
 */

/*
    ChibiOS/GFX - Copyright (C) 2012, 2013
                 Joel Bodenmann aka Tectu <joel@unormal.org>

    This file is part of ChibiOS/GFX.

    ChibiOS/GFX is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    ChibiOS/GFX is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file    drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
 * @brief   TDISP driver subsystem board interface for the HD44780 display
 *
 * @addtogroup TDISP
 * @{
 */

#ifndef _TDISP_LLD_BOARD_H
#define _TDISP_LLD_BOARD_H

/* Configure these to match the hardware connections on your board */
#define BUS_4BITS	TRUE

/* Configure the bitoffset in the dataport so they match with the
 * hardware pins. An offset of 0 means bit0 stays at bit0 of the dataport.
 * If the offset is set to 3, bit0 of the nibble will be positioned at
 * P[A..G]3 of the hardware-port.
 */
#define hardware_offset	3

/* The port where the data is sent to. In the
 * low-leveldriver het hardware_offset is taken
 * into account. If for example the hardware_offset
 * is set to 3, then de data will be sent to
 * PE3, PE4, PE5 en PE6, if the dataport where GPIOE.
 */
#define PORT_DATA	GPIOE

/* The port used to controle the controle lines of
 * the display.
 */
#define PORT_CTRL	GPIOD
/* Pin to controle the R/S-line of the display */
#define PIN_RS		0
/* Pin to controle the EN-line of the display */
#define PIN_EN		1
/* Pin to controle the R/W-pin of the display.
 * If reading of the display is not used disable
 * reading in the gfxconf.h and put a dummy value here
 * as it will not be used.
 */
#define PIN_RW		7


static void init_board(void) {
	/* Initialize the ports for data and controle-lines */
	palSetGroupMode(PORT_CTRL, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
	palSetGroupMode(PORT_DATA, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
	/* Set alle controle pins to low */
	palClearPad(PORT_CTRL, PIN_RS);
	palClearPad(PORT_CTRL, PIN_EN);
	#if TDISP_NEED_READ
	  palClearPad(PORT_CTRL, PIN_RW);
	#endif
}

/* This is the low-level routine for sending the bits
 * to the LCD-display. This routine shifts
 * the bits so they match the hardware port.
 */
static void writeToLCD(uint8_t data) {
	palWritePort(PORT_DATA, data<<hardware_offset);
	palSetPad(PORT_CTRL, PIN_EN);
	chThdSleepMicroseconds(1);
	palClearPad(PORT_CTRL, PIN_EN);
	/* wait a little while so that de display can process the data */
	chThdSleepMicroseconds(5);
}

/* Writes a command to the display. The
 * RS-line is pulled low and than the
 * data is send.
 */
static void write_cmd(uint8_t data) {
	palClearPad(PORT_CTRL, PIN_RS);
	#if BUS_4BITS
		/* first send the high-nibble */
		writeToLCD(data>>4);
	#endif
	/* send the low-nibble */
	#if BUS_4BITS
		/* in 4-bit mode the high-nibble is zeroed out */
		writeToLCD(data & 0x0F);
	#else
		writeToLCD(data);
	#endif
}

// static void write_initcmd(uint8_t data) {
//   write_cmd(data);
// }

/* Write data to the display. The
 * RS-line is pulled high and than the
 * data is send.
 */
static void write_data(uint8_t data) {
	palSetPad(PORT_CTRL, PIN_RS);
	#if BUS_4BITS
		/* first send the high-nibble */
		writeToLCD(data>>4);
	#endif
	/* send the low-nibble */
	#if BUS_4BITS
		/* in 4-bit mode the high-nibble is zeroed out */
		writeToLCD(data & 0x0F);
	#else
		writeToLCD(data);
	#endif
}

#endif /* _TDISP_LLD_BOARD_H */
/** @} */