00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <gpio/gpio.h>
00022 #include <error/error.h>
00023 #include <types/types.h>
00024 #include <clock/clock.h>
00025
00026
00027
00028
00029
00030
00031 static void wait_dot(void) {
00032 int i;
00033 for(i = 0; i < 50; i++)
00034 clock_delay_us(10000);
00035 }
00036
00037
00038 static void wait_dash(void) {
00039 int i;
00040 for(i = 0; i < 3; i++)
00041 wait_dot();
00042 }
00043
00044 static void wait_morse_letter(void) {
00045 int i;
00046 for(i = 0; i < 3; i++)
00047 wait_dot();
00048 }
00049
00050 static void wait_morse_word(void) {
00051 int i;
00052 for(i = 0; i < 7; i++)
00053 wait_dot();
00054 }
00055
00056 static void morse_dash(gpio led, int on, int off) {
00057 gpio_write(led, on);
00058 wait_dash();
00059 gpio_write(led, off);
00060 wait_dot();
00061 }
00062
00063 static void morse_dot(gpio led, int on, int off) {
00064 gpio_write(led, on);
00065 wait_dot();
00066 gpio_write(led, off);
00067 wait_dot();
00068 }
00069
00070 static void morse_number(unsigned int disp, gpio led, int on, int off) {
00071 switch(disp) {
00072 case 0:
00073 morse_dash(led, on, off);
00074 morse_dash(led, on, off);
00075 morse_dash(led, on, off);
00076 morse_dash(led, on, off);
00077 morse_dash(led, on, off);
00078 break;
00079 case 1:
00080 morse_dot(led, on, off);
00081 morse_dash(led, on, off);
00082 morse_dash(led, on, off);
00083 morse_dash(led, on, off);
00084 morse_dash(led, on, off);
00085 break;
00086 case 2:
00087 morse_dot(led, on, off);
00088 morse_dot(led, on, off);
00089 morse_dash(led, on, off);
00090 morse_dash(led, on, off);
00091 morse_dash(led, on, off);
00092 break;
00093 case 3:
00094 morse_dot(led, on, off);
00095 morse_dot(led, on, off);
00096 morse_dot(led, on, off);
00097 morse_dash(led, on, off);
00098 morse_dash(led, on, off);
00099 break;
00100 case 4:
00101 morse_dot(led, on, off);
00102 morse_dot(led, on, off);
00103 morse_dot(led, on, off);
00104 morse_dot(led, on, off);
00105 morse_dash(led, on, off);
00106 break;
00107 case 5:
00108 morse_dot(led, on, off);
00109 morse_dot(led, on, off);
00110 morse_dot(led, on, off);
00111 morse_dot(led, on, off);
00112 morse_dot(led, on, off);
00113 break;
00114 case 6:
00115 morse_dash(led, on, off);
00116 morse_dot(led, on, off);
00117 morse_dot(led, on, off);
00118 morse_dot(led, on, off);
00119 morse_dot(led, on, off);
00120 break;
00121 case 7:
00122 morse_dash(led, on, off);
00123 morse_dash(led, on, off);
00124 morse_dot(led, on, off);
00125 morse_dot(led, on, off);
00126 morse_dot(led, on, off);
00127 break;
00128 case 8:
00129 morse_dash(led, on, off);
00130 morse_dash(led, on, off);
00131 morse_dash(led, on, off);
00132 morse_dot(led, on, off);
00133 morse_dot(led, on, off);
00134 break;
00135 case 9:
00136 morse_dash(led, on, off);
00137 morse_dash(led, on, off);
00138 morse_dash(led, on, off);
00139 morse_dash(led, on, off);
00140 morse_dot(led, on, off);
00141 break;
00142 case 0xa:
00143 morse_dot(led, on, off);
00144 morse_dash(led, on, off);
00145 break;
00146 case 0xb:
00147 morse_dash(led, on, off);
00148 morse_dot(led, on, off);
00149 morse_dot(led, on, off);
00150 morse_dot(led, on, off);
00151 break;
00152 case 0xc:
00153 morse_dash(led, on, off);
00154 morse_dot(led, on, off);
00155 morse_dash(led, on, off);
00156 morse_dot(led, on, off);
00157 break;
00158 case 0xd:
00159 morse_dash(led, on, off);
00160 morse_dot(led, on, off);
00161 morse_dot(led, on, off);
00162 break;
00163 case 0xe:
00164 morse_dot(led, on, off);
00165 break;
00166 case 0xf:
00167 morse_dot(led, on, off);
00168 morse_dot(led, on, off);
00169 morse_dash(led, on, off);
00170 morse_dot(led, on, off);
00171 break;
00172 }
00173 }
00174
00175 void output_error(unsigned int value, gpio led, int on, int off) {
00176 int shift;
00177 bool hasSent = false;
00178 for (shift = 12; shift >= 0; shift -= 4)
00179 {
00180 unsigned disp = ((value & (0xF << shift)) >> shift);
00181
00182 if ((disp != 0) || (hasSent) || (shift == 0))
00183 {
00184 hasSent = true;
00185 morse_number(disp, led, on, off);
00186 wait_morse_letter();
00187 }
00188 }
00189 wait_morse_word();
00190 }
00191