first cut at turnon scripts for EasyTimer v2
[fw/altos] / src / drivers / ao_st7565.h
1 /*
2  * Copyright © 2023 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_ST7565_H_
20 #define _AO_ST7565_H_
21
22 #include <ao_draw.h>
23
24 /*
25  * Wiring the NewHaven NHD-C12864LZ-FSW-FBW-3V3 display
26  *
27  * PIN  Symbol  Connection
28  *  1   /CS1    Chip select. Active low.
29  *  2   /RES    Reset. Active low.
30  *  3   A0      Register select. 0: instruction, 1: data
31  *  4   /WR     NC
32  *  5   /RD     NC
33  *  6   DB0     NC
34  *  7   DB1     NC
35  *  8   DB2     NC
36  *  8   DB3     NC
37  *  10  DB4     NC
38  *  11  DB5     NC
39  *  12  DB6     SPI clock. Mode 3 (idle high, rising edge)
40  *  13  DB7     SPI data.
41  *  14  Vdd     +3.3V
42  *  15  Vss     Ground
43  *  16  Vout    1uF to ground
44  *  17  CAP3+   1uF to CAP1-
45  *  18  CAP1-   1uF to CAP3+ and CAP1+
46  *  19  CAP1+   1uF to CAP1-
47  *  20  CAP2+   1uF to CAP2-
48  *  21  CAP2-   1uF to CAP2+
49  *  22  V4      1uF to ground
50  *  23  V3      1uF to ground
51  *  24  V2      1uF to ground
52  *  25  V1      1uF to ground
53  *  26  V0      1uF to ground
54  *  27  C86     MPU select. Ground
55  *  28  PS      Parallel/serial select. Ground
56  */
57
58 #define ST7565_DISPLAY_OFF                      0xae
59 #define ST7565_DISPLAY_ON                       0xaf
60 #define ST7565_DISPLAY_START_LINE_SET(line)     (0x40 | (line))
61 #define ST7565_PAGE_ADDRESS_SET(page)           (0xb0 | (page))
62 #define ST7565_COLUMN_ADDRESS_SET_MSN(nib)      (0x10 | (nib))
63 #define ST7565_COLUMN_ADDRESS_SET_LSN(nib)      (0x00 | (nib))
64 #define ST7565_ADC_SELECT_NORMAL                0xa0
65 #define ST7565_ADC_SELECT_REVERSE               0xa1
66 #define ST7565_DISPLAY_NORMAL                   0xa6
67 #define ST7565_DISPLAY_REVERSE                  0xa7
68 #define ST7565_DISPLAY_ALL_POINTS_OFF           0xa4
69 #define ST7565_DISPLAY_ALL_POINTS_ON            0xa5
70 #define ST7565_LCD_BIAS_1_9                     0xa2
71 #define ST7565_LCD_BIAS_1_7                     0xa3
72 #define ST7565_RMW                              0xe0
73 #define ST7565_RMW_END                          0xee
74 #define ST7565_RESET                            0xe2
75 #define ST7565_COMMON_MODE_NORMAL               0xc0
76 #define ST7565_COMMON_MODE_REVERSE              0xc8
77 #define ST7565_POWER_CONTROL_SET(pc)            (0x28 | (pc))
78 #define ST7565_RESISTOR_RATIO_SET(rr)           (0x20 | (rr))
79 #define ST7565_ELECTRONIC_VOLUME_SET            0x81
80 #define ST7565_SLEEP_MODE                       0xac
81 #define ST7565_BOOSTER_RATIO_SET                0xf8
82 #define ST7565_NOP                              0xe3
83
84 /* Max 50ns SPI clock time */
85 #define AO_ST7565_SPI_SPEED                     ao_spi_speed(AO_ST7565_SPI_BUS, 20000000)
86
87 void
88 ao_st7565_update(struct ao_bitmap *bitmap);
89
90 void
91 ao_st7565_set_brightness(uint8_t val);
92
93 uint8_t
94 ao_st7565_get_brightness(void);
95
96 void
97 ao_st7565_init(void);
98
99 #endif /* _AO_ST7565_H_ */