![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
06/21/18
Fork of rtos_threading_with_callback by
main.cpp@3:3e8c16b6620c, 2018-06-21 (annotated)
- Committer:
- CactusSemi
- Date:
- Thu Jun 21 22:11:25 2018 +0000
- Revision:
- 3:3e8c16b6620c
- Parent:
- 2:c7229eac380b
- Child:
- 4:61f1412310af
06/21/2018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mab5449 | 0:d4b2a035ffe3 | 1 | #include "mbed.h" |
mab5449 | 0:d4b2a035ffe3 | 2 | |
CactusSemi | 2:c7229eac380b | 3 | Serial pc(USBTX, USBRX); |
CactusSemi | 3:3e8c16b6620c | 4 | const int frequ = 50; //unit kHz |
CactusSemi | 3:3e8c16b6620c | 5 | const char dev_addr = 0x00; //fixed |
CactusSemi | 3:3e8c16b6620c | 6 | const char version[4] = "0.0"; |
mab5449 | 0:d4b2a035ffe3 | 7 | |
CactusSemi | 3:3e8c16b6620c | 8 | void testmode(void); |
CactusSemi | 3:3e8c16b6620c | 9 | void i2c_read(void); |
CactusSemi | 3:3e8c16b6620c | 10 | void i2c_write(void); |
CactusSemi | 3:3e8c16b6620c | 11 | void EasyFuse_prog(void); |
CactusSemi | 3:3e8c16b6620c | 12 | void hot_read(void); |
CactusSemi | 3:3e8c16b6620c | 13 | |
CactusSemi | 3:3e8c16b6620c | 14 | void clear_screen() { |
CactusSemi | 3:3e8c16b6620c | 15 | int i=0; |
CactusSemi | 3:3e8c16b6620c | 16 | pc.printf("\033[%dm", 36);//change text color to cyan |
CactusSemi | 3:3e8c16b6620c | 17 | pc.printf("\033[2J");//clears screen |
CactusSemi | 3:3e8c16b6620c | 18 | pc.printf("\033[%d;%dH%c", 1, 1);//locate cursor to the 0,0 |
CactusSemi | 3:3e8c16b6620c | 19 | pc.printf("\n\r"); |
CactusSemi | 3:3e8c16b6620c | 20 | //Print CSI059 |
CactusSemi | 3:3e8c16b6620c | 21 | pc.printf("\n\r \332\304"); |
CactusSemi | 3:3e8c16b6620c | 22 | for ( i = 0; i<46; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 23 | pc.printf("\304\302"); |
CactusSemi | 3:3e8c16b6620c | 24 | pc.printf("\n\r \263\t\t\t\t\t\t \263"); |
CactusSemi | 3:3e8c16b6620c | 25 | pc.printf("\n\r \263 \334\334\334\t \334\334\334\t\334\334\334\t \334\334 \t\334\334\334\334\t \334\334 \263"); |
CactusSemi | 3:3e8c16b6620c | 26 | pc.printf("\n\r \263 \333 \t\333 \t \333 \t\333 \333\t\333 \t\333 \333 \263"); |
CactusSemi | 3:3e8c16b6620c | 27 | pc.printf("\n\r \263 \333 \t\337\337\334\334\t \333 \t\333 \333\t\337\337\337\334\t\337\334\334\333 \263"); |
CactusSemi | 3:3e8c16b6620c | 28 | pc.printf("\n\r \263 \333 \t \333\t \333 \t\333 \333\t \333\t \333 \263"); |
CactusSemi | 3:3e8c16b6620c | 29 | pc.printf("\n\r \263 \337\337\337\t\337\337\337 \t\337\337\337\t \337\337 \t\337\337\337 \t\337\337\337 \263"); |
CactusSemi | 3:3e8c16b6620c | 30 | pc.printf("\n\r \263\t\t\t\t\t\t \263\n\r \300\304"); |
CactusSemi | 3:3e8c16b6620c | 31 | for ( i = 0; i<46; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 32 | pc.printf("\304\331"); |
CactusSemi | 3:3e8c16b6620c | 33 | pc.printf("\n\n\n\r\tPROTYPE EVALUATION S/W"); |
CactusSemi | 3:3e8c16b6620c | 34 | pc.printf("\n\n\r\tVersion : %s",version); |
CactusSemi | 3:3e8c16b6620c | 35 | pc.printf("\n\n\r \315"); |
CactusSemi | 3:3e8c16b6620c | 36 | for ( i = 0; i<80; i++) pc.printf("\315"); |
CactusSemi | 3:3e8c16b6620c | 37 | pc.printf("\n\n\n\r"); |
CactusSemi | 3:3e8c16b6620c | 38 | pc.printf("\033[%dm", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 39 | } |
mab5449 | 0:d4b2a035ffe3 | 40 | |
CactusSemi | 3:3e8c16b6620c | 41 | void print_menu() { |
CactusSemi | 3:3e8c16b6620c | 42 | int i=0; |
CactusSemi | 3:3e8c16b6620c | 43 | pc.printf("\n\n\r\tWhat do you want to do next ?"); |
CactusSemi | 3:3e8c16b6620c | 44 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 3:3e8c16b6620c | 45 | pc.printf("\n\n\n\r\t\332\304"); |
CactusSemi | 3:3e8c16b6620c | 46 | for ( i = 0; i<45; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 47 | pc.printf("\304\302"); |
CactusSemi | 3:3e8c16b6620c | 48 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 49 | pc.printf("\n\r\t\263 Press 't' : to generate Test-Mode Sequence\t\263"); |
CactusSemi | 3:3e8c16b6620c | 50 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 51 | pc.printf("\n\r\t\263 Press 'r' : to perform Register Read \t\263"); |
CactusSemi | 3:3e8c16b6620c | 52 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 53 | pc.printf("\n\r\t\263 Press 'w' : to perform Register Write \t\263"); |
CactusSemi | 3:3e8c16b6620c | 54 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 55 | pc.printf("\n\r\t\263 Press 'p' : to program Easy Fuse \t\263"); |
CactusSemi | 3:3e8c16b6620c | 56 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 57 | pc.printf("\n\r\t\263 Press 'h' : to Perform Hot Register Read \t\263"); |
CactusSemi | 3:3e8c16b6620c | 58 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 59 | pc.printf("\n\r\t\263 Press 'c' : to clear screen \t\263"); |
CactusSemi | 3:3e8c16b6620c | 60 | pc.printf("\n\r\t\263\t\t\t\t\t\t\263"); |
CactusSemi | 3:3e8c16b6620c | 61 | pc.printf("\n\r\t\300\304"); |
CactusSemi | 3:3e8c16b6620c | 62 | for ( i = 0; i<45; i++) pc.printf("\304"); |
CactusSemi | 3:3e8c16b6620c | 63 | pc.printf("\304\331"); |
CactusSemi | 3:3e8c16b6620c | 64 | pc.printf("\033[%dm", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 65 | pc.printf("\n\n\n\r\tYour Selection : "); |
CactusSemi | 3:3e8c16b6620c | 66 | } |
CactusSemi | 3:3e8c16b6620c | 67 | |
CactusSemi | 3:3e8c16b6620c | 68 | void draw_line() { |
CactusSemi | 3:3e8c16b6620c | 69 | pc.printf("\033[%dm ", 33);//change text color to yellow |
CactusSemi | 3:3e8c16b6620c | 70 | pc.printf("\n\n\n\n\r \315"); |
CactusSemi | 3:3e8c16b6620c | 71 | for ( int i = 0; i<80; i++) pc.printf("\315"); |
CactusSemi | 3:3e8c16b6620c | 72 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 73 | pc.printf("\n\n\r"); |
CactusSemi | 3:3e8c16b6620c | 74 | } |
CactusSemi | 3:3e8c16b6620c | 75 | |
CactusSemi | 3:3e8c16b6620c | 76 | void draw_bar() { |
CactusSemi | 3:3e8c16b6620c | 77 | pc.printf("\033[%dm ", 33);//change text color to yellow |
CactusSemi | 3:3e8c16b6620c | 78 | pc.printf("\n\n\n\n\r \334"); |
CactusSemi | 3:3e8c16b6620c | 79 | for ( int i = 0; i<80; i++) pc.printf("\334"); |
CactusSemi | 3:3e8c16b6620c | 80 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 81 | pc.printf("\n\n\r"); |
CactusSemi | 3:3e8c16b6620c | 82 | } |
CactusSemi | 3:3e8c16b6620c | 83 | |
CactusSemi | 3:3e8c16b6620c | 84 | void clear_screen_ques() { |
CactusSemi | 3:3e8c16b6620c | 85 | int temp; |
CactusSemi | 3:3e8c16b6620c | 86 | pc.printf("\n\n\r\tClear Screen (y/n) : "); |
CactusSemi | 2:c7229eac380b | 87 | temp = 0; |
CactusSemi | 2:c7229eac380b | 88 | while ( temp!='y' && temp!='n') { |
CactusSemi | 2:c7229eac380b | 89 | temp = pc.getc(); |
CactusSemi | 2:c7229eac380b | 90 | } |
CactusSemi | 3:3e8c16b6620c | 91 | if (temp == 'y') clear_screen(); |
CactusSemi | 3:3e8c16b6620c | 92 | else draw_bar(); |
CactusSemi | 3:3e8c16b6620c | 93 | } |
CactusSemi | 3:3e8c16b6620c | 94 | |
CactusSemi | 3:3e8c16b6620c | 95 | char get_selection() { |
CactusSemi | 3:3e8c16b6620c | 96 | char current_char; |
CactusSemi | 3:3e8c16b6620c | 97 | int flag = 0; |
CactusSemi | 3:3e8c16b6620c | 98 | while (flag == 0) { |
CactusSemi | 3:3e8c16b6620c | 99 | current_char = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 100 | if ( current_char == 't' || current_char == 'r' || current_char == 'w' || current_char == 'p' || current_char == 'c' || current_char == 'h' ) flag = 1; |
CactusSemi | 3:3e8c16b6620c | 101 | else { |
CactusSemi | 3:3e8c16b6620c | 102 | pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 3:3e8c16b6620c | 103 | pc.printf("\n\n\r\tYour Selection : "); |
CactusSemi | 3:3e8c16b6620c | 104 | } |
CactusSemi | 2:c7229eac380b | 105 | } |
CactusSemi | 3:3e8c16b6620c | 106 | return current_char; |
CactusSemi | 3:3e8c16b6620c | 107 | } |
CactusSemi | 3:3e8c16b6620c | 108 | |
CactusSemi | 3:3e8c16b6620c | 109 | void print_note() { |
CactusSemi | 3:3e8c16b6620c | 110 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 3:3e8c16b6620c | 111 | pc.printf("\n\n\r\tNote : "); |
CactusSemi | 3:3e8c16b6620c | 112 | pc.printf("\n\r\t\304\304\304\304\304\304"); |
CactusSemi | 3:3e8c16b6620c | 113 | pc.printf("\n\n\r\t1. In Tera Term, enable 'Local echo' in Setup -> Terminal"); |
CactusSemi | 3:3e8c16b6620c | 114 | pc.printf("\n\n\r\t2. When not specified, please do not press 'enter' key after typing any entry "); |
CactusSemi | 3:3e8c16b6620c | 115 | pc.printf("\033[%dm", 32);//change text color to green |
CactusSemi | 3:3e8c16b6620c | 116 | draw_line(); |
CactusSemi | 2:c7229eac380b | 117 | } |
CactusSemi | 2:c7229eac380b | 118 | |
mab5449 | 0:d4b2a035ffe3 | 119 | int main() { |
CactusSemi | 3:3e8c16b6620c | 120 | char current_char=0; |
CactusSemi | 3:3e8c16b6620c | 121 | clear_screen(); |
CactusSemi | 3:3e8c16b6620c | 122 | print_note(); |
CactusSemi | 2:c7229eac380b | 123 | while(1) { |
CactusSemi | 3:3e8c16b6620c | 124 | print_menu(); |
CactusSemi | 3:3e8c16b6620c | 125 | current_char = get_selection(); |
CactusSemi | 3:3e8c16b6620c | 126 | draw_line(); |
CactusSemi | 3:3e8c16b6620c | 127 | |
CactusSemi | 3:3e8c16b6620c | 128 | switch (current_char) { |
CactusSemi | 3:3e8c16b6620c | 129 | |
CactusSemi | 3:3e8c16b6620c | 130 | case 't': |
CactusSemi | 3:3e8c16b6620c | 131 | testmode(); |
CactusSemi | 3:3e8c16b6620c | 132 | clear_screen_ques(); |
CactusSemi | 3:3e8c16b6620c | 133 | break; |
CactusSemi | 3:3e8c16b6620c | 134 | |
CactusSemi | 3:3e8c16b6620c | 135 | case 'r': |
CactusSemi | 3:3e8c16b6620c | 136 | i2c_read(); |
CactusSemi | 3:3e8c16b6620c | 137 | clear_screen_ques(); |
CactusSemi | 3:3e8c16b6620c | 138 | break; |
CactusSemi | 3:3e8c16b6620c | 139 | |
CactusSemi | 3:3e8c16b6620c | 140 | case 'w': |
CactusSemi | 3:3e8c16b6620c | 141 | i2c_write(); |
CactusSemi | 3:3e8c16b6620c | 142 | clear_screen_ques(); |
CactusSemi | 3:3e8c16b6620c | 143 | break; |
CactusSemi | 3:3e8c16b6620c | 144 | |
CactusSemi | 3:3e8c16b6620c | 145 | case 'p': |
CactusSemi | 3:3e8c16b6620c | 146 | EasyFuse_prog(); |
CactusSemi | 3:3e8c16b6620c | 147 | clear_screen_ques(); |
CactusSemi | 3:3e8c16b6620c | 148 | break; |
CactusSemi | 3:3e8c16b6620c | 149 | |
CactusSemi | 3:3e8c16b6620c | 150 | case 'h': |
CactusSemi | 3:3e8c16b6620c | 151 | hot_read(); |
CactusSemi | 3:3e8c16b6620c | 152 | clear_screen_ques(); |
CactusSemi | 3:3e8c16b6620c | 153 | break; |
CactusSemi | 3:3e8c16b6620c | 154 | |
CactusSemi | 3:3e8c16b6620c | 155 | case 'c': |
CactusSemi | 3:3e8c16b6620c | 156 | clear_screen(); |
CactusSemi | 3:3e8c16b6620c | 157 | break; |
CactusSemi | 3:3e8c16b6620c | 158 | |
CactusSemi | 3:3e8c16b6620c | 159 | } |
CactusSemi | 3:3e8c16b6620c | 160 | }//end of while |
mab5449 | 0:d4b2a035ffe3 | 161 | } |