Interface for Sharp LS012B7DD01 TFT-LCD
Dependents: MAX32630FTHR_iButton_uSD_Logger
Sharp_LS012B7DD01.cpp@2:ccef06c5becf, 2016-11-22 (annotated)
- Committer:
- j3
- Date:
- Tue Nov 22 20:49:39 2016 +0000
- Revision:
- 2:ccef06c5becf
- Parent:
- 1:ea88fe2c73ed
removed extern ref to Serial term
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 |
0:a857326491e8 | 1 | /******************************************************************************* |
j3 |
0:a857326491e8 | 2 | * The MIT License (MIT) |
j3 |
0:a857326491e8 | 3 | * |
j3 |
0:a857326491e8 | 4 | * Copyright (c) 2016 j3 |
j3 |
0:a857326491e8 | 5 | * |
j3 |
0:a857326491e8 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
j3 |
0:a857326491e8 | 7 | * of this software and associated documentation files (the "Software"), to deal |
j3 |
0:a857326491e8 | 8 | * in the Software without restriction, including without limitation the rights |
j3 |
0:a857326491e8 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
j3 |
0:a857326491e8 | 10 | * copies of the Software, and to permit persons to whom the Software is |
j3 |
0:a857326491e8 | 11 | * furnished to do so, subject to the following conditions: |
j3 |
0:a857326491e8 | 12 | * |
j3 |
0:a857326491e8 | 13 | * The above copyright notice and this permission notice shall be included in |
j3 |
0:a857326491e8 | 14 | * all copies or substantial portions of the Software. |
j3 |
0:a857326491e8 | 15 | * |
j3 |
0:a857326491e8 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
j3 |
0:a857326491e8 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
j3 |
0:a857326491e8 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
j3 |
0:a857326491e8 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
j3 |
0:a857326491e8 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
j3 |
0:a857326491e8 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
j3 |
0:a857326491e8 | 22 | * SOFTWARE. |
j3 |
0:a857326491e8 | 23 | ******************************************************************************/ |
j3 |
0:a857326491e8 | 24 | |
j3 |
0:a857326491e8 | 25 | |
j3 |
0:a857326491e8 | 26 | #include "Sharp_LS012B7DD01.h" |
j3 |
0:a857326491e8 | 27 | |
j3 |
0:a857326491e8 | 28 | //5x7 character bit map |
j3 |
0:a857326491e8 | 29 | static const uint8_t font_5x7[95][6] = { |
j3 |
0:a857326491e8 | 30 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //SPACE |
j3 |
0:a857326491e8 | 31 | {0x00, 0x00, 0x00, 0xf2, 0x00, 0x00}, //! |
j3 |
0:a857326491e8 | 32 | {0x00, 0x00, 0xe0, 0x00, 0xe0, 0x00}, //" |
j3 |
0:a857326491e8 | 33 | {0x00, 0x28, 0xfe, 0x28, 0xfe, 0x28}, //# |
j3 |
0:a857326491e8 | 34 | {0x00, 0x24, 0x54, 0xfe, 0x54, 0x48}, //$ |
j3 |
0:a857326491e8 | 35 | {0x00, 0xc4, 0xc8, 0x10, 0x26, 0x46}, //% |
j3 |
0:a857326491e8 | 36 | {0x00, 0x6c, 0x92, 0xaa, 0x44, 0x0a}, //& |
j3 |
0:a857326491e8 | 37 | {0x00, 0x00, 0xa0, 0xc0, 0x00, 0x00}, //' |
j3 |
0:a857326491e8 | 38 | {0x00, 0x00, 0x38, 0x44, 0x82, 0x00}, //( |
j3 |
0:a857326491e8 | 39 | {0x00, 0x00, 0x82, 0x44, 0x38, 0x00}, //) |
j3 |
0:a857326491e8 | 40 | {0x00, 0x28, 0x10, 0x7c, 0x10, 0x28}, //* |
j3 |
0:a857326491e8 | 41 | {0x00, 0x10, 0x10, 0x7c, 0x10, 0x10}, //+ |
j3 |
0:a857326491e8 | 42 | {0x00, 0x00, 0x0a, 0x0c, 0x00, 0x00}, //, |
j3 |
0:a857326491e8 | 43 | {0x00, 0x10, 0x10, 0x10, 0x10, 0x10}, //- |
j3 |
0:a857326491e8 | 44 | {0x00, 0x00, 0x06, 0x06, 0x00, 0x00}, //. |
j3 |
0:a857326491e8 | 45 | {0x00, 0x04, 0x08, 0x10, 0x20, 0x40}, /// |
j3 |
0:a857326491e8 | 46 | {0x00, 0x7c, 0x8a, 0x92, 0xa2, 0x7c}, //0 |
j3 |
0:a857326491e8 | 47 | {0x00, 0x00, 0x42, 0xfe, 0x02, 0x00}, //1 |
j3 |
0:a857326491e8 | 48 | {0x00, 0x42, 0x86, 0x8a, 0x92, 0x62}, //2 |
j3 |
0:a857326491e8 | 49 | {0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c}, //3 |
j3 |
0:a857326491e8 | 50 | {0x00, 0x18, 0x28, 0x48, 0xfe, 0x08}, //4 |
j3 |
0:a857326491e8 | 51 | {0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c}, //5 |
j3 |
0:a857326491e8 | 52 | {0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c}, //6 |
j3 |
0:a857326491e8 | 53 | {0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0}, //7 |
j3 |
0:a857326491e8 | 54 | {0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c}, //8 |
j3 |
0:a857326491e8 | 55 | {0x00, 0x60, 0x92, 0x92, 0x94, 0x78}, //9 |
j3 |
0:a857326491e8 | 56 | {0x00, 0x6c, 0x6c, 0x00, 0x00, 0x00}, //: |
j3 |
0:a857326491e8 | 57 | {0x00, 0x6a, 0x6c, 0x00, 0x00, 0x00}, //; |
j3 |
0:a857326491e8 | 58 | {0x00, 0x10, 0x28, 0x44, 0x82, 0x00}, //< |
j3 |
0:a857326491e8 | 59 | {0x00, 0x28, 0x28, 0x28, 0x28, 0x28}, //= |
j3 |
0:a857326491e8 | 60 | {0x00, 0x00, 0x82, 0x44, 0x28, 0x10}, //> |
j3 |
0:a857326491e8 | 61 | {0x00, 0x40, 0x80, 0x8a, 0x90, 0x60}, //? |
j3 |
0:a857326491e8 | 62 | {0x00, 0x0c, 0x92, 0x9e, 0x82, 0x7c}, //@ |
j3 |
0:a857326491e8 | 63 | {0x00, 0x7e, 0x88, 0x88, 0x88, 0x7e}, //A |
j3 |
0:a857326491e8 | 64 | {0x00, 0xfe, 0x92, 0x92, 0x92, 0x6c}, //B |
j3 |
0:a857326491e8 | 65 | {0x00, 0x7c, 0x82, 0x82, 0x82, 0x44}, //C |
j3 |
0:a857326491e8 | 66 | {0x00, 0xfe, 0x82, 0x82, 0x44, 0x38}, //D |
j3 |
0:a857326491e8 | 67 | {0x00, 0xfe, 0x92, 0x92, 0x92, 0x82}, //E |
j3 |
0:a857326491e8 | 68 | {0x00, 0xfe, 0x90, 0x90, 0x90, 0x80}, //F |
j3 |
0:a857326491e8 | 69 | {0x00, 0x7c, 0x82, 0x92, 0x92, 0x5e}, //G |
j3 |
0:a857326491e8 | 70 | {0x00, 0xfe, 0x10, 0x10, 0x10, 0xfe}, //H |
j3 |
0:a857326491e8 | 71 | {0x00, 0x00, 0x82, 0xfe, 0x82, 0x00}, //I |
j3 |
0:a857326491e8 | 72 | {0x00, 0x04, 0x02, 0x82, 0xfc, 0x80}, //J |
j3 |
0:a857326491e8 | 73 | {0x00, 0xfe, 0x10, 0x28, 0x44, 0x82}, //K |
j3 |
0:a857326491e8 | 74 | {0x00, 0xfe, 0x02, 0x02, 0x02, 0x02}, //L |
j3 |
0:a857326491e8 | 75 | {0x00, 0xfe, 0x40, 0x30, 0x40, 0xfe}, //M |
j3 |
0:a857326491e8 | 76 | {0x00, 0xfe, 0x20, 0x10, 0x08, 0xfe}, //N |
j3 |
0:a857326491e8 | 77 | {0x00, 0x7c, 0x82, 0x82, 0x82, 0x7c}, //O |
j3 |
0:a857326491e8 | 78 | {0x00, 0xfe, 0x90, 0x90, 0x90, 0x60}, //P |
j3 |
0:a857326491e8 | 79 | {0x00, 0x7c, 0x82, 0x8a, 0x84, 0x7a}, //Q |
j3 |
0:a857326491e8 | 80 | {0x00, 0xfe, 0x90, 0x98, 0x94, 0x62}, //R |
j3 |
0:a857326491e8 | 81 | {0x00, 0x62, 0x92, 0x92, 0x92, 0x8c}, //S |
j3 |
0:a857326491e8 | 82 | {0x00, 0x80, 0x80, 0xfe, 0x80, 0x80}, //T |
j3 |
0:a857326491e8 | 83 | {0x00, 0xfc, 0x02, 0x02, 0x02, 0xfc}, //U |
j3 |
0:a857326491e8 | 84 | {0x00, 0xf8, 0x04, 0x02, 0x04, 0xf8}, //V |
j3 |
0:a857326491e8 | 85 | {0x00, 0xfc, 0x02, 0x0c, 0x02, 0xfc}, //W |
j3 |
0:a857326491e8 | 86 | {0x00, 0xc6, 0x28, 0x10, 0x28, 0xc6}, //X |
j3 |
0:a857326491e8 | 87 | {0x00, 0xe0, 0x10, 0x0e, 0x10, 0xe0}, //Y |
j3 |
0:a857326491e8 | 88 | {0x00, 0x86, 0x8a, 0x92, 0xa2, 0xc2}, //Z |
j3 |
0:a857326491e8 | 89 | {0x00, 0x00, 0xfe, 0x82, 0x82, 0x00}, //[ |
j3 |
0:a857326491e8 | 90 | {0x00, 0x40, 0x20, 0x10, 0x08, 0x04}, //backslash |
j3 |
0:a857326491e8 | 91 | {0x00, 0x00, 0x82, 0x82, 0xfe, 0x00}, //] |
j3 |
0:a857326491e8 | 92 | {0x00, 0x20, 0x40, 0x80, 0x40, 0x20}, //^ |
j3 |
0:a857326491e8 | 93 | {0x00, 0x02, 0x02, 0x02, 0x02, 0x02}, //_ |
j3 |
0:a857326491e8 | 94 | {0x00, 0x00, 0x80, 0x40, 0x20, 0x00}, //` |
j3 |
0:a857326491e8 | 95 | {0x00, 0x04, 0x2a, 0x2a, 0x2a, 0x1e}, //a |
j3 |
0:a857326491e8 | 96 | {0x00, 0xfe, 0x0a, 0x12, 0x12, 0x0c}, //b |
j3 |
0:a857326491e8 | 97 | {0x00, 0x1c, 0x22, 0x22, 0x22, 0x04}, //c |
j3 |
0:a857326491e8 | 98 | {0x00, 0x1c, 0x22, 0x22, 0x12, 0xfe}, //d |
j3 |
0:a857326491e8 | 99 | {0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x18}, //e |
j3 |
0:a857326491e8 | 100 | {0x00, 0x10, 0x7e, 0x90, 0x80, 0x40}, //f |
j3 |
0:a857326491e8 | 101 | {0x00, 0x30, 0x4a, 0x4a, 0x4a, 0x7c}, //g |
j3 |
0:a857326491e8 | 102 | {0x00, 0xfe, 0x10, 0x20, 0x20, 0x1e}, //h |
j3 |
0:a857326491e8 | 103 | {0x00, 0x00, 0x22, 0xbe, 0x02, 0x00}, //i |
j3 |
0:a857326491e8 | 104 | {0x00, 0x04, 0x02, 0x22, 0xbc, 0x00}, //j |
j3 |
0:a857326491e8 | 105 | {0x00, 0xfe, 0x08, 0x14, 0x22, 0x00}, //k |
j3 |
0:a857326491e8 | 106 | {0x00, 0x00, 0x82, 0xfe, 0x02, 0x00}, //l |
j3 |
0:a857326491e8 | 107 | {0x00, 0x1e, 0x20, 0x1a, 0x22, 0x1e}, //m |
j3 |
0:a857326491e8 | 108 | {0x00, 0x3e, 0x10, 0x20, 0x20, 0x1e}, //n |
j3 |
0:a857326491e8 | 109 | {0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c}, //o |
j3 |
0:a857326491e8 | 110 | {0x00, 0x3e, 0x28, 0x28, 0x28, 0x10}, //p |
j3 |
0:a857326491e8 | 111 | {0x00, 0x10, 0x28, 0x28, 0x18, 0x3e}, //q |
j3 |
0:a857326491e8 | 112 | {0x00, 0x3e, 0x10, 0x20, 0x20, 0x10}, //r |
j3 |
0:a857326491e8 | 113 | {0x00, 0x12, 0x2a, 0x2a, 0x2a, 0x04}, //s |
j3 |
0:a857326491e8 | 114 | {0x00, 0x20, 0xfc, 0x22, 0x02, 0x04}, //t |
j3 |
0:a857326491e8 | 115 | {0x00, 0x3c, 0x02, 0x02, 0x04, 0x3e}, //u |
j3 |
0:a857326491e8 | 116 | {0x00, 0x38, 0x04, 0x02, 0x04, 0x38}, //v |
j3 |
0:a857326491e8 | 117 | {0x00, 0x3c, 0x02, 0x0c, 0x02, 0x3c}, //w |
j3 |
0:a857326491e8 | 118 | {0x00, 0x22, 0x14, 0x08, 0x14, 0x22}, //x |
j3 |
0:a857326491e8 | 119 | {0x00, 0x30, 0x0a, 0x0a, 0x0a, 0x3c}, //y |
j3 |
0:a857326491e8 | 120 | {0x00, 0x22, 0x26, 0x2a, 0x32, 0x22}, //z |
j3 |
0:a857326491e8 | 121 | {0x00, 0x00, 0x10, 0x6c, 0x82, 0x00}, //{ |
j3 |
0:a857326491e8 | 122 | {0x00, 0x00, 0x00, 0xfe, 0x00, 0x00}, //| |
j3 |
0:a857326491e8 | 123 | {0x00, 0x00, 0x82, 0x6c, 0x10, 0x00}, //} |
j3 |
0:a857326491e8 | 124 | {0x00, 0x30, 0x40, 0x30, 0x08, 0x30} //~ |
j3 |
0:a857326491e8 | 125 | }; |
j3 |
0:a857326491e8 | 126 | |
j3 |
0:a857326491e8 | 127 | /*****************************************************************************/ |
j3 | 1:ea88fe2c73ed | 128 | SharpLS012B7DD01::SharpLS012B7DD01(PinName disp, PinName extcomin, PinName cs, SPI &spiBus) |
j3 | 1:ea88fe2c73ed | 129 | :m_disp(disp, 0), m_extcomin(extcomin, 0), m_cs(cs, 0), m_spi(spiBus) |
j3 |
0:a857326491e8 | 130 | { |
j3 |
0:a857326491e8 | 131 | update(SharpLS012B7DD01::ALL_CLEAR_MODE); |
j3 |
0:a857326491e8 | 132 | m_disp = !m_disp; |
j3 |
0:a857326491e8 | 133 | wait_us(30); |
j3 |
0:a857326491e8 | 134 | m_extcominTicker.attach(callback(this, &SharpLS012B7DD01::toggle_extcomin), 0.016); |
j3 |
0:a857326491e8 | 135 | } |
j3 |
0:a857326491e8 | 136 | |
j3 |
0:a857326491e8 | 137 | |
j3 |
0:a857326491e8 | 138 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 139 | SharpLS012B7DD01::~SharpLS012B7DD01() |
j3 |
0:a857326491e8 | 140 | { |
j3 |
0:a857326491e8 | 141 | } |
j3 |
0:a857326491e8 | 142 | |
j3 |
0:a857326491e8 | 143 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 144 | SharpLS012B7DD01::SharpCmdResult SharpLS012B7DD01::print_char(uint8_t ln, uint8_t pos, char c) |
j3 |
0:a857326491e8 | 145 | { |
j3 |
0:a857326491e8 | 146 | SharpLS012B7DD01::SharpCmdResult rtnVal = SharpLS012B7DD01::Failure; |
j3 |
0:a857326491e8 | 147 | |
j3 |
0:a857326491e8 | 148 | uint8_t char_buff[6]; |
j3 |
0:a857326491e8 | 149 | memcpy(char_buff, &(font_5x7[c - 0x20][0]), 6); |
j3 |
0:a857326491e8 | 150 | |
j3 |
0:a857326491e8 | 151 | if((ln < 4) && (pos < 30)) |
j3 |
0:a857326491e8 | 152 | { |
j3 |
0:a857326491e8 | 153 | ln = ((ln * 8) + 4); |
j3 |
0:a857326491e8 | 154 | pos = ((pos * 6) + 2); |
j3 |
0:a857326491e8 | 155 | |
j3 |
0:a857326491e8 | 156 | uint8_t temp; |
j3 |
0:a857326491e8 | 157 | for(uint8_t c_bit = 0; c_bit < 8; c_bit++) |
j3 |
0:a857326491e8 | 158 | { |
j3 |
0:a857326491e8 | 159 | temp = 0; |
j3 |
0:a857326491e8 | 160 | for(uint8_t c_byte = 0; c_byte < 6; c_byte++) |
j3 |
0:a857326491e8 | 161 | { |
j3 |
0:a857326491e8 | 162 | if(((1 << (7 - c_bit)) & char_buff[c_byte])) |
j3 |
0:a857326491e8 | 163 | { |
j3 |
0:a857326491e8 | 164 | temp |= (1 << c_byte); |
j3 |
0:a857326491e8 | 165 | } |
j3 |
0:a857326491e8 | 166 | } |
j3 |
0:a857326491e8 | 167 | |
j3 |
0:a857326491e8 | 168 | //display is active low |
j3 |
0:a857326491e8 | 169 | temp = ~temp; |
j3 |
0:a857326491e8 | 170 | |
j3 |
0:a857326491e8 | 171 | if((pos % 8) == 0) |
j3 |
0:a857326491e8 | 172 | { |
j3 |
0:a857326491e8 | 173 | if(pos) |
j3 |
0:a857326491e8 | 174 | { |
j3 |
0:a857326491e8 | 175 | m_data[ln + c_bit][pos/8] &= ~(0x3F); |
j3 |
0:a857326491e8 | 176 | m_data[ln + c_bit][pos/8] |= temp; |
j3 |
0:a857326491e8 | 177 | } |
j3 |
0:a857326491e8 | 178 | else |
j3 |
0:a857326491e8 | 179 | { |
j3 |
0:a857326491e8 | 180 | m_data[ln + c_bit][0] &= ~(0x3F); |
j3 |
0:a857326491e8 | 181 | m_data[ln + c_bit][0] |= temp; |
j3 |
0:a857326491e8 | 182 | } |
j3 |
0:a857326491e8 | 183 | } |
j3 |
0:a857326491e8 | 184 | else |
j3 |
0:a857326491e8 | 185 | { |
j3 |
0:a857326491e8 | 186 | m_data[ln + c_bit][pos/8] &= ~(0x3F << (pos%8)); |
j3 |
0:a857326491e8 | 187 | m_data[ln + c_bit][pos/8] |= (temp << (pos%8)); |
j3 |
0:a857326491e8 | 188 | if((pos % 8) > 2) |
j3 |
0:a857326491e8 | 189 | { |
j3 |
0:a857326491e8 | 190 | uint8_t temp2 = 0; |
j3 |
0:a857326491e8 | 191 | for(uint8_t idx = 0; idx < ((pos%8) -2); idx++) |
j3 |
0:a857326491e8 | 192 | { |
j3 |
0:a857326491e8 | 193 | temp2 |= (1 << idx); |
j3 |
0:a857326491e8 | 194 | } |
j3 |
0:a857326491e8 | 195 | m_data[ln + c_bit][(pos/8) + 1] &= ~temp2; |
j3 |
0:a857326491e8 | 196 | m_data[ln + c_bit][(pos/8) + 1] |= (temp >> (8 - (pos%8))); |
j3 |
0:a857326491e8 | 197 | } |
j3 |
0:a857326491e8 | 198 | } |
j3 |
0:a857326491e8 | 199 | } |
j3 |
0:a857326491e8 | 200 | |
j3 |
0:a857326491e8 | 201 | rtnVal = write_memory(m_data, 8, ln); |
j3 |
0:a857326491e8 | 202 | } |
j3 |
0:a857326491e8 | 203 | |
j3 |
0:a857326491e8 | 204 | return rtnVal; |
j3 |
0:a857326491e8 | 205 | } |
j3 |
0:a857326491e8 | 206 | |
j3 |
0:a857326491e8 | 207 | |
j3 |
0:a857326491e8 | 208 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 209 | SharpLS012B7DD01::SharpCmdResult SharpLS012B7DD01::print_str(uint8_t ln, uint8_t pos, const char *s) |
j3 |
0:a857326491e8 | 210 | { |
j3 |
0:a857326491e8 | 211 | SharpLS012B7DD01::SharpCmdResult rtnVal = SharpLS012B7DD01::Failure; |
j3 |
0:a857326491e8 | 212 | |
j3 |
0:a857326491e8 | 213 | size_t len = strlen(s); |
j3 |
0:a857326491e8 | 214 | |
j3 | 2:ccef06c5becf | 215 | if((ln < 4) && ((pos + (len - 1)) < 30)) |
j3 |
0:a857326491e8 | 216 | { |
j3 |
0:a857326491e8 | 217 | for(size_t idx = 0; idx < len; idx++) |
j3 |
0:a857326491e8 | 218 | { |
j3 |
0:a857326491e8 | 219 | rtnVal = print_char(ln, (pos + idx), s[idx]); |
j3 |
0:a857326491e8 | 220 | } |
j3 |
0:a857326491e8 | 221 | } |
j3 |
0:a857326491e8 | 222 | |
j3 |
0:a857326491e8 | 223 | return rtnVal; |
j3 |
0:a857326491e8 | 224 | } |
j3 |
0:a857326491e8 | 225 | |
j3 |
0:a857326491e8 | 226 | |
j3 |
0:a857326491e8 | 227 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 228 | void SharpLS012B7DD01::clear_display() |
j3 |
0:a857326491e8 | 229 | { |
j3 |
0:a857326491e8 | 230 | update(SharpLS012B7DD01::ALL_CLEAR_MODE); |
j3 |
0:a857326491e8 | 231 | } |
j3 |
0:a857326491e8 | 232 | |
j3 |
0:a857326491e8 | 233 | |
j3 |
0:a857326491e8 | 234 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 235 | SharpLS012B7DD01::SharpCmdResult SharpLS012B7DD01::write_memory(uint8_t data[][23], uint8_t lines, uint8_t offset) |
j3 |
0:a857326491e8 | 236 | { |
j3 |
0:a857326491e8 | 237 | SharpLS012B7DD01::SharpCmdResult rtnVal = Failure; |
j3 |
0:a857326491e8 | 238 | |
j3 |
0:a857326491e8 | 239 | if((lines + offset) <= 38) |
j3 |
0:a857326491e8 | 240 | { |
j3 |
0:a857326491e8 | 241 | m_cs = !m_cs; |
j3 |
0:a857326491e8 | 242 | //send mode |
j3 |
0:a857326491e8 | 243 | m_spi.write(SharpLS012B7DD01::DATA_UPDATE_MODE); |
j3 |
0:a857326491e8 | 244 | for(uint8_t idy = offset; idy < (lines + offset); idy++) |
j3 |
0:a857326491e8 | 245 | { |
j3 |
0:a857326491e8 | 246 | //send line adrs |
j3 |
0:a857326491e8 | 247 | m_spi.write(rev_bit(idy + 1)); |
j3 |
0:a857326491e8 | 248 | for(uint8_t idx = 0; idx < 23; idx++) |
j3 |
0:a857326491e8 | 249 | { |
j3 |
0:a857326491e8 | 250 | m_spi.write(rev_bit(data[idy][idx])); |
j3 |
0:a857326491e8 | 251 | } |
j3 |
0:a857326491e8 | 252 | //dummy data required by datasheet |
j3 |
0:a857326491e8 | 253 | m_spi.write(0); |
j3 |
0:a857326491e8 | 254 | m_spi.write(0); |
j3 |
0:a857326491e8 | 255 | } |
j3 |
0:a857326491e8 | 256 | //last line requires 16 xfr clocks too |
j3 |
0:a857326491e8 | 257 | m_spi.write(0); |
j3 |
0:a857326491e8 | 258 | m_cs = !m_cs; |
j3 |
0:a857326491e8 | 259 | |
j3 |
0:a857326491e8 | 260 | rtnVal = Success; |
j3 |
0:a857326491e8 | 261 | } |
j3 |
0:a857326491e8 | 262 | |
j3 |
0:a857326491e8 | 263 | return rtnVal; |
j3 |
0:a857326491e8 | 264 | } |
j3 |
0:a857326491e8 | 265 | |
j3 |
0:a857326491e8 | 266 | |
j3 |
0:a857326491e8 | 267 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 268 | void SharpLS012B7DD01::update(const uint8_t mode) |
j3 |
0:a857326491e8 | 269 | { |
j3 |
0:a857326491e8 | 270 | m_cs = !m_cs; |
j3 |
0:a857326491e8 | 271 | //send mode |
j3 |
0:a857326491e8 | 272 | m_spi.write(mode); |
j3 |
0:a857326491e8 | 273 | m_spi.write(0); |
j3 |
0:a857326491e8 | 274 | m_spi.write(0); |
j3 |
0:a857326491e8 | 275 | m_cs = !m_cs; |
j3 |
0:a857326491e8 | 276 | |
j3 |
0:a857326491e8 | 277 | if(mode == SharpLS012B7DD01::ALL_CLEAR_MODE) |
j3 |
0:a857326491e8 | 278 | { |
j3 |
0:a857326491e8 | 279 | for(uint8_t idy = 0; idy < 38; idy++) |
j3 |
0:a857326491e8 | 280 | { |
j3 |
0:a857326491e8 | 281 | for(uint8_t idx = 0; idx < 23; idx ++) |
j3 |
0:a857326491e8 | 282 | { |
j3 |
0:a857326491e8 | 283 | m_data[idy][idx] = 0xFF; |
j3 |
0:a857326491e8 | 284 | } |
j3 |
0:a857326491e8 | 285 | } |
j3 |
0:a857326491e8 | 286 | } |
j3 |
0:a857326491e8 | 287 | } |
j3 |
0:a857326491e8 | 288 | |
j3 |
0:a857326491e8 | 289 | |
j3 |
0:a857326491e8 | 290 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 291 | uint8_t SharpLS012B7DD01::rev_bit(uint8_t data) |
j3 |
0:a857326491e8 | 292 | { |
j3 |
0:a857326491e8 | 293 | uint8_t temp = 0; |
j3 |
0:a857326491e8 | 294 | for(uint8_t idx = 0; idx < 8; idx++) |
j3 |
0:a857326491e8 | 295 | { |
j3 |
0:a857326491e8 | 296 | if((1 << idx) & data) |
j3 |
0:a857326491e8 | 297 | { |
j3 |
0:a857326491e8 | 298 | temp |= (0x80 >> idx); |
j3 |
0:a857326491e8 | 299 | } |
j3 |
0:a857326491e8 | 300 | } |
j3 |
0:a857326491e8 | 301 | |
j3 |
0:a857326491e8 | 302 | return temp; |
j3 |
0:a857326491e8 | 303 | } |
j3 |
0:a857326491e8 | 304 | |
j3 |
0:a857326491e8 | 305 | |
j3 |
0:a857326491e8 | 306 | /*****************************************************************************/ |
j3 |
0:a857326491e8 | 307 | void SharpLS012B7DD01::toggle_extcomin() |
j3 |
0:a857326491e8 | 308 | { |
j3 |
0:a857326491e8 | 309 | m_extcomin = !m_extcomin; |
j3 |
0:a857326491e8 | 310 | } |