00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "../include/beeos.h"
00023 #include "../include/bctype.h"
00024 #include "../include/bbit.h"
00025 #include "../include/bstring.h"
00026 #include "../include/bmalloc.h"
00027 #include "../include/exec.h"
00028 #include "../include/sci.h"
00029 #include "../include/ect.h"
00030 #include <stdarg.h>
00031 #include "../include/bprintf.h"
00032 #ifndef HOSTED_BUILD
00033 #include "../include/asm/vectors.h"
00034 #include "../include/asm/ports.h"
00035 #else
00036 #include <stdio.h>
00037 #endif
00038
00039
00040
00041
00042
00043
00044 bool toggle_scan_lk;
00045 uchar gbl_scani;
00046 uchar map_leds[8];
00047 uchar map_btns[8];
00048
00049
00050
00051
00052 void lbdrv_chg (void);
00053 void misc (void);
00054 void btnscan_chk (void);
00055
00056
00057
00058
00059
00060 int _start(void) __attribute__ ((noreturn));
00061
00062
00063 #ifdef HOSTED_BUILD
00064 int main (void)
00065 #else
00066 int _start (void)
00067 #endif
00068
00069
00070 {
00071 #ifndef HOSTED_BUILD
00072 ASM_SEI;
00073 RTICTL = 0x00;
00074 COPCTL = 0x00;
00075 _sp = (void *)0x3FFF;
00076 RDRIV = 0xFF;
00077 DDRA = 0x00; PORTA = 0x00;
00078 DDRB = 0x00; PORTB = 0x00;
00079 DDRE = 0x00; PORTE = 0x00;
00080 DDRK = 0x00; PORTK = 0x00;
00081 RDRT = 0xFF; PERT = 0xFF; PPST = 0xFF; DDRT = 0x00; PTT = 0x00;
00082 RDRS = 0xFF; PERS = 0x00; PPSS = 0xFF; WOMS = 0xFF; DDRS = 0x00; PTS = 0x00;
00083 RDRM = 0xFF; PERM = 0xFF; PPSM = 0xFF; WOMM = 0xFF; DDRM = 0x00; PTM = 0x00;
00084 PIEP = 0X00; RDRP = 0xFF; PERP = 0xFF; PPSP = 0xFF; DDRP = 0xFF; PTP = 0x01;
00085 PIEH = 0X00; RDRH = 0xFF; PERH = 0xFF; PPSH = 0xFF; DDRH = 0xFF; PTH = 0x00;
00086 PIEJ = 0X00; RDRJ = 0xFF; PERJ = 0xFF; PPSJ = 0xFF; DDRJ = 0x00; PTJ = 0x00;
00087 sci0_init(960);
00088 #endif
00089 lk_bputs = false;
00090 lk_putchar = false;
00091 bmallocinit();
00092 execprep();
00093 addtask(lbdrv_chg, (char) 1, (ushort) TOUSHORT(TCNT_H), 500);
00094 addtask(btnscan_chk, (char) 2, (ushort) TOUSHORT(TCNT_H) + MSEC2TCNT(10), 500);
00095 addtask(misc, (char) 3, (ushort) TOUSHORT(TCNT_H) + MSEC2TCNT(20), 500);
00096
00097 ect_init();
00098 ASM_CLI;
00099 ASM_SWI;
00100 while(1 == 1);
00101
00102 #ifdef HOSTED_BUILD
00103 return 0;
00104 #else
00105
00106 #endif
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 void lbdrv_chg (void)
00120 {
00121 while (1 == 1) {
00122 while (true != toggle_scan_lk);
00126 __asm__ __volatile__ ("inc %0" : "=m" (gbl_scani));
00127 if (7 < gbl_scani) gbl_scani = 0;
00128 PTP = 0x1 << gbl_scani;
00129 PTH = 0xFF & ~map_leds[gbl_scani];
00130 toggle_scan_lk = false;
00131
00132 PORTA ^= BIT5;
00133 bsleep(3);
00134 }
00135
00136 return;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void btnscan_chk (void)
00153 {
00154 uchar row_bit, ptt_bit, i;
00155 uchar ptt, scani, *row;
00156 uchar btni;
00157
00158 bmemset((char *)map_btns, '\0', sizeof(uchar) * 8);
00159 while (1 == 1) {
00160 while (true == toggle_scan_lk);
00161 ASM_MOVW_MM(PTT, ptt);
00162 ASM_MOVW_MM(gbl_scani, scani);
00163 toggle_scan_lk = true;
00164 row = &(map_btns[scani]);
00165
00166 if (*row != ptt) {
00167
00168 for (i = 0; i < 8; i++) {
00169 row_bit = bitncheck(row, i);
00170 ptt_bit = bitncheck((uchar *)&(ptt), i);
00171 if (row_bit != ptt_bit) {
00172 btni = 8*scani + i;
00173 if (row_bit < ptt_bit)
00174 bprintf(0, "Key pressed: %02x.\r\n", (sshort) btni);
00175 else bprintf(0, "Key released: %02x.\r\n", (sshort) btni);
00176 }
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186 *row = ptt;
00187
00188 }
00189 PORTA ^= BIT6;
00190
00191 bsleep(50);
00192 }
00193
00194 return;
00195 }
00196
00197 void misc (void)
00198 {
00199 while (1 == 1) {
00200
00201
00202
00203
00204
00205
00206 PORTA ^= BIT7;
00207
00208 bsleep(500);
00209 }
00210
00211 return;
00212 }