aboutsummaryrefslogtreecommitdiffstats
path: root/boards/addons/gdisp/board_SSD1351_teensy.cpp
blob: 8c92c6e64be828adf4fab1ee31983327fbb18148 (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
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

#include <Arduino.h>
#include <SPI.h>

// pin numbers
#define SSD1351_DC	14
#define SSD1351_R	15
#define SSD1351_CS	16

// Predefine the routine with "C" prototypes
extern "C" void ssd1351_init_board(void);
extern "C" void ssd1351_setpin_reset(int state);
extern "C" void ssd1351_acquire_bus(void);
extern "C" void ssd1351_release_bus(void);
extern "C" void ssd1351_write_cmd(unsigned char index);
extern "C" void ssd1351_write_data(unsigned char data);

static SPISettings settings(12000000, MSBFIRST, SPI_MODE0);

void ssd1351_init_board(void) {
	pinMode(SSD1351_R, OUTPUT);
	pinMode(SSD1351_CS, OUTPUT);
	pinMode(SSD1351_DC, OUTPUT);
	digitalWriteFast(SSD1351_R, 1);
	digitalWriteFast(SSD1351_CS, 1);
	digitalWriteFast(SSD1351_DC, 1);
}

void ssd1351_setpin_reset(int state) {
	if (state)
		digitalWriteFast(SSD1351_R, 0);
	else
		digitalWriteFast(SSD1351_R, 1);
}

void ssd1351_acquire_bus(void) {
	SPI.beginTransaction(settings);
	digitalWriteFast(SSD1351_CS, 0);
}

void ssd1351_release_bus(void) {
	digitalWriteFast(SSD1351_CS, 1);
	SPI.endTransaction();
}

void ssd1351_write_cmd(unsigned char index) {
	digitalWriteFast(SSD1351_DC, 0);
	SPI.transfer(index);
	digitalWriteFast(SSD1351_DC, 1);
}

void ssd1351_write_data(unsigned char data) {
	SPI.transfer(data);
}