Rev 1200 | Rev 1789 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1200 | Rev 1409 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | static unsigned char Splash_left[] PROGMEM = { |
4 | static unsigned char Splash_left[] PROGMEM = { |
| 5 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
5 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//Line 1 |
| 6 | 0xff,0xff,0xff,0xff,0xff, |
6 | 0xff,0xff,0xff,0x3,0x7f,0x7f,0xbf,0xbf,0xdf,0x7,0xff,0xff,0xff,0x3f,0xbf,0xdf,0xdf,0xdf,0x3f,0xff,0xff,0xff,0x3f,0x3f,0xdf,0x9f,0x7f,0x7f,0xbf,0x9f,0x3f,0xff,0xff,0x7f,0xbf,0xdf,0xdf,0x9f,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xc7,0xf3,0xf,0xff,0xff,0xff,0x1f,0xff,0xff,0xff,0xff,0x3f,0xdf,0xff,0xef,0xef,0xef,0x40,0x5,0xf7,0xff,0xff,0x3f,0xbf,0xdf,0xdf,0xdf,0x3f,0xff,0xff,0xff,0x1f,0x7f,0xdf,0x9f,0x7f,0x7f,0x9f,0xdf,0x3f,0xff,0xff,0xbf,0xbf,0xdf,0xdf,0xdf,0x3f,0xff,0xff,0xef,0xef,0xef,0x40,0x5,0xf7,0xff,0x1d,0xff,0xff,0xff,0xff,0x3f,0xbf,0xdf,0xdf,0xdf,0x3f,0xff,0xff,0xff,0x1f,0xff,0x7f,0x9f,0xdf,0x3f,0xff,0xff,0xff,0xff,0xff,//Line 2 |
| 7 | 0xff,0xff,0xff, |
7 | 0xff,0xff,0xff,0xd0,0xff,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xe0,0xef,0xdf,0xdf,0xcf,0xe3,0xf8,0xff,0xff,0xff,0xc0,0xfe,0xff,0xff,0xe0,0xfa,0xff,0xff,0xe0,0xff,0xff,0xf8,0xe6,0xee,0xee,0xf6,0xf7,0xfb,0xff,0xff,0xef,0xf3,0xfc,0xfe,0xfe,0xfe,0xff,0xf0,0xff,0xff,0xf4,0xcf,0xdf,0xe7,0xfb,0xf0,0xe7,0xff,0xff,0xff,0xff,0xff,0xe0,0xff,0xff,0xe0,0xef,0xdf,0xdf,0xcf,0xe3,0xf8,0xff,0xff,0xff,0xc0,0xfe,0xff,0xff,0xe0,0xfa,0xff,0xff,0xe0,0xff,0xff,0xf3,0xeb,0xed,0xed,0xf5,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0xff,0xff,0xe0,0xff,0xff,0xff,0xf0,0xcf,0xdf,0xdf,0xcf,0xe3,0xf8,0xff,0xff,0xff,0xf4,0xf9,0xfe,0xff,0xff,0xe0,0xff,0xff,0xff,0xff,0xff,//Line 3 |
| 8 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
8 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xff,0xff,0xff,0xff,0xff,//Line 4 |
| 9 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
9 | 0xff,0xff,0xff,0xff,0xff,0xdf,0xef,0xef,0xef,0x1f,0xff,0xff,0xf,0xff,0xff,0xff,0xff,0x3f,0xcf,0xff,0xff,0x1f,0x9f,0xef,0xcf,0x3f,0x3f,0xdf,0xcf,0x1f,0xff,0xff,0x40,0x2f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x5f,0xef,0xef,0xef,0xff,0xff,0x3f,0x1f,0x6f,0x6f,0xcf,0x9f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xcf,0xf3,0xfc,0xff,0xff,0xff,0x47,0xb7,0xf7,0xf7,0xf7,0x77,0x8f,0xff,0xff,0xf,0x7f,0x3f,0xdf,0xdf,0xff,0xff,0x7f,0x9f,0xdf,0xef,0xef,0xef,0x1f,0xff,0xff,0xff,0xff,0xdd,0x3f,0xff,0xff,0xff,0x3f,0x1f,0x6f,0x6f,0xcf,0x9f,0xff,0xff,0xfd,0x3,0x7f,0xbf,0xdf,0xef,0xff,0xff,0xf7,0xf7,0xf7,0xa0,0x2,0xfb,0xff,0xff,0xff,//Line 5 |
| 10 | 0xff,0xff,0xff,0xff, |
10 | 0xff,0xff,0xff,0xff,0xf9,0xf6,0xf6,0xfa,0xfa,0xf8,0xff,0xff,0xf8,0xe7,0xef,0xf3,0xfd,0xfc,0xf1,0xff,0xff,0xe0,0xff,0xff,0xff,0xf0,0xfd,0xff,0xff,0xf0,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xcf,0xc3,0xd3,0xe3,0xff,0xff,0xff,0xf7,0xe7,0xee,0xf6,0xf1,0xff,0xff,0xfc,0xf3,0xf7,0xf7,0xfb,0xfb,0xfd,0xff,0xff,0xff,0xcf,0xf3,0xfc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x5b,0xf9,0xfd,0xfe,0xff,0xff,0xff,0xf4,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,0xe7,0xef,0xef,0xe7,0xf1,0xfc,0xff,0xff,0xcf,0xbf,0xbf,0xc0,0xff,0xff,0xff,0xfc,0xfb,0xf7,0xf7,0xfb,0xfb,0xfd,0xff,0xff,0xf8,0xfd,0xfd,0xfb,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,//Line 6 |
| 11 |
|
11 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//Line 7 |
| 12 | 0xff, |
12 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0//Line 7 |
| 13 | }; |
13 | }; |
| - | 14 | ||
| - | 15 | ||
| - | 16 | ||
| - | 17 | ||
| 14 | #define SOLID 0 |
18 | #define SOLID 0 |
| 15 | #define TRANSPARENT 1 |
19 | #define TRANSPARENT 1 |
| 16 | uint8_t color=GLCD_COLOR_BLACK; |
20 | uint8_t color=GLCD_COLOR_BLACK; |
| 17 | uint8_t Transparent=SOLID; |
21 | uint8_t Transparent=SOLID; |
| 18 | 22 | ||
| - | 23 | #if act_ks0108_USE_EXTERNAL_EEPROM==1 |
|
| - | 24 | ||
| - | 25 | void storeImage(uint8_t id, uint8_t size_x , uint8_t size_y); |
|
| - | 26 | ||
| - | 27 | void saveImageFromScreen(uint8_t id, uint8_t size_x , uint8_t size_y); |
|
| - | 28 | ||
| - | 29 | #define MEMORY_I2C_ADDR 0x57 // 64K EEPROM - allowed addresses are 0x50 to 0x57 |
|
| - | 30 | #define MEMORY_ADDR_MSB 0 // start at base of memory. Next one is 0x01. |
|
| - | 31 | #define MEMORY_ADDR_LSB 0 // start on a page boundary. Next one is 0x80. |
|
| - | 32 | unsigned char messageBuf[MESSAGEBUF_SIZE]; |
|
| - | 33 | #endif |
|
| - | 34 | ||
| - | 35 | ||
| 19 | void numtoascii( int16_t num, char **str ); |
36 | void numtoascii( int16_t num, char **str ); |
| 20 | void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
37 | void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
| 21 | void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
38 | void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
| - | 39 | ||
| - | 40 | #if act_ks0108_USE_EXTERNAL_EEPROM==1 |
|
| - | 41 | //valid id is 1 to 255; |
|
| - | 42 | void printImage(uint8_t id, uint8_t x_start, uint8_t y_start) { |
|
| - | 43 | if (id == 0 ) |
|
| - | 44 | return; //id=0 not allowed |
|
| - | 45 | uint16_t address = 0; |
|
| - | 46 | uint16_t buf_index = 0; |
|
| - | 47 | uint8_t index; |
|
| - | 48 | uint8_t size_x = 0; |
|
| - | 49 | uint8_t size_y = 0; |
|
| - | 50 | uint16_t max_picture_size; |
|
| - | 51 | index = (id>>5)&0x07; |
|
| - | 52 | //find starting adress of the requested data |
|
| - | 53 | switch (index) { |
|
| - | 54 | case 0: |
|
| - | 55 | address = (index)*1024; |
|
| - | 56 | max_picture_size = 1024; |
|
| - | 57 | break; |
|
| - | 58 | case 1: |
|
| - | 59 | address = 32768+(index)*512; |
|
| - | 60 | max_picture_size = 512; |
|
| - | 61 | break; |
|
| - | 62 | case 2: |
|
| - | 63 | address = 32768+32*512+(index)*256; |
|
| - | 64 | max_picture_size = 256; |
|
| - | 65 | break; |
|
| - | 66 | case 3: |
|
| - | 67 | address = 32768+32*512+32*256+(index)*128; |
|
| - | 68 | max_picture_size = 128; |
|
| - | 69 | break; |
|
| - | 70 | case 4: |
|
| - | 71 | address = 32768+32*512+32*256+32*128+(index)*64; |
|
| - | 72 | max_picture_size = 64; |
|
| - | 73 | break; |
|
| - | 74 | case 5: |
|
| - | 75 | address = 32768+32*512+32*256+32*128+32*64+(index)*32; |
|
| - | 76 | max_picture_size = 32; |
|
| - | 77 | break; |
|
| - | 78 | case 6: |
|
| - | 79 | address = 32768+32*512+32*256+32*128+32*64+32*32+(index)*16; |
|
| - | 80 | max_picture_size = 16; |
|
| - | 81 | break; |
|
| - | 82 | case 7: |
|
| - | 83 | address = 32768+32*512+32*256+32*128+32*64+32*32+32*16+(index)*16; |
|
| - | 84 | max_picture_size = 16; |
|
| - | 85 | break; |
|
| - | 86 | } |
|
| - | 87 | //Get size of picture (every picture has an 4 byte info-tag) |
|
| - | 88 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 89 | messageBuf[1] = (uint8_t)(0); // Starting address in memory |
|
| - | 90 | messageBuf[2] = (uint8_t)(((id&0xe0)>>5) & 0xff); // Starting address in memory |
|
| - | 91 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 92 | // Could do other actions in here, then get data. |
|
| - | 93 | TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 94 | size_x = messageBuf[((id&0x1f)<<2)]; |
|
| - | 95 | size_y = messageBuf[((id&0x1f)<<2)+1]; |
|
| - | 96 | //more_data = messageBuf[((id&0x1f)<<2)+2]; |
|
| - | 97 | //last_data = messageBuf[((id&0x1f)<<2)+3]; |
|
| - | 98 | ||
| - | 99 | // get data from eeprom |
|
| - | 100 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 101 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 102 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 103 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 104 | // Could do other actions in here, then get data. |
|
| - | 105 | TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 106 | uint8_t jy = 0; |
|
| - | 107 | uint8_t jx = 0; |
|
| - | 108 | buf_index = 0; |
|
| - | 109 | for (jy = 0; jy< size_y; jy+=8){ |
|
| - | 110 | glcdSetXY(x_start,y_start+jy); |
|
| - | 111 | for (jx = 0; jx< size_x ; jx++){ |
|
| - | 112 | if (buf_index>=128) { //get new data if buffer empty |
|
| - | 113 | address +=128; |
|
| - | 114 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 115 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 116 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 117 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 118 | // Could do other actions in here, then get data. |
|
| - | 119 | TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 120 | buf_index=0; |
|
| - | 121 | } |
|
| - | 122 | glcdWriteData(messageBuf[buf_index+1], GLCD_COLOR_CLEAR); |
|
| - | 123 | buf_index++; |
|
| - | 124 | } |
|
| - | 125 | } |
|
| - | 126 | } |
|
| - | 127 | volatile uint8_t state; |
|
| - | 128 | volatile uint8_t lastId = 255; |
|
| - | 129 | #define IDLE 0 |
|
| - | 130 | #define RECEIVING_DATA 1 |
|
| - | 131 | void newImageData(StdCan_Msg_t *rxMsg) { |
|
| - | 132 | //State machine for storing new data |
|
| - | 133 | switch (state) { |
|
| - | 134 | case IDLE: |
|
| - | 135 | if (rxMsg->Header.Command == CAN_MODULE_CMD_KS0108_LCD_NEW_IMAGE) |
|
| - | 136 | { |
|
| - | 137 | storeImage(rxMsg->Data[0],rxMsg->Data[1],rxMsg->Data[2]); |
|
| - | 138 | state = RECEIVING_DATA; |
|
| - | 139 | lastId = 255; |
|
| - | 140 | //response message |
|
| - | 141 | rxMsg->Length = 1; |
|
| - | 142 | rxMsg->Header.Command = CAN_MODULE_CMD_KS0108_LCD_ACK; |
|
| - | 143 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
|
| - | 144 | }else { |
|
| - | 145 | //error message |
|
| - | 146 | rxMsg->Length = 0; |
|
| - | 147 | rxMsg->Header.Command = CAN_MODULE_CMD_KS0108_LCD_ERROR; |
|
| - | 148 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
|
| - | 149 | } |
|
| - | 150 | break; |
|
| - | 151 | case RECEIVING_DATA: |
|
| - | 152 | if (rxMsg->Header.Command == CAN_MODULE_CMD_KS0108_LCD_IMAGE_DATA) |
|
| - | 153 | { |
|
| - | 154 | if (rxMsg->Data[0] == (lastId+1)) { |
|
| - | 155 | storeImage(rxMsg->Data[0],rxMsg->Data[1],rxMsg->Data[2]); |
|
| - | 156 | state = RECEIVING_DATA; |
|
| - | 157 | lastId++; |
|
| - | 158 | ||
| - | 159 | //FIXME: call function that handles the data |
|
| - | 160 | ||
| - | 161 | //response message |
|
| - | 162 | rxMsg->Length = 1; |
|
| - | 163 | rxMsg->Header.Command = CAN_MODULE_CMD_KS0108_LCD_ACK; |
|
| - | 164 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
|
| - | 165 | } else { |
|
| - | 166 | //wrong id |
|
| - | 167 | rxMsg->Length = 1; |
|
| - | 168 | rxMsg->Header.Command = CAN_MODULE_CMD_KS0108_LCD_DATA_ID_ERROR; |
|
| - | 169 | rxMsg->Data[0] = (lastId+1); |
|
| - | 170 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
|
| - | 171 | } |
|
| - | 172 | } else if (rxMsg->Header.Command == CAN_MODULE_CMD_KS0108_LCD_DATA_DONE) { |
|
| - | 173 | //Call function to flush eeprom cache |
|
| - | 174 | //FIXME |
|
| - | 175 | state=IDLE; |
|
| - | 176 | } else { |
|
| - | 177 | //error message |
|
| - | 178 | rxMsg->Length = 0; |
|
| - | 179 | rxMsg->Header.Command = CAN_MODULE_CMD_KS0108_LCD_ERROR; |
|
| - | 180 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
|
| - | 181 | } |
|
| - | 182 | break; |
|
| - | 183 | } |
|
| - | 184 | ||
| - | 185 | } |
|
| - | 186 | ||
| - | 187 | ||
| - | 188 | //valid id is 1 to 255; |
|
| - | 189 | void storeImage(uint8_t id, uint8_t size_x , uint8_t size_y) { |
|
| - | 190 | if (id == 0 ) |
|
| - | 191 | return; //id=0 not allowed |
|
| - | 192 | //uint16_t address = 0; |
|
| - | 193 | //uint16_t buf_index = 0; |
|
| - | 194 | uint8_t index; |
|
| - | 195 | //uint16_t max_picture_size; |
|
| - | 196 | index = (id>>5)&0x07; |
|
| - | 197 | //find starting adress of the requested data |
|
| - | 198 | //Get size of picture (every picture has an 4 byte info-tag) |
|
| - | 199 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 200 | messageBuf[1] = (uint8_t)(0); // Starting address in memory |
|
| - | 201 | messageBuf[2] = (uint8_t)(((id&0xe0)>>5) & 0xff); // Starting address in memory |
|
| - | 202 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 203 | // Could do other actions in here, then get data. |
|
| - | 204 | TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 205 | messageBuf[((id&0x1f)<<2)+1] = size_x; |
|
| - | 206 | messageBuf[((id&0x1f)<<2)+2] = size_y; |
|
| - | 207 | //more_data = messageBuf[((id&0x1f)<<2)+2]; |
|
| - | 208 | //last_data = messageBuf[((id&0x1f)<<2)+3]; |
|
| - | 209 | ||
| - | 210 | //move data in the buffer |
|
| - | 211 | for (index = 128; index > 0; index--) { |
|
| - | 212 | messageBuf[index+2] = messageBuf[index]; |
|
| - | 213 | } |
|
| - | 214 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 215 | messageBuf[1] = (uint8_t)(0); // Starting address in memory |
|
| - | 216 | messageBuf[2] = (uint8_t)(((id&0xe0)>>5) & 0xff); // Starting address in memory |
|
| - | 217 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 218 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 219 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 220 | ||
| - | 221 | //Now the info-tag is written, only to add data left |
|
| - | 222 | ||
| - | 223 | //FIXME........ FIX!!! |
|
| - | 224 | ||
| - | 225 | } |
|
| - | 226 | ||
| - | 227 | ||
| - | 228 | //valid id is 1 to 255; |
|
| - | 229 | void saveImageFromScreen(uint8_t id, uint8_t size_x , uint8_t size_y) { |
|
| - | 230 | if (id == 0 ) |
|
| - | 231 | return; //id=0 not allowed |
|
| - | 232 | uint16_t max_picture_size; |
|
| - | 233 | uint8_t index; |
|
| - | 234 | uint8_t bufferIndex; |
|
| - | 235 | uint16_t address = 0; |
|
| - | 236 | index = (id>>5)&0x07; |
|
| - | 237 | //find starting adress of the requested data |
|
| - | 238 | switch (index) { |
|
| - | 239 | case 0: |
|
| - | 240 | address = (index)*1024; |
|
| - | 241 | max_picture_size = 1024; |
|
| - | 242 | break; |
|
| - | 243 | case 1: |
|
| - | 244 | address = 32768+(index)*512; |
|
| - | 245 | max_picture_size = 512; |
|
| - | 246 | break; |
|
| - | 247 | case 2: |
|
| - | 248 | address = 32768+32*512+(index)*256; |
|
| - | 249 | max_picture_size = 256; |
|
| - | 250 | break; |
|
| - | 251 | case 3: |
|
| - | 252 | address = 32768+32*512+32*256+(index)*128; |
|
| - | 253 | max_picture_size = 128; |
|
| - | 254 | break; |
|
| - | 255 | case 4: |
|
| - | 256 | address = 32768+32*512+32*256+32*128+(index)*64; |
|
| - | 257 | max_picture_size = 64; |
|
| - | 258 | break; |
|
| - | 259 | case 5: |
|
| - | 260 | address = 32768+32*512+32*256+32*128+32*64+(index)*32; |
|
| - | 261 | max_picture_size = 32; |
|
| - | 262 | break; |
|
| - | 263 | case 6: |
|
| - | 264 | address = 32768+32*512+32*256+32*128+32*64+32*32+(index)*16; |
|
| - | 265 | max_picture_size = 16; |
|
| - | 266 | break; |
|
| - | 267 | case 7: |
|
| - | 268 | address = 32768+32*512+32*256+32*128+32*64+32*32+32*16+(index)*16; |
|
| - | 269 | max_picture_size = 16; |
|
| - | 270 | break; |
|
| - | 271 | } |
|
| - | 272 | //Get size of picture (every picture has an 4 byte info-tag) |
|
| - | 273 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 274 | messageBuf[1] = (uint8_t)(0); // Starting address in memory |
|
| - | 275 | messageBuf[2] = (uint8_t)(((id&0xe0)>>5) & 0xff); // Starting address in memory |
|
| - | 276 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 277 | // Could do other actions in here, then get data. |
|
| - | 278 | TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 279 | messageBuf[((id&0x1f)<<2)+1] = size_x; |
|
| - | 280 | messageBuf[((id&0x1f)<<2)+2] = size_y; |
|
| - | 281 | ||
| - | 282 | //move data in the buffer |
|
| - | 283 | for (index = 128; index > 0; index--) { |
|
| - | 284 | messageBuf[index+2] = messageBuf[index]; |
|
| - | 285 | } |
|
| - | 286 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 287 | messageBuf[1] = (uint8_t)(0); // Starting address in memory |
|
| - | 288 | messageBuf[2] = (uint8_t)(((id&0xe0)>>5) & 0xff); // Starting address in memory |
|
| - | 289 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 290 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 291 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 292 | ||
| - | 293 | //Now the info-tag is written, only to add data left |
|
| - | 294 | uint8_t h, i ; |
|
| - | 295 | ||
| - | 296 | ||
| - | 297 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 298 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 299 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 300 | bufferIndex = 3; |
|
| - | 301 | ||
| - | 302 | h = 0; |
|
| - | 303 | while(h+8 <= size_y) { |
|
| - | 304 | h += 8; |
|
| - | 305 | glcdSetXY(0, h); |
|
| - | 306 | ||
| - | 307 | for(i=0; i<=size_x; i++) { |
|
| - | 308 | messageBuf[bufferIndex] = glcdReadData(); |
|
| - | 309 | bufferIndex++; |
|
| - | 310 | if (bufferIndex >= 131) { |
|
| - | 311 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 312 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 313 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 314 | bufferIndex = 3; |
|
| - | 315 | address+=128; |
|
| - | 316 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 317 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 318 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 319 | } |
|
| - | 320 | } |
|
| - | 321 | } |
|
| - | 322 | } |
|
| - | 323 | #endif |
|
| 22 | 324 | ||
| 23 | void act_ks0108_Init(void) |
325 | void act_ks0108_Init(void) |
| 24 | { |
326 | { |
| 25 | ///TODO: Initialize hardware etc here |
327 | ///TODO: Initialize hardware etc here |
| 26 | // Backlight |
328 | // Backlight |
| 27 | TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00); |
329 | TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00); |
| 28 | TCCR0B |= (1<<CS00); |
330 | TCCR0B |= (1<<CS00); |
| 29 | OCR0A = act_ks0108_INITIAL_BACKLIGHT; |
331 | OCR0A = act_ks0108_INITIAL_BACKLIGHT; |
| 30 | DDRD |= (1<<PD6); |
332 | DDRD |= (1<<PD6); |
| 31 | 333 | ||
| 32 | glcdPowerOn(); |
- | |
| 33 | 334 | ||
| - | 335 | #if act_ks0108_USE_EXTERNAL_EEPROM==1 |
|
| - | 336 | TWI_Master_Initialise(); |
|
| - | 337 | uint8_t temp = 0; |
|
| - | 338 | /// Do initial write to EEPROM. Write cycle takes 5 msecs, so flashing the led will delay enough. |
|
| - | 339 | // |
|
| - | 340 | ||
| - | 341 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 342 | messageBuf[1] = (((1024+128)>>8)&0xff); // Starting address MSB |
|
| - | 343 | messageBuf[2] = ((1024+128)&0xff); // Starting address LSB |
|
| - | 344 | ||
| - | 345 | for (temp=0; temp<128; temp++) |
|
| - | 346 | { |
|
| - | 347 | messageBuf[temp+3] = 128-temp; |
|
| - | 348 | } |
|
| - | 349 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 350 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 351 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 352 | ||
| - | 353 | //delay 10ms |
|
| - | 354 | uint32_t temp2; |
|
| - | 355 | temp2 =Timer_GetTicks(); |
|
| - | 356 | while (Timer_GetTicks() < temp2 + 10); |
|
| - | 357 | ||
| - | 358 | #define TEMPID 0 |
|
| - | 359 | uint16_t address = (TEMPID+1)*1024; //only addresses on page border is allowed |
|
| - | 360 | uint16_t ixa = 0; |
|
| - | 361 | uint8_t jxa = 0; |
|
| - | 362 | for (jxa = 0; jxa< 8; jxa++){ |
|
| - | 363 | for (ixa = 0; ixa < 128; ixa++){ |
|
| - | 364 | messageBuf[ixa+3] = (((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128)) ^ 0xff); |
|
| - | 365 | } |
|
| - | 366 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 367 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 368 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 369 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 370 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 371 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 372 | //delay 10ms |
|
| - | 373 | temp2 =Timer_GetTicks(); |
|
| - | 374 | while (Timer_GetTicks() < temp2 + 10); |
|
| - | 375 | address += 128; |
|
| - | 376 | } |
|
| - | 377 | ||
| - | 378 | address = (TEMPID+2)*1024; //only addresses on page border is allowed |
|
| - | 379 | ixa = 0; |
|
| - | 380 | jxa = 0; |
|
| - | 381 | for (jxa = 0; jxa< 8; jxa++){ |
|
| - | 382 | for (ixa = 0; ixa < 128; ixa++){ |
|
| - | 383 | messageBuf[ixa+3] = (uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128); |
|
| - | 384 | } |
|
| - | 385 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS) | (FALSE<<TWI_READ_BIT); |
|
| - | 386 | messageBuf[1] = (uint8_t)((address >> 8) & 0xff); // Starting address in memory |
|
| - | 387 | messageBuf[2] = (uint8_t)(address & 0xff); // Starting address in memory |
|
| - | 388 | TWI_Start_Read_Write( messageBuf, 131 ); |
|
| - | 389 | // Should wait for completion of EEPROM write cycle. Blinking the LED will do this. |
|
| - | 390 | while ( TWI_Transceiver_Busy() ); // Check for an error. |
|
| - | 391 | //delay 10ms |
|
| - | 392 | temp2 =Timer_GetTicks(); |
|
| - | 393 | while (Timer_GetTicks() < temp2 + 10); |
|
| - | 394 | address += 128; |
|
| - | 395 | } |
|
| - | 396 | for (temp=0; temp<131; temp++) |
|
| - | 397 | { |
|
| - | 398 | messageBuf[temp] = 0; |
|
| - | 399 | } |
|
| - | 400 | ||
| - | 401 | #endif |
|
| - | 402 | ||
| - | 403 | glcdPowerOn(); |
|
| - | 404 | ||
| - | 405 | #if act_ks0108_USE_EXTERNAL_EEPROM==0 |
|
| 34 | uint16_t ixa = 0; |
406 | uint16_t ixa = 0; |
| 35 | uint8_t jxa = 0; |
407 | uint8_t jxa = 0; |
| 36 | for (jxa = 0; jxa< 8; jxa++){ |
408 | for (jxa = 0; jxa< 8; jxa++){ |
| 37 | glcdSetXY(0,jxa*8); |
409 | glcdSetXY(0,jxa*8); |
| 38 | for (ixa = 0; ixa < 128; ixa++){ |
410 | for (ixa = 0; ixa < 128; ixa++){ |
| 39 | glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128), GLCD_COLOR_CLEAR); |
411 | glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128), GLCD_COLOR_CLEAR); |
| 40 | } |
412 | } |
| 41 | } |
413 | } |
| - | 414 | #endif |
|
| - | 415 | ||
| - | 416 | #if act_ks0108_USE_EXTERNAL_EEPROM==1 |
|
| - | 417 | printImage(1,0,0); |
|
| - | 418 | //delay 10ms |
|
| - | 419 | temp2 =Timer_GetTicks(); |
|
| - | 420 | while (Timer_GetTicks() < temp2 + 5000); |
|
| - | 421 | printImage(0,0,0); |
|
| - | 422 | #endif |
|
| 42 | //glcdSetXY(0,0); |
423 | //glcdSetXY(0,0); |
| 43 | //glcdPutStrTransparent("=_-[]_-=",GLCD_COLOR_SET); |
424 | //glcdPutStrTransparent("=_-[]_-=",GLCD_COLOR_SET); |
| 44 | //glcdSetXY(0,8); |
425 | //glcdSetXY(0,8); |
| 45 | //glcdPutStrTransparent("--------",GLCD_COLOR_SET); |
426 | //glcdPutStrTransparent("--------",GLCD_COLOR_SET); |
| 46 | //glcdSetXY(0,16); |
427 | //glcdSetXY(0,16); |
| Line 67... | Line 448... | ||
| 67 | ///TODO: Stuff that needs doing is done here |
448 | ///TODO: Stuff that needs doing is done here |
| 68 | } |
449 | } |
| 69 | 450 | ||
| 70 | void act_ks0108_HandleMessage(StdCan_Msg_t *rxMsg) |
451 | void act_ks0108_HandleMessage(StdCan_Msg_t *rxMsg) |
| 71 | { |
452 | { |
| 72 | StdCan_Msg_t txMsg |
453 | //StdCan_Msg_t txMsg; |
| 73 | uint8_t n = 0; |
454 | uint8_t n = 0; |
| 74 | 455 | ||
| 75 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT && |
456 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT && |
| 76 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
457 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
| 77 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_KS0108 && |
458 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_KS0108 && |
| Line 85... | Line 466... | ||
| 85 | } |
466 | } |
| 86 | glcdClear(); |
467 | glcdClear(); |
| 87 | rxMsg->Data[0] = glcdGetColor()<<7; |
468 | rxMsg->Data[0] = glcdGetColor()<<7; |
| 88 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
469 | StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER); |
| 89 | rxMsg->Length = 1; |
470 | rxMsg->Length = 1; |
| - | 471 | #if act_ks0108_USE_EXTERNAL_EEPROM==1 |
|
| - | 472 | uint8_t temp = 0; |
|
| - | 473 | // Read the data from Memory. Value of read/write bit doesn't matter. |
|
| - | 474 | messageBuf[0] = (MEMORY_I2C_ADDR<<TWI_ADR_BITS); // Read/write bit doesn't matter here |
|
| - | 475 | messageBuf[1] = MEMORY_ADDR_MSB; // Starting address in memory |
|
| - | 476 | messageBuf[2] = MEMORY_ADDR_LSB; // Starting address in memory |
|
| - | 477 | TWI_Start_Random_Read( messageBuf, 129, 3 ); // Desired data length plus one (command byte). |
|
| - | 478 | // Could do other actions in here, then get data. |
|
| - | 479 | temp = TWI_Read_Data_From_Buffer( messageBuf, 129 ); |
|
| - | 480 | rxMsg->Length = 6; |
|
| - | 481 | rxMsg->Data[1] = temp; |
|
| - | 482 | rxMsg->Data[2] = messageBuf[0+3]; |
|
| - | 483 | rxMsg->Data[3] = messageBuf[0+4]; |
|
| - | 484 | rxMsg->Data[4] = messageBuf[0+5]; |
|
| - | 485 | rxMsg->Data[5] = messageBuf[0+80]; |
|
| - | 486 | #endif |
|
| 90 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
487 | while (StdCan_Put(rxMsg) != StdCan_Ret_OK); |
| 91 | break; |
488 | break; |
| 92 | case CAN_MODULE_CMD_KS0108_LCD_INVERT: |
489 | case CAN_MODULE_CMD_KS0108_LCD_INVERT: |
| 93 | if (rxMsg->Length == 1) { |
490 | if (rxMsg->Length == 1) { |
| 94 | if ((0x80&rxMsg->Data[0])>>7 != glcdGetColor()) |
491 | if ((0x80&rxMsg->Data[0])>>7 != glcdGetColor()) |
| Line 137... | Line 534... | ||
| 137 | } |
534 | } |
| 138 | break; |
535 | break; |
| 139 | 536 | ||
| 140 | case CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT: |
537 | case CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT: |
| 141 | if (rxMsg->Length > 0) { |
538 | if (rxMsg->Length > 0) { |
| - | 539 | if ( rxMsg->Data[0] == 0) { |
|
| - | 540 | TCCR0A &= ~(1<<COM0A0); |
|
| - | 541 | TCCR0A &= ~(1<<COM0A1); |
|
| - | 542 | PORTD &= ~(1<<PD6); |
|
| 142 | OCR0A = rxMsg->Data[0]; |
543 | OCR0A = rxMsg->Data[0]; |
| - | 544 | } else { |
|
| - | 545 | TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00); |
|
| - | 546 | OCR0A = rxMsg->Data[0]; |
|
| - | 547 | } |
|
| - | 548 | ||
| 143 | } |
549 | } |
| 144 | StdCan_Msg_t txMsg; |
550 | StdCan_Msg_t txMsg; |
| 145 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
551 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); |
| 146 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
552 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 147 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108; |
553 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108; |