iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_dev_st7565_64128n.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_dev_st7565_64128n.c (Displaytech) |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Copyright (c) 2011, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 8 | All rights reserved. |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 11 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 14 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 17 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 18 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 19 | |
iforce2d | 0:972874f31c98 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 33 | |
iforce2d | 0:972874f31c98 | 34 | |
iforce2d | 0:972874f31c98 | 35 | */ |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 38 | |
iforce2d | 0:972874f31c98 | 39 | #define WIDTH 128 |
iforce2d | 0:972874f31c98 | 40 | #define HEIGHT 64 |
iforce2d | 0:972874f31c98 | 41 | #define PAGE_HEIGHT 8 |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | /* init sequence from https://github.com/adafruit/ST7565-LCD/blob/master/ST7565/ST7565.cpp */ |
iforce2d | 0:972874f31c98 | 44 | static const uint8_t u8g_dev_st7565_64128n_init_seq[] PROGMEM = { |
iforce2d | 0:972874f31c98 | 45 | U8G_ESC_CS(0), /* disable chip */ |
iforce2d | 0:972874f31c98 | 46 | U8G_ESC_ADR(0), /* instruction mode */ |
iforce2d | 0:972874f31c98 | 47 | U8G_ESC_CS(1), /* enable chip */ |
iforce2d | 0:972874f31c98 | 48 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ |
iforce2d | 0:972874f31c98 | 49 | |
iforce2d | 0:972874f31c98 | 50 | 0x0A2, /* 0x0a2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */ |
iforce2d | 0:972874f31c98 | 51 | 0x0A0, /* Normal ADC Select (according to Displaytech 64128N datasheet) */ |
iforce2d | 0:972874f31c98 | 52 | |
iforce2d | 0:972874f31c98 | 53 | 0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */ |
iforce2d | 0:972874f31c98 | 54 | 0x040, /* Display start line for Displaytech 64128N */ |
iforce2d | 0:972874f31c98 | 55 | |
iforce2d | 0:972874f31c98 | 56 | 0x028 | 0x04, /* power control: turn on voltage converter */ |
iforce2d | 0:972874f31c98 | 57 | U8G_ESC_DLY(50), /* delay 50 ms */ |
iforce2d | 0:972874f31c98 | 58 | |
iforce2d | 0:972874f31c98 | 59 | 0x028 | 0x06, /* power control: turn on voltage regulator */ |
iforce2d | 0:972874f31c98 | 60 | U8G_ESC_DLY(50), /* delay 50 ms */ |
iforce2d | 0:972874f31c98 | 61 | |
iforce2d | 0:972874f31c98 | 62 | 0x028 | 0x07, /* power control: turn on voltage follower */ |
iforce2d | 0:972874f31c98 | 63 | U8G_ESC_DLY(50), /* delay 50 ms */ |
iforce2d | 0:972874f31c98 | 64 | |
iforce2d | 0:972874f31c98 | 65 | 0x010, /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */ |
iforce2d | 0:972874f31c98 | 66 | |
iforce2d | 0:972874f31c98 | 67 | 0x0a6, /* display normal, bit val 0: LCD pixel off. */ |
iforce2d | 0:972874f31c98 | 68 | |
iforce2d | 0:972874f31c98 | 69 | 0x081, /* set contrast */ |
iforce2d | 0:972874f31c98 | 70 | 0x01e, /* Contrast value. Setting for controlling brightness of Displaytech 64128N */ |
iforce2d | 0:972874f31c98 | 71 | |
iforce2d | 0:972874f31c98 | 72 | |
iforce2d | 0:972874f31c98 | 73 | 0x0af, /* display on */ |
iforce2d | 0:972874f31c98 | 74 | |
iforce2d | 0:972874f31c98 | 75 | U8G_ESC_DLY(100), /* delay 100 ms */ |
iforce2d | 0:972874f31c98 | 76 | 0x0a5, /* display all points, ST7565 */ |
iforce2d | 0:972874f31c98 | 77 | U8G_ESC_DLY(100), /* delay 100 ms */ |
iforce2d | 0:972874f31c98 | 78 | U8G_ESC_DLY(100), /* delay 100 ms */ |
iforce2d | 0:972874f31c98 | 79 | 0x0a4, /* normal display */ |
iforce2d | 0:972874f31c98 | 80 | U8G_ESC_CS(0), /* disable chip */ |
iforce2d | 0:972874f31c98 | 81 | U8G_ESC_END /* end of sequence */ |
iforce2d | 0:972874f31c98 | 82 | }; |
iforce2d | 0:972874f31c98 | 83 | |
iforce2d | 0:972874f31c98 | 84 | static const uint8_t u8g_dev_st7565_64128n_data_start[] PROGMEM = { |
iforce2d | 0:972874f31c98 | 85 | U8G_ESC_ADR(0), /* instruction mode */ |
iforce2d | 0:972874f31c98 | 86 | U8G_ESC_CS(1), /* enable chip */ |
iforce2d | 0:972874f31c98 | 87 | 0x010, /* set upper 4 bit of the col adr to 0x10 */ |
iforce2d | 0:972874f31c98 | 88 | 0x000, /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */ |
iforce2d | 0:972874f31c98 | 89 | U8G_ESC_END /* end of sequence */ |
iforce2d | 0:972874f31c98 | 90 | }; |
iforce2d | 0:972874f31c98 | 91 | |
iforce2d | 0:972874f31c98 | 92 | static const uint8_t u8g_dev_st7565_64128n_sleep_on[] PROGMEM = { |
iforce2d | 0:972874f31c98 | 93 | U8G_ESC_ADR(0), /* instruction mode */ |
iforce2d | 0:972874f31c98 | 94 | U8G_ESC_CS(1), /* enable chip */ |
iforce2d | 0:972874f31c98 | 95 | 0x0ac, /* static indicator off */ |
iforce2d | 0:972874f31c98 | 96 | 0x000, /* indicator register set (not sure if this is required) */ |
iforce2d | 0:972874f31c98 | 97 | 0x0ae, /* display off */ |
iforce2d | 0:972874f31c98 | 98 | 0x0a5, /* all points on */ |
iforce2d | 0:972874f31c98 | 99 | U8G_ESC_CS(1), /* disable chip */ |
iforce2d | 0:972874f31c98 | 100 | U8G_ESC_END /* end of sequence */ |
iforce2d | 0:972874f31c98 | 101 | }; |
iforce2d | 0:972874f31c98 | 102 | |
iforce2d | 0:972874f31c98 | 103 | static const uint8_t u8g_dev_st7565_64128n_sleep_off[] PROGMEM = { |
iforce2d | 0:972874f31c98 | 104 | U8G_ESC_ADR(0), /* instruction mode */ |
iforce2d | 0:972874f31c98 | 105 | U8G_ESC_CS(1), /* enable chip */ |
iforce2d | 0:972874f31c98 | 106 | 0x0a4, /* all points off */ |
iforce2d | 0:972874f31c98 | 107 | 0x0af, /* display on */ |
iforce2d | 0:972874f31c98 | 108 | U8G_ESC_DLY(50), /* delay 50 ms */ |
iforce2d | 0:972874f31c98 | 109 | U8G_ESC_CS(1), /* disable chip */ |
iforce2d | 0:972874f31c98 | 110 | U8G_ESC_END /* end of sequence */ |
iforce2d | 0:972874f31c98 | 111 | }; |
iforce2d | 0:972874f31c98 | 112 | |
iforce2d | 0:972874f31c98 | 113 | uint8_t u8g_dev_st7565_64128n_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 114 | { |
iforce2d | 0:972874f31c98 | 115 | switch(msg) |
iforce2d | 0:972874f31c98 | 116 | { |
iforce2d | 0:972874f31c98 | 117 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 118 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); |
iforce2d | 0:972874f31c98 | 119 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq); |
iforce2d | 0:972874f31c98 | 120 | break; |
iforce2d | 0:972874f31c98 | 121 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 122 | break; |
iforce2d | 0:972874f31c98 | 123 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 124 | { |
iforce2d | 0:972874f31c98 | 125 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 126 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start); |
iforce2d | 0:972874f31c98 | 127 | u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (ST7565R) */ |
iforce2d | 0:972874f31c98 | 128 | u8g_SetAddress(u8g, dev, 1); /* data mode */ |
iforce2d | 0:972874f31c98 | 129 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) |
iforce2d | 0:972874f31c98 | 130 | return 0; |
iforce2d | 0:972874f31c98 | 131 | u8g_SetChipSelect(u8g, dev, 0); |
iforce2d | 0:972874f31c98 | 132 | } |
iforce2d | 0:972874f31c98 | 133 | break; |
iforce2d | 0:972874f31c98 | 134 | case U8G_DEV_MSG_CONTRAST: |
iforce2d | 0:972874f31c98 | 135 | u8g_SetChipSelect(u8g, dev, 1); |
iforce2d | 0:972874f31c98 | 136 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ |
iforce2d | 0:972874f31c98 | 137 | u8g_WriteByte(u8g, dev, 0x081); |
iforce2d | 0:972874f31c98 | 138 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); |
iforce2d | 0:972874f31c98 | 139 | u8g_SetChipSelect(u8g, dev, 0); |
iforce2d | 0:972874f31c98 | 140 | return 1; |
iforce2d | 0:972874f31c98 | 141 | case U8G_DEV_MSG_SLEEP_ON: |
iforce2d | 0:972874f31c98 | 142 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_on); |
iforce2d | 0:972874f31c98 | 143 | return 1; |
iforce2d | 0:972874f31c98 | 144 | case U8G_DEV_MSG_SLEEP_OFF: |
iforce2d | 0:972874f31c98 | 145 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_off); |
iforce2d | 0:972874f31c98 | 146 | return 1; |
iforce2d | 0:972874f31c98 | 147 | } |
iforce2d | 0:972874f31c98 | 148 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); |
iforce2d | 0:972874f31c98 | 149 | } |
iforce2d | 0:972874f31c98 | 150 | |
iforce2d | 0:972874f31c98 | 151 | uint8_t u8g_dev_st7565_64128n_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 152 | { |
iforce2d | 0:972874f31c98 | 153 | switch(msg) |
iforce2d | 0:972874f31c98 | 154 | { |
iforce2d | 0:972874f31c98 | 155 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 156 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); |
iforce2d | 0:972874f31c98 | 157 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_init_seq); |
iforce2d | 0:972874f31c98 | 158 | break; |
iforce2d | 0:972874f31c98 | 159 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 160 | break; |
iforce2d | 0:972874f31c98 | 161 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 162 | { |
iforce2d | 0:972874f31c98 | 163 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 164 | |
iforce2d | 0:972874f31c98 | 165 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start); |
iforce2d | 0:972874f31c98 | 166 | u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */ |
iforce2d | 0:972874f31c98 | 167 | u8g_SetAddress(u8g, dev, 1); /* data mode */ |
iforce2d | 0:972874f31c98 | 168 | u8g_WriteSequence(u8g, dev, pb->width, pb->buf); |
iforce2d | 0:972874f31c98 | 169 | u8g_SetChipSelect(u8g, dev, 0); |
iforce2d | 0:972874f31c98 | 170 | |
iforce2d | 0:972874f31c98 | 171 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_data_start); |
iforce2d | 0:972874f31c98 | 172 | u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */ |
iforce2d | 0:972874f31c98 | 173 | u8g_SetAddress(u8g, dev, 1); /* data mode */ |
iforce2d | 0:972874f31c98 | 174 | u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width); |
iforce2d | 0:972874f31c98 | 175 | u8g_SetChipSelect(u8g, dev, 0); |
iforce2d | 0:972874f31c98 | 176 | } |
iforce2d | 0:972874f31c98 | 177 | break; |
iforce2d | 0:972874f31c98 | 178 | case U8G_DEV_MSG_CONTRAST: |
iforce2d | 0:972874f31c98 | 179 | u8g_SetChipSelect(u8g, dev, 1); |
iforce2d | 0:972874f31c98 | 180 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ |
iforce2d | 0:972874f31c98 | 181 | u8g_WriteByte(u8g, dev, 0x081); |
iforce2d | 0:972874f31c98 | 182 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); |
iforce2d | 0:972874f31c98 | 183 | u8g_SetChipSelect(u8g, dev, 0); |
iforce2d | 0:972874f31c98 | 184 | return 1; |
iforce2d | 0:972874f31c98 | 185 | case U8G_DEV_MSG_SLEEP_ON: |
iforce2d | 0:972874f31c98 | 186 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_on); |
iforce2d | 0:972874f31c98 | 187 | return 1; |
iforce2d | 0:972874f31c98 | 188 | case U8G_DEV_MSG_SLEEP_OFF: |
iforce2d | 0:972874f31c98 | 189 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7565_64128n_sleep_off); |
iforce2d | 0:972874f31c98 | 190 | return 1; |
iforce2d | 0:972874f31c98 | 191 | } |
iforce2d | 0:972874f31c98 | 192 | return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg); |
iforce2d | 0:972874f31c98 | 193 | } |
iforce2d | 0:972874f31c98 | 194 | |
iforce2d | 0:972874f31c98 | 195 | U8G_PB_DEV(u8g_dev_st7565_64128n_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_SW_SPI); |
iforce2d | 0:972874f31c98 | 196 | U8G_PB_DEV(u8g_dev_st7565_64128n_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_HW_SPI); |
iforce2d | 0:972874f31c98 | 197 | U8G_PB_DEV(u8g_dev_st7565_64128n_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_st7565_64128n_fn, U8G_COM_PARALLEL); |
iforce2d | 0:972874f31c98 | 198 | |
iforce2d | 0:972874f31c98 | 199 | uint8_t u8g_dev_st7565_64128n_2x_buf[WIDTH*2] U8G_NOCOMMON ; |
iforce2d | 0:972874f31c98 | 200 | u8g_pb_t u8g_dev_st7565_64128n_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_st7565_64128n_2x_buf}; |
iforce2d | 0:972874f31c98 | 201 | u8g_dev_t u8g_dev_st7565_64128n_2x_sw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_SW_SPI }; |
iforce2d | 0:972874f31c98 | 202 | u8g_dev_t u8g_dev_st7565_64128n_2x_hw_spi = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_HW_SPI }; |
iforce2d | 0:972874f31c98 | 203 | u8g_dev_t u8g_dev_st7565_64128n_2x_hw_parallel = { u8g_dev_st7565_64128n_2x_fn, &u8g_dev_st7565_64128n_2x_pb, U8G_COM_PARALLEL }; |
iforce2d | 0:972874f31c98 | 204 |