PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
Display
libil3820
il3820_spiWrite.c
1
/*
2
* @file il3820_spiWrite.c
3
*
4
* @author Matthew Matz & Roy Eltham
5
*
6
* @version 0.5
7
*
8
* @copyright Copyright (C) Parallax, Inc. 2018. See end of file for
9
* terms of use (MIT License).
10
*
11
* @brief Waveshare ePaper display bitmap driver, see il3820_h. for documentation.
12
*
13
* @detail Please submit bug reports, suggestions, and improvements to
14
* this code to editor@parallax.com.
15
*/
16
17
18
#include "il3820.h"
19
#include <propeller.h>
20
21
// ------------------- low level pin interface --------------------
22
static
char
_writeLock = 0;
23
24
void
il3820_spiWrite(
int
mask_cs,
int
mask_sdi,
int
mask_clk,
int
mask_dc,
char
c,
char
dc) {
25
26
// Conditionally set _rs (Source: https://graphics.stanford.edu/~seander/bithacks.html)
27
unsigned
int
mask = (-(dc) ^
OUTA
) & mask_dc;
28
OUTA
^= mask;
29
30
OUTA
&= ~mask_cs;
31
OUTA
&= ~mask_clk;
// Pin output state to low
32
DIRA
|= mask_clk;
// Pin direction to output
33
34
for
(
int
i = 7; i >= 0 ; i--) {
35
if
((c >> i) & 1)
OUTA
|= mask_sdi;
36
else
OUTA
&= (~mask_sdi);
37
OUTA
^= mask_clk;
38
OUTA
^= mask_clk;
39
}
40
OUTA
|= mask_cs;
41
}
42
43
44
__attribute__((fcache))
// allows function to run directly from cog ram, 10x+ speed increase
45
void
il3820_spiWriteBytes(
int
mask_cs,
int
mask_sdi,
int
mask_clk,
const
unsigned
char
* data,
int
numBytes) {
46
OUTA
&= ~mask_cs;
47
OUTA
&= ~mask_clk;
// Pin output state to low
48
DIRA
|= mask_clk;
// Pin direction to output
49
50
for
(
int
j = 0; j < numBytes; j++) {
51
for
(
int
i = 7; i >= 0; i--) {
52
if
((data[j] >> i) & 1)
OUTA
|= mask_sdi;
53
else
OUTA
&= (~mask_sdi);
54
OUTA
^= mask_clk;
55
OUTA
^= mask_clk;
56
}
57
}
58
OUTA
|= mask_cs;
59
}
60
61
62
char
il3820_writeLock() {
63
return
_writeLock;
64
}
65
66
void
il3820_writeLockSet(
char
devId) {
67
while
(_writeLock);
68
_writeLock = devId;
69
}
70
71
void
il3820_writeLockClear(
char
devId) {
72
if
(_writeLock == devId) {
73
_writeLock = 0;
74
}
75
}
76
77
OUTA
#define OUTA
Use to set output pin states when corresponding DIRA bits are 1.
Definition:
propeller1.h:157
DIRA
#define DIRA
Use to set pins to input (0) or output (1).
Definition:
propeller1.h:161
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17