Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rc0 ready for testing

  • Loading branch information...
commit acc8c714c10b37edb3ec7cdf2a743b20b5ad9c0d 1 parent 15f53fc
@tuxcodejohn tuxcodejohn authored
View
12 firmware_buzzIface/README
@@ -12,18 +12,12 @@ BuzIface: Interface Platine (USB client)
Befehle vom BuzIface zum Server
-
-opcode: "W"
-args : keymask (ein byte, bits 1-4 bedeuten die keys A-D)
-funktion: wait_keys_blocking(keymask) hier timeout adden ???
-antwort : <KEYID> | "X" (timeout)
-
-
opcode "L"
args : <LEDID> <BRIGHT>
funktion: set_led_state
-opcode "R"
-funktion: reset BuzIface
+
+
+
View
238 firmware_buzzIface/buzzIface.c
@@ -29,27 +29,107 @@
/* functions: */
-uint8_t wait_keys_blocking(uint8_t keymask /* TODO timeout?,*/ );
+//uint8_t wait_keys_blocking(uint8_t keymask /* TODO timeout?,*/ );
+
uint8_t send_uart_key(uint8_t key);
+static void PCI_init(void );
+static void phasentimer_init(void);
+static uint8_t do_command (uint8_t * commline);
+
+/* GLOBALZ */
+volatile uint8_t key_buf;
-/* GLOBALZ */
-volatile uint8_t keys_armed;
-volatile uint8_t key_input;
-volatile uint8_t bufreg_b;
-volatile uint8_t bufreg_d;
+
+
+#define MASKI_B (0x03)
+#define MASKI_D (0xd0)
+#define SENDPLACESIZE (8)
+#undef KEYS_HAVE_EXTERN_PULLUP
+
+volatile uint8_t phasemask_b;
+volatile uint8_t phasemask_d;
+volatile uint8_t sendline[SENDPLACESIZE] ;
+volatile uint8_t sendplace ;
+
struct channel cz[5];
+//TODO:
+//reduce PCIRQ indem die semantik von phasemask und PCMSK getauscht wird.
-inline void hardware_init(void)
+ISR(PCINT0_vect)
+{
+ uint8_t act ;
+ act = PINB & (MASKI_B & phasemask_b);
+ if (act){
+ switch (act){
+ case (1 << 0): //Chan A key is B0 --> PCINT0
+ case (1 << 1): //Chan B key is B1 --> PCINT1
+ phasemask_b &= ~(act);
+ sendline[sendplace] = act;
+ break;
+ default :
+ sendline[sendplace] = 0xff;
+
+ }
+ sendplace = (sendplace +1) % SENDPLACESIZE;
+ }
+}
+
+ISR(PCINT2_vect) {
+ uint8_t act,c ;
+ act = PIND & MASKI_D & phasemask_d;
+ if (act){
+ switch (act){
+ case (1 << 6): //Chan C key is D6 --> PCINT22
+ c=CHAN_C;
+ phasemask_d &= ~(act);
+ PCMSK2 &= ~(act);
+ break;
+ case (1 << 7): //Chan D key is D7 --> PCINT23
+ c=CHAN_D;
+ phasemask_d &= ~(act);
+ PCMSK2 &= ~(act);
+ break;
+ case (1<<4): //Chan E key is D4 --> PCINT20
+ c=CHAN_E;
+ phasemask_d &= ~(act);
+ PCMSK2 &= ~(act);
+ break;
+ default :
+ c= 0xff;
+ }
+ sendline[sendplace] = c;
+ sendplace = (sendplace +1) % SENDPLACESIZE;
+ }
+}
+
+ISR(TIMER0_COMPA_vect) {
+
+ uint8_t j;
+
+ //bis die letzte phase ausgeschaltet worden:
+ j = MASKI_B & ( PCMSK0 ^ MASKI_B) ;
+ PCMSK0 = MASKI_B;
+ //in der phasenmaske nur die setzen die zu j nicht gehören
+ phasemask_b |= MASKI_B & (~ j) ;
+
+ //same for PCIE2
+ j = MASKI_D * (PCMSK2 ^ MASKI_D) ;
+ PCMSK2 = MASKI_D ;
+ phasemask_d |= MASKI_D & ( ~ j) ;
+
+}
+
+
+
+static inline void hardware_init(void)
{
uint8_t i ;
- keys_armed = 0;
- key_input = 0;
cz[0].led1port = &PORTC ;
cz[0].led1pin = PIN0;
cz[0].led2port = &PORTC;
@@ -85,16 +165,6 @@ inline void hardware_init(void)
cz[4].keyport = &PIND;
cz[4].keypin = PIN4;
-
-/*{ PORTC, PORTC, PORTC, PORTD, PORTD };*/
-/*{ PIN0, PIN2, PIN4, PIN5, PIN2 };*/
-/*{ PORTC, PORTC, PORTC, PORTB, PORTD };*/
-/*{ PIN1, PIN3, PIN5, PIN2, PIN3 };*/
-/*{ PINB, PINB, PIND, PIND, PIND };*/
-/*{ PIN0, PIN1, PIN6, PIN7, PIN4 };*/
-
-
-
for(i=0; i< CHAN_NUM ; i++){
/*leds get outputs */
@@ -112,33 +182,50 @@ inline void hardware_init(void)
#endif
}
+ sendplace = 0 ;
USART_Init();
+ PCI_init();
+ phasentimer_init();
+}
+
+
+
+static inline void phasentimer_init()
+{
+//20MHz / 1024 = 19 KHz
+//prescaler
+//(1.0/19) * 18 = 0.9473684 -> phasenwechsel alle ~ millisekunde
+ TCCR0A = 0 | (1 << WGM01); // CTC Modus
+ TCCR0B = 0 | (1<< CS02) | (1<< CS00); //Prescale 1024
+ OCR0A = 0x09 ; //9 ist 18/2 s.o.
+ TIMSK0 = 0 | (1<<OCIE0A); //IRQ CTM erlauben
+ return;
+}
+
+static inline void PCI_init()
+{
+ PCIFR = 0; //sanity
+ PCMSK0 = MASKI_B;
+ PCMSK2 = MASKI_D;
+ PCICR = (1<<PCIE0) | (1<<PCIE2); //dont have keys at port c ...
+ return;
}
+
uint8_t set_led_state(ledid_t led_id, uint8_t brightness)
{
- uint8_t ch;
- switch (led_id){
- case (LED1_BASE + CHAN_A) :
- case (LED1_BASE + CHAN_B) :
- case (LED1_BASE + CHAN_C) :
- case (LED1_BASE + CHAN_D) :
- case (LED1_BASE + CHAN_E) :
- ch = led_id - LED1_BASE;
+ uint8_t ch=led_id.channel;
+ switch (led_id.led){
+ case (0) :
if (brightness) {
*(cz[ch].led1port) |= cz[ch].led1pin ;
} else {
*(cz[ch].led2port) &= ~(cz[ch].led1pin) ;
}
break ;
- case (LED2_BASE + CHAN_A) :
- case (LED2_BASE + CHAN_B) :
- case (LED2_BASE + CHAN_C) :
- case (LED2_BASE + CHAN_D) :
- case (LED2_BASE + CHAN_E) :
- ch = led_id - LED2_BASE;
+ case (1) :
if (brightness) {
*(cz[ch].led2port) |= cz[ch].led2pin ;
} else {
@@ -179,55 +266,90 @@ uint8_t send_uart_key(uint8_t key){
return 0;
}
+static inline uint8_t do_setled_command(uint8_t * commline){
+ ledid_t lid;
+ switch (commline[0]){
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ lid.channel = commline[0] - 'A';
+
+ default:
+ return ERROR_COMCHAN ;
+ }
+ switch (commline[1]){
+ case '1':
+ case '2':
+ lid.led = commline[1] - '1';
+ default:
+ return ERROR_COMLED ;
+ }
+ return set_led_state (lid, commline[2]) ;
+}
-inline void arm_buttons(uint8_t buttonbits){
- keys_armed = 1 ;
- key_input = 0;
- return ;
+
+
+static uint8_t do_command (uint8_t * commline){
+ switch (commline[0]){
+ case 'L':
+ return do_setled_command(commline+1);
+ default:
+ return ERROR_COMAND ;
+ }
+ return 0; //useless
}
int main(void)
{
+ uint8_t commandbuf[8];
+ uint8_t commidx=0 , i=0 ,k;
hardware_init();
sei();
//------------------------------------
- uint8_t c ,i ;
- char buf[16];
-
-
- USART_puts("Test");
- USART_puts("\n\r");
+// USART_puts("Test");
+// USART_puts("\n\r");
for(;;){ //ever
-
- i = uart_getc_nb(&c);
- if (i) {
- USART_putc(c);
- switch (c){
- case 'r' :
- PORTC = 0 | (1<<DDC3);
- break;
- case 'g' :
- PORTC = 0 | (1<<DDC2);
- break;
- default :
- PORTC = 0 | (1<<DDC3)|(1<<DDC2);
+ /* PART 1 :check if host tells us to do something:*/
+ i = uart_getc_nb(&commandbuf[commidx]);
+ if(i){
+ if (commandbuf[commidx] == '\n'){
+ //befehlszeile zu ende :-)
+ commandbuf[commidx] = 0 ;
+ do_command(commandbuf);
+ commidx = 0;
+ commandbuf[0] = 0 ;
+ }else{
+ commidx ++ ;
+ if(commidx >= 8 ){
+ commidx = 0;
+ commandbuf[0] = 0 ;
+ }
}
}
+ /*PART 2 : send stuff to send, if any... */
+ i = 0;
+ cli(); //prevent sendplace from bein altered //TODO: better only disable all PC IRQS
+ while (i < sendplace ) {
+ send_uart_key(sendline[sendplace]);
+ i++;
+ }
+ sendplace = 0;
+ sei();
}
/* never gets here*/
return 0;
}
-
-uint8_t wait_keys_blocking(uint8_t keymask /* TODO timeout?,*/ );
View
68 firmware_buzzIface/buzzIface.h
@@ -0,0 +1,68 @@
+/*
+ * ============================================================================
+ *
+ * Filename: buzzIface.h
+ *
+ * ============================================================================
+ */
+
+
+typedef uint8_t u8;
+
+//---BUZZER CHANNELS
+#define CHAN_A 0
+#define CHAN_B 1
+#define CHAN_C 2
+#define CHAN_D 3
+#define CHAN_E 4
+#define CHAN_NUM 5
+
+//---BUZZER-HARDWARE CANNEL CONFIGURATION
+//
+struct channel {
+typeof(&PORTC) led1port ;
+typeof(PIN0) led1pin ;
+typeof(&PORTC) led2port ;
+typeof(PIN0) led2pin ;
+typeof(&PINB) keyport;
+typeof(PIN7) keypin;
+} ;
+
+
+
+#define port2ddr(prt) ( (uint8_t *)( (int)&DDRB + (int)prt - (int)&(PORTB) ))
+#define pin2port(pin) ((u8 *)((int)&PORTB + (int)pin - (int)&PINB ))
+#define pin2ddr(pin) ( (u8*)((int)&DDRB + (int)pin - (int)&PINB ))
+
+
+typedef struct {
+ uint8_t channel;
+ uint8_t led;
+} ledid_t ;
+
+
+
+//----------------
+#define LED_OFF 0
+#define LED_ON 255
+
+//LED IDs: LED Base + CHAN num
+#define LED1_BASE 16
+#define LED2_BASE 32
+
+
+
+/* ERROR DEFINITIONS: */
+#define ERROR_GENERALI 1 //general error
+#define ERROR_IKEY 2 //invalid keycode
+#define ERROR_TIMEOUT 3 //timeout
+#define ERROR_INIT 4 //init failed
+#define ERROR_LED 5 //invalid LED
+#define ERROR_COMAND 6 // invalid command
+#define ERROR_COMCHAN 7 // invalid command channel argument
+#define ERROR_COMLED 8 // invalid commane led argument
+
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.