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