
Se her
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
DOGM_STREAM_SPI.cpp@2:6ae05f48fe57, 2017-03-28 (annotated)
- Committer:
- Matias123
- Date:
- Tue Mar 28 09:49:27 2017 +0000
- Revision:
- 2:6ae05f48fe57
- Parent:
- 1:957e5e772f20
g
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matias123 | 1:957e5e772f20 | 1 | #include "DOGM_STREAM_SPI.h" |
Matias123 | 1:957e5e772f20 | 2 | |
Matias123 | 1:957e5e772f20 | 3 | DogM::DogM(PinName mosi, PinName miso, PinName sclk, PinName _rs_, PinName _csb_, PinName _res_) : |
Matias123 | 1:957e5e772f20 | 4 | dogm(mosi, miso, sclk), rs(_rs_), csb(_csb_), res(_res_) { |
Matias123 | 1:957e5e772f20 | 5 | |
Matias123 | 1:957e5e772f20 | 6 | // Setup the spi for 8 bit data, high steady state clock, |
Matias123 | 1:957e5e772f20 | 7 | // second edge capture, with a 1MHz clock rate |
Matias123 | 1:957e5e772f20 | 8 | dogm.format(8,0); |
Matias123 | 1:957e5e772f20 | 9 | dogm.frequency(100000); // Also working with 1MHz |
Matias123 | 1:957e5e772f20 | 10 | |
Matias123 | 1:957e5e772f20 | 11 | // RESETTING DOGM MODULE |
Matias123 | 1:957e5e772f20 | 12 | res = 0; |
Matias123 | 1:957e5e772f20 | 13 | wait_ms(10); |
Matias123 | 1:957e5e772f20 | 14 | res = 1; |
Matias123 | 1:957e5e772f20 | 15 | wait_ms(10); |
Matias123 | 1:957e5e772f20 | 16 | res = 0; |
Matias123 | 1:957e5e772f20 | 17 | wait_ms(40); |
Matias123 | 1:957e5e772f20 | 18 | res = 1; |
Matias123 | 1:957e5e772f20 | 19 | wait_ms(10); |
Matias123 | 1:957e5e772f20 | 20 | |
Matias123 | 1:957e5e772f20 | 21 | //command(0x39); // FUNCTION SET |
Matias123 | 1:957e5e772f20 | 22 | //wait_ms(40); |
Matias123 | 1:957e5e772f20 | 23 | |
Matias123 | 1:957e5e772f20 | 24 | // FROM DOGM DATABLAD - OPPSETT FOR 3 LINJER 3.3 V |
Matias123 | 1:957e5e772f20 | 25 | |
Matias123 | 1:957e5e772f20 | 26 | command(0x39); // FUNCTION SET |
Matias123 | 1:957e5e772f20 | 27 | wait_us(100); |
Matias123 | 1:957e5e772f20 | 28 | |
Matias123 | 1:957e5e772f20 | 29 | command(0x15); // BIAS SET |
Matias123 | 1:957e5e772f20 | 30 | wait_us(50); |
Matias123 | 1:957e5e772f20 | 31 | |
Matias123 | 1:957e5e772f20 | 32 | command(0x55); // POWER CONTROL |
Matias123 | 1:957e5e772f20 | 33 | wait_ms(200); |
Matias123 | 1:957e5e772f20 | 34 | |
Matias123 | 1:957e5e772f20 | 35 | command(0x6E); // FOLLOWER CONTROL |
Matias123 | 1:957e5e772f20 | 36 | wait_ms(200); |
Matias123 | 1:957e5e772f20 | 37 | |
Matias123 | 1:957e5e772f20 | 38 | command(0x72); // CONTRAST SET |
Matias123 | 1:957e5e772f20 | 39 | wait_ms(50); |
Matias123 | 1:957e5e772f20 | 40 | |
Matias123 | 1:957e5e772f20 | 41 | command(0x38); // FUNCTION SET |
Matias123 | 1:957e5e772f20 | 42 | wait_us(50); |
Matias123 | 1:957e5e772f20 | 43 | |
Matias123 | 1:957e5e772f20 | 44 | command(0x0F); // DISPLAY ON/OFF |
Matias123 | 1:957e5e772f20 | 45 | wait_us(50); |
Matias123 | 1:957e5e772f20 | 46 | |
Matias123 | 1:957e5e772f20 | 47 | command(0x01); // CLEAR DISPLAY |
Matias123 | 1:957e5e772f20 | 48 | wait_us(50); |
Matias123 | 1:957e5e772f20 | 49 | |
Matias123 | 1:957e5e772f20 | 50 | command(0x06); // ENTRY MODE SET |
Matias123 | 1:957e5e772f20 | 51 | wait_us(50); |
Matias123 | 1:957e5e772f20 | 52 | |
Matias123 | 1:957e5e772f20 | 53 | _rows = 3; |
Matias123 | 1:957e5e772f20 | 54 | _columns = 16; |
Matias123 | 1:957e5e772f20 | 55 | } |
Matias123 | 1:957e5e772f20 | 56 | |
Matias123 | 1:957e5e772f20 | 57 | |
Matias123 | 1:957e5e772f20 | 58 | void DogM::data(uint8_t c) { |
Matias123 | 1:957e5e772f20 | 59 | csb = 0; |
Matias123 | 1:957e5e772f20 | 60 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 61 | rs = 1; |
Matias123 | 1:957e5e772f20 | 62 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 63 | dogm.write(c); |
Matias123 | 1:957e5e772f20 | 64 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 65 | csb = 1; |
Matias123 | 1:957e5e772f20 | 66 | wait_us(40); // Default delay |
Matias123 | 1:957e5e772f20 | 67 | } |
Matias123 | 1:957e5e772f20 | 68 | |
Matias123 | 1:957e5e772f20 | 69 | void DogM::command(uint8_t c) { |
Matias123 | 1:957e5e772f20 | 70 | csb = 0; |
Matias123 | 1:957e5e772f20 | 71 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 72 | rs = 0; |
Matias123 | 1:957e5e772f20 | 73 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 74 | dogm.write(c); |
Matias123 | 1:957e5e772f20 | 75 | wait_us(1); |
Matias123 | 1:957e5e772f20 | 76 | csb = 1; |
Matias123 | 1:957e5e772f20 | 77 | wait_us(40); // Default delay |
Matias123 | 1:957e5e772f20 | 78 | } |
Matias123 | 1:957e5e772f20 | 79 | |
Matias123 | 1:957e5e772f20 | 80 | void DogM::blank() { |
Matias123 | 1:957e5e772f20 | 81 | command(0x01); |
Matias123 | 1:957e5e772f20 | 82 | wait_us(2000); |
Matias123 | 1:957e5e772f20 | 83 | } |
Matias123 | 1:957e5e772f20 | 84 | |
Matias123 | 1:957e5e772f20 | 85 | void DogM::home() { |
Matias123 | 1:957e5e772f20 | 86 | command (0x02); |
Matias123 | 1:957e5e772f20 | 87 | wait_us(2000); |
Matias123 | 1:957e5e772f20 | 88 | } |
Matias123 | 1:957e5e772f20 | 89 | |
Matias123 | 1:957e5e772f20 | 90 | void DogM::upper() { |
Matias123 | 1:957e5e772f20 | 91 | command (0x80); |
Matias123 | 1:957e5e772f20 | 92 | } |
Matias123 | 1:957e5e772f20 | 93 | |
Matias123 | 1:957e5e772f20 | 94 | void DogM::middle() { |
Matias123 | 1:957e5e772f20 | 95 | command (0x90); |
Matias123 | 1:957e5e772f20 | 96 | } |
Matias123 | 1:957e5e772f20 | 97 | |
Matias123 | 1:957e5e772f20 | 98 | void DogM::lower() { |
Matias123 | 1:957e5e772f20 | 99 | command (0xA0); |
Matias123 | 1:957e5e772f20 | 100 | } |
Matias123 | 1:957e5e772f20 | 101 | |
Matias123 | 1:957e5e772f20 | 102 | void DogM::chr(uint8_t c) { |
Matias123 | 1:957e5e772f20 | 103 | data(c); |
Matias123 | 1:957e5e772f20 | 104 | } |
Matias123 | 1:957e5e772f20 | 105 | |
Matias123 | 1:957e5e772f20 | 106 | void DogM::out(char *s) { |
Matias123 | 1:957e5e772f20 | 107 | while (*s) { |
Matias123 | 1:957e5e772f20 | 108 | data(*s++); |
Matias123 | 1:957e5e772f20 | 109 | } |
Matias123 | 1:957e5e772f20 | 110 | } |
Matias123 | 1:957e5e772f20 | 111 | |
Matias123 | 1:957e5e772f20 | 112 | void DogM::line(uint8_t column, uint8_t row, char *s) { |
Matias123 | 1:957e5e772f20 | 113 | command(address(column, row)); |
Matias123 | 1:957e5e772f20 | 114 | for (int i = column; i < _columns; i++) { |
Matias123 | 1:957e5e772f20 | 115 | if (*s != '\0') { |
Matias123 | 1:957e5e772f20 | 116 | data(*s); |
Matias123 | 1:957e5e772f20 | 117 | s++; |
Matias123 | 1:957e5e772f20 | 118 | } else { |
Matias123 | 1:957e5e772f20 | 119 | data(' '); |
Matias123 | 1:957e5e772f20 | 120 | } |
Matias123 | 1:957e5e772f20 | 121 | } |
Matias123 | 1:957e5e772f20 | 122 | } |
Matias123 | 1:957e5e772f20 | 123 | |
Matias123 | 1:957e5e772f20 | 124 | // Upper line = 0, middle line = 1, lower line = 2 |
Matias123 | 1:957e5e772f20 | 125 | // First position on line is 0 - last is 15 |
Matias123 | 1:957e5e772f20 | 126 | void DogM::pos(uint8_t column, uint8_t row) { |
Matias123 | 1:957e5e772f20 | 127 | uint8_t adress; |
Matias123 | 1:957e5e772f20 | 128 | switch (row) { |
Matias123 | 1:957e5e772f20 | 129 | case 1: |
Matias123 | 1:957e5e772f20 | 130 | adress = 0x10; |
Matias123 | 1:957e5e772f20 | 131 | break; |
Matias123 | 1:957e5e772f20 | 132 | case 2: |
Matias123 | 1:957e5e772f20 | 133 | adress = 0x20; |
Matias123 | 1:957e5e772f20 | 134 | break; |
Matias123 | 1:957e5e772f20 | 135 | default: |
Matias123 | 1:957e5e772f20 | 136 | adress = 0x00; |
Matias123 | 1:957e5e772f20 | 137 | break; |
Matias123 | 1:957e5e772f20 | 138 | } |
Matias123 | 1:957e5e772f20 | 139 | adress += (column + 0x80); |
Matias123 | 1:957e5e772f20 | 140 | _row = row; |
Matias123 | 1:957e5e772f20 | 141 | _column = column; |
Matias123 | 1:957e5e772f20 | 142 | command (adress); |
Matias123 | 1:957e5e772f20 | 143 | } |
Matias123 | 1:957e5e772f20 | 144 | |
Matias123 | 1:957e5e772f20 | 145 | void DogM::c_off() { |
Matias123 | 1:957e5e772f20 | 146 | command (0x0C); |
Matias123 | 1:957e5e772f20 | 147 | } |
Matias123 | 1:957e5e772f20 | 148 | void DogM::c_on () { |
Matias123 | 1:957e5e772f20 | 149 | command (0x0E); |
Matias123 | 1:957e5e772f20 | 150 | } |
Matias123 | 1:957e5e772f20 | 151 | |
Matias123 | 1:957e5e772f20 | 152 | void DogM::c_blink() { |
Matias123 | 1:957e5e772f20 | 153 | command (0x0F); |
Matias123 | 1:957e5e772f20 | 154 | } |
Matias123 | 1:957e5e772f20 | 155 | |
Matias123 | 1:957e5e772f20 | 156 | void DogM::c_left() { |
Matias123 | 1:957e5e772f20 | 157 | command (0x10); |
Matias123 | 1:957e5e772f20 | 158 | } |
Matias123 | 1:957e5e772f20 | 159 | |
Matias123 | 1:957e5e772f20 | 160 | void DogM::c_right() { |
Matias123 | 1:957e5e772f20 | 161 | command (0x14); |
Matias123 | 1:957e5e772f20 | 162 | } |
Matias123 | 1:957e5e772f20 | 163 | |
Matias123 | 1:957e5e772f20 | 164 | // COPIED FROM TxtLCD class |
Matias123 | 1:957e5e772f20 | 165 | |
Matias123 | 1:957e5e772f20 | 166 | void DogM::character(int column, int row, int c) { |
Matias123 | 1:957e5e772f20 | 167 | int a = address(column, row); |
Matias123 | 1:957e5e772f20 | 168 | command(a); |
Matias123 | 1:957e5e772f20 | 169 | data(c); |
Matias123 | 1:957e5e772f20 | 170 | } |
Matias123 | 1:957e5e772f20 | 171 | |
Matias123 | 1:957e5e772f20 | 172 | void DogM::cls() { |
Matias123 | 1:957e5e772f20 | 173 | command(0x01); // cls, and set cursor to 0 |
Matias123 | 1:957e5e772f20 | 174 | wait(0.00164f); // This command takes 1.64 ms |
Matias123 | 1:957e5e772f20 | 175 | locate(0, 0); |
Matias123 | 1:957e5e772f20 | 176 | } |
Matias123 | 1:957e5e772f20 | 177 | |
Matias123 | 1:957e5e772f20 | 178 | void DogM::locate(int column, int row) { |
Matias123 | 1:957e5e772f20 | 179 | _column = column; |
Matias123 | 1:957e5e772f20 | 180 | _row = row; |
Matias123 | 1:957e5e772f20 | 181 | } |
Matias123 | 1:957e5e772f20 | 182 | |
Matias123 | 1:957e5e772f20 | 183 | int DogM::_putc(int value) { |
Matias123 | 1:957e5e772f20 | 184 | if (value == '\n') { |
Matias123 | 1:957e5e772f20 | 185 | _column = 0; |
Matias123 | 1:957e5e772f20 | 186 | _row++; |
Matias123 | 1:957e5e772f20 | 187 | if (_row >= _rows) { |
Matias123 | 1:957e5e772f20 | 188 | _row = 0; |
Matias123 | 1:957e5e772f20 | 189 | } |
Matias123 | 1:957e5e772f20 | 190 | } else { |
Matias123 | 1:957e5e772f20 | 191 | character(_column, _row, value); |
Matias123 | 1:957e5e772f20 | 192 | _column++; |
Matias123 | 1:957e5e772f20 | 193 | if (_column >= _columns) { |
Matias123 | 1:957e5e772f20 | 194 | _column = 0; |
Matias123 | 1:957e5e772f20 | 195 | _row++; |
Matias123 | 1:957e5e772f20 | 196 | if (_row >= _rows) { |
Matias123 | 1:957e5e772f20 | 197 | _row = 0; |
Matias123 | 1:957e5e772f20 | 198 | } |
Matias123 | 1:957e5e772f20 | 199 | } |
Matias123 | 1:957e5e772f20 | 200 | } |
Matias123 | 1:957e5e772f20 | 201 | return value; |
Matias123 | 1:957e5e772f20 | 202 | } |
Matias123 | 1:957e5e772f20 | 203 | |
Matias123 | 1:957e5e772f20 | 204 | int DogM::_getc() { |
Matias123 | 1:957e5e772f20 | 205 | return -1; |
Matias123 | 1:957e5e772f20 | 206 | } |
Matias123 | 1:957e5e772f20 | 207 | |
Matias123 | 1:957e5e772f20 | 208 | int DogM::address(int column, int row) { |
Matias123 | 1:957e5e772f20 | 209 | return 0x80 + (row * 0x10) + column; |
Matias123 | 1:957e5e772f20 | 210 | } |
Matias123 | 1:957e5e772f20 | 211 |