Nikita Ivanykov
/
LAB_DISPLAY
7
main.cpp@2:82f5f57eac91, 2017-11-05 (annotated)
- Committer:
- codebreaker7
- Date:
- Sun Nov 05 14:51:21 2017 +0000
- Revision:
- 2:82f5f57eac91
- Parent:
- 1:cdeae0693b01
- Child:
- 3:9909607749dd
Updated to work with display correctly
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
codebreaker7 | 0:02841331478b | 1 | #include "mbed.h" |
codebreaker7 | 0:02841331478b | 2 | #include "ILI9341_Defines.h" |
codebreaker7 | 0:02841331478b | 3 | |
codebreaker7 | 0:02841331478b | 4 | SPI spi_dev(PB_15, PB_14, PB_13); |
codebreaker7 | 0:02841331478b | 5 | DigitalOut cs(PC_4); |
codebreaker7 | 0:02841331478b | 6 | DigitalOut ao(PB_3); |
codebreaker7 | 2:82f5f57eac91 | 7 | uint8_t tarr[1024]; |
codebreaker7 | 2:82f5f57eac91 | 8 | uint8_t rarr[1024]; |
codebreaker7 | 0:02841331478b | 9 | |
codebreaker7 | 0:02841331478b | 10 | void writecommand(uint8_t command) { |
codebreaker7 | 0:02841331478b | 11 | cs = 0; |
codebreaker7 | 0:02841331478b | 12 | ao = 0; |
codebreaker7 | 0:02841331478b | 13 | spi_dev.write(command); |
codebreaker7 | 0:02841331478b | 14 | cs = 1; |
codebreaker7 | 0:02841331478b | 15 | } |
codebreaker7 | 0:02841331478b | 16 | |
codebreaker7 | 0:02841331478b | 17 | void writedata(uint8_t data) { |
codebreaker7 | 0:02841331478b | 18 | cs = 0; |
codebreaker7 | 0:02841331478b | 19 | ao = 1; |
codebreaker7 | 0:02841331478b | 20 | spi_dev.write(data); |
codebreaker7 | 0:02841331478b | 21 | cs = 1; |
codebreaker7 | 0:02841331478b | 22 | } |
codebreaker7 | 0:02841331478b | 23 | |
codebreaker7 | 2:82f5f57eac91 | 24 | void setAddress(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { |
codebreaker7 | 2:82f5f57eac91 | 25 | writecommand(0x2a); |
codebreaker7 | 2:82f5f57eac91 | 26 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 27 | writedata(x1); |
codebreaker7 | 2:82f5f57eac91 | 28 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 29 | writedata(x2); |
codebreaker7 | 2:82f5f57eac91 | 30 | writecommand(0x2b); |
codebreaker7 | 2:82f5f57eac91 | 31 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 32 | writedata(y1); |
codebreaker7 | 2:82f5f57eac91 | 33 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 34 | writedata(y2); |
codebreaker7 | 2:82f5f57eac91 | 35 | writecommand(0x2c); |
codebreaker7 | 2:82f5f57eac91 | 36 | } |
codebreaker7 | 2:82f5f57eac91 | 37 | |
codebreaker7 | 2:82f5f57eac91 | 38 | void writeColorData(uint8_t * arr, int length) { |
codebreaker7 | 2:82f5f57eac91 | 39 | cs = 0; |
codebreaker7 | 2:82f5f57eac91 | 40 | ao = 1; |
codebreaker7 | 2:82f5f57eac91 | 41 | spi_dev.write((char*)arr, length, NULL, length); |
codebreaker7 | 2:82f5f57eac91 | 42 | cs = 1; |
codebreaker7 | 2:82f5f57eac91 | 43 | } |
codebreaker7 | 2:82f5f57eac91 | 44 | |
codebreaker7 | 0:02841331478b | 45 | int main() { |
codebreaker7 | 1:cdeae0693b01 | 46 | HAL_Init(); |
codebreaker7 | 0:02841331478b | 47 | #include "ILI9341_Init.h" |
codebreaker7 | 2:82f5f57eac91 | 48 | setAddress(0, 0, 127, 127); |
codebreaker7 | 2:82f5f57eac91 | 49 | for (int i = 0; i < 1024; i++) { |
codebreaker7 | 2:82f5f57eac91 | 50 | tarr[i] = 0; |
codebreaker7 | 2:82f5f57eac91 | 51 | } |
codebreaker7 | 2:82f5f57eac91 | 52 | for (int i = 0; i < 32; i++) { |
codebreaker7 | 2:82f5f57eac91 | 53 | writeColorData(tarr, 1024); |
codebreaker7 | 2:82f5f57eac91 | 54 | } |
codebreaker7 | 0:02841331478b | 55 | while(1) { |
codebreaker7 | 0:02841331478b | 56 | } |
codebreaker7 | 0:02841331478b | 57 | } |