#include "buttons.h"
-void button_init(void) {
+void button_init(t_button *button) {
/*
* select as input the following pins
- * - p0.30 : interrupt, wtf is the 'vw 3 p9'?
+ * - p0.30 : interrupt! wtf is the 'vw 3 p9'?
* - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : column select
*
* select as output
PINSEL1&=~((1<<23)|(1<<22)); // p0.27
PINSEL1&=~((1<<13)|(1<<12)); // p0.22
PINSEL0&=~((1<<27)|(1<<26)); // p0.13
+
// ctrl databus for p2.18 - p2.24
PINSEL2&=(PINSEL2&(~((1<<5)|(1<<4))))|(1<<4);
+
// ctrl addr bus for p3.20, p3.21
PINSEL2=(PINSEL2&(~((1<<27)|(1<<26)|(1<<25))))|(1<<27)|(1<<26);
+
// input
IODIR0&=~((1<<30)|(1<<28)|(1<<27)|(1<<22)|(1<<13));
IODIR3&=~((1<<21)|(1<<20));
+
// output + pull them high
IODIR2|=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
+
+ /* poll / interrupt mode */
+ if(button->mode&BUTTON_INT) {
+ }
+ else if(button->mode&BUTTON_POLL) {
+ }
}
+void button_set_retries(t_button *button,int retries) {
+
+ button->retries=retries;
+}
+
+#define BUTTON_RESET \
+ IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24))
+
void button_select_row(u8 row) {
- IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
+ BUTTON_RESET;
if(row>6)
return;
IOCLR2=(1<<(18+row));
}
-u8 button_get_event(u64 *keys,int retries) {
+#define COUNT_AND_CHECK cnt++; \
+ if(cnt==BUTTON_MAX) \
+ break
+
+u8 button_get_event(t_button *button) {
u8 row;
u8 offset;
u8 cnt;
u32 port0,port3;
+ u8 retries;
- *keys=0;
cnt=0;
+ retries=button->retries;
while(retries--) {
- /* rest counter */
+ /* rest offset counter */
offset=0;
/* rows */
for(row=0;row<7;row++) {
button_select_row(row);
/* scan the columns 6 */
port0=IOPIN0;
- port3=IOPIN2;
+ port3=IOPIN3;
if(!(port0&(1<<28))) {
- *keys|=(1<<(offset+0));
- cnt+=1;
+ button->key[cnt]=offset+0;
+ COUNT_AND_CHECK;
}
if(!(port0&(1<<27))) {
- *keys|=(1<<(offset+1));
- cnt+=1;
+ button->key[cnt]=offset+1;
+ COUNT_AND_CHECK;
}
if(!(port0&(1<<22))) {
- *keys|=(1<<(offset+2));
- cnt+=1;
+ button->key[cnt]=offset+2;
+ COUNT_AND_CHECK;
}
if(!(port0&(1<<13))) {
- *keys|=(1<<(offset+3));
- cnt+=1;
+ button->key[cnt]=offset+3;
+ COUNT_AND_CHECK;
}
if(!(port3&(1<<21))) {
- *keys|=(1<<(offset+4));
- cnt+=1;
+ button->key[cnt]=offset+4;
+ COUNT_AND_CHECK;
}
if(!(port3&(1<<20))) {
- *keys|=(1<<(offset+5));
- cnt+=1;
+ button->key[cnt]=offset+5;
+ COUNT_AND_CHECK;
}
offset+=6;
}
- if(*keys)
+ if(cnt)
break;
}
+ BUTTON_RESET;
+ button->cnt=cnt;
+
return cnt;
}
/* includes */
#include "betty.h"
+/* defines */
+#define BUTTON_MAX 8
+#define BUTTON_INT (1<<0)
+#define BUTTON_POLL (1<<1)
+
+/* typedefs */
+typedef struct s_button {
+ unsigned char mode; // mode of the button api
+ int retries; // amount of retries per event capture
+ unsigned char cnt; // amount of recognized key presses
+ unsigned char key[BUTTON_MAX]; // pressed keys
+} t_button;
+
/* function prototypes */
-void button_init(void);
-unsigned char button_get_event(unsigned long long int *keys,int retries);
+void button_init(t_button *button);
+void button_set_retries(t_button *button,int retries);
+unsigned char button_get_event(t_button *button);
+
+/* button definitions */
+#define BUTTON_A 0x04
+#define BUTTON_B 0x03
+#define BUTTON_C 0x02
+#define BUTTON_D 0x08
+#define BUTTON_BETTY 0x0a
+#define BUTTON_EXIT 0x14
+#define BUTTON_UP 0x09
+#define BUTTON_DOWN 0x1b
+#define BUTTON_RIGHT 0x0e
+#define BUTTON_LEFT 0x0f
+#define BUTTON_OK 0x15
+#define BUTTON_VOL_UP 0x10
+#define BUTTON_VOL_DOWN 0x16
+#define BUTTON_PRG_UP 0x1a
+#define BUTTON_PRG_DOWN 0x20
+#define BUTTON_MUTE 0x21
+#define BUTTON_1 0x05
+#define BUTTON_2 0x27
+#define BUTTON_3 0x26
+#define BUTTON_4 0x0b
+#define BUTTON_5 0x00
+#define BUTTON_6 0x01
+#define BUTTON_7 0x11
+#define BUTTON_8 0x06
+#define BUTTON_9 0x07
+#define BUTTON_SHIFT 0x17
+#define BUTTON_0 0x0c
+#define BUTTON_AV 0x0d
+#define BUTTON_MENU 0x1c
+#define BUTTON_PIP 0x1d
+#define BUTTON_A_B 0x12
+#define BUTTON_16_9 0x13
+#define BUTTON_INFO 0x22
+#define BUTTON_TV1 0x23
+#define BUTTON_TV2 0x18
+#define BUTTON_TV3 0x19
+#define BUTTON_RED 0x28
+#define BUTTON_GREEN 0x29
+#define BUTTON_YELLOW 0x1e
+#define BUTTON_BLUE 0x1f
+#define BUTTON_TV 0x24
+#define BUTTON_POWER 0x25
#endif