UniGraphics Library Fork to support mbed os 6.3 Release for ILI9341
Dependents: TFT_ILI9341_UniGraphic TFT_ILI9341_os6
Protocols/I2C_bus.cpp@0:bb2bda4f5846, 2020-10-06 (annotated)
- Committer:
- amouroug
- Date:
- Tue Oct 06 05:07:55 2020 +0000
- Revision:
- 0:bb2bda4f5846
Unigraphics Library Fork to support mbed-os 6.3 for ILI9341;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amouroug | 0:bb2bda4f5846 | 1 | /* mbed UniGraphic library - I2C protocol class |
amouroug | 0:bb2bda4f5846 | 2 | * Copyright (c) 2017 Peter Drescher |
amouroug | 0:bb2bda4f5846 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
amouroug | 0:bb2bda4f5846 | 4 | * |
amouroug | 0:bb2bda4f5846 | 5 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
amouroug | 0:bb2bda4f5846 | 6 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
amouroug | 0:bb2bda4f5846 | 7 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
amouroug | 0:bb2bda4f5846 | 8 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
amouroug | 0:bb2bda4f5846 | 9 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
amouroug | 0:bb2bda4f5846 | 10 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
amouroug | 0:bb2bda4f5846 | 11 | * THE SOFTWARE. |
amouroug | 0:bb2bda4f5846 | 12 | */ |
amouroug | 0:bb2bda4f5846 | 13 | |
amouroug | 0:bb2bda4f5846 | 14 | #include "I2C_bus.h" |
amouroug | 0:bb2bda4f5846 | 15 | |
amouroug | 0:bb2bda4f5846 | 16 | I2C_bus::I2C_bus(int Hz, int address, PinName sda, PinName scl) |
amouroug | 0:bb2bda4f5846 | 17 | : _i2c(sda,scl) |
amouroug | 0:bb2bda4f5846 | 18 | { |
amouroug | 0:bb2bda4f5846 | 19 | _i2c.frequency(Hz); |
amouroug | 0:bb2bda4f5846 | 20 | _address = address; |
amouroug | 0:bb2bda4f5846 | 21 | //hw_reset(); |
amouroug | 0:bb2bda4f5846 | 22 | } |
amouroug | 0:bb2bda4f5846 | 23 | |
amouroug | 0:bb2bda4f5846 | 24 | void I2C_bus::wr_cmd8(unsigned char cmd) |
amouroug | 0:bb2bda4f5846 | 25 | { |
amouroug | 0:bb2bda4f5846 | 26 | char tmp[2]; |
amouroug | 0:bb2bda4f5846 | 27 | tmp[0] = 0x00; //command |
amouroug | 0:bb2bda4f5846 | 28 | tmp[1] = cmd; |
amouroug | 0:bb2bda4f5846 | 29 | _i2c.write(_address,tmp,2); |
amouroug | 0:bb2bda4f5846 | 30 | } |
amouroug | 0:bb2bda4f5846 | 31 | void I2C_bus::wr_data8(unsigned char data) |
amouroug | 0:bb2bda4f5846 | 32 | { |
amouroug | 0:bb2bda4f5846 | 33 | _i2c.write(data); // write 8bit |
amouroug | 0:bb2bda4f5846 | 34 | } |
amouroug | 0:bb2bda4f5846 | 35 | void I2C_bus::wr_cmd16(unsigned short cmd) |
amouroug | 0:bb2bda4f5846 | 36 | { |
amouroug | 0:bb2bda4f5846 | 37 | char tmp[3]; |
amouroug | 0:bb2bda4f5846 | 38 | tmp[0] = 00; //command |
amouroug | 0:bb2bda4f5846 | 39 | tmp[1] = cmd>>8; |
amouroug | 0:bb2bda4f5846 | 40 | tmp[2] = cmd&0xFF; |
amouroug | 0:bb2bda4f5846 | 41 | |
amouroug | 0:bb2bda4f5846 | 42 | _i2c.write(_address,tmp,3); |
amouroug | 0:bb2bda4f5846 | 43 | } |
amouroug | 0:bb2bda4f5846 | 44 | void I2C_bus::wr_data16(unsigned short data) |
amouroug | 0:bb2bda4f5846 | 45 | { |
amouroug | 0:bb2bda4f5846 | 46 | _i2c.write(data>>8); // write 8bit |
amouroug | 0:bb2bda4f5846 | 47 | _i2c.write(data&0xFF); // write 8bit |
amouroug | 0:bb2bda4f5846 | 48 | } |
amouroug | 0:bb2bda4f5846 | 49 | void I2C_bus::wr_gram(unsigned short data) |
amouroug | 0:bb2bda4f5846 | 50 | { |
amouroug | 0:bb2bda4f5846 | 51 | _i2c.write(data>>8); // write 8bit |
amouroug | 0:bb2bda4f5846 | 52 | _i2c.write(data&0xFF); // write 8bit |
amouroug | 0:bb2bda4f5846 | 53 | } |
amouroug | 0:bb2bda4f5846 | 54 | void I2C_bus::wr_gram(unsigned short data, unsigned int count) |
amouroug | 0:bb2bda4f5846 | 55 | { |
amouroug | 0:bb2bda4f5846 | 56 | _i2c.start(); |
amouroug | 0:bb2bda4f5846 | 57 | _i2c.write(_address); |
amouroug | 0:bb2bda4f5846 | 58 | _i2c.write(0x40); // data continue |
amouroug | 0:bb2bda4f5846 | 59 | if((data>>8)==(data&0xFF)) |
amouroug | 0:bb2bda4f5846 | 60 | { |
amouroug | 0:bb2bda4f5846 | 61 | count<<=1; |
amouroug | 0:bb2bda4f5846 | 62 | while(count) |
amouroug | 0:bb2bda4f5846 | 63 | { |
amouroug | 0:bb2bda4f5846 | 64 | _i2c.write(data); // write 8bit |
amouroug | 0:bb2bda4f5846 | 65 | count--; |
amouroug | 0:bb2bda4f5846 | 66 | } |
amouroug | 0:bb2bda4f5846 | 67 | } |
amouroug | 0:bb2bda4f5846 | 68 | else |
amouroug | 0:bb2bda4f5846 | 69 | { |
amouroug | 0:bb2bda4f5846 | 70 | while(count) |
amouroug | 0:bb2bda4f5846 | 71 | { |
amouroug | 0:bb2bda4f5846 | 72 | _i2c.write(data>>8); // write 8bit |
amouroug | 0:bb2bda4f5846 | 73 | _i2c.write(data&0xFF); // write 8bit |
amouroug | 0:bb2bda4f5846 | 74 | count--; |
amouroug | 0:bb2bda4f5846 | 75 | } |
amouroug | 0:bb2bda4f5846 | 76 | } |
amouroug | 0:bb2bda4f5846 | 77 | _i2c.stop(); |
amouroug | 0:bb2bda4f5846 | 78 | } |
amouroug | 0:bb2bda4f5846 | 79 | void I2C_bus::wr_grambuf(unsigned short* data, unsigned int lenght) |
amouroug | 0:bb2bda4f5846 | 80 | { |
amouroug | 0:bb2bda4f5846 | 81 | _i2c.start(); |
amouroug | 0:bb2bda4f5846 | 82 | _i2c.write(_address); |
amouroug | 0:bb2bda4f5846 | 83 | _i2c.write(0x40); // data continue |
amouroug | 0:bb2bda4f5846 | 84 | while(lenght) |
amouroug | 0:bb2bda4f5846 | 85 | { |
amouroug | 0:bb2bda4f5846 | 86 | _i2c.write((*data)>>8); // write 8bit |
amouroug | 0:bb2bda4f5846 | 87 | _i2c.write((*data)&0xFF); // write 8bit |
amouroug | 0:bb2bda4f5846 | 88 | data++; |
amouroug | 0:bb2bda4f5846 | 89 | lenght--; |
amouroug | 0:bb2bda4f5846 | 90 | } |
amouroug | 0:bb2bda4f5846 | 91 | _i2c.stop(); |
amouroug | 0:bb2bda4f5846 | 92 | } |
amouroug | 0:bb2bda4f5846 | 93 | |
amouroug | 0:bb2bda4f5846 | 94 | void I2C_bus::hw_reset() |
amouroug | 0:bb2bda4f5846 | 95 | { |
amouroug | 0:bb2bda4f5846 | 96 | |
amouroug | 0:bb2bda4f5846 | 97 | } |
amouroug | 0:bb2bda4f5846 | 98 | void I2C_bus::BusEnable(bool enable) |
amouroug | 0:bb2bda4f5846 | 99 | { |
amouroug | 0:bb2bda4f5846 | 100 | } |
amouroug | 0:bb2bda4f5846 | 101 | |
amouroug | 0:bb2bda4f5846 | 102 | void I2C_bus::reg_select(unsigned char reg, bool forread) |
amouroug | 0:bb2bda4f5846 | 103 | { |
amouroug | 0:bb2bda4f5846 | 104 | } |
amouroug | 0:bb2bda4f5846 | 105 | |
amouroug | 0:bb2bda4f5846 | 106 | unsigned int I2C_bus::rd_reg_data32(unsigned char reg) |
amouroug | 0:bb2bda4f5846 | 107 | { |
amouroug | 0:bb2bda4f5846 | 108 | return 0; |
amouroug | 0:bb2bda4f5846 | 109 | } |
amouroug | 0:bb2bda4f5846 | 110 | |
amouroug | 0:bb2bda4f5846 | 111 | unsigned int I2C_bus::rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) |
amouroug | 0:bb2bda4f5846 | 112 | { |
amouroug | 0:bb2bda4f5846 | 113 | return 0; |
amouroug | 0:bb2bda4f5846 | 114 | } |
amouroug | 0:bb2bda4f5846 | 115 | |
amouroug | 0:bb2bda4f5846 | 116 | void I2C_bus::dummyread() |
amouroug | 0:bb2bda4f5846 | 117 | { |
amouroug | 0:bb2bda4f5846 | 118 | } |
amouroug | 0:bb2bda4f5846 | 119 | |
amouroug | 0:bb2bda4f5846 | 120 | unsigned short I2C_bus::rd_gram(bool convert) |
amouroug | 0:bb2bda4f5846 | 121 | { |
amouroug | 0:bb2bda4f5846 | 122 | return (0); |
amouroug | 0:bb2bda4f5846 | 123 | } |
amouroug | 0:bb2bda4f5846 | 124 | |
amouroug | 0:bb2bda4f5846 | 125 | unsigned short I2C_bus::reg_read(unsigned char reg) |
amouroug | 0:bb2bda4f5846 | 126 | { |
amouroug | 0:bb2bda4f5846 | 127 | return (0); |
amouroug | 0:bb2bda4f5846 | 128 | } |
amouroug | 0:bb2bda4f5846 | 129 | |
amouroug | 0:bb2bda4f5846 | 130 | void I2C_bus::reg_write(unsigned char reg, unsigned short data) |
amouroug | 0:bb2bda4f5846 | 131 | { |
amouroug | 0:bb2bda4f5846 | 132 | } |