This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
displaybus.h
89 lines (63 loc) · 2.62 KB
/
displaybus.h
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
/** \file
\brief Display bus broker.
Here we map generic calls to the display bus to calls to the actually used
bus.
This is a slightly different #include strategy than the one used for display
and fonts. Instead of including a selected .c file and having the same
function names in each included .c file, we map functions with simple,
generic named inline funtions to get what we want. This allows to re-use
functions used elsewhere. For example SPI functions, which are used for SD
card reading and some temperature sensors, too.
The other approach, in turn, needs no mapping and can use variables, too,
but allows to use the functions in one place, only.
*/
#ifndef _DISPLAYBUS_H
#define _DISPLAYBUS_H
#include "config_wrapper.h"
#if defined DISPLAY_BUS_4BIT
#include "parallel-4bit.h"
static void displaybus_init(uint8_t address) __attribute__ ((always_inline));
inline void displaybus_init(uint8_t address) {
return parallel_4bit_init();
}
static uint8_t displaybus_busy(void) __attribute__ ((always_inline));
inline uint8_t displaybus_busy(void) {
return parallel_4bit_busy();
}
/**
Note: we use 'rs' here to decide wether to send data or a command. Other
buses, like I2C, make no such distinction, but have last_byte
instead. This works, because there is currently no display supported
which can use both, I2C and the 4-bit bus.
In case such support is wanted, displaybus_write() likely needs to
take both parameters. The actually best solution will be seen better
if such a display actually appears.
*/
static void displaybus_write(uint8_t data, enum rs_e rs) \
__attribute__ ((always_inline));
inline void displaybus_write(uint8_t data, enum rs_e rs) {
return parallel_4bit_write(data, rs);
}
#define DISPLAY_BUS
#elif defined DISPLAY_BUS_8BIT
#error Display connected directly via 8 pins is not yet supported.
#elif defined DISPLAY_BUS_I2C
#include "i2c.h"
static void displaybus_init(uint8_t address) __attribute__ ((always_inline));
inline void displaybus_init(uint8_t address) {
return i2c_init(address);
}
static uint8_t displaybus_busy(void) __attribute__ ((always_inline));
inline uint8_t displaybus_busy(void) {
return i2c_busy();
}
static void displaybus_write(uint8_t data, uint8_t last_byte) \
__attribute__ ((always_inline));
inline void displaybus_write(uint8_t data, uint8_t last_byte) {
return i2c_write(data, last_byte);
}
#define DISPLAY_BUS
#elif defined DISPLAY_BUS_SPI
#error Display connected via SPI not yet supported.
#endif
#endif /* _DISPLAYBUS_H */