-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathssd_1306.h
More file actions
120 lines (105 loc) · 4.26 KB
/
Copy pathssd_1306.h
File metadata and controls
120 lines (105 loc) · 4.26 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
/***************************************************************************//**
* @file ssd_1306.h
* @brief Header file for ssd_1306 Driver.
* @author Andrei Porumb (andrei.porumb@analog.com)
********************************************************************************
* Copyright 2021(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef SSD_1306_H
#define SSD_1306_H
#include <stdint.h>
#include <stdlib.h>
#include "display.h"
#include "no_os_gpio.h"
enum comm_type {
SSD1306_I2C,
SSD1306_SPI
};
enum transmit_type {
SSD1306_CMD,
SSD1306_DATA
};
#ifndef SSD1306_I2C_ADDR
#define SSD1306_I2C_ADDR 0x3C
#endif
/*
* Build-time display orientation, in degrees. Supported values are 0 and 180
* (the SSD1306 can only mirror the segment/COM scan direction in hardware).
*/
#ifndef SSD1306_ROTATION
#define SSD1306_ROTATION 0
#endif
/*
* Command-byte builders derived from SSD1306_ROTATION. A 180-degree rotation
* mirrors both the segment remap (0xA0) and the COM output scan direction
* (0xC0).
*/
#define SSD1306_SEG_REMAP_CMD \
(0xA0U | (((SSD1306_ROTATION) == 180) ? 0x00U : 0x01U))
#define SSD1306_COM_SCAN_CMD \
(0xC0U | (((SSD1306_ROTATION) == 180) ? 0x00U : 0x08U))
/**
* @struct ssd_1306_extra
* @brief Extra parameters needed for ssd_1306 usage.
*/
typedef struct ssd_1306_extra {
/** Data/Command pin gpio initial param */
struct no_os_gpio_init_param *dc_pin_ip;
/** RESET pin gpio initial param */
struct no_os_gpio_init_param *reset_pin_ip;
/** Data/Command pin gpio desc */
struct no_os_gpio_desc *dc_pin;
/** RESET pin gpio desc*/
struct no_os_gpio_desc *reset_pin;
/* SPI initial param */
struct no_os_spi_init_param *spi_ip;
/* SPI descriptor*/
struct no_os_spi_desc *spi_desc;
/* I2C initial param*/
struct no_os_i2c_init_param *i2c_ip;
/* I2C descriptor*/
struct no_os_i2c_desc *i2c_desc;
/* Communication type */
enum comm_type comm_type;
} ssd_1306_extra;
extern const struct display_controller_ops ssd1306_ops;
/** Initialize the ssd_1306 peripheral for display operation. */
int32_t ssd_1306_init(struct display_dev *device);
/** ssd_1306 ssd_1306 turns display on/off. */
int32_t ssd_1306_display_on_off(struct display_dev *device, uint8_t on_off);
/* Moves cursor to desired row/column. */
int32_t ssd_1306_move_cursor(struct display_dev *device, uint8_t row,
uint8_t column);
/** Prints character at selected position. */
int32_t ssd_1306_print_ascii(struct display_dev *device, uint8_t ascii,
uint8_t row, uint8_t column);
/** Removes resources allocated by device. */
int32_t ssd_1306_remove(struct display_dev *device);
/** Print entire screen buffer */
int32_t ssd_1306_print_buffer(struct display_dev *device, char *buffer);
#endif