-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.h
More file actions
165 lines (140 loc) · 4.71 KB
/
module.h
File metadata and controls
165 lines (140 loc) · 4.71 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef _MODULE_H_
#define _MODULE_H_
/*
* module.h:
* Code relating to the "module" (a PCB) used to hold the eInk device.
*
* This stripped down to JUST the -llgpio implementation for the Raspberry PI (4 & 5)
*
* The vast majority of this code comes from DEV_Config.h in the waveshare
* project @ https://github.com/waveshareteam/e-Paper
*
* Modded to follow normal C convections (variables lowercase, MACROs and constants upper case, types capitalised)
*
*
* Their PD statement reproduced below
*
*/
/*****************************************************************************
* | File : DEV_Config.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V2.0
* | Date : 2018-10-30
* | Info :
* 1.add:
* UBYTE\UWORD\UDOUBLE
* 2.Change:
* EPD_RST -> EPD_RST_PIN
* EPD_DC -> EPD_DC_PIN
* EPD_CS -> EPD_CS_PIN
* EPD_BUSY -> EPD_BUSY_PIN
* 3.Remote:
* EPD_RST_1\EPD_RST_0
* EPD_DC_1\EPD_DC_0
* EPD_CS_1\EPD_CS_0
* EPD_BUSY_1\EPD_BUSY_0
* 3.add:
* #define DEV_Digital_Write(_pin, _value) bcm2835_GPIOI_write(_pin, _value)
* #define DEV_Digital_Read(_pin) bcm2835_GPIOI_lev(_pin)
* #define DEV_SPI_WriteByte(__value) bcm2835_spi_transfer(__value)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
/* Autoconf */
#include "config.h"
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "Debug.h"
#include <lgpio.h>
#include <pthread.h>
#define LFLAGS 0
#define NUM_MAXBUF 4
extern int EINK_RST_PIN;
extern int EINK_DC_PIN;
extern int EINK_CS_PIN;
extern int EINK_BUSY_PIN;
extern int EINK_PWR_PIN;
extern int EINK_MOSI_PIN;
extern int EINK_SCLK_PIN;
/**
* data
**/
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t
extern UBYTE module_turn_on (void);
extern void gpio_init (void);
extern void gpio_mode (UWORD Pin, UWORD Mode); // Mode0 == Input , Mode1 == Output
extern void gpio_write (UWORD Pin, UBYTE Value); // Write value to Pin
extern UBYTE gpio_read (UWORD Pin); // Read a value from Pin
extern void gpio_delay (UDOUBLE xms);
extern void module_turn_off(void);
extern void spi_writebyte (uint8_t Value);
extern pthread_mutex_t eink_mutex;
extern pthread_cond_t eink_cond;
/* GPV TBD , future proofing
*
* The sample code from WaveShare describes a single eInk device on fixed pins
* We have also simplified the code so it only supports the 1.54inch e-Paper Module (B)
* which is a 200x200 display.
*
* So sombody who knows the rpi better than me could:
*
* - Add support for a second or third eInk 1.54inch display
* - Add support for differnet display sizes
*
* The first would require different PIN allocations for each display (at least)
* The second MAY simply be a matter of using diffent display sizes
*
* While this is here and the grammar will be modified to support a display number
* on the verbs, NONE (almost) OF THE CODE HAS BEEN MODIFIED TO SUPPORT MULTIPLE
* DISPLAYS.
*
*
*/
/*
* displays can have a name of up to 32 characters.
*/
#define MAX_DISPLAY_NAME 32
struct display_settings
{
int eink_rst_pin;
int eink_dc_pin;
int eink_cs_pin;
int eink_busy_pin;
int eink_pwr_pin;
int eink_mosi_pin;
int eink_sclk_pin;
int no_columns;
int no_rows;
char part_name[MAX_DISPLAY_NAME]; // e.g '1.54" Module(B)'
char local_name[MAX_DISPLAY_NAME]; // e.g 'Front panel'
};
extern struct display_settings * get_display(int i);
#endif